/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
- /*
-
- Author: KRM
- Compiler: ANY
- Date creation: 14.09.2010
- Date updated: 03.11.2010 12:08:58
- Description:
- Name:
- Name file:
- Name project: Static
- Processor: ANY
- Software: Eclipse v 3.7 Indigo
- Type:
- Version: 1.00
-
- */
- #define DECODER_MODULATION_GLOBALS
- //#include "inc_amcos.h"
- //#include "LPC11xx.h"
- //#include <htc.h>
- #include "..\..\..\common\c\definitions.h"
- #include "decoder_modulation.h"
-
-
- /*
- ??? ???????? ???????????? ??????? ? ????.
- ???????? ???????? - ??????? ?????? ??????
-
-
-
- unsigned long long decode_am3(unsigned short iPeriod, unsigned char iMode)
- {
- static unsigned char i,iCurrentBit,iBitPosition,iCurrenByte;
- static union
- {
- unsigned long long i64bits;
- unsigned char aByte[8];
- } uCodeFromPeriods;
- if ((iMode==12)&&(!i))
- {
- i=2;
- uCodeFromPeriods.aByte[7]=0x40; // ????? ? ????? ?????? ??????? ???? ???? ???????????????? ??????? ??? iCurentBit
- iCurrentBit=1;
- }
- if (i)
- {
- if ((iPeriod>T_PERIOD_L2_MIN)&&(iPeriod<T_PERIOD_L2_MAX))
- {
- if (iCurrentBit)
- {
- iCurrentBit=0;
- i++;
- }
- else iCurrentBit=1;
- }
- else
- {
- if ((iPeriod>T_PERIOD_L3_MIN)&&(iPeriod<T_PERIOD_L3_MAX))
- {
- iCurrentBit=1;
- i++;
- }
- else
- {
- if (iPeriod>T_PERIOD_L1_MAX) // ??? ??? ?? ? ???? ?? ?????????? ?? ??????, ????????? ?????????
- {// ????????? ????????? ? ?????? ???? ?????? ?????????????? ?????? ????? ??????
- i=0; // ???? ?? ?????? ?? ? ???? ???????? - ??????? ?? ???????
- return 0;
- }// ???? ?????? ? ????????? ???????? ?????? ?????? ?? ????
- }
- }
- if (iPeriod>T_PERIOD_L1_MIN)
- {
- iBitPosition=7-(i%8);
- iCurrenByte=7-((unsigned char)(i/8));
- uCodeFromPeriods.aByte[iCurrenByte]|=iCurrentBit<<iBitPosition;
- if (i>62)
- {
- i=0;
- return uCodeFromPeriods.i64bits;
- }
- i++;
- return STATE_RESULT2;
- }
- else return 1;// ???? ?????? ??????? ???????? ?????? ????? ?????? ?????????? 1 ????? ????? ????????? ? ????? ??????? ?????????
- }
- else
- {
- // ??? ??? ?? ????? ??????? ??????? ????? ???????? ? ??????????? ?????????????????? 0b10 . ????? ????????? ? 2-??? ????
- if (iMode==RESULT_FOUND_LONG_PULSE)
- {
- i=3;
- if ((iPeriod>T_LOW_L1_MIN)&&(iPeriod<T_LOW_L1_MAX))
- {
- uCodeFromPeriods.i64bits=0x8000000000000000UL; // ????? ? ????? ?????? ??????? ???? ???? ???????????????? ??????? ??? Curent
- iCurrentBit=0;
- }
- else
- {
- if ((iPeriod>T_LOW_L2_MIN)&&(iPeriod<T_LOW_L2_MAX))
- {
- uCodeFromPeriods.i64bits=0xA000000000000000UL; // ??? ????
- iCurrentBit=1;
- }
- else
- {
- i=0;
- return 0;
- }
- }
- }
- }
- return 2;
- }
- */
-
-
- /* TODO
- ??? ???????? ???????????? ??????? ? ????. ??? ????? ?? ???????????? ? ????? ?? ???????
- ???????? ???????? - ??????? ???????? ???????
- ,unsigned char iMode
-
- unsigned long long decode_am_periods(unsigned short iPeriod)
- {
- static unsigned char i,iCurrentBit,iBitPosition,iCurrenByte;
-
- static union
- {
- unsigned long long i64bits;
- unsigned char aByte[8];
- } uCodeFromPeriods;
-
- if ((iPeriod>T_PERIOD_L2_MIN)&&(iPeriod<T_PERIOD_L2_MAX))
- {
- if (iCurrentBit)
- {
- iCurrentBit=0;
- i++;
- }
- else
- {
- iCurrentBit=1;
- }
- }
- else
- {
- if ((iPeriod>T_PERIOD_L3_MIN)&&(iPeriod<T_PERIOD_L3_MAX))
- {
- iCurrentBit=1;
- i++;
- }
- else
- {
- if (((iPeriod>300)&&(iPeriod<T_PERIOD_L1_MIN))||(iPeriod>T_PERIOD_L1_MAX)) // ??? ??? ?? ? ???? ?? ?????????? ?? ??????, ????????? ?????????
- {// ????????? ????????? ? ?????? ???? ?????? ?????????????? ?????? ????? ??????
- iCurrentBit=i=0; // ???? ?? ?????? ?? ? ???? ???????? - ??????? ?? ???????
- uCodeFromPeriods.i64bits=0;
- return 0; // TODO ? ???? ?????? ????????? ??????? iCurrentBit=0; ????????? ??? ??? ????????
- } // ???? ?????? ? ????????? ???????? ?????? ?????? ?? ????
- }
- }
- if (iPeriod>300)// ???? ?????? ?????????????? ?????? ????? ?????? ?????? ?????????? ??? ???? ????
- {
- iBitPosition=7-(i%8);
- iCurrenByte=7-((unsigned char)(i/8));
- uCodeFromPeriods.aByte[iCurrenByte]|=iCurrentBit<<iBitPosition;
- if (i>62)
- {
- iCurrentBit=i=0;
- return uCodeFromPeriods.i64bits;
- }
- i++;
- }
-
- return (unsigned long long) i;
- }
- */
- /*
- ??? ???????? ???????????? ??????? ? ????.
- ???????? ???????? - ??????? ??????
-
-
- unsigned long long decode_am2bits(unsigned short iPeriod, unsigned char iMode, unsigned char bitStateSignal)
- {
- static unsigned char i,iCurrentBit,iBitPosition,iCurrenByte,fTnext_enable;
- static unsigned short iPeriodSave, iPeriodAfterTnext;
- static union
- {
- unsigned long long i64bits;
- unsigned char aByte[8];
- } uCodeFromPeriods;
- //if ((iPeriod>10000)&&(iPeriod<11000)&& (!bitStateSignal)) return STATE_RESULT3;// ???????????? ??????? ????? ???????? ????
- if(i==0) uCodeFromPeriods.i64bits=0;
-
- if (fTnext_enable==0)
- {
- iPeriod+=iPeriodSave;
- if (iPeriod>T_NEXT) fTnext_enable=1;
- else iPeriodSave=iPeriod;
- }
- if (fTnext_enable==1)
- {
- iPeriodAfterTnext=iPeriod-T_NEXT;
- if (iPeriodAfterTnext>T_S2)
- {
- fTnext_enable=0;
- iPeriodAfterTnext=iPeriodSave=0;
- i=0;
- uCodeFromPeriods.i64bits=0;
- return 0;
- }
- iCurrentBit=bitStateSignal;
- iBitPosition=7- (i%8);
- iCurrenByte =7-((unsigned char) (i/8));
- uCodeFromPeriods.aByte[iCurrenByte]|=iCurrentBit<<iBitPosition;
- fTnext_enable=0;
- iPeriodAfterTnext=iPeriodSave=0;
- if (i>62)
- {
- fTnext_enable=i=0;
- return uCodeFromPeriods.i64bits;
- }
- i++;
- }
- return STATE_RESULT2;
- }
- */
-
- /*
- ?????????? ?? ???????? ???? ??????????,
- ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
- 01 = 0
- 10 = 1
- ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
- ? ?????????? ????? ?????????? ?? ???? ???????
-
- unsigned long * decode_fm2manchester(unsigned short iPeriod,unsigned short iTPeriodLowMin,unsigned short iTPeriodLowMax,unsigned short iTPeriodHighMin,unsigned short iTPeriodHighMax)
- {
- unsigned long *plReturn;
- unsigned long lReturn;
- unsigned char j;
- plReturn=&lReturn;
- if ((iPeriod>iTPeriodLowMin)&&(iPeriod<iTPeriodLowMax)) // ????????? ?????? ??????? ??? ???? ? ??
- {
- if (iCurrentState) iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
- iCurrentState=0;
- }
- else
- {
- if ((iPeriod>iTPeriodHighMin)&&(iPeriod<iTPeriodHighMax)) // ????????? ??????? ??????? ??? ???? ? ??
- {
- if (!iCurrentState) iStateChange=1;
- iCurrentState=1;
- }
- else
- {
- iCounterPeriodsInDecode=iCounterManchBits=0;
- *plReturn=0;
- return plReturn;
- }
- }
-
- if (iStateChange) // ???? ????????? ??????? ??????????
- {
- iStateChange=0;
-
- for (j=1;j<5;j++)
- {
- if (iCounterPeriodsInDecode>(j*(4+iCurrentState)-1))
- {
- iPosition=31-(iCounterManchBits%32);
- iCurrentByte=32-((unsigned char)(iCounterManchBits>>5)); //??????? ?? 32
- if (iCurrentState) aCodeManchester[iCurrentByte]&=~(1<<iPosition);
- else aCodeManchesters[iCurrentByte]|= (1<<iPosition);
- if (iCounterManchBits>94)
- {
- iCounterPeriodsInDecode=iCounterManchBits=0;
- return &aCodeManchester[0]; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
- }
- iCounterManchBits++;
- }
- }
- iCounterPeriodsInDecode=0;
- }
- iCounterPeriodsInDecode++;
- *plReturn=1;
- return plReturn; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
- }
- */
- /*
- ?????????? ?? ???????? ???? ??????????,
- ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
- 01 = 0
- 10 = 1
- ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
- ? ?????????? ????? ?????????? ?? ???? ???????
-
- PIC18F14K50 (40 ???) ??????????? ?? 33 ???)
-
- unsigned char decode8_fm2manchester(unsigned char iCodeLength,unsigned char iNumberArray, unsigned short iPeriod,unsigned short iTPeriodBoundary,unsigned short iTPeriodHighMax)
- {
- unsigned char j;
- static unsigned char iCounterManchBits,iCounterPeriodsInDecode,iPosition,iCurrentByte,iCurrentState, iStateChange;
- if (iPeriod<iTPeriodBoundary) // ????????? ?????? ??????? ??? ???? ? ??
- {
- if (iCurrentState) iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
- iCurrentState=0;
- }
- else
- {
- if (iPeriod<iTPeriodHighMax) // ????????? ??????? ??????? ??? ???? ? ??
- {
- if (!iCurrentState) iStateChange=1;
- iCurrentState=1;
- }
- else
- {
- iCounterPeriodsInDecode=iCounterManchBits=0; // ????? ??? ??????????? ????????? ??????? ?????? ?? 2 ? ???????? 2 ????????
- return 0;
- }
- }
- if (iStateChange) // ???? ????????? ??????? ??????????
- {
- iStateChange=0;
- if (iCounterPeriodsInDecode==1) return 0;
-
- if (iCounterPeriodsInDecode>(4+iCurrentState))
- {
- iPosition=7-(iCounterManchBits&7);
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
-
- if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
- else { aCodeManchester[iNumberArray][iCurrentByte]&=~(1<<iPosition); }
-
- if (iCounterManchBits>iCodeLength)
- {
- iCounterPeriodsInDecode=iCounterManchBits=0;
- return 0x10; // ????? ?? ?????????? ??? ?????? ??? ??? ?? ?? ????? ????????? ??????? ??????
- }
- iCounterManchBits++;
- }
-
- if (iCounterPeriodsInDecode>(8+(iCurrentState<<1))) // ?? ????? ???? ?????? ???? 8 ?? 1 ??? ???????? ??? ???????? ??????
- {
- iPosition=7-(iCounterManchBits&7);
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
- if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
- else { aCodeManchester[iNumberArray][iCurrentByte]&=~(1<<iPosition); }
- if (iCounterManchBits>iCodeLength)
- {
- iCounterPeriodsInDecode=iCounterManchBits=0;
- return 0x10;
- }
- iCounterManchBits++;
- }
-
- if (iCounterPeriodsInDecode>(12+((iCurrentState<<1)|iCurrentState)))// ??????? iCurrentState *3
- {
- iPosition=7-(iCounterManchBits&7);
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
- if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
- else { aCodeManchester[iNumberArray][iCurrentByte]&=~(1<<iPosition); }
- if (iCounterManchBits>iCodeLength)
- {
- iCounterPeriodsInDecode=iCounterManchBits=0;
- return 0x10;
- }
- iCounterManchBits++;
- }
- iCounterPeriodsInDecode=0;
- }
- iCounterPeriodsInDecode++;
- return 1; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
- }
- */
- /*
- ?????????? ?? ???????? ???? ??????????,
- ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
- 01 = 0
- 10 = 1
- ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
- ? ?????????? ????? ?????????? ?? ???? ???????
-
- PIC18F14K50 (40 ???) ??????????? ?? 33 ???)
- */
- unsigned char decode8_fm2manchester2(unsigned char iCodeLength,unsigned char iNumberArray, unsigned short iPeriodCur,unsigned short iTPeriodBoundary,unsigned short iTPeriodHighMax)
- {
- unsigned char j, iStateChange=0,iPosition=0,iCurrentByte=0,iCurrentManchBit=0;// ????????? ?? ? decode8_fm2manchester
- static unsigned char iCurrentState,iCounterManchBits,iCounterPeriodsDecoding,iCounterHighBits,iCounterLowBits;// static ?? ? decode8_fm2manchester
-
- if (iPeriodCur<iTPeriodBoundary) // ????????? ?????? ??????? ??? ???? ? ??
- {
- if (iCurrentState)
- {
- iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
- }
- iCurrentState=0;
- iCounterLowBits++;
- }
- else
- {
- if (iPeriodCur<iTPeriodHighMax) // ????????? ??????? ??????? ??? ???? ? ??
- {
- if (!iCurrentState)
- {
- iStateChange=1;
- }
- iCurrentState=1;
- iCounterHighBits++;
- }
- else
- {
- iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0; // ????? ??? ??????????? ????????? ??????? ?????? ?? 2 ? ???????? 2 ????????
- return 0;
- }
- }
-
- if (iStateChange) // ???? ????????? ??????? ??????????
- {
- iStateChange=0;
- if (iCounterLowBits>iCounterHighBits)
- {
- iCounterPeriodsDecoding=iCounterLowBits;
- iCounterLowBits=0;
- iCurrentManchBit=0;
- }
- else
- {
- iCounterPeriodsDecoding=iCounterHighBits;
- iCounterHighBits=0;
- iCurrentManchBit=1;
- }
-
- if (iCounterPeriodsDecoding>(3+iCurrentState))
- {
- iPosition=7-(iCounterManchBits&7); // 7 - ??????? ?? ??????? ?? 8
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
- if (iCurrentManchBit) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
- else { aCodeManchester[iNumberArray][iCurrentByte]&= ~(1<<iPosition); }
- if (iCounterManchBits>iCodeLength)
- {
- iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0;
- return 0x10; // ????? ?? ?????????? ??? ?????? ??? ??? ?? ?? ????? ????????? ??????? ??????
- }
- iCounterManchBits++;
- }
-
- if (iCounterPeriodsDecoding>(8+(iCurrentState<<1))) // ?? ????? ???? ?????? ???? 8 ?? 1 ??? ???????? ??? ???????? ??????
- {
- iPosition=7-(iCounterManchBits&7); // 7 - ??????? ?? ??????? ?? 8
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
- if (iCurrentManchBit) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
- else { aCodeManchester[iNumberArray][iCurrentByte]&= ~(1<<iPosition); }
- if (iCounterManchBits>iCodeLength)
- {
- iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0;
- return 0x10;
- }
- iCounterManchBits++;
- }
-
- if (iCounterPeriodsDecoding>(13+((iCurrentState<<1)|iCurrentState)))// ??????? iCurrentState *3
- {
- iPosition=7-(iCounterManchBits&7); // 7 - ??????? ?? ??????? ?? 8
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
- if (iCurrentManchBit) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
- else { aCodeManchester[iNumberArray][iCurrentByte]&= ~(1<<iPosition); }
- if (iCounterManchBits>iCodeLength)
- {
- iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0;
- return 0x10;
- }
- iCounterManchBits++;
- }
- if (iCounterPeriodsDecoding>(18+(iCurrentState<<2)))// ? ???? ?????????? ????? ???? 4 ???? ?????? ??? ??? ?? ????????? ????? ???????? ??????? ?????? ??????? 000
- {
- iPosition=7-(iCounterManchBits&7); // 7 - ??????? ?? ??????? ?? 8
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
- if (iCurrentManchBit) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
- else { aCodeManchester[iNumberArray][iCurrentByte]&= ~(1<<iPosition); }
- if (iCounterManchBits>iCodeLength)
- {
- iCounterHighBits=iCounterLowBits=iCounterPeriodsDecoding=iCounterManchBits=0;
- return 0x10;
- }
- iCounterManchBits++;
- }
- iCounterPeriodsDecoding=0;
- }
- return 1; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
- }
-
- /*
- ?????????? ?? ???????? ???? ??????????,
- ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
- 01 = 0
- 10 = 1
- ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
- ? ?????????? ????? ?????????? ?? ???? ???????
-
- PIC18F14K50 (40 ???) ??????????? ?? 33 ???)
-
- unsigned char decode8_fm2manchester3(unsigned char iCodeLength,unsigned char iNumberArray, unsigned int iPeriodCur,unsigned int iTPeriodBoundary,unsigned int iTPeriodHighMax)
- {
- unsigned char j, iStateChange=0,iPosition=0,iCurrentByte=0;// ????????? ?? ? decode8_fm2manchester
- if (iPeriodCur<iTPeriodBoundary) // ????????? ?????? ??????? ??? ???? ? ??, ?????? ?? 55 ??? ???????? ?? ????? ?????? ??????
- {
- iCounterLowBits++;
- if (iCurrentState)
- {
- iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
- }
- }
- else
- {
- if (iPeriodCur<iTPeriodHighMax) // ????????? ??????? ??????? ??? ???? ? ??
- {
- iCounterHighBits++;
- if (!iCurrentState)
- {
- iStateChange=1;
- }
- }
- else
- {
- iCounterHighBits=iCounterPeriodsDecoding=iCounterManchBits=0; // ????? ??? ??????????? ????????? ??????? ?????? ?? 2 ? ???????? 2 ????????
- return 0;
- }
- }
-
- if (iStateChange) // ???? ????????? ??????? ??????????
- {
- iStateChange=0;
- if (iCounterLowBits>iCounterHighBits)
- {
- iCounterPeriodsDecoding=iCounterLowBits;
- iCounterLowBits=0;
- iCurrentState=0;
- }
- else
- {
- iCounterPeriodsDecoding=iCounterHighBits;
- iCounterHighBits=0;
- iCurrentState=1;
- }
- if (iCounterPeriodsDecoding>(4+iCurrentState))
- {
- if (iCounterPeriodsDecoding<(7+(iCurrentState<<1)))
- {
- iPosition=7-(iCounterManchBits&7);
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
- if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
- if (iCounterManchBits>iCodeLength)
- {
- iCounterPeriodsDecoding=iCounterManchBits=0;
- return 0x10; // ????? ?? ?????????? ??? ?????? ??? ??? ?? ?? ????? ????????? ??????? ??????
- }
- iCounterManchBits++;
- }
- else
- {
- if (iCounterPeriodsDecoding<(11+((iCurrentState<<1)|iCurrentState))) // ?? ????? ???? ?????? ???? 8 ?? 1 ??? ???????? ??? ???????? ??????
- {
- iPosition=7-(iCounterManchBits&7);
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
- if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
- if (iCounterManchBits>iCodeLength)
- {
- iCounterPeriodsDecoding=iCounterManchBits=0;
- return 0x10;
- }
- iCounterManchBits++;
- }
- else
- {
- iPosition=7-(iCounterManchBits&7); // ? ?????? ??????? ??????? ?? ??????? ?? 8
- iCurrentByte=11-(iCounterManchBits>>3);// ??????? ?? 8
- if (iCurrentState) { aCodeManchester[iNumberArray][iCurrentByte]|= (1<<iPosition); }
-
- if (iCounterManchBits>iCodeLength)
- {
- iCounterPeriodsDecoding=iCounterManchBits=0;
- return 0x10;
- }
- iCounterManchBits++;
- }
- }
- }
- }
- return 1; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
- }
-
- */
- /*
- ?????????? ?? ???????? ???? ??????????,
- ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
- 01 = 0
- 10 = 1
- ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
- ? ?????????? ????? ?????????? ?? ???? ???????
-
- PIC18F14K50 (40 ???) ??????????? ?? 72 ???)
-
- unsigned char decode32_fm2manchester(unsigned short iPeriod,unsigned short iTPeriodBoundary,unsigned short iTPeriodHighMax)
- {
- unsigned char j;
- if (iPeriod<iTPeriodBoundary) // ????????? ?????? ??????? ??? ???? ? ??
- {
- if (iCurrentState) iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
- iCurrentState=0;
- }
- else
- {
- if (iPeriod<iTPeriodHighMax) // ????????? ??????? ??????? ??? ???? ? ??
- {
- if (!iCurrentState) iStateChange=1;
- iCurrentState=1;
- }
- else
- {
- iCounterPeriodsInDecode=iCounterManchBits=0; // ????? ??? ??????????? ????????? ??????? ?????? ?? 2 ? ???????? 2 ????????
- return 0;
- }
- }
-
- if (iStateChange) // ???? ????????? ??????? ??????????
- {
- iStateChange=0;
- if (iCounterPeriodsInDecode==1) return 0;
- if (iCounterPeriodsInDecode>(2+iCurrentState))
- {
- iPosition=31-(iCounterManchBits%32);
- iCurrentByte=2-((unsigned char)(iCounterManchBits>>5));// ??????? ?? 32
- if (iCurrentState) aCodeManchester[iCurrentByte]&=~(1<<iPosition);
- else aCodeManchester[iCurrentByte]|= (1<<iPosition);
- if (iCounterManchBits>94)
- {
- iCounterPeriodsInDecode=iCounterManchBits=0;
- return 0x10; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
- }
- iCounterManchBits++;
- }
- if (iCounterPeriodsInDecode>(7+(iCurrentState<<1))) // ?? ????? ???? ?????? ???? 8 ?? 1 ??? ???????? ??? ???????? ??????
- {
- iPosition=31-(iCounterManchBits%32);
- iCurrentByte=2-((unsigned char)(iCounterManchBits>>5));// ??????? ?? 32
- if (iCurrentState) aCodeManchester[iCurrentByte]&=~(1<<iPosition);
- else aCodeManchester[iCurrentByte]|= (1<<iPosition);
- if (iCounterManchBits>94)
- {
- iCounterPeriodsInDecode=iCounterManchBits=0;
- return 0x10; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
- }
- iCounterManchBits++;
- }
-
- if (iCounterPeriodsInDecode>(11+((iCurrentState<<1)|iCurrentState)))// ??????? iCurrentState *3
- {
- iPosition=31-(iCounterManchBits%32);
- iCurrentByte=2-((unsigned char)(iCounterManchBits>>5));// ??????? ?? 32
- if (iCurrentState) aCodeManchester[iCurrentByte]&=~(1<<iPosition);
- else aCodeManchester[iCurrentByte]|= (1<<iPosition);
- if (iCounterManchBits>94)
- {
- iCounterPeriodsInDecode=iCounterManchBits=0;
- return 0x10; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
- }
- iCounterManchBits++;
- }
- iCounterPeriodsInDecode=0;
- }
- iCounterPeriodsInDecode++;
- return 1; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
- }
- */
- /*
- ?????????? ?? ?????? ????????? ??????? ???? ??????????,
- ???? ?? ????????? 96 ?????? ?? ??????? ????????? 1. ???? ????????? ?? ??????? ?????????? ??????? ?????????????????? ???? ?????????? ? ????
- 01 = 0
- 10 = 1
- ? ?????? ????? ??????? ?????? ???????? ?? ??????? ????????? ??????? ?????????? 0
- ? ?????????? ????? ?????????? ?? ???? ???????
-
- unsigned long * decode_fm_flag2manchester(unsigned char iFlag)
- {
- unsigned long *plReturn;
- unsigned long lReturn;
- unsigned char j;
- plReturn=&lReturn;
- if (iFlag) // ????????? ??????? ??????? ??? ???? ? ??
- {
- if (!iCurrentState) iStateChange=1;
- iCurrentState=1;
- }
- else
- {
- if (iCurrentState) iStateChange=1; // TODO ?? ?????? ??????? ????? ???????? ???? ???????? ??????
- iCurrentState=0;
- }
- if (iStateChange) // ???? ????????? ??????? ??????????
- {
- iStateChange=0;
- for (j=1;j<5;j++)
- {
- if (iCounterPeriodsInDecode>(j*(4+iCurrentState)-1))
- {
- iPosition=31-(iCounterManchBits%32);
- iCurrentByte=3-((unsigned char)(iCounterManchBits/32));
- if (iCurrentState) aCodeManchester[0][iCurrentByte]&=~(1<<iPosition);
- else aCodeManchester[0][iCurrentByte]|= (1<<iPosition);
- if (iCounterManchBits>94)
- {
- iCounterPeriodsInDecode=iCounterManchBits=0;
- return (unsigned long *)&aCodeManchester[0][0]; // ?????????? ????????????????????? ???, ????? ??????? ???????? ???????, ??? ??? ? ??????? ??? ???????? ??????????
- }
- iCounterManchBits++;
- }
- }
- iCounterPeriodsInDecode=0;
- }
- iCounterPeriodsInDecode++;
- *plReturn=1;
- return plReturn; // ?????????? 1 ??????? ???? ??? ??? ??? ????????????????? ?? ??????? ??????? ? ?????????
- }
- */
- /*
- ??????? ??? ?????? ????????? ?? ???? ???? 0x1D
- ??????????? ????? ?????
- TODO ?????? ????? ??? ??????? ? ?????????? ????? ???????
- */
- unsigned char search_header_fm(unsigned char *psCodeFromPeriods,unsigned char iLengthBits)
- {
- unsigned char iBitLast,iScan,iC;
- for (iScan=0;iScan<iLengthBits;iScan++)
- {
- if (psCodeFromPeriods[11]==HID_PREAMBLE) return 1;
- iBitLast=((psCodeFromPeriods[11]&0x80)>>7);
- for (iC=11;iC>0;iC--)
- {
- psCodeFromPeriods[iC]=(psCodeFromPeriods[iC]<<1)|((psCodeFromPeriods[iC-1]>>7)&1);
- }
- psCodeFromPeriods[0]=(psCodeFromPeriods[0]<<1)|iBitLast;
- }
- return 0;
- }
- /*
- ????????????? ?????????? ?? ?????????????????? ?????????
- ??? 01 = 0
- 10 = 1
- ??????? ???????? ????????? ?? ?????? ????????? unsigned char
- ? ????????? ??? ?????????????? ?????? ??? ???? ? ??
- TODO ????? ??????? ???????????? ??? ??? ?????????? ???? ?? ????? ? ????? ????????? ???????? ? ???????????? ????????????
- ? ?????????? ????? ?????????? ?? ???? ???????
-
- unsigned char * decode_manchester(unsigned char *psCodeFromPeriods )
- {
- static unsigned char aCodeCard[10],iPosition,iCurentBit,iShift; // ?????????????? ?????? aCodeCard[10] ?? ?????????? ? ???????????????? ? ???????? ?????????????
- for (unsigned char i=1;i<12;i++) // ??????? ??????? ??????? ??? ?? ?????????
- {
- iPosition=(unsigned char) ((i-1)/2);
- for (unsigned char j=1;j<5;j++)
- {
- iCurentBit=(psCodeFromPeriods[i]>>(2*j-1))&1; // ?????????? ??????? ??? ??????? ? ???????? ????? 1 ????, ??? ??? ? 0 ???? ??? ???????? ??????????
- iShift=j-1;
- if(!(i%2)) iShift+=4; // ???????? ???? ?????????? ?????? ??????? ? ??????????????? ???????, ?? ??? ????????? ??????? ????????, ???????? ?? ???? ???? ?? ?????? ????????? ????????? ???????, ?? ???? ??????? ? 4-?? ????
- if (iCurentBit)
- {
- aCodeCard[iPosition]|=(1<<iShift);
- }
- else
- {
- aCodeCard[iPosition]&=~(1<<iShift);
- }
- }
- }
- return &aCodeCard[0];
- }
-
- */
- /*
- ????????????? ?????????? ?? ?????????????????? ????????? ? ?????????????????? ????? ? ??????????
- ??? 01 = 0
- 10 = 1
-
- ??????? ???????? ????????? ?? ?????? ????????? unsigned char ? ?????? ???????
-
- ?????? ???????: ?????????????
- ???????? ??: LPC1114 PIC18F14K50
- */
- unsigned char * decode_manchester2bits(unsigned char *pcManchesterBits, unsigned char iSize )
- {
- unsigned char i,j,iNumberEl,iBitNextVerify=0,iCurentBit=0;
- static unsigned char aCodeBits[14],iShift; // static ?? ??????? decode_manchester2bits
- for (i=0;i<iSize;i++)
- {
- iNumberEl=i>>1;
- for (j=1;j<5;j++)
- {
- iCurentBit =(pcManchesterBits[i]>>((j<<1)-1))&1; // ?????????? ??????? ??? ??????? ? ???????? ????? 1 ????, ??? ??? ? 0 ???? ??? ???????? ??????????
- //iBitNextVerify =(pcManchesterBits[i]>>(j-1))&1;
- //if (iCurentBit==iBitNextVerify) return 0; // ????????? ??? ??? ???????? ???? ?? ??????????? ????? ??? ?? ?????????
- iShift=j-1;
- if (i&1) { iShift+=4; }// ???????? ???? ?????????? ?????? ??????? ? ??????????????? ???????, ?? ??? ????????? ??????? ????????, ???????? ?? ???? ???? ?? ?????? ????????? ????????? ???????, ?? ???? ??????? ? 4-?? ????
- if (iCurentBit)
- {
- aCodeBits[iNumberEl]|=(1<<iShift); // TODO ??????? ????????? static ??? ???? ?????????
- }
- else
- {
- aCodeBits[iNumberEl]&=~(1<<iShift);
- }
- }
- }
- return &aCodeBits[0];
- }
-
- /*
- ????????????? ?????????? ?? ?????????????????? ????????? ? ?????????????????? ????? ? ??????????
- ??? 01 = 0
- 10 = 1
-
- ??????? ???????? ????????? ?? ?????? ????????? unsigned char ? ?????? ???????
-
- ?????? ???????: ?????????????
- ???????? ??: LPC1114 PIC18F14K50
- */
- unsigned char decode_manchester2bits2(unsigned char *pcManchesterBits,unsigned char *pcBitsOut, unsigned char iSize )
- {
- unsigned char i,j,iNumberEl,iCurentBit=0,iBitNextVerify=0,iShift=0;
- for (i=0;i<iSize;i++)
- {
- iNumberEl=i>>1;
- for (j=1;j<5;j++)
- {
- iCurentBit=(pcManchesterBits[i]>>((j<<1)-1))&1; // ?????????? ??????? ??? ??????? ? ???????? ????? 1 ????, ??? ??? ? 0 ???? ??? ???????? ??????????
- //iBitNextVerify =(pcManchesterBits[i]>>(j-1))&1;
- //if (iCurentBit==iBitNextVerify) return 0; // ????????? ??? ??? ???????? ???? ?? ??????????? ????? ??? ?? ?????????
- iShift=j-1;
- if(i&1) { iShift+=4; }// ???????? ???? ?????????? ?????? ??????? ? ??????????????? ???????, ?? ??? ????????? ??????? ????????, ???????? ?? ???? ???? ?? ?????? ????????? ????????? ???????, ?? ???? ??????? ? 4-?? ????
- if (iCurentBit)
- {
- pcBitsOut[iNumberEl]|=(1<<iShift); // TODO ??????? ????????? static ??? ???? ?????????
- }
- else
- {
- pcBitsOut[iNumberEl]&=~(1<<iShift);
- }
- }
- }
- return STATE_RESULT1;
- }
-
- /*
- ????? ????????? ? ???? ?????
- ??????? ?? ??? ??? ???? ?? ?????? 9 ??????,
- ??????? ???????? ??????? ?????????????????? ? ??????? 64 ???? ( unsigned long long )
- ???????? ????????
- ???? 9 ?????? ??????? - ??????? ?????????????????? ? ?????? ??????? ???? 9 ??????
- ???? 9 ?????? ?? ??????? - 0
-
- unsigned long long search_header(unsigned long long llCodeBits)
- {
- for (int i=0;i<64;i++)
- {
- if ((0xFF80000000000000ULL&llCodeBits)==0xFF80000000000000ULL) return llCodeBits;
- llCodeBits=(llCodeBits<<1)|(llCodeBits>>63);
- }
- return 0;
- }
- */
- /*
- ??????? ??? ?????? ????????? ?? ???? ???? 0000111
- ??????????? ????? ?????
- TODO ?????? ????? ??? ??????? ? ?????????? ????? ???????
-
-
- unsigned char search_header_fm(unsigned char *psCodeFromPeriods)
- {
- static unsigned char iBitLast;
- for (int iScan=0;iScan<96;iScan++)
- {
- iBitLast=((psCodeFromPeriods[12]&0x80)>>7);
- for (int i=12;i>1;i--)
- {
- psCodeFromPeriods[i]=(psCodeFromPeriods[i]<<1)|((psCodeFromPeriods[i-1]>>7)&1);
- }
- psCodeFromPeriods[1]=(psCodeFromPeriods[1]<<1)|iBitLast;
- if ((psCodeFromPeriods[12]&HID_PREAMBLE)==HID_PREAMBLE) return 1;
- }
- return 0;
- }
- */
- /*
- ??????? ??? ?????? ?????????
- HID ???? ? ?? ???? 0x1D
- ????? ? ??????? 48 ??? ?? ????? ??????? ?? ????????? (????? ????? ??????????)
- ?? ????????? HID_format_example.pdf ? ????? www.proxclone.com
- TODO ??????????? ??????? ????? ????? ??? ??? wiegand 37( ???? ?? ????? 48-26+37)
-
-
- unsigned char search_symbol(unsigned long long *pllCodeIn, unsigned long lSizeArrayBits,unsigned int iSizeBitsInSearchSymbol,unsigned int iSearchSymbol )
- {
- unsigned char iBitLast,iSizeBitsInLast,iSearchSymbolShift;
- unsigned int i,j;
- unsigned int iSizeLongArray,iNLastElement;
- unsigned long long llMaskSymbolShift,llSymbol,*pllCode;
- pllCode=pllCodeIn;
- iSizeBitsInLast=(lSizeArrayBits%64);
- if (iSizeBitsInLast>=iSizeBitsInSearchSymbol) iSearchSymbolShift=iSizeBitsInLast -iSizeBitsInSearchSymbol; // TODO ????????? ???????? ??? ????????? ????????
- else iSearchSymbolShift=iSizeBitsInLast+64 -iSizeBitsInSearchSymbol;// ???? ???????? ???? ????? ??????? ???? ????????? ????? ? 2-? ????????? ???????
- llMaskSymbolShift = (unsigned long long)(0xFFFFFFFFFFFFFFFFULL<<iSearchSymbolShift);
- llSymbol = (unsigned long long)(iSearchSymbol <<iSearchSymbolShift);
- iSizeLongArray=(((unsigned int)(lSizeArrayBits>>6))+1); // ??????? ?????????? ?????????: long long ????? ?? ??? long long (64 ????) ? ?????????? 1
- iNLastElement=iSizeLongArray-1; // ????? ?????????? ???????? ? ???????
- for (i=0;i<lSizeArrayBits;i++)
- {
- iBitLast=*pllCode&1; //?????????? ?????? ??? ??? ??? ??? ??????? ?????? ???
- for (j=0;j<iNLastElement;j++) *(pllCode+j)=(*(pllCode+j)>>1)|(*(pllCode+j+1)<<63);
- *(pllCode+iNLastElement)=(*(pllCode+iNLastElement)>>1)|((unsigned long long)iBitLast<<(iSizeBitsInLast-1));
- if ((*(pllCode+iNLastElement)&llMaskSymbolShift)==llSymbol) return 0x11;
- }
- return 0;
- }
- */
- /*
- ??? ???????? ?????????
-
-
- unsigned char verify_code_wiegand26(unsigned long lCodeWiegand )
- {
- unsigned char bitEP,bitOP,bitXOR;
- bitEP=(lCodeWiegand>>25)&1;
- bitOP=(lCodeWiegand&1);
- bitXOR=0;
- for (int i=0;i<12;i++)
- {
- lCodeWiegand>>=1;
- bitXOR ^=(lCodeWiegand&1);
- }
- if (bitXOR==bitOP ) return 0x22;//????????? ???????
- bitXOR=0;
- for (int i=0;i<12;i++)
- {
- lCodeWiegand>>=1;
- bitXOR ^=(lCodeWiegand&1);
- }
- if (bitXOR!=bitEP ) return 0x21;
- return 0x11;
- }
- */
- /*
- ??? ???????? ?????????
-
- */
- unsigned char verify_code_card_HID(unsigned long llCodeBits )
- {
- if ((verify_code_wiegand26((unsigned long) llCodeBits)&0x20)==0x20) return 0x21;
- return 0x11;
- }
-
- unsigned char verify_code_wiegand26(unsigned long lCodeWiegand )
- {
- unsigned char bitEP,bitOP,bitXOR,i;
- bitEP=(lCodeWiegand>>25)&1;
- bitOP=(lCodeWiegand&1);
- bitXOR=0;
- for (i=0;i<12;i++)
- {
- lCodeWiegand>>=1;
- bitXOR ^=(lCodeWiegand&1);
- }
- if (bitXOR==bitOP ) { return 0x22; }//????????? ???????
- bitXOR=0;
- for (i=0;i<12;i++)
- {
- lCodeWiegand>>=1;
- bitXOR ^=(lCodeWiegand&1);
- }
- if (bitXOR!=bitEP ) { return 0x21; }
- return 0x11;
- }
-
-
- /*
- ????????? ???????????? ????
- ??????? ???????? ???????? ???????? ?? ??????? ? ???????? ???????? ?? ????????
- ???????? ????? ????????? ????????? ? ???????????? ??? ????? ? ?? EM4100 ???????? 5
- ??????? ???????? ??????? ?????????????????? ? ??????? 64 ???? ( unsigned long long )
- ???????? ???????? ??? ??????
- 0 ?????? ???
- 1 ?????? ???????? ??????
- 2 ?????? ???????? ???????
- TODO ????? ???????? ?????? ???????? ???? ??????? ? ?????? ????
-
- unsigned char verify_code_card(unsigned long long llCodeBits)
- {
- unsigned char aLine[15];
- unsigned char iXor,i,j;
- unsigned long long llCodeShiftBits;
- llCodeShiftBits=llCodeBits;
- aLine[0]=(unsigned char)(llCodeBits&0x1F);
- for (i=1;i<11; i++)
- {
- llCodeShiftBits=(llCodeShiftBits>>5);
- aLine[i]=(unsigned char)(llCodeShiftBits&0x1F);
- if (calculate_parity_line(aLine[i])) return 1; // ?????????? ??????
- }
- for (j=1;j<5;j++)
- {
- iXor=0;
- for (i=1;i<11; i++)
- {
- iXor=iXor^((aLine[i]>>j)&1);
- }
- if (iXor!=((aLine[0]>>j)&1)) return 2; // ?????????? ??????
- }
- return 0;
- }
- */
- /*
- ???? ????????? ?????? ???????? ?? ?????????? 1
-
-
- unsigned char calculate_parity_line(unsigned char iLine)
- {
- unsigned char iLineReal=0,iBitParity=0;
- iBitParity=iLine&1;
- for (int i=0;i<5; i++)
- {
- iLine=(iLine>>1);
- iLineReal=iLineReal^(iLine&1);
- }
- if (iLineReal==iBitParity) return 0;
- else return 1;
- }
- */
- /*
- unsigned char calculate_parity_line(unsigned char iLine)
- {
- unsigned char iLineReal;
- unsigned char aCodeCard[4];
- iBitParity=aLine&1;
- for (int i=0;i<5; i++)
- {
- iLineReal=iLineReal^((iLine>>1)&1);
- aLine[i]=(llCodeBits>>10);
- aLine[i]=(unsigned char)(llCodeBits&0x1F);
- }
- for (int i=0;i<4; i++)
- {
- aCodeCard[i]=(llCodeBits&0xF)|((llCodeBits>>1)&0xF0);
- llCodeBits=llCodeBits>>10;
- }
- return ;
- }*/
- /*
- ?????????? ???? ????? ?? ??????? ??????????????????
- ??????? ???????? ??? ????? ? ??????? 64 ???? ( unsigned long long )
-
- unsigned char *extract_code_card(unsigned long long llCodeBits)
- {
- static unsigned char aCodeCard[]={0,0,0,0,0,0,0,0};
- llCodeBits=(llCodeBits>>6);
- for (int i=0;i<5; i++)
- {
- aCodeCard[i]=(llCodeBits&0x0F)|((llCodeBits>>1)&0xF0);
- llCodeBits=llCodeBits>>10;
- }
- return &aCodeCard[0];
- }
- */
- unsigned char *extract_code_card_HID(unsigned long lCodeBits)
- {
- unsigned char i;
- static unsigned char aCodeCard[4];
- lCodeBits=(lCodeBits>>1);
- for (i=0;i<3;i++)
- {
- aCodeCard[i]=(unsigned char) (lCodeBits&0xFF);
- lCodeBits>>=8;
- }
- aCodeCard[3]=0;
- return &aCodeCard[0];
- }