20260324
This commit is contained in:
339
IAPV1.1/Driver/BC25/BC25.c
Normal file
339
IAPV1.1/Driver/BC25/BC25.c
Normal file
@ -0,0 +1,339 @@
|
||||
#include "general_type.h"
|
||||
#include "bc25.h"
|
||||
#include "delay.h"
|
||||
#include "bsp.h"
|
||||
|
||||
BC25 BC25_Status;
|
||||
void BC25CTR_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
PWRKEY_L;
|
||||
}
|
||||
//ģ<>鿪<EFBFBD><E9BFAA>
|
||||
void BC25_PWRKEY_ON(void)
|
||||
{
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_1);
|
||||
delay_ms(200);
|
||||
delay_ms(1000);
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
|
||||
}
|
||||
void BC25_POWERON(void)
|
||||
{
|
||||
PWR_CTRLBC25_H;
|
||||
}
|
||||
void BC25_POWEROFF(void)
|
||||
{
|
||||
PWR_CTRLBC25_L;
|
||||
}
|
||||
u8 BC25_Init(void)
|
||||
{
|
||||
u8 i=0;
|
||||
char *strx;
|
||||
BC25CTR_Init();
|
||||
BC25_POWERON();
|
||||
delay_ms(1000);
|
||||
BC25_PWRKEY_ON();
|
||||
strx=NULL;
|
||||
while((!strx)&(i<10))
|
||||
{
|
||||
i++;
|
||||
strx=strstr((const char*)USART2_RX_BUF,"+CPIN: READY");//<2F><><EFBFBD><EFBFBD>OK
|
||||
delay_ms(1000);
|
||||
|
||||
}
|
||||
strx=NULL;
|
||||
while((!strx)&(i<10))
|
||||
{
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT\r\n");
|
||||
delay_ms(500);
|
||||
strx=strstr((const char*)USART2_RX_BUF,"OK");//<2F><><EFBFBD><EFBFBD>OK
|
||||
if(!strx)
|
||||
{
|
||||
// BC25_POWEROFF();
|
||||
// delay_ms(300);
|
||||
BC25_POWERON();
|
||||
delay_ms(500);
|
||||
BC25_PWRKEY_ON();
|
||||
// delay_ms(500);
|
||||
|
||||
}
|
||||
u5_printf("AT....\r\n");
|
||||
i++;
|
||||
// if(i>9)return 1;
|
||||
}
|
||||
printf("AT+QSELFREGISTER=1\r\n"); //<2F>Զ<EFBFBD>ע<EFBFBD><D7A2>
|
||||
delay_ms(300);
|
||||
printf("ATE0\r\n"); //<2F>رջ<D8B1><D5BB><EFBFBD>
|
||||
delay_ms(1000);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"OK");//<2F><><EFBFBD><EFBFBD>OK
|
||||
printf("AT+CPSMS=0\r\n");//<2F><><EFBFBD><EFBFBD>PSM
|
||||
delay_ms(1000);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"OK");//<2F><><EFBFBD><EFBFBD>OK
|
||||
printf("AT+CPIN=?\r\n");//<2F><><EFBFBD><EFBFBD>SIM<49><4D>
|
||||
delay_ms(300);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"OK");//<2F><><EFBFBD><EFBFBD>OK
|
||||
if(!strx)//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||
{
|
||||
u5_printf("AT+CPIN=fail\r\n");//<2F><><EFBFBD><EFBFBD>SIM<49><4D>
|
||||
return 1;
|
||||
}
|
||||
|
||||
USART2_ReceiveBuff_Clear();
|
||||
|
||||
printf("AT+CGATT?\r\n");//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>״̬
|
||||
delay_ms(1000);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CGATT: 1");//<2F><>1
|
||||
i=0;
|
||||
while((i<15)&(!strx))
|
||||
{
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+CGATT?\r\n");//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>״̬
|
||||
delay_ms(2000);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CGATT: 1");//<2F><>1
|
||||
i++;
|
||||
}
|
||||
printf("AT+CESQ\r\n");//<2F>鿴<EFBFBD><E9BFB4>ȡCSQֵ
|
||||
delay_ms(300);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CESQ");//<2F><><EFBFBD><EFBFBD>CSQ
|
||||
if(strx)
|
||||
{
|
||||
BC25_Status.CSQ=(strx[7]-0x30)*10+(strx[8]-0x30);//<2F><>ȡCSQ
|
||||
if((BC25_Status.CSQ==99)||((strx[7]-0x30)==0))//˵<><CBB5>ɨ<EFBFBD><C9A8>ʧ<EFBFBD><CAA7>
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
BC25_Status.netstatus=1;
|
||||
}
|
||||
|
||||
}
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+CSQ\r\n");//
|
||||
delay_ms(500);
|
||||
u5_printf("AT+CSQ:%s\r\n",(const char*)USART2_RX_BUF);
|
||||
return 0; //<2F><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>
|
||||
}
|
||||
void BC25_CloseSocket(void)
|
||||
{
|
||||
char *strx;
|
||||
u8 i=0;
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+QICLOSE=0\r\n");//<2F>ر<EFBFBD>socekt<6B><74><EFBFBD><EFBFBD>
|
||||
delay_ms(500);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"CLOSE OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>
|
||||
while((!strx)&(i<3))
|
||||
{
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+QICLOSE=0\r\n");//<2F>ر<EFBFBD>socekt<6B><74><EFBFBD><EFBFBD>
|
||||
delay_ms(500);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"CLOSE OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>
|
||||
u5_printf("BC25_CloseSocket %d\r\n",i);
|
||||
u5_printf("USART2_RX_BUF:%s\r\n",(const char*)USART2_RX_BUF);
|
||||
i++;
|
||||
}
|
||||
if(strx)
|
||||
{
|
||||
u5_printf("BC25_CloseSocket OK");
|
||||
return;
|
||||
}
|
||||
if(!strx)
|
||||
{
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+QICLOSE=0\r\n");//<2F>ر<EFBFBD>socekt<6B><74><EFBFBD><EFBFBD>
|
||||
delay_ms(500);
|
||||
u5_printf("BC25_CloseSocket 2");
|
||||
}
|
||||
}
|
||||
void BC25_CreateSokcet(char *ip,char *port)//<2F><><EFBFBD><EFBFBD>sokcet
|
||||
{
|
||||
char *strx;
|
||||
u8 i=0;
|
||||
USART2_ReceiveBuff_Clear();
|
||||
// printf("AT+QIOPEN=1,0,\"TCP\",\"219.238.240.58\",9022,0,1\r\n");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TCP,<2C><><EFBFBD><EFBFBD>IP<49>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ں<CBBF><DABA><EFBFBD> ,<2C><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>³<EFBFBD><C2B3>ķ<EFBFBD>ʽ
|
||||
printf("AT+QIOPEN=1,0,\"TCP\",%s,%s,0,1\r\n",Init_Data_Equipment.Bc25_Ip,Init_Data_Equipment.Bc25_Port);
|
||||
delay_ms(1000);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+QIOPEN: 0,0");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>½<EFBFBD>ɹ<EFBFBD>
|
||||
while((!strx)&(i<5))
|
||||
{
|
||||
BC25_CloseSocket();
|
||||
delay_ms(500);
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+QIOPEN=1,0,\"TCP\",%s,%s,0,1\r\n",Init_Data_Equipment.Bc25_Ip,Init_Data_Equipment.Bc25_Port);//219.238.240.58 9022
|
||||
delay_ms(1000);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+QIOPEN: 0,0");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>½<EFBFBD>ɹ<EFBFBD>
|
||||
i++;
|
||||
}
|
||||
if(strx)
|
||||
{
|
||||
BC25_Status.socket=1;
|
||||
u5_printf("BC25_CreateSokcet sucess\r\n");
|
||||
}
|
||||
|
||||
if(!strx)
|
||||
{
|
||||
BC25_Status.socket=0;
|
||||
u5_printf("BC25_CreateSokcet fail\r\n");
|
||||
}
|
||||
}
|
||||
/*
|
||||
<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int len <20><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
char *data <20><><EFBFBD><EFBFBD>
|
||||
*/
|
||||
void BC25_Senddata(int len,char *data)
|
||||
{
|
||||
char *strx;
|
||||
char lens[5]={'\0'};
|
||||
u8 times=0;
|
||||
USART2_ReceiveBuff_Clear();
|
||||
sprintf(lens,"%d",len);
|
||||
u5_printf("BC25_Senddata_lens:%s\r\n",lens);
|
||||
printf("AT+QISEND=0,%s,\"%s\"\r\n",lens,data);//AT+QISEND
|
||||
delay_ms(1000);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"SEND OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ͳɹ<CDB3>
|
||||
while((!strx)&&(times<10))
|
||||
{
|
||||
delay_ms(1000);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"SEND OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ͳɹ<CDB3>
|
||||
times++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int len <20><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
char *data <20><><EFBFBD><EFBFBD>
|
||||
*/
|
||||
u8 BC25_Senddata_mode(int len,char *data)
|
||||
{
|
||||
char *strx;
|
||||
// char lens[5]={'\0'};
|
||||
u8 times=0;
|
||||
USART2_ReceiveBuff_Clear();
|
||||
// sprintf(lens,"%d",len);
|
||||
// printf("AT+QISEND=0,%s\r\n",lens);
|
||||
printf("AT+QISEND=0,%d\r\n",len);
|
||||
delay_ms(300);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)">");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>յ<EFBFBD>>
|
||||
while((!strx)&×<20)
|
||||
{
|
||||
times++;
|
||||
// printf("AT+QISEND=0,%d\r\n",len);
|
||||
delay_ms(500);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)">");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>յ<EFBFBD>>
|
||||
if(!strx)
|
||||
{
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+QISEND=0,%d\r\n",len);
|
||||
}
|
||||
}
|
||||
delay_ms(500);
|
||||
printf("%s",data);
|
||||
delay_ms(300);
|
||||
times=0;
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"SEND OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ͳɹ<CDB3>
|
||||
while((!strx)&×<20)
|
||||
{
|
||||
times++;
|
||||
// printf("%s",data);
|
||||
delay_ms(300);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"SEND OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ͳɹ<CDB3>
|
||||
if(!strx)
|
||||
{
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("%s",data);
|
||||
}
|
||||
}
|
||||
if(strx)return 0;
|
||||
else return 1;
|
||||
}
|
||||
|
||||
|
||||
void BC25_RECData(void)
|
||||
{
|
||||
char *strx;
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+QIURC");//<2F><><EFBFBD><EFBFBD>+QIURC
|
||||
if(strx)
|
||||
{
|
||||
USART2_ReceiveBuff_Clear(); //<2F><>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
void BC25_time_RTC(void)
|
||||
{
|
||||
int set_years, set_mons, set_days, set_hours, set_mins , set_secs;
|
||||
u8 i=0;
|
||||
char *strx;
|
||||
BC25CTR_Init();
|
||||
BC25_POWERON();
|
||||
delay_ms(1000);
|
||||
BC25_PWRKEY_ON();
|
||||
delay_ms(8000);
|
||||
//printf("AT+QSELFREGISTER=1\r\n"); //<2F>Զ<EFBFBD>ע<EFBFBD><D7A2>
|
||||
strx=NULL;
|
||||
while((i<60)&(!strx))
|
||||
{
|
||||
i++;
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+CGATT?\r\n");//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>״̬
|
||||
delay_ms(500);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CGATT: 1");//<2F><>1
|
||||
}
|
||||
if(!strx)return;
|
||||
strx=NULL;
|
||||
while((i<60)&(!strx))
|
||||
{
|
||||
USART2_ReceiveBuff_Clear();
|
||||
printf("AT+CCLK?\r\n");//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
delay_ms(500);
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CCLK:");//<2F><>1
|
||||
}
|
||||
if(!strx)return;
|
||||
strx=strstr((const char*)USART2_RX_BUF,(const char*)"\"");//
|
||||
strx++;
|
||||
|
||||
set_years=(strx[0]-'0')*10+(strx[1]-'0');//<2F><>
|
||||
set_mons=(strx[3]-'0')*10+(strx[4]-'0');//<2F><>
|
||||
set_days=(strx[6]-'0')*10+(strx[7]-'0');//<2F><>
|
||||
|
||||
set_hours=(strx[9]-'0')*10+(strx[10]-'0');//ʱ
|
||||
set_mins=(strx[12]-'0')*10+(strx[13]-'0');//<2F><>
|
||||
set_secs=(strx[15]-'0')*10+(strx[16]-'0');//<2F><>
|
||||
if(set_years>20)
|
||||
SetRTC(set_years,set_mons,set_days,set_hours,set_mins,set_secs);
|
||||
|
||||
// printf("AT+QENG=0\r\n");//
|
||||
// delay_ms(500);
|
||||
// u5_printf("AT+QENG=0:%s\r\n",(const char*)USART2_RX_BUF);
|
||||
// USART2_ReceiveBuff_Clear();
|
||||
// printf("AT+CSQ\r\n");//
|
||||
// delay_ms(500);
|
||||
// u5_printf("AT+CSQ:%s\r\n",(const char*)USART2_RX_BUF);
|
||||
// USART2_ReceiveBuff_Clear();
|
||||
// printf("ATI\r\n");//
|
||||
// delay_ms(500);
|
||||
// u5_printf("ATI:%s\r\n",(const char*)USART2_RX_BUF);
|
||||
}
|
||||
|
||||
void BC25_Process(void)
|
||||
{
|
||||
BC25_Init(); //<2F><>ʼ<EFBFBD><CABC>
|
||||
BC25_CloseSocket();//<2F>ر<EFBFBD><D8B1><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BC25_CreateSokcet(Init_Data_Equipment.Bc25_Ip,Init_Data_Equipment.Bc25_Port);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BC25_Senddata_mode(4,"Pub-");
|
||||
BC25_Senddata_mode(strlen(data_common1.Pack_data),(data_common1.Pack_data));
|
||||
BC25_Senddata_mode(2,"\r\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user