GLOBAL.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*******************************************************************************
  2. *
  3. * SW AS
  4. * Soft version:
  5. * File Name: GLOBAL.c
  6. * Author : zzw (zhangzw_3@163.com)
  7. * creation date: 2022-07-20
  8. * module description:定义系统中的全局变量
  9. * Copyright (C)
  10. *
  11. ********************************************************************************/
  12. #include "GLOBAL.h"
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. ///////////////////////////////////////////
  17. volatile DBit _BitParament0;
  18. volatile word tickcount; /* Timer tick count */
  19. volatile byte sysTickfor10ms; /* 10millisecond timer */
  20. volatile byte sysTickfor100ms;/* 100millisecond timer */
  21. volatile byte sysTickfor1000ms;/* 100millisecond timer */
  22. SWParameters switchState;//面板状态
  23. unsigned char gRelayOnOff=0;//继电器状态
  24. byte gLedState = 0;//按键灯状态
  25. byte gRelayState = 0; // 4bit 继电器值
  26. byte ZG_Joining;//模块进入配网模式, 指示灯快速闪烁10秒
  27. WORD ZG_JoinCounter;//模块进入配网计数器,倒计时开始
  28. byte ZG_Joining_S;//模块进入配网模式
  29. byte Brightflag; //强光标志位,1:白天,0,夜晚
  30. byte BrightPWMH=6; //强光灯强光PWM占空比
  31. byte NightPWMH=1; //暗光PWM占空比
  32. byte Light_Intensity;//光强度
  33. //byte mKeyLedWeakLight;//背光最大亮度值,根据光感设置
  34. byte mBLedWeakLight;//背光最大亮度值,根据光感设置
  35. unsigned int gRadarKeepTimer=0;//有人存在时,LED灯等相关动作保持时间
  36. byte gRadarCheckNull;//雷达监测,1为无人,0为有人
  37. byte shockCounter;//震动计数器
  38. byte shockStart;//按键按下震动触发
  39. byte appControlLedEnable = 0; // app控制背光灯点亮使能位,0:忽略,1:强制点亮10秒
  40. byte burn_in_test_start=0;//产测标志位
  41. u32 burn_in_test_counter=0;//产测计数器
  42. u32 burn_in_test_timeout=0;//产测开机30秒内收到信标才有效
  43. u32 IAPUpdateFlag = 0;
  44. u32 OTA_Reciv_Datalen;
  45. static const char g_sas8Base64digits[] =
  46. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  47. //编码
  48. void Base64Encode(char *ps8Dest, const char *ps8Source, int s32InLen)
  49. {
  50. if (ps8Dest==NULL || ps8Source==NULL || s32InLen<=0)
  51. {
  52. return;
  53. }
  54. for (; s32InLen >= 3; s32InLen -= 3)
  55. {
  56. *ps8Dest++ = g_sas8Base64digits[ps8Source[0] >> 2];
  57. *ps8Dest++ = g_sas8Base64digits[((ps8Source[0] << 4) & 0x30) | (ps8Source[1] >> 4)];
  58. *ps8Dest++ = g_sas8Base64digits[((ps8Source[1] << 2) & 0x3c) | (ps8Source[2] >> 6)];
  59. *ps8Dest++ = g_sas8Base64digits[ps8Source[2] & 0x3f];
  60. ps8Source += 3;
  61. }
  62. if (s32InLen > 0)
  63. {
  64. unsigned char fragment;
  65. *ps8Dest++ = g_sas8Base64digits[ps8Source[0] >> 2];
  66. fragment = (ps8Source[0] << 4) & 0x30;
  67. if (s32InLen > 1)
  68. fragment |= ps8Source[1] >> 4;
  69. *ps8Dest++ = g_sas8Base64digits[fragment];
  70. *ps8Dest++ = (s32InLen < 2) ? '=' : g_sas8Base64digits[(ps8Source[1] << 2) & 0x3c];
  71. *ps8Dest++ = '=';
  72. }
  73. *ps8Dest = '\0';
  74. }
  75. //解码
  76. void Base64Decode(char *ps8Dest, const char *ps8Source, int s32InLen)
  77. {
  78. int s32Num = 64;
  79. int i,j;
  80. char as8ValuePre[4];
  81. char s8Temp;
  82. int s32Flag = 0;
  83. if (ps8Dest==NULL || ps8Source==NULL || s32InLen<=0)
  84. {
  85. return;
  86. }
  87. for (i=0; i<s32InLen; i++)
  88. {
  89. s32Flag = 0;
  90. for (j=0; j<64; j++)
  91. {
  92. if (ps8Source[i] == g_sas8Base64digits[j])
  93. {
  94. as8ValuePre[i%4] = j;
  95. s32Flag = 1;
  96. break;
  97. }
  98. }
  99. if (s32Flag == 0)
  100. {
  101. break;
  102. }
  103. if (i%4 == 3)
  104. {
  105. s8Temp = (as8ValuePre[1]>>4)&0x3;
  106. *ps8Dest++ = (as8ValuePre[0]<<2) | s8Temp ;
  107. s8Temp = (as8ValuePre[2]>>2)&0xF;
  108. *ps8Dest++ = (as8ValuePre[1]<<4) | s8Temp ;
  109. s8Temp = (as8ValuePre[3])&0x3F;
  110. *ps8Dest++ = (as8ValuePre[2]<<6) | s8Temp ;
  111. }
  112. }
  113. i--;
  114. if (i%4==1)
  115. {
  116. s8Temp = (as8ValuePre[1]>>4)&0x3;
  117. *ps8Dest++ = (as8ValuePre[0]<<2) | s8Temp ;
  118. }
  119. else if (i%4==2)
  120. {
  121. s8Temp = (as8ValuePre[1]>>4)&0x3;
  122. *ps8Dest++ = (as8ValuePre[0]<<2) | s8Temp ;
  123. s8Temp = (as8ValuePre[2]>>2)&0xF;
  124. *ps8Dest++ = (as8ValuePre[1]<<4) | s8Temp ;
  125. }
  126. *ps8Dest = '\0';
  127. }
  128. /* EOF */