GLOBAL.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 long data_dp_add_ele[3] = 0;
  24. unsigned long data_dp_cur_current[3] = 0;
  25. unsigned long data_dp_cur_power[3] = 0;
  26. unsigned long data_dp_cur_voltage = 0;
  27. unsigned long Flash_dp_add_ele[3]={0};
  28. unsigned long Flash_dp_add_ele_backups[3] = {0};
  29. unsigned char Save_data_ele_flag = 0;
  30. unsigned long Save_data_nun = 0;
  31. unsigned char gRelayOnOff=0;//继电器状态
  32. byte gLedState = 0;//按键灯状态
  33. byte gRelayState = 0; // 4bit 继电器值
  34. byte ZG_Joining;//模块进入配网模式, 指示灯快速闪烁10秒
  35. WORD ZG_JoinCounter;//模块进入配网计数器,倒计时开始
  36. byte ZG_Joining_S;//模块进入配网模式
  37. byte Brightflag; //强光标志位,1:白天,0,夜晚
  38. byte BrightPWMH=6; //强光灯强光PWM占空比
  39. byte NightPWMH=1; //暗光PWM占空比
  40. byte Light_Intensity;//光强度
  41. //byte mKeyLedWeakLight;//背光最大亮度值,根据光感设置
  42. byte mBLedWeakLight;//背光最大亮度值,根据光感设置
  43. unsigned int gRadarKeepTimer=0;//有人存在时,LED灯等相关动作保持时间
  44. byte gRadarCheckNull;//雷达监测,1为无人,0为有人
  45. byte shockCounter;//震动计数器
  46. byte shockStart;//按键按下震动触发
  47. byte appControlLedEnable = 0; // app控制背光灯点亮使能位,0:忽略,1:强制点亮10秒
  48. byte burn_in_test_start=0;//产测标志位
  49. u32 burn_in_test_counter=0;//产测计数器
  50. u32 burn_in_test_timeout=0;//产测开机30秒内收到信标才有效
  51. u32 IAPUpdateFlag = 0;
  52. u32 OTA_Reciv_Datalen;
  53. static const char g_sas8Base64digits[] =
  54. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  55. //编码
  56. void Base64Encode(char *ps8Dest, const char *ps8Source, int s32InLen)
  57. {
  58. if (ps8Dest==NULL || ps8Source==NULL || s32InLen<=0)
  59. {
  60. return;
  61. }
  62. for (; s32InLen >= 3; s32InLen -= 3)
  63. {
  64. *ps8Dest++ = g_sas8Base64digits[ps8Source[0] >> 2];
  65. *ps8Dest++ = g_sas8Base64digits[((ps8Source[0] << 4) & 0x30) | (ps8Source[1] >> 4)];
  66. *ps8Dest++ = g_sas8Base64digits[((ps8Source[1] << 2) & 0x3c) | (ps8Source[2] >> 6)];
  67. *ps8Dest++ = g_sas8Base64digits[ps8Source[2] & 0x3f];
  68. ps8Source += 3;
  69. }
  70. if (s32InLen > 0)
  71. {
  72. unsigned char fragment;
  73. *ps8Dest++ = g_sas8Base64digits[ps8Source[0] >> 2];
  74. fragment = (ps8Source[0] << 4) & 0x30;
  75. if (s32InLen > 1)
  76. fragment |= ps8Source[1] >> 4;
  77. *ps8Dest++ = g_sas8Base64digits[fragment];
  78. *ps8Dest++ = (s32InLen < 2) ? '=' : g_sas8Base64digits[(ps8Source[1] << 2) & 0x3c];
  79. *ps8Dest++ = '=';
  80. }
  81. *ps8Dest = '\0';
  82. }
  83. //解码
  84. void Base64Decode(char *ps8Dest, const char *ps8Source, int s32InLen)
  85. {
  86. int s32Num = 64;
  87. int i,j;
  88. char as8ValuePre[4];
  89. char s8Temp;
  90. int s32Flag = 0;
  91. if (ps8Dest==NULL || ps8Source==NULL || s32InLen<=0)
  92. {
  93. return;
  94. }
  95. for (i=0; i<s32InLen; i++)
  96. {
  97. s32Flag = 0;
  98. for (j=0; j<64; j++)
  99. {
  100. if (ps8Source[i] == g_sas8Base64digits[j])
  101. {
  102. as8ValuePre[i%4] = j;
  103. s32Flag = 1;
  104. break;
  105. }
  106. }
  107. if (s32Flag == 0)
  108. {
  109. break;
  110. }
  111. if (i%4 == 3)
  112. {
  113. s8Temp = (as8ValuePre[1]>>4)&0x3;
  114. *ps8Dest++ = (as8ValuePre[0]<<2) | s8Temp ;
  115. s8Temp = (as8ValuePre[2]>>2)&0xF;
  116. *ps8Dest++ = (as8ValuePre[1]<<4) | s8Temp ;
  117. s8Temp = (as8ValuePre[3])&0x3F;
  118. *ps8Dest++ = (as8ValuePre[2]<<6) | s8Temp ;
  119. }
  120. }
  121. i--;
  122. if (i%4==1)
  123. {
  124. s8Temp = (as8ValuePre[1]>>4)&0x3;
  125. *ps8Dest++ = (as8ValuePre[0]<<2) | s8Temp ;
  126. }
  127. else if (i%4==2)
  128. {
  129. s8Temp = (as8ValuePre[1]>>4)&0x3;
  130. *ps8Dest++ = (as8ValuePre[0]<<2) | s8Temp ;
  131. s8Temp = (as8ValuePre[2]>>2)&0xF;
  132. *ps8Dest++ = (as8ValuePre[1]<<4) | s8Temp ;
  133. }
  134. *ps8Dest = '\0';
  135. }
  136. //float FF_AC_V; // 电压有效值
  137. /* EOF */