utils.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdarg.h>
  4. #include <time.h>
  5. #include "bsp.h"
  6. #include "utils.h"
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #define SencondsPerMinute 60
  9. #define SencondsPerHour 3600
  10. #define SencondsPerDay 86400
  11. #define NormalDayInYear 365
  12. #define YearCentry 2000
  13. #define YearUtcStart 1970
  14. #define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
  15. #define LEAP_YEAR(year) ((!((year) % 4) && ((year) % 100)) || !((year) % 400))
  16. static const unsigned char rtc_days_in_month[] = {
  17. 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  18. };
  19. static const unsigned short rtc_ydays[2][13] = {
  20. /* Normal years */
  21. { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
  22. /* Leap years */
  23. { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
  24. };
  25. //CRC High bytes table
  26. const unsigned char auchCRCHi[]={
  27. 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  28. 0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  29. 0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,
  30. 0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
  31. 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,
  32. 0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,
  33. 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,
  34. 0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  35. 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  36. 0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,
  37. 0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,
  38. 0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
  39. 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  40. 0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,
  41. 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,
  42. 0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,
  43. 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  44. 0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  45. 0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,
  46. 0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  47. 0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,
  48. 0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,
  49. 0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,
  50. 0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,
  51. 0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,
  52. 0x80,0x41,0x00,0xC1,0x81,0x40
  53. };
  54. //CRC Low bytes table
  55. const unsigned char auchCRCLo[]={
  56. 0x00,0xC0,0xC1,0x01,0xC3,0x03,0x02,0xC2,0xC6,0x06,
  57. 0x07,0xC7,0x05,0xC5,0xC4,0x04,0xCC,0x0C,0x0D,0xCD,
  58. 0x0F,0xCF,0xCE,0x0E,0x0A,0xCA,0xCB,0x0B,0xC9,0x09,
  59. 0x08,0xC8,0xD8,0x18,0x19,0xD9,0x1B,0xDB,0xDA,0x1A,
  60. 0x1E,0xDE,0xDF,0x1F,0xDD,0x1D,0x1C,0xDC,0x14,0xD4,
  61. 0xD5,0x15,0xD7,0x17,0x16,0xD6,0xD2,0x12,0x13,0xD3,
  62. 0x11,0xD1,0xD0,0x10,0xF0,0x30,0x31,0xF1,0x33,0xF3,
  63. 0xF2,0x32,0x36,0xF6,0xF7,0x37,0xF5,0x35,0x34,0xF4,
  64. 0x3C,0xFC,0xFD,0x3D,0xFF,0x3F,0x3E,0xFE,0xFA,0x3A,
  65. 0x3B,0xFB,0x39,0xF9,0xF8,0x38,0x28,0xE8,0xE9,0x29,
  66. 0xEB,0x2B,0x2A,0xEA,0xEE,0x2E,0x2F,0xEF,0x2D,0xED,
  67. 0xEC,0x2C,0xE4,0x24,0x25,0xE5,0x27,0xE7,0xE6,0x26,
  68. 0x22,0xE2,0xE3,0x23,0xE1,0x21,0x20,0xE0,0xA0,0x60,
  69. 0x61,0xA1,0x63,0xA3,0xA2,0x62,0x66,0xA6,0xA7,0x67,
  70. 0xA5,0x65,0x64,0xA4,0x6C,0xAC,0xAD,0x6D,0xAF,0x6F,
  71. 0x6E,0xAE,0xAA,0x6A,0x6B,0xAB,0x69,0xA9,0xA8,0x68,
  72. 0x78,0xB8,0xB9,0x79,0xBB,0x7B,0x7A,0xBA,0xBE,0x7E,
  73. 0x7F,0xBF,0x7D,0xBD,0xBC,0x7C,0xB4,0x74,0x75,0xB5,
  74. 0x77,0xB7,0xB6,0x76,0x72,0xB2,0xB3,0x73,0xB1,0x71,
  75. 0x70,0xB0,0x50,0x90,0x91,0x51,0x93,0x53,0x52,0x92,
  76. 0x96,0x56,0x57,0x97,0x55,0x95,0x94,0x54,0x9C,0x5C,
  77. 0x5D,0x9D,0x5F,0x9F,0x9E,0x5E,0x5A,0x9A,0x9B,0x5B,
  78. 0x99,0x59,0x58,0x98,0x88,0x48,0x49,0x89,0x4B,0x8B,
  79. 0x8A,0x4A,0x4E,0x8E,0x8F,0x4F,0x8D,0x4D,0x4C,0x8C,
  80. 0x44,0x84,0x85,0x45,0x87,0x47,0x46,0x86,0x82,0x42,
  81. 0x43,0x83,0x41,0x81,0x80,0x40
  82. };
  83. ///////////////////////////////////////////////////////////////////////////////
  84. /*
  85. int tm_sec:0~59;
  86. int tm_min:0~59;
  87. int tm_hour:0~59;
  88. int tm_mday:1~31;
  89. int tm_mon:0~11;
  90. int tm_year:0~255;
  91. int tm_wday:0~6;
  92. int tm_yday:0~365;
  93. */
  94. stRtcTime rtcTime = {0};
  95. /*The seconds from 2000-01-01 00:00:00*/
  96. volatile stTimeSetValue g_stTimeValue = {0};
  97. //static unsigned char fac_us=0;//us
  98. //static unsigned short fac_ms=0;//ms
  99. #define KEYSCAN_PEROID 53
  100. #define TCPFLUSH_PEROID 1000
  101. #define RECORD_PEROID 500
  102. #define SECOND_PEROID 1000
  103. #define HALF_MINUTE_PEROID 30000
  104. volatile stTickTimer keyScanTimer =
  105. {
  106. .limit = KEYSCAN_PEROID,
  107. .enabled = 1,
  108. };
  109. volatile stTickTimer rakTimer =
  110. {
  111. .limit = 100,
  112. .enabled = 1,
  113. };
  114. volatile stTickTimer senderTimer={
  115. //.limit = 50,
  116. .limit = 30,
  117. .enabled = 1,
  118. };
  119. volatile stTickTimer tcpFlushTimer={
  120. .limit = TCPFLUSH_PEROID,
  121. .enabled = 1,
  122. };
  123. volatile stTickTimer recordTimer =
  124. {
  125. .limit = RECORD_PEROID,
  126. .enabled = 1,
  127. };
  128. volatile stTickTimer secondTimer =
  129. {
  130. .limit = SECOND_PEROID,
  131. .enabled = 1,
  132. };
  133. volatile stTickTimer halfMntTimer =
  134. {
  135. .limit = HALF_MINUTE_PEROID,
  136. .enabled = 1,
  137. };
  138. ///////////////////////////////////////////////////////////////////////////////
  139. void RefreshTimer(void)
  140. {
  141. if(keyScanTimer.enabled)
  142. {
  143. if(keyScanTimer.count++>keyScanTimer.limit)
  144. {
  145. keyScanTimer.flag=1;
  146. }
  147. }
  148. if(rakTimer.enabled)
  149. {
  150. if(++rakTimer.count >= rakTimer.limit)
  151. {
  152. rakTimer.flag=1;
  153. }
  154. }
  155. if(senderTimer.enabled)
  156. {
  157. if(++senderTimer.count >= senderTimer.limit)
  158. {
  159. senderTimer.flag=1;
  160. }
  161. }
  162. if(recordTimer.enabled)
  163. {
  164. if(++recordTimer.count >= recordTimer.limit)
  165. {
  166. recordTimer.flag = 1;
  167. }
  168. }
  169. if (secondTimer.enabled)
  170. {
  171. if(++secondTimer.count >= secondTimer.limit)
  172. {
  173. secondTimer.flag = 1;
  174. }
  175. }
  176. if (halfMntTimer.enabled)
  177. {
  178. if(++halfMntTimer.count >= halfMntTimer.limit)
  179. {
  180. halfMntTimer.flag = 1;
  181. }
  182. }
  183. }
  184. void StartTimer(pTickTimer timer, uint32_t period)
  185. {
  186. timer->enabled=1;
  187. timer->limit = period;
  188. }
  189. void StopTimer(pTickTimer timer)
  190. {
  191. timer->enabled=0;
  192. ClearTimer(timer);
  193. }
  194. void ClearTimer(pTickTimer timer )
  195. {
  196. timer->count=0;
  197. timer->flag=0;
  198. }
  199. ///////////////////////////////////////////////////////////////////////////////
  200. #ifdef __GNUC__
  201. #pragma GCC optimize ("O0")
  202. #elif defined(__ICCARM__)
  203. #pragma optimize=none
  204. #endif
  205. void Delay_s( unsigned int time_s )
  206. {
  207. for(;time_s>0;time_s--)
  208. {
  209. Delay_ms(1000);
  210. }
  211. }
  212. #ifdef __GNUC__
  213. #pragma GCC optimize ("O0")
  214. #elif defined(__ICCARM__)
  215. #pragma optimize=none
  216. #endif
  217. void Delay_ms( unsigned int time_ms )
  218. {
  219. unsigned int temp=0;
  220. unsigned int start = HAL_GetTick();
  221. do
  222. {
  223. temp = HAL_GetTick();
  224. }
  225. while(time_ms > temp - start);//wait here
  226. }
  227. #ifdef __GNUC__
  228. #pragma GCC optimize ("O0")
  229. #elif defined(__ICCARM__)
  230. #pragma optimize=none
  231. #endif
  232. void Delay_us( unsigned int time_us )
  233. {
  234. unsigned int temp=0;
  235. do
  236. {
  237. temp = 160;
  238. while(temp-->0)
  239. {
  240. ;
  241. }
  242. //temp++;
  243. }
  244. while(time_us-->0);
  245. }
  246. /*
  247. #define _clock(x) clock(x)
  248. unsigned int __weak sleep(unsigned int seconds)
  249. {
  250. clock_t t0 = _clock();
  251. clock_t dt = seconds * CLOCKS_PER_SEC;
  252. while (_clock() - t0 < dt);
  253. return 0;
  254. }
  255. int __weak usleep(useconds_t useconds)
  256. {
  257. clock_t t0 = _clock();
  258. clock_t dt = useconds / (1000000/CLOCKS_PER_SEC);
  259. clock_t tc = _clock();
  260. while (tc - t0 < dt)
  261. {
  262. tc =_clock();
  263. }
  264. return 0;
  265. }*/
  266. ///////////////////////////////////////////////////////////////////////////////
  267. unsigned short ATOI(char* str,unsigned char base)
  268. {
  269. unsigned int num = 0;
  270. while (*str !=0)
  271. {
  272. num = num * base + C2D(*str++);
  273. }
  274. return num;
  275. }
  276. unsigned int ATOI32(char* str,unsigned char base)
  277. {
  278. unsigned int num = 0;
  279. while (*str !=0)
  280. {
  281. num = num * base + C2D(*str++);
  282. }
  283. return num;
  284. }
  285. void itoa(unsigned int n, char* str, unsigned char len)
  286. {
  287. unsigned char i=len-1;
  288. memset(str,0x20,len);
  289. do{
  290. str[i--]=n%10+'0';
  291. }while((n/=10)>0);
  292. return;
  293. }
  294. int ValidATOI(char* str, int base,int* ret)
  295. {
  296. int c;
  297. char* tstr = str;
  298. if(str == 0 || *str == '\0') return 0;
  299. while(*tstr != '\0')
  300. {
  301. c = C2D(*tstr);
  302. if( c >= 0 && c < base) tstr++;
  303. else return 0;
  304. }
  305. *ret = ATOI(str,base);
  306. return 1;
  307. }
  308. void replacetochar(char * str, char oldchar,char newchar )
  309. {
  310. int x;
  311. for (x = 0; str[x]; x++)
  312. if (str[x] == oldchar) str[x] = newchar;
  313. }
  314. char C2D(unsigned char c )
  315. {
  316. if (c >= '0' && c <= '9')
  317. return c - '0';
  318. if (c >= 'a' && c <= 'f')
  319. return 10 + c -'a';
  320. if (c >= 'A' && c <= 'F')
  321. return 10 + c -'A';
  322. return (char)c;
  323. }
  324. uint16_t swaps(uint16_t i)
  325. {
  326. uint16_t ret=0;
  327. ret = (i & 0xFF) << 8;
  328. ret |= ((i >> 8)& 0xFF);
  329. return ret;
  330. }
  331. unsigned int swapl(unsigned int l)
  332. {
  333. unsigned int ret=0;
  334. ret = (l & 0xFF) << 24;
  335. ret |= ((l >> 8) & 0xFF) << 16;
  336. ret |= ((l >> 16) & 0xFF) << 8;
  337. ret |= ((l >> 24) & 0xFF);
  338. return ret;
  339. }
  340. //get mid str
  341. void mid(char* src, char* s1, char* s2, char* sub)
  342. {
  343. char* sub1;
  344. char* sub2;
  345. unsigned short n;
  346. sub1=strstr(src,s1);
  347. sub1+=strlen(s1);
  348. sub2=strstr(sub1,s2);
  349. n=sub2-sub1;
  350. strncpy(sub,sub1,n);
  351. sub[n]=0;
  352. }
  353. void inet_addr_(unsigned char* addr,unsigned char *ip)
  354. {
  355. int i;
  356. char taddr[30];
  357. char * nexttok;
  358. char num;
  359. strcpy(taddr,(char *)addr);
  360. nexttok = taddr;
  361. for(i = 0; i < 4 ; i++)
  362. {
  363. nexttok = strtok(nexttok,".");
  364. if(nexttok[0] == '0' && nexttok[1] == 'x') num = ATOI(nexttok+2,0x10);
  365. else num = ATOI(nexttok,10);
  366. ip[i] = num;
  367. nexttok = NULL;
  368. }
  369. }
  370. ///////////////////////////////////////////////////////////////////////////////
  371. /*
  372. * The number of days in the month.
  373. */
  374. int rtc_month_days(unsigned int month, unsigned int year)
  375. {
  376. return rtc_days_in_month[month] + (LEAP_YEAR(year) && month == 1);
  377. }
  378. /*
  379. * The number of days since January 1. (0 to 365)
  380. */
  381. int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
  382. {
  383. return rtc_ydays[LEAP_YEAR(year)][month] + day-1;
  384. }
  385. /*
  386. * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
  387. */
  388. void rtc_time_to_tm(unsigned long time, stRtcTime *tm)
  389. {
  390. int days, month, year;
  391. days = time / SencondsPerDay;
  392. time -= days * SencondsPerDay;
  393. /* day of the week, 1970-01-01 was a Thursday */
  394. tm->tm_wday = (days + 4) % 7;
  395. year = YearUtcStart + days / NormalDayInYear;
  396. days -= (year - YearUtcStart) * NormalDayInYear
  397. + LEAPS_THRU_END_OF(year - 1)
  398. - LEAPS_THRU_END_OF(YearUtcStart - 1);
  399. if (days < 0) {
  400. year -= 1;
  401. days += NormalDayInYear + LEAP_YEAR(year);
  402. }
  403. tm->tm_year = year - 1900;
  404. tm->tm_yday = days + 1;
  405. for (month = 0; month < 11; month++) {
  406. int newdays;
  407. newdays = days - rtc_month_days(month, year);
  408. if (newdays < 0)
  409. break;
  410. days = newdays;
  411. }
  412. tm->tm_mon = month;
  413. tm->tm_mday = days + 1;
  414. tm->tm_hour = time / SencondsPerHour;
  415. time -= tm->tm_hour * SencondsPerHour;
  416. tm->tm_min = time / SencondsPerMinute;
  417. tm->tm_sec = time - tm->tm_min * SencondsPerMinute;
  418. }
  419. void utc_tm_to_time(const stRtcTime *tm, unsigned long * time)
  420. {
  421. unsigned long days;
  422. int temp;
  423. temp = LEAPS_THRU_END_OF(tm->tm_year - 1);
  424. temp -= LEAPS_THRU_END_OF(YearUtcStart - 1);
  425. days = (tm->tm_year - YearUtcStart) * NormalDayInYear;
  426. days += temp;
  427. temp = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
  428. days += temp;
  429. *time = days * SencondsPerDay;
  430. *time += tm->tm_hour *SencondsPerHour+tm->tm_min *SencondsPerMinute+tm->tm_sec;
  431. }
  432. void rtcBySecondFromCentry(uint32_t time, stRtcTime *tm)
  433. {
  434. int days, month, year;
  435. days = time / SencondsPerDay;
  436. time -= days * SencondsPerDay;
  437. /* day of the week, 2000-01-01 was a Satarday */
  438. tm->tm_wday = (days + 6) % 7;
  439. year = YearCentry + days / NormalDayInYear;
  440. days -= (year - YearCentry) * NormalDayInYear
  441. + LEAPS_THRU_END_OF(year - 1)
  442. - LEAPS_THRU_END_OF(YearCentry - 1);
  443. if (days < 0) {
  444. year -= 1;
  445. days += NormalDayInYear + LEAP_YEAR(year);
  446. }
  447. tm->tm_year = year - YearCentry;
  448. tm->tm_yday = days + 1;
  449. for (month = 0; month < 11; month++) {
  450. int newdays;
  451. newdays = days - rtc_month_days(month, year);
  452. if (newdays < 0)
  453. break;
  454. days = newdays;
  455. }
  456. tm->tm_mon = month + 1;
  457. tm->tm_mday = days + 1;
  458. tm->tm_hour = time / SencondsPerHour;
  459. time -= tm->tm_hour * SencondsPerHour;
  460. tm->tm_min = time / SencondsPerMinute;
  461. tm->tm_sec = time - tm->tm_min * SencondsPerMinute;
  462. }
  463. void secondsFromCentry(const stRtcTime *tm, unsigned int * time)
  464. {
  465. unsigned long days;
  466. int temp;
  467. unsigned int years = tm->tm_year + YearCentry;
  468. //days = (tm->tm_year - YearCentry) * NormalDayInYear;
  469. days = (tm->tm_year) * NormalDayInYear;
  470. temp = LEAPS_THRU_END_OF(years - 1);
  471. temp -= LEAPS_THRU_END_OF(YearCentry - 1);
  472. days += temp;
  473. temp = rtc_year_days(tm->tm_mday, tm->tm_mon-1, years);
  474. days += temp;
  475. *time = days * SencondsPerDay;
  476. *time += tm->tm_hour * SencondsPerHour + tm->tm_min * SencondsPerMinute + tm->tm_sec;
  477. }
  478. uint8_t BCC_CheckSum(uint8_t *buf, uint8_t len)
  479. {
  480. uint8_t i;
  481. uint8_t checksum = 0;
  482. for(i = 0; i < len; i++) {
  483. checksum ^= *buf++;
  484. }
  485. return checksum;
  486. }
  487. /*
  488. * CRC_modbus: little-endian; in modbus protocol, the crc value is big-endian.
  489. * If changed to big-endian, exchange the uchCRCHi/uchCRCLo locations in the while(){};
  490. */
  491. static unsigned char uchCRCHi = 0xff;
  492. static unsigned char uchCRCLo = 0xff;
  493. static unsigned char crc16_flag = 0;
  494. unsigned int CalculateCRC16(unsigned char *updata, unsigned int len)
  495. {
  496. unsigned int uindex;
  497. crc16_flag = 1;
  498. uchCRCHi = 0xff;
  499. uchCRCLo = 0xff;
  500. while(len--)
  501. {
  502. uindex = uchCRCHi ^ *updata++;
  503. uchCRCHi = uchCRCLo ^ auchCRCHi[uindex];
  504. uchCRCLo = auchCRCLo[uindex];
  505. }
  506. crc16_flag = 0;
  507. return (uchCRCHi<<8 | uchCRCLo);
  508. }
  509. /*
  510. * CRC16 data calculate
  511. * return: -1, fails; 0, ongoing; >0: finish;
  512. *
  513. *
  514. */
  515. int CRC16_Start()
  516. {
  517. if(crc16_flag)return -1;
  518. crc16_flag = 1 ;
  519. uchCRCHi = 0xff;
  520. uchCRCLo = 0xff;
  521. return 0;
  522. }
  523. int CRC16_AddData(unsigned char *updata, unsigned int len)
  524. {
  525. if(!crc16_flag)return -1;
  526. unsigned int uindex;
  527. while(len--)
  528. {
  529. uindex = uchCRCHi ^ *updata++;
  530. uchCRCHi = uchCRCLo ^ auchCRCHi[uindex];
  531. uchCRCLo = auchCRCLo[uindex];
  532. }
  533. return 0;
  534. }
  535. int CRC16_Finish()
  536. {
  537. if(!crc16_flag) return -1;
  538. crc16_flag = 0;
  539. return (uchCRCHi<<8 | uchCRCLo);
  540. }
  541. ///////////////////////////////////////////////////////////////////////////////
  542. #ifdef USE_FULL_ASSERT
  543. void assert_failed(uint8_t* file, uint32_t line)
  544. {
  545. while (1)
  546. {
  547. ;
  548. }
  549. }
  550. #endif
  551. /*************************************************************************************************/