/standarts/decoders/c/decoder_modulation.c

http://project-static.googlecode.com/ · C · 1085 lines · 205 code · 17 blank · 863 comment · 39 complexity · 4e105fa297b28aac98a12ee9f1ea12d8 MD5 · raw file

  1. /*
  2. Author: KRM
  3. Compiler: ANY
  4. Date creation: 14.09.2010
  5. Date updated: 03.11.2010 12:08:58
  6. Description:
  7. Name:
  8. Name file:
  9. Name project: Static
  10. Processor: ANY
  11. Software: Eclipse v 3.7 Indigo
  12. Type:
  13. Version: 1.00
  14. */
  15. #define DECODER_MODULATION_GLOBALS
  16. //#include "inc_amcos.h"
  17. //#include "LPC11xx.h"
  18. //#include <htc.h>
  19. #include "..\..\..\common\c\definitions.h"
  20. #include "decoder_modulation.h"
  21. /*
  22. ??? ???????? ???????????? ??????? ? ????.
  23. ???????? ???????? - ??????? ?????? ??????
  24. unsigned long long decode_am3(unsigned short iPeriod, unsigned char iMode)
  25. {
  26. static unsigned char i,iCurrentBit,iBitPosition,iCurrenByte;
  27. static union
  28. {
  29. unsigned long long i64bits;
  30. unsigned char aByte[8];
  31. } uCodeFromPeriods;
  32. if ((iMode==12)&&(!i))
  33. {
  34. i=2;
  35. uCodeFromPeriods.aByte[7]=0x40; // ????? ? ????? ?????? ??????? ???? ???? ???????????????? ??????? ??? iCurentBit
  36. iCurrentBit=1;
  37. }
  38. if (i)
  39. {
  40. if ((iPeriod>T_PERIOD_L2_MIN)&&(iPeriod<T_PERIOD_L2_MAX))
  41. {
  42. if (iCurrentBit)
  43. {
  44. iCurrentBit=0;
  45. i++;
  46. }
  47. else iCurrentBit=1;
  48. }
  49. else
  50. {
  51. if ((iPeriod>T_PERIOD_L3_MIN)&&(iPeriod<T_PERIOD_L3_MAX))
  52. {
  53. iCurrentBit=1;
  54. i++;
  55. }
  56. else
  57. {
  58. if (iPeriod>T_PERIOD_L1_MAX) // ??? ??? ?? ? ???? ?? ?????????? ?? ??????, ????????? ?????????
  59. {// ????????? ????????? ? ?????? ???? ?????? ?????????????? ?????? ????? ??????
  60. i=0; // ???? ?? ?????? ?? ? ???? ???????? - ??????? ?? ???????
  61. return 0;
  62. }// ???? ?????? ? ????????? ???????? ?????? ?????? ?? ????
  63. }
  64. }
  65. if (iPeriod>T_PERIOD_L1_MIN)
  66. {
  67. iBitPosition=7-(i%8);
  68. iCurrenByte=7-((unsigned char)(i/8));
  69. uCodeFromPeriods.aByte[iCurrenByte]|=iCurrentBit<<iBitPosition;
  70. if (i>62)
  71. {
  72. i=0;
  73. return uCodeFromPeriods.i64bits;
  74. }
  75. i++;
  76. return STATE_RESULT2;
  77. }
  78. else return 1;// ???? ?????? ??????? ???????? ?????? ????? ?????? ?????????? 1 ????? ????? ????????? ? ????? ??????? ?????????
  79. }
  80. else
  81. {
  82. // ??? ??? ?? ????? ??????? ??????? ????? ???????? ? ??????????? ?????????????????? 0b10 . ????? ????????? ? 2-??? ????
  83. if (iMode==RESULT_FOUND_LONG_PULSE)
  84. {
  85. i=3;
  86. if ((iPeriod>T_LOW_L1_MIN)&&(iPeriod<T_LOW_L1_MAX))
  87. {
  88. uCodeFromPeriods.i64bits=0x8000000000000000UL; // ????? ? ????? ?????? ??????? ???? ???? ???????????????? ??????? ??? Curent
  89. iCurrentBit=0;
  90. }
  91. else
  92. {
  93. if ((iPeriod>T_LOW_L2_MIN)&&(iPeriod<T_LOW_L2_MAX))
  94. {
  95. uCodeFromPeriods.i64bits=0xA000000000000000UL; // ??? ????
  96. iCurrentBit=1;
  97. }
  98. else
  99. {
  100. i=0;
  101. return 0;
  102. }
  103. }
  104. }
  105. }
  106. return 2;
  107. }
  108. */
  109. /* TODO
  110. ??? ???????? ???????????? ??????? ? ????. ??? ????? ?? ???????????? ? ????? ?? ???????
  111. ???????? ???????? - ??????? ???????? ???????
  112. ,unsigned char iMode
  113. unsigned long long decode_am_periods(unsigned short iPeriod)
  114. {
  115. static unsigned char i,iCurrentBit,iBitPosition,iCurrenByte;
  116. static union
  117. {
  118. unsigned long long i64bits;
  119. unsigned char aByte[8];
  120. } uCodeFromPeriods;
  121. if ((iPeriod>T_PERIOD_L2_MIN)&&(iPeriod<T_PERIOD_L2_MAX))
  122. {
  123. if (iCurrentBit)
  124. {
  125. iCurrentBit=0;
  126. i++;
  127. }
  128. else
  129. {
  130. iCurrentBit=1;
  131. }
  132. }
  133. else
  134. {
  135. if ((iPeriod>T_PERIOD_L3_MIN)&&(iPeriod<T_PERIOD_L3_MAX))
  136. {
  137. iCurrentBit=1;
  138. i++;
  139. }
  140. else
  141. {
  142. if (((iPeriod>300)&&(iPeriod<T_PERIOD_L1_MIN))||(iPeriod>T_PERIOD_L1_MAX)) // ??? ??? ?? ? ???? ?? ?????????? ?? ??????, ????????? ?????????
  143. {// ????????? ????????? ? ?????? ???? ?????? ?????????????? ?????? ????? ??????
  144. iCurrentBit=i=0; // ???? ?? ?????? ?? ? ???? ???????? - ??????? ?? ???????
  145. uCodeFromPeriods.i64bits=0;
  146. return 0; // TODO ? ???? ?????? ????????? ??????? iCurrentBit=0; ????????? ??? ??? ????????
  147. } // ???? ?????? ? ????????? ???????? ?????? ?????? ?? ????
  148. }
  149. }
  150. if (iPeriod>300)// ???? ?????? ?????????????? ?????? ????? ?????? ?????? ?????????? ??? ???? ????
  151. {
  152. iBitPosition=7-(i%8);
  153. iCurrenByte=7-((unsigned char)(i/8));
  154. uCodeFromPeriods.aByte[iCurrenByte]|=iCurrentBit<<iBitPosition;
  155. if (i>62)
  156. {
  157. iCurrentBit=i=0;
  158. return uCodeFromPeriods.i64bits;
  159. }
  160. i++;
  161. }
  162. return (unsigned long long) i;
  163. }
  164. */
  165. /*
  166. ??? ???????? ???????????? ??????? ? ????.
  167. ???????? ???????? - ??????? ??????
  168. unsigned long long decode_am2bits(unsigned short iPeriod, unsigned char iMode, unsigned char bitStateSignal)
  169. {
  170. static unsigned char i,iCurrentBit,iBitPosition,iCurrenByte,fTnext_enable;
  171. static unsigned short iPeriodSave, iPeriodAfterTnext;
  172. static union
  173. {
  174. unsigned long long i64bits;
  175. unsigned char aByte[8];
  176. } uCodeFromPeriods;
  177. //if ((iPeriod>10000)&&(iPeriod<11000)&& (!bitStateSignal)) return STATE_RESULT3;// ???????????? ??????? ????? ???????? ????
  178. if(i==0) uCodeFromPeriods.i64bits=0;
  179. if (fTnext_enable==0)
  180. {
  181. iPeriod+=iPeriodSave;
  182. if (iPeriod>T_NEXT) fTnext_enable=1;
  183. else iPeriodSave=iPeriod;
  184. }
  185. if (fTnext_enable==1)
  186. {
  187. iPeriodAfterTnext=iPeriod-T_NEXT;
  188. if (iPeriodAfterTnext>T_S2)
  189. {
  190. fTnext_enable=0;
  191. iPeriodAfterTnext=iPeriodSave=0;
  192. i=0;
  193. uCodeFromPeriods.i64bits=0;
  194. return 0;
  195. }
  196. iCurrentBit=bitStateSignal;
  197. iBitPosition=7- (i%8);
  198. iCurrenByte =7-((unsigned char) (i/8));
  199. uCodeFromPeriods.aByte[iCurrenByte]|=iCurrentBit<<iBitPosition;
  200. fTnext_enable=0;
  201. iPeriodAfterTnext=iPeriodSave=0;
  202. if (i>62)
  203. {
  204. fTnext_enable=i=0;
  205. return uCodeFromPeriods.i64bits;
  206. }
  207. i++;
  208. }
  209. return STATE_RESULT2;
  210. }
  211. */
  212. /*
  213. ?????????? ?? ???????? ???? ??????????,
  214. ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
  215. 01 = 0
  216. 10 = 1
  217. ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
  218. ? ?????????? ????? ?????????? ?? ???? ???????
  219. unsigned long * decode_fm2manchester(unsigned short iPeriod,unsigned short iTPeriodLowMin,unsigned short iTPeriodLowMax,unsigned short iTPeriodHighMin,unsigned short iTPeriodHighMax)
  220. {
  221. unsigned long *plReturn;
  222. unsigned long lReturn;
  223. unsigned char j;
  224. plReturn=&lReturn;
  225. if ((iPeriod>iTPeriodLowMin)&&(iPeriod<iTPeriodLowMax)) // ????????? ?????? ??????? ??? ???? ? ??
  226. {
  227. if (iCurrentState) iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
  228. iCurrentState=0;
  229. }
  230. else
  231. {
  232. if ((iPeriod>iTPeriodHighMin)&&(iPeriod<iTPeriodHighMax)) // ????????? ??????? ??????? ??? ???? ? ??
  233. {
  234. if (!iCurrentState) iStateChange=1;
  235. iCurrentState=1;
  236. }
  237. else
  238. {
  239. iCounterPeriodsInDecode=iCounterManchBits=0;
  240. *plReturn=0;
  241. return plReturn;
  242. }
  243. }
  244. if (iStateChange) // ???? ????????? ??????? ??????????
  245. {
  246. iStateChange=0;
  247. for (j=1;j<5;j++)
  248. {
  249. if (iCounterPeriodsInDecode>(j*(4+iCurrentState)-1))
  250. {
  251. iPosition=31-(iCounterManchBits%32);
  252. iCurrentByte=32-((unsigned char)(iCounterManchBits>>5)); //??????? ?? 32
  253. if (iCurrentState) aCodeManchester[iCurrentByte]&=~(1<<iPosition);
  254. else aCodeManchesters[iCurrentByte]|= (1<<iPosition);
  255. if (iCounterManchBits>94)
  256. {
  257. iCounterPeriodsInDecode=iCounterManchBits=0;
  258. return &aCodeManchester[0]; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
  259. }
  260. iCounterManchBits++;
  261. }
  262. }
  263. iCounterPeriodsInDecode=0;
  264. }
  265. iCounterPeriodsInDecode++;
  266. *plReturn=1;
  267. return plReturn; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
  268. }
  269. */
  270. /*
  271. ?????????? ?? ???????? ???? ??????????,
  272. ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
  273. 01 = 0
  274. 10 = 1
  275. ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
  276. ? ?????????? ????? ?????????? ?? ???? ???????
  277. PIC18F14K50 (40 ???) ??????????? ?? 33 ???)
  278. unsigned char decode8_fm2manchester(unsigned char iCodeLength,unsigned char iNumberArray, unsigned short iPeriod,unsigned short iTPeriodBoundary,unsigned short iTPeriodHighMax)
  279. {
  280. unsigned char j;
  281. static unsigned char iCounterManchBits,iCounterPeriodsInDecode,iPosition,iCurrentByte,iCurrentState, iStateChange;
  282. if (iPeriod<iTPeriodBoundary) // ????????? ?????? ??????? ??? ???? ? ??
  283. {
  284. if (iCurrentState) iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
  285. iCurrentState=0;
  286. }
  287. else
  288. {
  289. if (iPeriod<iTPeriodHighMax) // ????????? ??????? ??????? ??? ???? ? ??
  290. {
  291. if (!iCurrentState) iStateChange=1;
  292. iCurrentState=1;
  293. }
  294. else
  295. {
  296. iCounterPeriodsInDecode=iCounterManchBits=0; // ????? ??? ??????????? ????????? ??????? ?????? ?? 2 ? ???????? 2 ????????
  297. return 0;
  298. }
  299. }
  300. if (iStateChange) // ???? ????????? ??????? ??????????
  301. {
  302. iStateChange=0;
  303. if (iCounterPeriodsInDecode==1) return 0;
  304. if (iCounterPeriodsInDecode>(4+iCurrentState))
  305. {
  306. iPosition=7-(iCounterManchBits&7);
  307. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  308. if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  309. else { aCodeManchester[iNumberArray][iCurrentByte]&=~(1<<iPosition); }
  310. if (iCounterManchBits>iCodeLength)
  311. {
  312. iCounterPeriodsInDecode=iCounterManchBits=0;
  313. return 0x10; // ????? ?? ?????????? ??? ?????? ??? ??? ?? ?? ????? ????????? ??????? ??????
  314. }
  315. iCounterManchBits++;
  316. }
  317. if (iCounterPeriodsInDecode>(8+(iCurrentState<<1))) // ?? ????? ???? ?????? ???? 8 ?? 1 ??? ???????? ??? ???????? ??????
  318. {
  319. iPosition=7-(iCounterManchBits&7);
  320. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  321. if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  322. else { aCodeManchester[iNumberArray][iCurrentByte]&=~(1<<iPosition); }
  323. if (iCounterManchBits>iCodeLength)
  324. {
  325. iCounterPeriodsInDecode=iCounterManchBits=0;
  326. return 0x10;
  327. }
  328. iCounterManchBits++;
  329. }
  330. if (iCounterPeriodsInDecode>(12+((iCurrentState<<1)|iCurrentState)))// ??????? iCurrentState *3
  331. {
  332. iPosition=7-(iCounterManchBits&7);
  333. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  334. if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  335. else { aCodeManchester[iNumberArray][iCurrentByte]&=~(1<<iPosition); }
  336. if (iCounterManchBits>iCodeLength)
  337. {
  338. iCounterPeriodsInDecode=iCounterManchBits=0;
  339. return 0x10;
  340. }
  341. iCounterManchBits++;
  342. }
  343. iCounterPeriodsInDecode=0;
  344. }
  345. iCounterPeriodsInDecode++;
  346. return 1; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
  347. }
  348. */
  349. /*
  350. ?????????? ?? ???????? ???? ??????????,
  351. ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
  352. 01 = 0
  353. 10 = 1
  354. ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
  355. ? ?????????? ????? ?????????? ?? ???? ???????
  356. PIC18F14K50 (40 ???) ??????????? ?? 33 ???)
  357. */
  358. unsigned char decode8_fm2manchester2(unsigned char iCodeLength,unsigned char iNumberArray, unsigned short iPeriodCur,unsigned short iTPeriodBoundary,unsigned short iTPeriodHighMax)
  359. {
  360. unsigned char j, iStateChange=0,iPosition=0,iCurrentByte=0,iCurrentManchBit=0;// ????????? ?? ? decode8_fm2manchester
  361. static unsigned char iCurrentState,iCounterManchBits,iCounterPeriodsDecoding,iCounterHighBits,iCounterLowBits;// static ?? ? decode8_fm2manchester
  362. if (iPeriodCur<iTPeriodBoundary) // ????????? ?????? ??????? ??? ???? ? ??
  363. {
  364. if (iCurrentState)
  365. {
  366. iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
  367. }
  368. iCurrentState=0;
  369. iCounterLowBits++;
  370. }
  371. else
  372. {
  373. if (iPeriodCur<iTPeriodHighMax) // ????????? ??????? ??????? ??? ???? ? ??
  374. {
  375. if (!iCurrentState)
  376. {
  377. iStateChange=1;
  378. }
  379. iCurrentState=1;
  380. iCounterHighBits++;
  381. }
  382. else
  383. {
  384. iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0; // ????? ??? ??????????? ????????? ??????? ?????? ?? 2 ? ???????? 2 ????????
  385. return 0;
  386. }
  387. }
  388. if (iStateChange) // ???? ????????? ??????? ??????????
  389. {
  390. iStateChange=0;
  391. if (iCounterLowBits>iCounterHighBits)
  392. {
  393. iCounterPeriodsDecoding=iCounterLowBits;
  394. iCounterLowBits=0;
  395. iCurrentManchBit=0;
  396. }
  397. else
  398. {
  399. iCounterPeriodsDecoding=iCounterHighBits;
  400. iCounterHighBits=0;
  401. iCurrentManchBit=1;
  402. }
  403. if (iCounterPeriodsDecoding>(3+iCurrentState))
  404. {
  405. iPosition=7-(iCounterManchBits&7); // 7 - ??????? ?? ??????? ?? 8
  406. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  407. if (iCurrentManchBit) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  408. else { aCodeManchester[iNumberArray][iCurrentByte]&= ~(1<<iPosition); }
  409. if (iCounterManchBits>iCodeLength)
  410. {
  411. iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0;
  412. return 0x10; // ????? ?? ?????????? ??? ?????? ??? ??? ?? ?? ????? ????????? ??????? ??????
  413. }
  414. iCounterManchBits++;
  415. }
  416. if (iCounterPeriodsDecoding>(8+(iCurrentState<<1))) // ?? ????? ???? ?????? ???? 8 ?? 1 ??? ???????? ??? ???????? ??????
  417. {
  418. iPosition=7-(iCounterManchBits&7); // 7 - ??????? ?? ??????? ?? 8
  419. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  420. if (iCurrentManchBit) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  421. else { aCodeManchester[iNumberArray][iCurrentByte]&= ~(1<<iPosition); }
  422. if (iCounterManchBits>iCodeLength)
  423. {
  424. iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0;
  425. return 0x10;
  426. }
  427. iCounterManchBits++;
  428. }
  429. if (iCounterPeriodsDecoding>(13+((iCurrentState<<1)|iCurrentState)))// ??????? iCurrentState *3
  430. {
  431. iPosition=7-(iCounterManchBits&7); // 7 - ??????? ?? ??????? ?? 8
  432. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  433. if (iCurrentManchBit) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  434. else { aCodeManchester[iNumberArray][iCurrentByte]&= ~(1<<iPosition); }
  435. if (iCounterManchBits>iCodeLength)
  436. {
  437. iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0;
  438. return 0x10;
  439. }
  440. iCounterManchBits++;
  441. }
  442. if (iCounterPeriodsDecoding>(18+(iCurrentState<<2)))// ? ???? ?????????? ????? ???? 4 ???? ?????? ??? ??? ?? ????????? ????? ???????? ??????? ?????? ??????? 000
  443. {
  444. iPosition=7-(iCounterManchBits&7); // 7 - ??????? ?? ??????? ?? 8
  445. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  446. if (iCurrentManchBit) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  447. else { aCodeManchester[iNumberArray][iCurrentByte]&= ~(1<<iPosition); }
  448. if (iCounterManchBits>iCodeLength)
  449. {
  450. iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0;
  451. return 0x10;
  452. }
  453. iCounterManchBits++;
  454. }
  455. iCounterPeriodsDecoding=0;
  456. }
  457. return 1; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
  458. }
  459. /*
  460. ?????????? ?? ???????? ???? ??????????,
  461. ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
  462. 01 = 0
  463. 10 = 1
  464. ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
  465. ? ?????????? ????? ?????????? ?? ???? ???????
  466. PIC18F14K50 (40 ???) ??????????? ?? 33 ???)
  467. unsigned char decode8_fm2manchester3(unsigned char iCodeLength,unsigned char iNumberArray, unsigned int iPeriodCur,unsigned int iTPeriodBoundary,unsigned int iTPeriodHighMax)
  468. {
  469. unsigned char j, iStateChange=0,iPosition=0,iCurrentByte=0;// ????????? ?? ? decode8_fm2manchester
  470. if (iPeriodCur<iTPeriodBoundary) // ????????? ?????? ??????? ??? ???? ? ??, ?????? ?? 55 ??? ???????? ?? ????? ?????? ??????
  471. {
  472. iCounterLowBits++;
  473. if (iCurrentState)
  474. {
  475. iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
  476. }
  477. }
  478. else
  479. {
  480. if (iPeriodCur<iTPeriodHighMax) // ????????? ??????? ??????? ??? ???? ? ??
  481. {
  482. iCounterHighBits++;
  483. if (!iCurrentState)
  484. {
  485. iStateChange=1;
  486. }
  487. }
  488. else
  489. {
  490. iCounterHighBits=iCounterPeriodsDecoding=iCounterManchBits=0; // ????? ??? ??????????? ????????? ??????? ?????? ?? 2 ? ???????? 2 ????????
  491. return 0;
  492. }
  493. }
  494. if (iStateChange) // ???? ????????? ??????? ??????????
  495. {
  496. iStateChange=0;
  497. if (iCounterLowBits>iCounterHighBits)
  498. {
  499. iCounterPeriodsDecoding=iCounterLowBits;
  500. iCounterLowBits=0;
  501. iCurrentState=0;
  502. }
  503. else
  504. {
  505. iCounterPeriodsDecoding=iCounterHighBits;
  506. iCounterHighBits=0;
  507. iCurrentState=1;
  508. }
  509. if (iCounterPeriodsDecoding>(4+iCurrentState))
  510. {
  511. if (iCounterPeriodsDecoding<(7+(iCurrentState<<1)))
  512. {
  513. iPosition=7-(iCounterManchBits&7);
  514. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  515. if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  516. if (iCounterManchBits>iCodeLength)
  517. {
  518. iCounterPeriodsDecoding=iCounterManchBits=0;
  519. return 0x10; // ????? ?? ?????????? ??? ?????? ??? ??? ?? ?? ????? ????????? ??????? ??????
  520. }
  521. iCounterManchBits++;
  522. }
  523. else
  524. {
  525. if (iCounterPeriodsDecoding<(11+((iCurrentState<<1)|iCurrentState))) // ?? ????? ???? ?????? ???? 8 ?? 1 ??? ???????? ??? ???????? ??????
  526. {
  527. iPosition=7-(iCounterManchBits&7);
  528. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  529. if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  530. if (iCounterManchBits>iCodeLength)
  531. {
  532. iCounterPeriodsDecoding=iCounterManchBits=0;
  533. return 0x10;
  534. }
  535. iCounterManchBits++;
  536. }
  537. else
  538. {
  539. iPosition=7-(iCounterManchBits&7); // ? ?????? ??????? ??????? ?? ??????? ?? 8
  540. iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
  541. if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
  542. if (iCounterManchBits>iCodeLength)
  543. {
  544. iCounterPeriodsDecoding=iCounterManchBits=0;
  545. return 0x10;
  546. }
  547. iCounterManchBits++;
  548. }
  549. }
  550. }
  551. }
  552. return 1; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
  553. }
  554. */
  555. /*
  556. ?????????? ?? ???????? ???? ??????????,
  557. ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
  558. 01 = 0
  559. 10 = 1
  560. ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
  561. ? ?????????? ????? ?????????? ?? ???? ???????
  562. PIC18F14K50 (40 ???) ??????????? ?? 72 ???)
  563. unsigned char decode32_fm2manchester(unsigned short iPeriod,unsigned short iTPeriodBoundary,unsigned short iTPeriodHighMax)
  564. {
  565. unsigned char j;
  566. if (iPeriod<iTPeriodBoundary) // ????????? ?????? ??????? ??? ???? ? ??
  567. {
  568. if (iCurrentState) iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
  569. iCurrentState=0;
  570. }
  571. else
  572. {
  573. if (iPeriod<iTPeriodHighMax) // ????????? ??????? ??????? ??? ???? ? ??
  574. {
  575. if (!iCurrentState) iStateChange=1;
  576. iCurrentState=1;
  577. }
  578. else
  579. {
  580. iCounterPeriodsInDecode=iCounterManchBits=0; // ????? ??? ??????????? ????????? ??????? ?????? ?? 2 ? ???????? 2 ????????
  581. return 0;
  582. }
  583. }
  584. if (iStateChange) // ???? ????????? ??????? ??????????
  585. {
  586. iStateChange=0;
  587. if (iCounterPeriodsInDecode==1) return 0;
  588. if (iCounterPeriodsInDecode>(2+iCurrentState))
  589. {
  590. iPosition=31-(iCounterManchBits%32);
  591. iCurrentByte=2-((unsigned char)(iCounterManchBits>>5));// ??????? ?? 32
  592. if (iCurrentState) aCodeManchester[iCurrentByte]&=~(1<<iPosition);
  593. else aCodeManchester[iCurrentByte]|= (1<<iPosition);
  594. if (iCounterManchBits>94)
  595. {
  596. iCounterPeriodsInDecode=iCounterManchBits=0;
  597. return 0x10; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
  598. }
  599. iCounterManchBits++;
  600. }
  601. if (iCounterPeriodsInDecode>(7+(iCurrentState<<1))) // ?? ????? ???? ?????? ???? 8 ?? 1 ??? ???????? ??? ???????? ??????
  602. {
  603. iPosition=31-(iCounterManchBits%32);
  604. iCurrentByte=2-((unsigned char)(iCounterManchBits>>5));// ??????? ?? 32
  605. if (iCurrentState) aCodeManchester[iCurrentByte]&=~(1<<iPosition);
  606. else aCodeManchester[iCurrentByte]|= (1<<iPosition);
  607. if (iCounterManchBits>94)
  608. {
  609. iCounterPeriodsInDecode=iCounterManchBits=0;
  610. return 0x10; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
  611. }
  612. iCounterManchBits++;
  613. }
  614. if (iCounterPeriodsInDecode>(11+((iCurrentState<<1)|iCurrentState)))// ??????? iCurrentState *3
  615. {
  616. iPosition=31-(iCounterManchBits%32);
  617. iCurrentByte=2-((unsigned char)(iCounterManchBits>>5));// ??????? ?? 32
  618. if (iCurrentState) aCodeManchester[iCurrentByte]&=~(1<<iPosition);
  619. else aCodeManchester[iCurrentByte]|= (1<<iPosition);
  620. if (iCounterManchBits>94)
  621. {
  622. iCounterPeriodsInDecode=iCounterManchBits=0;
  623. return 0x10; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
  624. }
  625. iCounterManchBits++;
  626. }
  627. iCounterPeriodsInDecode=0;
  628. }
  629. iCounterPeriodsInDecode++;
  630. return 1; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
  631. }
  632. */
  633. /*
  634. ?????????? ?? ?????? ????????? ??????? ???? ??????????,
  635. ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
  636. 01 = 0
  637. 10 = 1
  638. ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
  639. ? ?????????? ????? ?????????? ?? ???? ???????
  640. unsigned long * decode_fm_flag2manchester(unsigned char iFlag)
  641. {
  642. unsigned long *plReturn;
  643. unsigned long lReturn;
  644. unsigned char j;
  645. plReturn=&lReturn;
  646. if (iFlag) // ????????? ??????? ??????? ??? ???? ? ??
  647. {
  648. if (!iCurrentState) iStateChange=1;
  649. iCurrentState=1;
  650. }
  651. else
  652. {
  653. if (iCurrentState) iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
  654. iCurrentState=0;
  655. }
  656. if (iStateChange) // ???? ????????? ??????? ??????????
  657. {
  658. iStateChange=0;
  659. for (j=1;j<5;j++)
  660. {
  661. if (iCounterPeriodsInDecode>(j*(4+iCurrentState)-1))
  662. {
  663. iPosition=31-(iCounterManchBits%32);
  664. iCurrentByte=3-((unsigned char)(iCounterManchBits/32));
  665. if (iCurrentState) aCodeManchester[0][iCurrentByte]&=~(1<<iPosition);
  666. else aCodeManchester[0][iCurrentByte]|= (1<<iPosition);
  667. if (iCounterManchBits>94)
  668. {
  669. iCounterPeriodsInDecode=iCounterManchBits=0;
  670. return (unsigned long *)&aCodeManchester[0][0]; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
  671. }
  672. iCounterManchBits++;
  673. }
  674. }
  675. iCounterPeriodsInDecode=0;
  676. }
  677. iCounterPeriodsInDecode++;
  678. *plReturn=1;
  679. return plReturn; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
  680. }
  681. */
  682. /*
  683. ??????? ??? ?????? ????????? ?? ???? ???? 0x1D
  684. ??????????? ????? ?????
  685. TODO ?????? ????? ??? ??????? ? ?????????? ????? ???????
  686. */
  687. unsigned char search_header_fm(unsigned char *psCodeFromPeriods,unsigned char iLengthBits)
  688. {
  689. unsigned char iBitLast,iScan,iC;
  690. for (iScan=0;iScan<iLengthBits;iScan++)
  691. {
  692. if (psCodeFromPeriods[11]==HID_PREAMBLE) return 1;
  693. iBitLast=((psCodeFromPeriods[11]&0x80)>>7);
  694. for (iC=11;iC>0;iC--)
  695. {
  696. psCodeFromPeriods[iC]=(psCodeFromPeriods[iC]<<1)|((psCodeFromPeriods[iC-1]>>7)&1);
  697. }
  698. psCodeFromPeriods[0]=(psCodeFromPeriods[0]<<1)|iBitLast;
  699. }
  700. return 0;
  701. }
  702. /*
  703. ????????????? ?????????? ?? ?????????????????? ?????????
  704. ??? 01 = 0
  705. 10 = 1
  706. ??????? ???????? ????????? ?? ?????? ????????? unsigned char
  707. ? ????????? ??? ?????????????? ?????? ??? ???? ? ??
  708. TODO ????? ??????? ???????????? ??? ??? ?????????? ???? ?? ????? ? ????? ????????? ???????? ? ???????????? ????????????
  709. ? ?????????? ????? ?????????? ?? ???? ???????
  710. unsigned char * decode_manchester(unsigned char *psCodeFromPeriods )
  711. {
  712. static unsigned char aCodeCard[10],iPosition,iCurentBit,iShift; // ?????????????? ?????? aCodeCard[10] ?? ?????????? ? ???????????????? ? ???????? ?????????????
  713. for (unsigned char i=1;i<12;i++) // ??????? ??????? ??????? ??? ?? ?????????
  714. {
  715. iPosition=(unsigned char) ((i-1)/2);
  716. for (unsigned char j=1;j<5;j++)
  717. {
  718. iCurentBit=(psCodeFromPeriods[i]>>(2*j-1))&1; // ?????????? ??????? ??? ??????? ? ???????? ????? 1 ????, ??? ??? ? 0 ???? ??? ???????? ??????????
  719. iShift=j-1;
  720. if(!(i%2)) iShift+=4; // ???????? ???? ?????????? ?????? ??????? ? ??????????????? ???????, ?? ??? ????????? ??????? ????????, ???????? ?? ???? ???? ?? ?????? ????????? ????????? ???????, ?? ???? ??????? ? 4-?? ????
  721. if (iCurentBit)
  722. {
  723. aCodeCard[iPosition]|=(1<<iShift);
  724. }
  725. else
  726. {
  727. aCodeCard[iPosition]&=~(1<<iShift);
  728. }
  729. }
  730. }
  731. return &aCodeCard[0];
  732. }
  733. */
  734. /*
  735. ????????????? ?????????? ?? ?????????????????? ????????? ? ?????????????????? ????? ? ??????????
  736. ??? 01 = 0
  737. 10 = 1
  738. ??????? ???????? ????????? ?? ?????? ????????? unsigned char ? ?????? ???????
  739. ?????? ???????: ?????????????
  740. ???????? ??: LPC1114 PIC18F14K50
  741. */
  742. unsigned char * decode_manchester2bits(unsigned char *pcManchesterBits, unsigned char iSize )
  743. {
  744. unsigned char i,j,iNumberEl,iBitNextVerify=0,iCurentBit=0;
  745. static unsigned char aCodeBits[14],iShift; // static ?? ??????? decode_manchester2bits
  746. for (i=0;i<iSize;i++)
  747. {
  748. iNumberEl=i>>1;
  749. for (j=1;j<5;j++)
  750. {
  751. iCurentBit =(pcManchesterBits[i]>>((j<<1)-1))&1; // ?????????? ??????? ??? ??????? ? ???????? ????? 1 ????, ??? ??? ? 0 ???? ??? ???????? ??????????
  752. //iBitNextVerify =(pcManchesterBits[i]>>(j-1))&1;
  753. //if (iCurentBit==iBitNextVerify) return 0; // ????????? ??? ??? ???????? ???? ?? ??????????? ????? ??? ?? ?????????
  754. iShift=j-1;
  755. if (i&1) { iShift+=4; }// ???????? ???? ?????????? ?????? ??????? ? ??????????????? ???????, ?? ??? ????????? ??????? ????????, ???????? ?? ???? ???? ?? ?????? ????????? ????????? ???????, ?? ???? ??????? ? 4-?? ????
  756. if (iCurentBit)
  757. {
  758. aCodeBits[iNumberEl]|=(1<<iShift); // TODO ??????? ????????? static ??? ???? ?????????
  759. }
  760. else
  761. {
  762. aCodeBits[iNumberEl]&=~(1<<iShift);
  763. }
  764. }
  765. }
  766. return &aCodeBits[0];
  767. }
  768. /*
  769. ????????????? ?????????? ?? ?????????????????? ????????? ? ?????????????????? ????? ? ??????????
  770. ??? 01 = 0
  771. 10 = 1
  772. ??????? ???????? ????????? ?? ?????? ????????? unsigned char ? ?????? ???????
  773. ?????? ???????: ?????????????
  774. ???????? ??: LPC1114 PIC18F14K50
  775. */
  776. unsigned char decode_manchester2bits2(unsigned char *pcManchesterBits,unsigned char *pcBitsOut, unsigned char iSize )
  777. {
  778. unsigned char i,j,iNumberEl,iCurentBit=0,iBitNextVerify=0,iShift=0;
  779. for (i=0;i<iSize;i++)
  780. {
  781. iNumberEl=i>>1;
  782. for (j=1;j<5;j++)
  783. {
  784. iCurentBit=(pcManchesterBits[i]>>((j<<1)-1))&1; // ?????????? ??????? ??? ??????? ? ???????? ????? 1 ????, ??? ??? ? 0 ???? ??? ???????? ??????????
  785. //iBitNextVerify =(pcManchesterBits[i]>>(j-1))&1;
  786. //if (iCurentBit==iBitNextVerify) return 0; // ????????? ??? ??? ???????? ???? ?? ??????????? ????? ??? ?? ?????????
  787. iShift=j-1;
  788. if(i&1) { iShift+=4; }// ???????? ???? ?????????? ?????? ??????? ? ??????????????? ???????, ?? ??? ????????? ??????? ????????, ???????? ?? ???? ???? ?? ?????? ????????? ????????? ???????, ?? ???? ??????? ? 4-?? ????
  789. if (iCurentBit)
  790. {
  791. pcBitsOut[iNumberEl]|=(1<<iShift); // TODO ??????? ????????? static ??? ???? ?????????
  792. }
  793. else
  794. {
  795. pcBitsOut[iNumberEl]&=~(1<<iShift);
  796. }
  797. }
  798. }
  799. return STATE_RESULT1;
  800. }
  801. /*
  802. ????? ????????? ? ???? ?????
  803. ??????? ?? ??? ??? ???? ?? ?????? 9 ??????,
  804. ??????? ???????? ??????? ?????????????????? ? ??????? 64 ???? ( unsigned long long )
  805. ???????? ????????
  806. ???? 9 ?????? ??????? - ??????? ?????????????????? ? ?????? ??????? ???? 9 ??????
  807. ???? 9 ?????? ?? ??????? - 0
  808. unsigned long long search_header(unsigned long long llCodeBits)
  809. {
  810. for (int i=0;i<64;i++)
  811. {
  812. if ((0xFF80000000000000ULL&llCodeBits)==0xFF80000000000000ULL) return llCodeBits;
  813. llCodeBits=(llCodeBits<<1)|(llCodeBits>>63);
  814. }
  815. return 0;
  816. }
  817. */
  818. /*
  819. ??????? ??? ?????? ????????? ?? ???? ???? 0000111
  820. ??????????? ????? ?????
  821. TODO ?????? ????? ??? ??????? ? ?????????? ????? ???????
  822. unsigned char search_header_fm(unsigned char *psCodeFromPeriods)
  823. {
  824. static unsigned char iBitLast;
  825. for (int iScan=0;iScan<96;iScan++)
  826. {
  827. iBitLast=((psCodeFromPeriods[12]&0x80)>>7);
  828. for (int i=12;i>1;i--)
  829. {
  830. psCodeFromPeriods[i]=(psCodeFromPeriods[i]<<1)|((psCodeFromPeriods[i-1]>>7)&1);
  831. }
  832. psCodeFromPeriods[1]=(psCodeFromPeriods[1]<<1)|iBitLast;
  833. if ((psCodeFromPeriods[12]&HID_PREAMBLE)==HID_PREAMBLE) return 1;
  834. }
  835. return 0;
  836. }
  837. */
  838. /*
  839. ??????? ??? ?????? ?????????
  840. HID ???? ? ?? ???? 0x1D
  841. ????? ? ??????? 48 ??? ?? ????? ??????? ?? ????????? (????? ????? ??????????)
  842. ?? ????????? HID_format_example.pdf ? ????? www.proxclone.com
  843. TODO ??????????? ??????? ????? ????? ??? ??? wiegand 37( ???? ?? ????? 48-26+37)
  844. unsigned char search_symbol(unsigned long long *pllCodeIn, unsigned long lSizeArrayBits,unsigned int iSizeBitsInSearchSymbol,unsigned int iSearchSymbol )
  845. {
  846. unsigned char iBitLast,iSizeBitsInLast,iSearchSymbolShift;
  847. unsigned int i,j;
  848. unsigned int iSizeLongArray,iNLastElement;
  849. unsigned long long llMaskSymbolShift,llSymbol,*pllCode;
  850. pllCode=pllCodeIn;
  851. iSizeBitsInLast=(lSizeArrayBits%64);
  852. if (iSizeBitsInLast>=iSizeBitsInSearchSymbol) iSearchSymbolShift=iSizeBitsInLast -iSizeBitsInSearchSymbol; // TODO ????????? ???????? ??? ????????? ????????
  853. else iSearchSymbolShift=iSizeBitsInLast+64 -iSizeBitsInSearchSymbol;// ???? ???????? ???? ????? ??????? ???? ????????? ????? ? 2-? ????????? ???????
  854. llMaskSymbolShift = (unsigned long long)(0xFFFFFFFFFFFFFFFFULL<<iSearchSymbolShift);
  855. llSymbol = (unsigned long long)(iSearchSymbol <<iSearchSymbolShift);
  856. iSizeLongArray=(((unsigned int)(lSizeArrayBits>>6))+1); // ??????? ?????????? ?????????: long long ????? ?? ??? long long (64 ????) ? ?????????? 1
  857. iNLastElement=iSizeLongArray-1; // ????? ?????????? ???????? ? ???????
  858. for (i=0;i<lSizeArrayBits;i++)
  859. {
  860. iBitLast=*pllCode&1; //?????????? ?????? ??? ??? ??? ??? ??????? ?????? ???
  861. for (j=0;j<iNLastElement;j++) *(pllCode+j)=(*(pllCode+j)>>1)|(*(pllCode+j+1)<<63);
  862. *(pllCode+iNLastElement)=(*(pllCode+iNLastElement)>>1)|((unsigned long long)iBitLast<<(iSizeBitsInLast-1));
  863. if ((*(pllCode+iNLastElement)&llMaskSymbolShift)==llSymbol) return 0x11;
  864. }
  865. return 0;
  866. }
  867. */
  868. /*
  869. ??? ???????? ?????????
  870. unsigned char verify_code_wiegand26(unsigned long lCodeWiegand )
  871. {
  872. unsigned char bitEP,bitOP,bitXOR;
  873. bitEP=(lCodeWiegand>>25)&1;
  874. bitOP=(lCodeWiegand&1);
  875. bitXOR=0;
  876. for (int i=0;i<12;i++)
  877. {
  878. lCodeWiegand>>=1;
  879. bitXOR ^=(lCodeWiegand&1);
  880. }
  881. if (bitXOR==bitOP ) return 0x22;//????????? ???????
  882. bitXOR=0;
  883. for (int i=0;i<12;i++)
  884. {
  885. lCodeWiegand>>=1;
  886. bitXOR ^=(lCodeWiegand&1);
  887. }
  888. if (bitXOR!=bitEP ) return 0x21;
  889. return 0x11;
  890. }
  891. */
  892. /*
  893. ??? ???????? ?????????
  894. */
  895. unsigned char verify_code_card_HID(unsigned long llCodeBits )
  896. {
  897. if ((verify_code_wiegand26((unsigned long) llCodeBits)&0x20)==0x20) return 0x21;
  898. return 0x11;
  899. }
  900. unsigned char verify_code_wiegand26(unsigned long lCodeWiegand )
  901. {
  902. unsigned char bitEP,bitOP,bitXOR,i;
  903. bitEP=(lCodeWiegand>>25)&1;
  904. bitOP=(lCodeWiegand&1);
  905. bitXOR=0;
  906. for (i=0;i<12;i++)
  907. {
  908. lCodeWiegand>>=1;
  909. bitXOR ^=(lCodeWiegand&1);
  910. }
  911. if (bitXOR==bitOP ) { return 0x22; }//????????? ???????
  912. bitXOR=0;
  913. for (i=0;i<12;i++)
  914. {
  915. lCodeWiegand>>=1;
  916. bitXOR ^=(lCodeWiegand&1);
  917. }
  918. if (bitXOR!=bitEP ) { return 0x21; }
  919. return 0x11;
  920. }
  921. /*
  922. ????????? ???????????? ????
  923. ??????? ???????? ???????? ???????? ?? ??????? ? ???????? ???????? ?? ????????
  924. ???????? ????? ????????? ????????? ? ???????????? ??? ????? ? ?? EM4100 ???????? 5
  925. ??????? ???????? ??????? ?????????????????? ? ??????? 64 ???? ( unsigned long long )
  926. ???????? ???????? ??? ??????
  927. 0 ?????? ???
  928. 1 ?????? ???????? ??????
  929. 2 ?????? ???????? ???????
  930. TODO ????? ???????? ?????? ???????? ???? ??????? ? ?????? ????
  931. unsigned char verify_code_card(unsigned long long llCodeBits)
  932. {
  933. unsigned char aLine[15];
  934. unsigned char iXor,i,j;
  935. unsigned long long llCodeShiftBits;
  936. llCodeShiftBits=llCodeBits;
  937. aLine[0]=(unsigned char)(llCodeBits&0x1F);
  938. for (i=1;i<11; i++)
  939. {
  940. llCodeShiftBits=(llCodeShiftBits>>5);
  941. aLine[i]=(unsigned char)(llCodeShiftBits&0x1F);
  942. if (calculate_parity_line(aLine[i])) return 1; // ?????????? ??????
  943. }
  944. for (j=1;j<5;j++)
  945. {
  946. iXor=0;
  947. for (i=1;i<11; i++)
  948. {
  949. iXor=iXor^((aLine[i]>>j)&1);
  950. }
  951. if (iXor!=((aLine[0]>>j)&1)) return 2; // ?????????? ??????
  952. }
  953. return 0;
  954. }
  955. */
  956. /*
  957. ???? ????????? ?????? ???????? ?? ?????????? 1
  958. unsigned char calculate_parity_line(unsigned char iLine)
  959. {
  960. unsigned char iLineReal=0,iBitParity=0;
  961. iBitParity=iLine&1;
  962. for (int i=0;i<5; i++)
  963. {
  964. iLine=(iLine>>1);
  965. iLineReal=iLineReal^(iLine&1);
  966. }
  967. if (iLineReal==iBitParity) return 0;
  968. else return 1;
  969. }
  970. */
  971. /*
  972. unsigned char calculate_parity_line(unsigned char iLine)
  973. {
  974. unsigned char iLineReal;
  975. unsigned char aCodeCard[4];
  976. iBitParity=aLine&1;
  977. for (int i=0;i<5; i++)
  978. {
  979. iLineReal=iLineReal^((iLine>>1)&1);
  980. aLine[i]=(llCodeBits>>10);
  981. aLine[i]=(unsigned char)(llCodeBits&0x1F);
  982. }
  983. for (int i=0;i<4; i++)
  984. {
  985. aCodeCard[i]=(llCodeBits&0xF)|((llCodeBits>>1)&0xF0);
  986. llCodeBits=llCodeBits>>10;
  987. }
  988. return ;
  989. }*/
  990. /*
  991. ?????????? ???? ????? ?? ??????? ??????????????????
  992. ??????? ???????? ??? ????? ? ??????? 64 ???? ( unsigned long long )
  993. unsigned char *extract_code_card(unsigned long long llCodeBits)
  994. {
  995. static unsigned char aCodeCard[]={0,0,0,0,0,0,0,0};
  996. llCodeBits=(llCodeBits>>6);
  997. for (int i=0;i<5; i++)
  998. {
  999. aCodeCard[i]=(llCodeBits&0x0F)|((llCodeBits>>1)&0xF0);
  1000. llCodeBits=llCodeBits>>10;
  1001. }
  1002. return &aCodeCard[0];
  1003. }
  1004. */
  1005. unsigned char *extract_code_card_HID(unsigned long lCodeBits)
  1006. {
  1007. unsigned char i;
  1008. static unsigned char aCodeCard[4];
  1009. lCodeBits=(lCodeBits>>1);
  1010. for (i=0;i<3;i++)
  1011. {
  1012. aCodeCard[i]=(unsigned char) (lCodeBits&0xFF);
  1013. lCodeBits>>=8;
  1014. }
  1015. aCodeCard[3]=0;
  1016. return &aCodeCard[0];
  1017. }