|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663 |
- #include "DataProc.h"
- #include <string.h>
- #include "printf.h"
- #include "flash.h"
- #include "LCD.h"
- //SPIType SPI_Using = SPI_PORT1; //ѡһSPIӿ
-
- extern void IWDG_Feed(void);
-
- u8 CheckData_1356[10] = {0xD1,0xD1,0xE0,0xD0,0x00,0x00,0x00,0x00,0xD2,0xD2}; //13.56M
- u8 GetNum_1356[5] = {0x00,0x00,0x00,0x00,0x00}; //13.56M
- static u8 ResNum_1356[5]; //13.56M棬ڻظA2
- static u8 oldResNum_1356[5];
-
- u8 uartSendData[100]; //100ֽ
- u8 uartRecData[100]; //100ֽ
-
- u8 uartSendRdNumData[100];
- u8 uartSendWrNumOkData[100];
- u8 uartSendConfigKaoQinData[100];
- volatile u16 count;
- u16 count_num;
- u8 flag_1ms;
- u8 first_clear_flag;
- u8 HW_Open;
- u16 HW_OpenCount;
-
- u8 Flag_update;
- u8 WriteOKFlag=0;
- u8 protocol_config_flg;
-
- struct Protocol_send_data //ͨѶЭ
- {
- u8 HeadFix;
- u8 Control;
- u8 Magic[4];
- u8 SequenceID[4];
- u8 Command;
- u8 Tag;
- u8 Length;
- u8 Value[6]; //ֵ6
- u8 FootCRC[2]; //CRC ʱ̶Ϊ00 00
- u8 FootFix; //̶Ϊ0xFB
- };
-
- struct Protocol_rec_data //ͨѶЭ
- {
- u8 HeadFix;
- u8 Control;
- u8 Magic[4];
- u8 SequenceID[4];
- u8 Command;
- u8 Tag;
- u8 Length;
- u8 Value[62]; //ֵ62
- u8 FootCRC[2]; //CRC ʱ̶Ϊ00 00
- u8 FootFix; //̶Ϊ0xFB
- };
-
- //struct ReadNum_send_data //Żظָ 30Byte
- //{
- // u8 HeadFix;
- // u8 Control;
- // u8 Magic[4];
- // u8 SequenceID[4];
- // u8 Command;
- // u8 Tag1;
- // u8 Length1;
- // u8 Value1[6]; //ֵ6
- // u8 Tag2;
- // u8 Length2;
- // u8 Value2[6]; //ֵ6
- // u8 FootCRC[2]; //CRC ʱ̶Ϊ00 00
- // u8 FootFix; //̶Ϊ0xFB
- //};
-
- struct ReadNum_send_data //Żظָ 22Byte
- {
- u8 HeadFix;
- u8 Control;
- u8 Magic[4];
- u8 SequenceID[4];
- u8 Command;
- u8 Tag1;
- u8 Length1;
- u8 Value1[6]; //ֵ6
- u8 FootCRC[2]; //CRC ʱ̶Ϊ00 00
- u8 FootFix; //̶Ϊ0xFB
- };
-
- struct WrNumOk_send_data //дɹظָ
- {
- u8 HeadFix;
- u8 Control;
- u8 Magic[4];
- u8 SequenceID[4];
- u8 Command;
- u8 FootCRC[2]; //CRC ʱ̶Ϊ00 00
- u8 FootFix; //̶Ϊ0xFB
- };
-
- struct ConfigKaoQin_send_data
- {
- u8 HeadFix; //̶Ϊ0xFA
- u8 Control; // 1ʾɹ
- u8 Magic[4];
- u8 SequenceID[4];
- u8 Command; // A8
- u8 FootCRC[2]; //CRC ʱ̶Ϊ00 00
- u8 FootFix; //̶Ϊ0xFB
- };
-
-
- #define ReceiveBuf ((struct Protocol_rec_data *)&uartRecData[0])
- #define SendBuf ((struct Protocol_send_data *)&uartSendData[0])
- #define ConfigKaoQinBuf ((struct ConfigKaoQin_send_data *)&uartSendConfigKaoQinData[0])
- #define WrNumOkBuf ((struct WrNumOk_send_data *)&uartSendWrNumOkData[0])
- #define ReadNumBuf ((struct ReadNum_send_data *)&uartSendRdNumData[0])
-
- #define CndRspBufferSize 100
-
- unsigned char CmdRspBuffer[CndRspBufferSize];
- unsigned char CmdRspBufferWr_Rx = 0;
-
- u8 idBuf[5]; //2.4G IDռ
-
-
- u16 count_A34;
- u8 idResA3Buf[5]; //2.4G ID棬ڻظA3
- u8 ReadAttenID[5]; //2.4G ڿID
-
- u8 newIdFlag; //д2.4G ID־
- u8 recFlag;
- u8 rspFlag_A3;
- u8 read1356flag;
-
- unsigned char txBuf[32]="123456789123456789";
- unsigned char txA3Buf[32]="123456789123456789";
- unsigned char rspFlag = 0; //Ƿϵ2.4GϢ ־
- unsigned char wrNumFlag = 0;//дǷɱ־
-
- /****************************************************
- : У
-
- : sum = ~(data0+...+datan)+1;
- *****************************************************/
- u8 CheckSum(u8 *buf,u8 len)
- {
- u8 sum = 0;
- u8 i;
- for(i = 0;i < len; i++)
- {
- sum += buf[i];
- }
- sum = ~sum;
- sum += 1;
- return sum;
- }
-
- //void AT_AddNewRxByte(u8 c)
- //{
- // if (c != 0x0D)
- // {
- // if (c < 32) return; // ignore control charcters
- // if (CmdRspBufferWr_Rx >= (CndRspBufferSize - 1)) return; // buffer overflow - ignore character
- // CmdRspBuffer[CmdRspBufferWr_Rx++] = c;
- // CmdRspBuffer[CmdRspBufferWr_Rx] = 0;
- // return;
- // }
- // //----------------------------------------------------
- // // ID=XXXXX
- // if((CmdRspBuffer[0] == 'I')&&(CmdRspBuffer[1] == 'D')&&(CmdRspBuffer[2] == '='))
- // {
- // memcpy(idBuf,&CmdRspBuffer[3],5);
- // SendConsoleStr("id=");
- // SendConsoleData(idBuf,5);
- // SendConsoleStr("\n");
- // newIdFlag = 1;
- // }
- // else if((CmdRspBuffer[0] == 'I')&&(CmdRspBuffer[1] == 'D')&&(CmdRspBuffer[2] == '?'))
- // {
- // SendConsoleStr("id=");
- // SendConsoleData(idBuf,5);
- // SendConsoleStr("\n");
- // }
- // memset(CmdRspBuffer,0,sizeof(CmdRspBuffer));
- // CmdRspBufferWr_Rx = 0;
- //}
-
-
- void Data_Init(void) //ݳʼ
- {
- SendBuf->HeadFix = 0xFA; //ͻʼ
- SendBuf->Control = 0x10;
- SendBuf->Magic[0]= 0;
- SendBuf->Magic[1]= 0;
- SendBuf->Magic[2]= 0;
- SendBuf->Magic[3]= 0;
- SendBuf->SequenceID[0] = 0;
- SendBuf->SequenceID[1] = 0;
- SendBuf->SequenceID[2] = 0;
- SendBuf->SequenceID[3] = 0;
- SendBuf->FootCRC[0] = 0;
- SendBuf->FootCRC[1] = 0;
- SendBuf->FootFix = 0xFB;
-
- ReceiveBuf->HeadFix = 0xFA; //ջʼ
- ReceiveBuf->Control = 0x10;
- ReceiveBuf->Magic[0]= 0;
- ReceiveBuf->Magic[1]= 0;
- ReceiveBuf->Magic[2]= 0;
- ReceiveBuf->Magic[3]= 0;
- ReceiveBuf->SequenceID[0] = 0;
- ReceiveBuf->SequenceID[1] = 0;
- ReceiveBuf->SequenceID[2] = 0;
- ReceiveBuf->SequenceID[3] = 0;
- ReceiveBuf->FootCRC[0] = 0;
- ReceiveBuf->FootCRC[1] = 0;
- ReceiveBuf->FootFix = 0xFB;
-
- ConfigKaoQinBuf->HeadFix = 0xFA; //ջʼ
- ConfigKaoQinBuf->Control = 0x10;
- ConfigKaoQinBuf->Magic[0]= 0;
- ConfigKaoQinBuf->Magic[1]= 0;
- ConfigKaoQinBuf->Magic[2]= 0;
- ConfigKaoQinBuf->Magic[3]= 0;
- ConfigKaoQinBuf->SequenceID[0] = 0;
- ConfigKaoQinBuf->SequenceID[1] = 0;
- ConfigKaoQinBuf->SequenceID[2] = 0;
- ConfigKaoQinBuf->SequenceID[3] = 0;
- ConfigKaoQinBuf->FootCRC[0] = 0;
- ConfigKaoQinBuf->FootCRC[1] = 0;
- ConfigKaoQinBuf->FootFix = 0xFB;
-
-
- ReadNumBuf->HeadFix = 0xFA; //ջʼ
- ReadNumBuf->Control = 0x10;
- ReadNumBuf->Magic[0]= 0;
- ReadNumBuf->Magic[1]= 0;
- ReadNumBuf->Magic[2]= 0;
- ReadNumBuf->Magic[3]= 0;
- ReadNumBuf->SequenceID[0] = 0;
- ReadNumBuf->SequenceID[1] = 0;
- ReadNumBuf->SequenceID[2] = 0;
- ReadNumBuf->SequenceID[3] = 0;
- ReadNumBuf->FootCRC[0] = 0;
- ReadNumBuf->FootCRC[1] = 0;
- ReadNumBuf->FootFix = 0xFB;
-
- WrNumOkBuf->HeadFix = 0xFA; //ջʼ
- WrNumOkBuf->Control = 0x10;
- WrNumOkBuf->Magic[0]= 0;
- WrNumOkBuf->Magic[1]= 0;
- WrNumOkBuf->Magic[2]= 0;
- WrNumOkBuf->Magic[3]= 0;
- WrNumOkBuf->SequenceID[0] = 0;
- WrNumOkBuf->SequenceID[1] = 0;
- WrNumOkBuf->SequenceID[2] = 0;
- WrNumOkBuf->SequenceID[3] = 0;
- WrNumOkBuf->FootCRC[0] = 0;
- WrNumOkBuf->FootCRC[1] = 0;
- WrNumOkBuf->FootFix = 0xFB;
- }
-
- //void Usart1_Process(void)
- //{
- //
- // if(USART1_RX_CNT==10 && USART1_RX_BUF[0]==0xd1 && USART1_RX_BUF[9]==0xd2)
- // {
- // USART1_REC_Status |= 0x8000; //յIDʮ10λID
- // }
- //
- //
- // if(USART1_REC_Status & 0x8000)
- // {
- //// memcpy(idBuf,&USART1_RX_BUF[3],5); //5λʮIDдidBuf
- // idBuf[0]=0;
- // idBuf[1]=USART1_RX_BUF[4];
- // idBuf[2]=USART1_RX_BUF[5];
- // idBuf[3]=USART1_RX_BUF[6];
- // idBuf[4]=USART1_RX_BUF[7]; //յIDд뵽idBuf
- //
- // SendConsoleStr("id=");
- // SendConsoleData(idBuf,5);
- // SendConsoleStr("\n");
- // newIdFlag = 1;
- //
- // USART1_RX_CNT = 0;
- // USART1_REC_Status = 0;
- // }
- //}
-
-
- void DataProc_1356(void)
- {
- u32 dat1,dat2,dat3,dat4;
- u8 IdBuf[10]={0};
- IWDG_Feed();
- if(USART3_RX_CNT==10)
- {
- if(USART3_RX_BUF[0]==CheckData_1356[0] && USART3_RX_BUF[1]==CheckData_1356[1]
- && USART3_RX_BUF[8]==CheckData_1356[8] && USART3_RX_BUF[9]==CheckData_1356[9])
- {
- USART3_REC_Status |= 0x8000; //3ɽһ֡
- }
- else
- {
- memset(USART3_RX_BUF,0,20);
- }
- }
-
- if(USART3_REC_Status & 0x8000)
- {
- //дֹһдӰ
- //delay_ms(1);
- #if 0
- idBuf[0]=0;
- idBuf[1]=0;
- idBuf[2]=0;
- idBuf[3]=0;
- idBuf[4]=0;
-
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
-
- idResA3Buf[0]=0;
- idResA3Buf[1]=0;
- idResA3Buf[2]=0;
- idResA3Buf[3]=0;
- idResA3Buf[4]=0;
-
- ReadAttenID[0]=0;
- ReadAttenID[1]=0;
- ReadAttenID[2]=0;
- ReadAttenID[3]=0;
- ReadAttenID[4]=0;
- #else
- memset(idBuf,0,5);
- memset(GetNum_1356,0,5);
- memset(idResA3Buf,0,5);
- memset(ReadAttenID,0,5);
- #endif
- // SendConsoleData(USART3_RX_BUF,10);
- // DegugPrintf(USART3_RX_BUF,10);
- // SendConsoleStr("\n");
-
- //IWDG_Feed();
- GetNum_1356[0]=0;
- GetNum_1356[1]=USART3_RX_BUF[4];
- GetNum_1356[2]=USART3_RX_BUF[5];
- GetNum_1356[3]=USART3_RX_BUF[6];
- GetNum_1356[4]=USART3_RX_BUF[7]; //յIDд뵽idBuf
-
- ResNum_1356[0]=0;
- ResNum_1356[1]=GetNum_1356[1];
- ResNum_1356[2]=GetNum_1356[2];
- ResNum_1356[3]=GetNum_1356[3];
- ResNum_1356[4]=GetNum_1356[4];
-
- // NRF24L01_RX_Mode(SPI_SEND); //
- dat1 = (GetNum_1356[1]<<24);
- dat2 = (GetNum_1356[2]<<16);
- dat3 = (GetNum_1356[3]<<8);
- dat4 = dat1 + dat2 + dat3 + GetNum_1356[4];
- #if LCD
- HexToDec(dat4,IdBuf,sizeof(IdBuf));
- vDispClearLine(2);
- vDispStr(2,1,"13.56:",6);
- vDispStr(2,7,(char*)IdBuf,10);
- #endif
- read1356flag = 1;
- // printf("1356_0=%x\r\n",GetNum_1356[0]);
- // printf("1356_1=%x\r\n",GetNum_1356[1]);
- // printf("1356_2=%x\r\n",GetNum_1356[2]);
- // printf("1356_3=%x\r\n",GetNum_1356[3]);
- // printf("1356_4=%x\r\n",GetNum_1356[4]);
- // printf("\r\n13.56Mţ%u\r\n",dat4);
- IWDG_Feed();
- // idBuf[0]=GetNum_1356[0];
- // idBuf[1]=GetNum_1356[1];
- // idBuf[2]=GetNum_1356[2];
- // idBuf[3]=GetNum_1356[3];
- // idBuf[4]=GetNum_1356[4];
- // delay_ms(100);delay_ms(100);
-
- //HW_Open = 1; //غɨǹ
-
- // newIdFlag = 1; //2.4Gʼд
- // count = 0;
-
- //IWDG_Feed();
- USART3_RX_CNT = 0; //
- USART3_REC_Status = 0;
- memset(USART3_RX_BUF,0,20);
- }
- }
- #if 0
- void DataProc_RecNrf24L01(void)
- {
- u8 buffer[7];
- u8 temp;
- u32 dat1,dat2,dat3,dat4;
- IWDG_Feed();
- // if(WriteOKFlag==1)
- // {
-
- if(SPI2_IRQ == 0)
- {
- IWDG_Feed();
- temp = NRF24L01_RxPacket(SPI_SEND,buffer);
-
- // printf("temp=%x\r\n",temp);
- // SendConsoleData(buffer,RX_PLOAD_WIDTH);
-
- idBuf[0] = 0;
- idBuf[1] = buffer[1];
- idBuf[2] = buffer[2];
- idBuf[3] = buffer[3];
- idBuf[4] = buffer[4];
-
- // if(idBuf[0]==GetNum_1356[0] && idBuf[1]==GetNum_1356[1] && idBuf[2]==GetNum_1356[2] && idBuf[3]==GetNum_1356[3] && idBuf[4]==GetNum_1356[4])
- // {
- // recFlag = 2; //д2.4G
- dat1 = idBuf[1]<<24;
- dat2 = idBuf[2]<<16;
- dat3 = idBuf[3]<<8;
- dat4 = dat1 + dat2 + dat3 + idBuf[4];
- // if(WriteOKFlag)
- // printf("ID=%u\r\n",dat4);
- delay_ms(10);
- // else
- // printf("дţ:%u\r\n",dat4);
-
- WriteOKFlag = 0;
- idBuf[0]=0;
- idBuf[1]=0;
- idBuf[2]=0;
- idBuf[3]=0;
- idBuf[4]=0;
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
- // }
- // else
- // {
- //// printf("δдţ\r\n");
- //// NRF24L01_RX_Mode(SPI_SEND);
- // IWDG_Feed();
- //
- // WriteOKFlag = 0;
- // WriteFailFlag = 0;
- // idBuf[0] = 0;
- // idBuf[1] = 0;
- // idBuf[2] = 0;
- // idBuf[3] = 0;
- // idBuf[4] = 0;
- // GetNum_1356[0]=0;
- // GetNum_1356[1]=0;
- // GetNum_1356[2]=0;
- // GetNum_1356[3]=0;
- // GetNum_1356[4]=0;
- //
- // NRF24L01_TX_Mode(SPI_SEND);
- // }
- }
-
-
- }
-
- #else
- void DataProc_RecNrf24L01(void)
- {
- u8 tmp;
- u32 IdData;
- u8 IdBuf[10]={0};
- //if(read1356flag)
- {
- NRF24L01_RX_Mode_NOACK(SPI_SEND,protocol_config_flg);//NOACK??,?????
- count_A34 = 0;
- {
- while(1) //
- {
-
- tmp = DataProc_A4_nrf();
-
- if(tmp)
- break;
- }
- read1356flag = 0;
- #if LCD
- IdData =(ReadAttenID[1]<<24)|(ReadAttenID[2]<<16)|(ReadAttenID[3]<<8)|(ReadAttenID[4]);
- HexToDec(IdData,IdBuf,sizeof(IdBuf));
- vDispClearLine(3);
- vDispStr(3,1,"ID:",3);
- vDispStr(3,4,(char*)IdBuf,10);
- if((ReadAttenID[0] & 0x80) !=0)
- {
- vDispStr(3,15,"1",1);
- }
- else
- {
- vDispStr(3,15,"0",1);
- }
- #endif
- SendConsoleData((char*)uartSendRdNumData,22); //ԣظPC
- delay_ms(50);
-
- DegugPrintf(uartSendRdNumData,22);
- SendUSART2Str("\n");
- #if LCD
- if(ResNum_1356[0] ==ReadAttenID[0] &&ResNum_1356[1] ==ReadAttenID[1] && ResNum_1356[2] ==ReadAttenID[2]
- &&ResNum_1356[3] ==ReadAttenID[3] && ResNum_1356[4] ==ReadAttenID[4])
- {
- vDispClearLine(4);
- vDispStr(4,4,"OK",2);
-
- }
- else
- {
- vDispClearLine(4);
- vDispStr(4,4,"NG",2);
-
- }
- #endif
- //дֹһдӰ
- ReadAttenID[0]=0;
- ReadAttenID[1]=0;
- ReadAttenID[2]=0;
- ReadAttenID[3]=0;
- ReadAttenID[4]=0;
- ResNum_1356[0]=0;
- ResNum_1356[1]=0;
- ResNum_1356[2]=0;
- ResNum_1356[3]=0;
- ResNum_1356[4]=0;
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
- }
- }
-
- }
-
- #endif
-
- void DataProc_Nrf24l01_SPI2(void)
- {
- u8 buffer[32];
- u8 temp;
- //u32 dat1,dat2,dat3,dat4,cardid;
- IWDG_Feed();
-
- if(newIdFlag==1)
- {
- newIdFlag = 0;
- txBuf[0] = 0xfc;
- txBuf[1] = 0x11;
- // if(idBuf[0]==GetNum_1356[0] && idBuf[1]==GetNum_1356[1] && idBuf[2]==GetNum_1356[2] && idBuf[3]==GetNum_1356[3] && idBuf[4]==GetNum_1356[4])
- // {
- txBuf[2] = idBuf[0];
- txBuf[3] = idBuf[1];
- txBuf[4] = idBuf[2];
- txBuf[5] = idBuf[3];
- txBuf[6] = idBuf[4];
- // }
-
- txBuf[7] = CheckSum(txBuf,7); //дŵtxBuf
- SPI2_CE =0;
-
- NRF24L01_Write_Reg(SPI_SEND,FLUSH_TX,0xff);//TX FIFOĴ
- NRF24L01_Write_Buf(SPI_SEND,W_ACK_PAYLOAD,txBuf,8); //дݵTX BUF 8ֽڣԶ
- NRF24L01_RX_Mode(SPI_SEND); //24L01Ϊģʽ
- rspFlag = 1;
- count=0;
- IWDG_Feed();
-
- }
-
-
-
- if(rspFlag) //ϵ緢͵
- {
- IWDG_Feed();
- if(count<=2000) //2Sδյ2.4GظźţrspFlagʧЧ
- {
- if(SPI2_IRQ == 0) //24L01յϵ緢͵
- {
- IWDG_Feed();
- temp = NRF24L01_RxPacket(SPI_SEND,buffer);
- // SendConsoleByte(temp);
-
- if((temp&0x40)==0x40) //յʾ
- {
- buffer[RX_PLOAD_WIDTH]='\0';
- led0=~led0;
-
- // SendConsoleData(buffer,RX_PLOAD_WIDTH); //
-
- if((buffer[1]==idBuf[0])&& (buffer[2]==idBuf[1])&&(buffer[3]==idBuf[2])&&(buffer[4]==idBuf[3])&&(buffer[5]==idBuf[4])) //յд
- {
- // if((buffer[1]==GetNum_1356[0])&& (buffer[2]==GetNum_1356[1])&&(buffer[3]==GetNum_1356[2])&&(buffer[4]==GetNum_1356[3])&&(buffer[5]==GetNum_1356[4]))
- // {
- if(rspFlag == 1)
- {
- rspFlag++;
- txBuf[1] = 0x12; ///0xfc + cmd(0x12) +id +crc ----cmd=0x12 ȷ
- txBuf[7] = CheckSum(txBuf,7); //дŵtxBuf
- NRF24L01_Write_Buf(SPI_SEND,W_ACK_PAYLOAD,txBuf,8); //дݵTX BUF 8ֽڣԶ
- }
- else
- {
- rspFlag=0; //IDѾ£rspFlag㣬
- count = 0; //
- idBuf[0]=0;
-
- WrNumOkBuf->Control = 0x10; //д
- SendConsoleData((char*)uartSendWrNumOkData,14); //ԣظPC
-
- DegugPrintf(uartSendWrNumOkData,14);
- SendUSART2Str("\n");
-
- //dat1 = (idBuf[1]<<24);
- //dat2 = (idBuf[2]<<16);
- //dat3 = (idBuf[3]<<8);
- //dat4 = idBuf[4];
- //cardid = dat1 + dat2 + dat3 + dat4;
- // printf("дɣţ%u\r\n",cardid);
-
- //NRF24L01_RX_Mode_NOACK(SPI_SEND);//
- #if APP
- NRF24L01_RX_Mode_NOACK(SPI_SEND,protocol_config_flg);//???
- #else
- NRF24L01_RX_Mode_NOACK(SPI_SEND);//
- #endif
- WriteOKFlag = 1;
- }
- // }
-
-
- }
- else
- {
- SPI2_CE =0;
- txBuf[1] = 0x11;
- txBuf[7] = CheckSum(txBuf,7); //дŵtxBuf
- NRF24L01_Write_Buf(SPI_SEND,W_ACK_PAYLOAD,txBuf,8); //дݵTX BUF 8ֽ
- SPI2_CE =1;
- }
- }
- }
-
- }
- else //2sʱظ
- {
- IWDG_Feed();
- rspFlag=0; //IDѾ£rspFlag㣬
- count = 0; //
-
- idBuf[0]=0;
- idBuf[1]=0;
- idBuf[2]=0;
- idBuf[3]=0;
- idBuf[4]=0;
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
-
-
- WrNumOkBuf->Control = 0x30; //
- SendConsoleData((char*)uartSendWrNumOkData,14); //ԣظPC
-
- DegugPrintf(uartSendWrNumOkData,14);
- SendUSART2Str("\n");
- // printf("дʧ:ʱ\r\n");
- // NRF24L01_RX_Mode_NOACK(SPI_SEND);//
- }
-
- }
-
- }
-
-
- u8 DataProc_A0_WriteNum_SPI2(void)
- {
- u8 temp;
- u8 buffer[32];
-
- if(newIdFlag==1)
- {
- newIdFlag = 0;
- txBuf[0] = 0xfc;
- txBuf[1] = 0x11;
- txBuf[2] = idBuf[0];
- txBuf[3] = idBuf[1];
- txBuf[4] = idBuf[2];
- txBuf[5] = idBuf[3];
- txBuf[6] = idBuf[4];
-
- txBuf[7] = CheckSum(txBuf,7); //дŵtxBuf
- SPI2_CE =0;
- NRF24L01_Write_Reg(SPI_SEND,FLUSH_TX,0xff);//TX FIFOĴ
- NRF24L01_Write_Buf(SPI_SEND,W_ACK_PAYLOAD,txBuf,8); //дݵTX BUF 8ֽڣԶ
- NRF24L01_RX_Mode(SPI_SEND); //24L01Ϊģʽ
- SPI2_CE =1;
- rspFlag = 1;
- count=0;
- IWDG_Feed();
-
- }
-
- if(count<=3000)
- {
- IWDG_Feed();
- if(SPI2_IRQ == 0) //24L01յϵ緢͵
- {
- IWDG_Feed();
- temp = NRF24L01_RxPacket(SPI_SEND,buffer);
- SendUSART2Byte(temp);
- SendUSART2Str("\n");
-
- if((temp&0x40)==0x40) //յʾ
- {
- buffer[RX_PLOAD_WIDTH]='\0';
-
- DegugPrintf(buffer,7);
- SendUSART2Str("\n");
-
- if((buffer[1]==idBuf[0])&& (buffer[2]==idBuf[1])&&(buffer[3]==idBuf[2])&&(buffer[4]==idBuf[3])&&(buffer[5]==idBuf[4])) //յд
- {
- if(rspFlag == 1)
- {
- rspFlag++;
- txBuf[1] = 0x12; ///0xfc + cmd(0x12) +id +crc ----cmd=0x12 ȷ
- txBuf[7] = CheckSum(txBuf,7); //дŵtxBuf
- SPI2_CE =0;
- NRF24L01_Write_Buf(SPI_SEND,W_ACK_PAYLOAD,txBuf,8); //дݵTX BUF 8ֽڣԶ
- SPI2_CE =1;
- }
- else
- {
- rspFlag=0; //IDѾ£rspFlag㣬
-
- DegugPrintf(uartSendWrNumOkData,14);
- SendUSART2Str("\n");
-
- //NRF24L01_RX_Mode_NOACK(SPI_SEND);//
- #if APP
- NRF24L01_RX_Mode_NOACK(SPI_SEND,protocol_config_flg);//???
- #else
- NRF24L01_RX_Mode_NOACK(SPI_SEND);//
- #endif
- WrNumOkBuf->Control = 0x10; //д
- SendConsoleData((char*)uartSendWrNumOkData,14); //ԣظPC
-
- SendUSART2Str("OK\n");
- return 1;
- }
-
- }
- else
- {
- SPI2_CE =0;
- txBuf[1] = 0x11;
- txBuf[7] = CheckSum(txBuf,7); //дŵtxBuf
- NRF24L01_Write_Buf(SPI_SEND,W_ACK_PAYLOAD,txBuf,8); //дݵTX BUF 8ֽ
- SPI2_CE =1;
-
- }
- }
-
- }
- }
- else
- {
- idBuf[0] = 0;
- idBuf[1] = 0x00;
- idBuf[2] = 0x00;
- idBuf[3] = 0x00;
- idBuf[4] = 0x00;
- ReadAttenID[0]=0;
- ReadAttenID[1]=0;
- ReadAttenID[2]=0;
- ReadAttenID[3]=0;
- ReadAttenID[4]=0;
- ResNum_1356[0]=0;
- ResNum_1356[1]=0;
- ResNum_1356[2]=0;
- ResNum_1356[3]=0;
- ResNum_1356[4]=0;
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
- WrNumOkBuf->Control = 0x30; //дʧ
- SendConsoleData((char*)uartSendWrNumOkData,14); //ԣظPC
- // USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //ʼ1ж
- SendUSART2Str("3000\n");
- return 1;
- }
- IWDG_Feed();
- return 0;
- }
-
-
- u8 DataProc_A3_nrf(void)
- {
- u8 temp;
- u8 buffer[32];
-
- if(rspFlag_A3)
- {
- rspFlag_A3=0;
- SPI2_CE = 0;
- NRF24L01_Write_Reg(SPI_SEND,FLUSH_TX,0xff);//TX FIFOĴ
- NRF24L01_Write_Buf(SPI_SEND,W_ACK_PAYLOAD,txA3Buf,8); //дݵTX BUF 8ֽڣԶ
- NRF24L01_RX_Mode(SPI_SEND); //24L01Ϊģʽ
- SPI2_CE = 1;
- }
- if(count_A34<1500)
- {
- if(SPI2_IRQ == 0) //24L01յϵ緢͵
- {
- IWDG_Feed();
- temp = NRF24L01_RxPacket(SPI_SEND,buffer);
-
-
-
- if((temp&0x40)==0x40) //յʾ
- {
- buffer[RX_PLOAD_WIDTH]='\0';
-
- DegugPrintf(buffer,7);
- SendUSART2Str("\n");
-
- if((buffer[1]==0)&& (buffer[2]==0)&&(buffer[3]==0)&&(buffer[4]==0)&&(buffer[5]==0)) //δд
- {
- idResA3Buf[0] = 0;
- idResA3Buf[1] = 0;
- idResA3Buf[2] = 0;
- idResA3Buf[3] = 0;
- idResA3Buf[4] = 0;
- // USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //ʼ1ж
- return 1;
- }
- else
- {
- idResA3Buf[0] = buffer[1];
- idResA3Buf[1] = buffer[2];
- idResA3Buf[2] = buffer[3];
- idResA3Buf[3] = buffer[4];
- idResA3Buf[4] = buffer[5];
- // USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //ʼ1ж
- return 1;
- }
-
- }
- }
- IWDG_Feed();
- }
- else
- {
- idResA3Buf[0] = 0;
- idResA3Buf[1] = 0x00;
- idResA3Buf[2] = 0x00;
- idResA3Buf[3] = 0x00;
- idResA3Buf[4] = 0x00;
- // USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //ʼ1ж
- return 1;
- }
- return 0;
- }
-
- u8 DataProc_A4_nrf(void)
- {
- u8 temp;
- u8 buffer[32];
- if(count_A34<3000)
- {
- if(SPI2_IRQ == 0) //24L01յϵ緢͵
- {
- IWDG_Feed();
- temp = NRF24L01_RxPacket(SPI_SEND,buffer);
-
- if((temp&0x40)==0x40) //յʾ
- {
- buffer[RX_PLOAD_WIDTH]='\0';
-
- //DegugPrintf(buffer,7);
- //SendUSART2Str("\n");
- //SendConsoleData(buffer,32); //ԣظPC
- if((buffer[1]==0)&& (buffer[2]==0)&&(buffer[3]==0)) //δд
- {
- ReadAttenID[0] = 0;
- ReadAttenID[1] = 0;
- ReadAttenID[2] = 0;
- ReadAttenID[3] = 0;
- ReadAttenID[4] = 0;
- return 1;
- }
- else
- {
- if((protocol_config_flg == 7)||(protocol_config_flg == 13))
- {
- ReadAttenID[0] = 0;
- ReadAttenID[1] = buffer[0];
- ReadAttenID[2] = buffer[1];
- ReadAttenID[3] = buffer[2];
- ReadAttenID[4] = buffer[3];
- }
- else if((protocol_config_flg == 8))
- {
- ReadAttenID[0] = buffer[1];
- ReadAttenID[1] = buffer[2];
- ReadAttenID[2] = buffer[3];
- ReadAttenID[3] = buffer[4];
- ReadAttenID[4] = buffer[5];
- }
- else if((protocol_config_flg == 9)||(protocol_config_flg == 14))
- {
- ReadAttenID[0] = 0;
- ReadAttenID[1] = (buffer[1]^0x53);
- ReadAttenID[2] = (buffer[2]^0x43);
- ReadAttenID[3] = (buffer[3]^0x44);
- ReadAttenID[4] = (buffer[4]^0x58);
-
- }
- else if(protocol_config_flg == 20)
- {
- ReadAttenID[0] = 0;
- ReadAttenID[1] = buffer[4];
- ReadAttenID[2] = buffer[5];
- ReadAttenID[3] = buffer[6];
- ReadAttenID[4] = buffer[7];
- }
- else
- {
- ReadAttenID[0] = 0;
- ReadAttenID[1] = buffer[1];
- ReadAttenID[2] = buffer[2];
- ReadAttenID[3] = buffer[3];
- ReadAttenID[4] = buffer[4];
- }
- return 1;
- }
-
- }
- }
- IWDG_Feed();
- }
- else
- {
- ReadAttenID[0] = 0;
- ReadAttenID[1] = 0;
- ReadAttenID[2] = 0;
- ReadAttenID[3] = 0;
- ReadAttenID[4] = 0;
- return 1;
- }
- return 0;
- }
-
-
-
- void DataProc_USART1(void)
- {
- // u8 i;
- // u16 reclen;
- // u32 IdData;
- // u8 IdBuf[10]={0};
- IWDG_Feed();
-
- if(USART1_RX_CNT==8 && USART1_RX_BUF[0]=='u' && USART1_RX_BUF[1]=='p' && USART1_RX_BUF[2]=='d' && USART1_RX_BUF[3]=='a' && USART1_RX_BUF[4]=='t' && USART1_RX_BUF[5]=='e' )
- {
- USART1_RX_CNT =0;
- NVIC_SystemReset(); //ϵͳλ
- }
-
- if(USART1_RX_BUF[0]!='u' && USART1_RX_BUF[0]!=0xFA)
- {
- USART1_RX_CNT =0;
- return;
- }
-
- if(USART1_RX_CNT < 14)
- {
- return;
- }
- if(USART1_RX_BUF[USART1_RX_CNT-1] != 0xFB)
- {
- return;
- }
- if(USART1_RX_BUF[10]==0xA0 && USART1_RX_CNT != 21)
- {
- return;
- }
-
- if(USART1_RX_CNT == 14) //һָ־
- {
-
- if(USART1_RX_BUF[0]==0xFA && USART1_RX_BUF[13]==0xFB)//ͷβ
- {
- USART1_REC_Status |= 0x8000;
- USART1_RX_CNT = 0;
- // SendUartData(USART1_RX_BUF,14,USART2);
- DegugPrintf(USART1_RX_BUF,14);
- SendUSART2Str("\n");
- }
- else
- {
- USART1_RX_CNT = 0;
- USART1_REC_Status = 0; //ճȷͷβûͨ
- }
- }
- else if(USART1_RX_CNT == 21)
- {
-
- if(USART1_RX_BUF[0]==0xFA && USART1_RX_BUF[20]==0xFB)//ͷβ
- {
- USART1_REC_Status |= 0x8000;
- USART1_RX_CNT = 0;
- // SendUartData(USART1_RX_BUF,21,USART2);
- DegugPrintf(USART1_RX_BUF,21);
- SendUSART2Str("\n");
- }
- else
- {
- USART1_RX_CNT = 0;
- USART1_REC_Status = 0; //ճȷͷβûͨ
- }
- }
- else if(USART1_RX_CNT == 17)
- {
- if(USART1_RX_BUF[0]==0xFA && USART1_RX_BUF[16]==0xFB)//ͷβ
- {
- USART1_REC_Status |= 0x8000;
- USART1_RX_CNT = 0;
- // SendUartData(USART1_RX_BUF,21,USART2);
- DegugPrintf(USART1_RX_BUF,17);
- SendUSART2Str("\n");
- }
- else
- {
- USART1_RX_CNT = 0;
- USART1_REC_Status = 0; //ճȷͷβûͨ
- }
- }
-
-
-
- if(USART1_REC_Status & 0x8000) //һ֡
- {
- // DegugPrintf(USART1_RX_BUF,strlen(USART1_RX_BUF));
- // printf("len=%d\n",USART1_RX_CNT);
-
-
- IWDG_Feed();
- // printf("Rec = %d\r\n",USART1_RX_CNT);
- ReceiveBuf->SequenceID[0] = USART1_RX_BUF[6];
- ReceiveBuf->SequenceID[1] = USART1_RX_BUF[7];
- ReceiveBuf->SequenceID[2] = USART1_RX_BUF[8];
- ReceiveBuf->SequenceID[3] = USART1_RX_BUF[9];
-
- ReceiveBuf->Command = USART1_RX_BUF[10]; //
- // ReceiveBuf->Tag = USART1_RX_BUF[11]; //Tag
- // ReceiveBuf->Length = USART1_RX_BUF[12]; //ݳ
-
- SendBuf->SequenceID[0] = ReceiveBuf->SequenceID[0];
- SendBuf->SequenceID[1] = ReceiveBuf->SequenceID[1];
- SendBuf->SequenceID[2] = ReceiveBuf->SequenceID[2];
- SendBuf->SequenceID[3] = ReceiveBuf->SequenceID[3]; //SequenceIDͬ
-
- //USART1_REC_Status = 0;
- //USART1_RX_CNT =0;
-
-
- switch(ReceiveBuf->Command)
- {
- case Reset: //λ
- // printf("Reset\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case GetFirmversion: //ȡ̼汾
- // printf("GetFirmversion\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case SetReaderID: //ĶID
- // printf("SetReaderID\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case GetReaderID: //ȡĶID
- // printf("GetReaderID\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case DelWhite: //ɾ
- // printf("DelWhite\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case OpenWhite: //
- // printf("OpenWhite\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case CloseWhite: //رհ
- // printf("CloseWhite\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case AddWhite: //Ӱ
- // printf("AddWhite\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case GetWhite: //ȡ
- // printf("GetWhite\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case Heart: //
- // printf("Heart\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case GetWhiteState: //ȡ״̬
- // printf("GetWhiteState\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case WriteNum: //д A0
- //FA 00 00 00 00 00 00 00 00 00 A0 01 05 00 01 02 03 04 00 00 FB --21byte
- // printf("д 2.4G \n");
- // DegugPrintf(USART1_RX_BUF,21);
- // SendUSART2Str("\n");
- {
- u8 tmp;
- //ݴ
- USART1_RX_CNT = 0;
- WrNumOkBuf->SequenceID[0] = ReceiveBuf->SequenceID[0];
- WrNumOkBuf->SequenceID[1] = ReceiveBuf->SequenceID[1];
- WrNumOkBuf->SequenceID[2] = ReceiveBuf->SequenceID[2];
- WrNumOkBuf->SequenceID[3] = ReceiveBuf->SequenceID[3]; //SequenceIDͬ
-
- WrNumOkBuf->Command = ReceiveBuf->Command;
-
- ReceiveBuf->Value[0] = USART1_RX_BUF[13];
- ReceiveBuf->Value[1] = USART1_RX_BUF[14];
- ReceiveBuf->Value[2] = USART1_RX_BUF[15];
- ReceiveBuf->Value[3] = USART1_RX_BUF[16];
- ReceiveBuf->Value[4] = USART1_RX_BUF[17];
-
- idBuf[0] = USART1_RX_BUF[13];
- idBuf[1] = USART1_RX_BUF[14];
- idBuf[2] = USART1_RX_BUF[15];
- idBuf[3] = USART1_RX_BUF[16];
- idBuf[4] = USART1_RX_BUF[17];
-
- newIdFlag = 1; //2.4Gд
- count = 0; //ʱ
- NRF24L01_RX_Mode(SPI_SEND);
-
- SendUSART2Str("0000\n");
- while(1) //
- {
-
- tmp = DataProc_A0_WriteNum_SPI2();
-
- if(tmp)
- break;
- }
- SendUSART2Str("0000\n");
-
- ReadAttenID[0]=0;
- ReadAttenID[1]=0;
- ReadAttenID[2]=0;
- ReadAttenID[3]=0;
- ReadAttenID[4]=0;
- ResNum_1356[0]=0;
- ResNum_1356[1]=0;
- ResNum_1356[2]=0;
- ResNum_1356[3]=0;
- ResNum_1356[4]=0;
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
-
- // USART1_REC_Status = 0;
- // USART1_RX_CNT =0;
- // for(i=0;i<30;i++)
- // {
- // USART3_RX_BUF[i] = 0;
- // }
- ReceiveBuf->Command = 0; //
- }
-
-
- break;
-
- case WriteNumState: //дŽϱ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case Read_1345Num: //13.45M A2
- //FA 00 00 00 00 00 00 00 00 00 A2 00 00 FB
- if(first_clear_flag == 0)
- {
- memset(ResNum_1356,0,5);
- //memset(oldResNum_1356,0,5);
- first_clear_flag = 1;
- }
- if((ResNum_1356[1] == 0) && (ResNum_1356[2] == 0)&& (ResNum_1356[3] == 0)&&(ResNum_1356[4] ==0))
- {
- break;
- }
- //ledL;
- USART1_RX_CNT = 0;
- ReadNumBuf->SequenceID[0] = ReceiveBuf->SequenceID[0];
- ReadNumBuf->SequenceID[1] = ReceiveBuf->SequenceID[1];
- ReadNumBuf->SequenceID[2] = ReceiveBuf->SequenceID[2];
- ReadNumBuf->SequenceID[3] = ReceiveBuf->SequenceID[3]; //SequenceIDͬ
-
- ReadNumBuf->Command = ReceiveBuf->Command;
- ReadNumBuf->Tag1 = 1;
- ReadNumBuf->Length1 = 6;
- ReadNumBuf->Value1[0] = 0; //len=0 Ч
- ReadNumBuf->Value1[1] = ResNum_1356[0];
- ReadNumBuf->Value1[2] = ResNum_1356[1];
- ReadNumBuf->Value1[3] = ResNum_1356[2];
- ReadNumBuf->Value1[4] = ResNum_1356[3];
- ReadNumBuf->Value1[5] = ResNum_1356[4];
-
- // SendUartData(uartSendRdNumData,22,USART2);
-
- SendConsoleData((char*)uartSendRdNumData,22); //ԣظPC
- delay_ms(50);
-
- DegugPrintf(uartSendRdNumData,22);
- SendUSART2Str("\n");
- //ledH;
- ResNum_1356[0]=0;
- ResNum_1356[1]=0;
- ResNum_1356[2]=0;
- ResNum_1356[3]=0;
- ResNum_1356[4]=0;
- // USART1_REC_Status = 0;
- // USART1_RX_CNT =0;
- // for(i=0;i<30;i++)
- // {
- // USART3_RX_BUF[i] = 0;
- // }
- first_clear_flag = 0;
-
- ReceiveBuf->Command = 0; //
- // ledH;
- break;
-
- case Read_24Num: //A3 һ2.4G
- //FA 00 00 00 00 00 00 00 00 00 A3 00 00 FB
- /* USART1_RX_CNT = 0;
- NRF24L01_RX_Mode(SPI_SEND);
- count_A34 = 0;
- rspFlag_A3 = 1;
-
- {
- u8 tmp;
- SendUSART2Str("3333\n");
- while(1) //
- {
-
- tmp = DataProc_A3_nrf();
-
- if(tmp)
- break;
- }
- SendUSART2Str("3333\n");
- ReadNumBuf->SequenceID[0] = ReceiveBuf->SequenceID[0];
- ReadNumBuf->SequenceID[1] = ReceiveBuf->SequenceID[1];
- ReadNumBuf->SequenceID[2] = ReceiveBuf->SequenceID[2];
- ReadNumBuf->SequenceID[3] = ReceiveBuf->SequenceID[3]; //SequenceIDͬ
-
- ReadNumBuf->Command = ReceiveBuf->Command;
- ReadNumBuf->Tag1 = 1;
- ReadNumBuf->Length1 = 6;
- ReadNumBuf->Value1[0] = 0; //len=0 Ч
- ReadNumBuf->Value1[1] = idResA3Buf[0];
- ReadNumBuf->Value1[2] = idResA3Buf[1];
- ReadNumBuf->Value1[3] = idResA3Buf[2];
- ReadNumBuf->Value1[4] = idResA3Buf[3];
- ReadNumBuf->Value1[5] = idResA3Buf[4];
-
-
- DegugPrintf(uartSendRdNumData,22);
- SendUSART2Str("\n");
-
- SendConsoleData(uartSendRdNumData,22); //ԣظPC
- delay_ms(50);
-
-
- //дֹһдӰ
- ReadAttenID[0]=0;
- ReadAttenID[1]=0;
- ReadAttenID[2]=0;
- ReadAttenID[3]=0;
- ReadAttenID[4]=0;
- ResNum_1356[0]=0;
- ResNum_1356[1]=0;
- ResNum_1356[2]=0;
- ResNum_1356[3]=0;
- ResNum_1356[4]=0;
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
-
- // USART1_REC_Status = 0;
- // USART1_RX_CNT =0;
- // for(i=0;i<30;i++)
- // {
- // USART3_RX_BUF[i] = 0;
- // }
- ReceiveBuf->Command = 0; //
-
- }
-
- */ break;
-
- case ReadCardNum: //A4
- USART1_RX_CNT = 0;
- //SendConsoleByte(protocol_config_flg); //ԣظPC
- //NRF24L01_RX_Mode_NOACK(SPI_SEND);//NOACKģʽ
- #if APP
- NRF24L01_RX_Mode_NOACK(SPI_SEND,protocol_config_flg);//NOACK??,?????
- #else
- NRF24L01_RX_Mode_NOACK(SPI_SEND);////NOACKģʽ
- #endif
- count_A34 = 0;
- {
- u8 tmp;
- SendUSART2Str("4444\n");
- while(1) //
- {
-
- tmp = DataProc_A4_nrf();
-
- if(tmp)
- break;
- }
-
- SendUSART2Str("4444\n");
- ReadNumBuf->SequenceID[0] = ReceiveBuf->SequenceID[0];
- ReadNumBuf->SequenceID[1] = ReceiveBuf->SequenceID[1];
- ReadNumBuf->SequenceID[2] = ReceiveBuf->SequenceID[2];
- ReadNumBuf->SequenceID[3] = ReceiveBuf->SequenceID[3]; //SequenceID
-
- ReadNumBuf->Command = ReceiveBuf->Command;
- ReadNumBuf->Tag1 = 1;
- ReadNumBuf->Length1 = 6;
- ReadNumBuf->Value1[0] = 0; //
- ReadNumBuf->Value1[1] = ReadAttenID[0];
- ReadNumBuf->Value1[2] = ReadAttenID[1];
- ReadNumBuf->Value1[3] = ReadAttenID[2];
- ReadNumBuf->Value1[4] = ReadAttenID[3];
- ReadNumBuf->Value1[5] = ReadAttenID[4];
-
-
- SendConsoleData((char*)uartSendRdNumData,22); //ԣظPC
- delay_ms(50);
-
- DegugPrintf(uartSendRdNumData,22);
- SendUSART2Str("\n");
-
- //дֹһдӰ
- ReadAttenID[0]=0;
- ReadAttenID[1]=0;
- ReadAttenID[2]=0;
- ReadAttenID[3]=0;
- ReadAttenID[4]=0;
- ResNum_1356[0]=0;
- ResNum_1356[1]=0;
- ResNum_1356[2]=0;
- ResNum_1356[3]=0;
- ResNum_1356[4]=0;
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
- //memset(ResNum_1356,0,5);
-
- ReceiveBuf->Command = 0; //
-
- }
- break;
- #if APP1
- case Config24Agreement:
-
- protocol_config_flg = USART1_RX_BUF[13];
- ConfigKaoQinBuf->SequenceID[0] = ReceiveBuf->SequenceID[0];
- ConfigKaoQinBuf->SequenceID[1] = ReceiveBuf->SequenceID[1];
- ConfigKaoQinBuf->SequenceID[2] = ReceiveBuf->SequenceID[2];
- ConfigKaoQinBuf->SequenceID[3] = ReceiveBuf->SequenceID[3]; //SequenceID
- ConfigKaoQinBuf->Command = ReceiveBuf->Command;
- ConfigKaoQinBuf->Control =0x01;
- SendConsoleData((char*)uartSendConfigKaoQinData,14); //ԣظPC
- delay_ms(50);
- #if 1
- StoreBuffer[0] = protocol_config_flg;//Э汾
- SavePara_to_flash(); //ݵFlash
- //Readpara_from_flash(); //ݲӡ
- //protocol_config_flg = Save_Buffer[2*0];
- #endif
- //SendConsoleByte(protocol_config_flg); //ԣظPC
- //SendConsoleByte(0xff);
- //SendConsoleByte(protocol_config_flg);
- //дֹһдӰ
- ReadAttenID[0]=0;
- ReadAttenID[1]=0;
- ReadAttenID[2]=0;
- ReadAttenID[3]=0;
- ReadAttenID[4]=0;
- ResNum_1356[0]=0;
- ResNum_1356[1]=0;
- ResNum_1356[2]=0;
- ResNum_1356[3]=0;
- ResNum_1356[4]=0;
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
- ReceiveBuf->Command = 0; //??
-
- break;
- #endif
- case UpdateFirmversion: //̼
- // printf("UpdateFirmversion\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case UpdateFirm: //̼
- // printf("UpdateFirm\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- case UpdateFirmState: //̼ϱ
- // printf("UpdateFirmState\n");
- //ݴ
-
- ReceiveBuf->Command = 0; //
- break;
-
- default:
- break;
- }
-
-
-
- USART1_REC_Status = 0; //
- //USART1_RX_CNT = 0;
-
- }
-
- }
-
- void DataProc_Nrf24l01(void)
- {
- u8 buffer[32];
- u8 temp;
- IWDG_Feed();
-
- if(newIdFlag==1)
- {
- newIdFlag = 0;
- recFlag = 0;
- txBuf[0] = 0xfc;
- txBuf[1] = 0x11;
- if(idBuf[0]==GetNum_1356[0] && idBuf[1]==GetNum_1356[1] && idBuf[2]==GetNum_1356[2] && idBuf[3]==GetNum_1356[3] && idBuf[4]==GetNum_1356[4])
- {
- txBuf[2] = idBuf[0];
- txBuf[3] = idBuf[1];
- txBuf[4] = idBuf[2];
- txBuf[5] = idBuf[3];
- txBuf[6] = idBuf[4];
- }
-
- txBuf[7] = CheckSum(txBuf,7); //дŵtxBuf
- SPI1_CE =0;
- NRF24L01_Write_Reg(SPI_REV,FLUSH_TX,0xff);//TX FIFOĴ
- NRF24L01_Write_Buf(SPI_REV,W_ACK_PAYLOAD,txBuf,8); //дݵTX BUF 8ֽڣԶ
- NRF24L01_RX_Mode(SPI_REV); //24L01Ϊģʽ
- rspFlag = 1;
- count=0;
- IWDG_Feed();
-
- }
-
-
-
- if(rspFlag) //ϵ緢͵
- {
- IWDG_Feed();
- if(count<=2000) //1.5Sδյ2.4GظźţrspFlagʧЧ
- {
- if(SPI1_IRQ == 0) //24L01յϵ緢͵
- {
- IWDG_Feed();
- temp = NRF24L01_RxPacket(SPI_REV,buffer);
- // SendConsoleByte(temp);
-
- if((temp&0x40)==0x40) //յʾ
- {
- buffer[RX_PLOAD_WIDTH]='\0';
- led0=~led0;
-
- // SendConsoleData(buffer,RX_PLOAD_WIDTH); //
-
- if((buffer[1]==idBuf[0])&& (buffer[2]==idBuf[1])&&(buffer[3]==idBuf[2])&&(buffer[4]==idBuf[3])&&(buffer[5]==idBuf[4])) //յд
- {
- if((buffer[1]==GetNum_1356[0])&& (buffer[2]==GetNum_1356[1])&&(buffer[3]==GetNum_1356[2])&&(buffer[4]==GetNum_1356[3])&&(buffer[5]==GetNum_1356[4]))
- {
- if(rspFlag == 1)
- {
- rspFlag++;
- txBuf[1] = 0x12; ///0xfc + cmd(0x12) +id +crc ----cmd=0x12 ȷ
- txBuf[7] = CheckSum(txBuf,7); //дŵtxBuf
- NRF24L01_Write_Buf(SPI_REV,W_ACK_PAYLOAD,txBuf,8); //дݵTX BUF 8ֽڣԶ
- }
- else
- {
- rspFlag=0; //IDѾ£rspFlag㣬
- count = 0; //
- idBuf[0]=0;
- WrNumOkBuf->Control = 0x10; //д
- SendConsoleData((char*)uartSendWrNumOkData,14); //ԣظPC
-
- }
- }
-
-
- }
- else
- {
- SPI1_CE =0;
- txBuf[1] = 0x11;
- txBuf[7] = CheckSum(txBuf,7); //дŵtxBuf
- NRF24L01_Write_Buf(SPI_REV,W_ACK_PAYLOAD,txBuf,8); //дݵTX BUF 8ֽ
- SPI1_CE =1;
- }
- }
- }
-
- }
- else //2sʱظ
- {
- IWDG_Feed();
- rspFlag=0; //IDѾ£rspFlag㣬
- count = 0; //
-
- idBuf[0]=0;
- idBuf[1]=0;
- idBuf[2]=0;
- idBuf[3]=0;
- idBuf[4]=0;
- GetNum_1356[0]=0;
- GetNum_1356[1]=0;
- GetNum_1356[2]=0;
- GetNum_1356[3]=0;
- GetNum_1356[4]=0;
-
- WrNumOkBuf->Control = 0x30; //
- SendConsoleData((char*)uartSendWrNumOkData,14); //ԣظPC
- }
-
- }
- }
-
- //------------------------------------------------------------------
- //void TIM3_IRQHandler(void)
- //null
- //زnull
- //˵ʱ3жϷ
- //------------------------------------------------------------------
- void TIM3_IRQHandler(void)
- {
- if(TIM_GetITStatus(TIM3,TIM_IT_Update)!=RESET) //жǷΪʱ3ж
- {
- TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //жϱ
- count ++;
- count_A34 ++;
- count_num ++;
- if(HW_Open)
- {
- GPIO_SetBits(GPIOC,GPIO_Pin_9); //ɨǹ
- HW_OpenCount ++;
- if(HW_OpenCount>=400)
- {
- GPIO_ResetBits(GPIOC,GPIO_Pin_9); //رպɨǹ
- HW_OpenCount = 0;
- HW_Open = 0;
- }
-
- }
- if(count_num==5000)
- {
- count_num = 0;
- // printf("1356_0=%x\r\n",GetNum_1356[0]);
- // printf("1356_1=%x\r\n",GetNum_1356[1]);
- // printf("1356_2=%x\r\n",GetNum_1356[2]);
- // printf("1356_3=%x\r\n",GetNum_1356[3]);
- // printf("1356_4=%x\r\n",GetNum_1356[4]);
- //
- // printf("2.4G_0=%x\r\n",idBuf[0]);
- // printf("2.4G_1=%x\r\n",idBuf[1]);
- // printf("2.4G_2=%x\r\n",idBuf[2]);
- // printf("2.4G_3=%x\r\n",idBuf[3]);
- // printf("2.4G_4=%x\r\n",idBuf[4]);
- }
- flag_1ms = 1;
- }
- }
|