系统供电3.3V,USART1串口1中断接收初始化(PA9,PA10),115200波特率,采用中断接收,主动发送,接收完成的处理函数为LOG串口AT指令解析,解析应用代码中有字符串解析测试指令和相关外设模块测试指令,移植时候可以根据项目需求,替换成自己的应用代码即可。同样,前面是头文件代码,后面是应用代码,仅做记录,方便以后移植应用,代码已实测。
#ifndef __USART1_H__
#define __USART1_H__
#include "main.h" //
// #define USART1_DMA 1
#define USART1_RX_LEN 156 //接受数据缓存区长度
#define USART1_TX_LEN 128 //接受数据缓存区长度
struct __USART1_ //串口数据结构体
{
char rxBuf[USART1_RX_LEN]; //接收缓存区
// char txBuf[USART1_TX_LEN]; //发送缓存区
u16 rxLen; //串口1接收到的数据长度
u16 txLen; //串口1接收到的数据长度
u8 rxOkFlag; //RX 数据接收完成标志
u8 txOkFlag; //tx数据发送ready flag
u8 test;
u32 rxTimeOut;
};
extern struct __USART1_ Usart1; //串口数据结构体
void usart1Init(u32 baudRate ); //usart1 initial
void usart1Deal(void); //usart data deal,figure out whether it's data EC800 or data JT808.
#endif
#include "usart1.h"
struct __USART1_ Usart1; //串口数据结构体
void usart1DmaInit(u32 baudRate ) //usart1 initial
{
}
void usart1IntInit(u32 baudRate) //usart initial,interupt rx mode
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_USART1, ENABLE); // Enable USART Clock
// USART_DeInit(USART1);
NVIC_InitType NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; //
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_InitType GPIO_InitStructure;
GPIO_InitStruct(&GPIO_InitStructure); //初始化结构体
/* Configure USARTx Tx as alternate function push-pull */
GPIO_InitStructure.Pin = GPIO_PIN_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
/* Configure USARTx Rx as input floating */
GPIO_InitStructure.Pin = GPIO_PIN_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
// GPIO_ConfigPinRemap(GPIO_RMP_USART1,ENABLE);
USART_InitType USART_InitStructure;
USART_StructInit(&USART_InitStructure);
USART_InitStructure.BaudRate = baudRate;
USART_InitStructure.WordLength = USART_WL_8B;
USART_InitStructure.StopBits = USART_STPB_1;
USART_InitStructure.Parity = USART_PE_NO;
USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX;
USART_Init(USART1, &USART_InitStructure);
USART_ConfigInt(USART1, USART_INT_RXDNE, ENABLE);
// USART_ConfigInt(USART1, USART_INT_TXDE, ENABLE);
USART_Enable(USART1, ENABLE);
// USART_ClrFlag(USART1, USART_FLAG_TXC);
// USART_ClrFlag(USART1, USART_FLAG_RXDNE);
}
void usart1Init(u32 baudRate )
{
#ifdef USART1_DMA
usart1DmaInit(baudRate); //usart initial,DMA rx mode
#else
usart1IntInit(baudRate); //usart initial,interupt rx mode
// printf("-------------------11111-----------------------------------");
#endif
}
void usart1RxBuf(u8 rxData)
{
if(Usart1.rxLen<USART1_RX_LEN)
{
Usart1.rxBuf[Usart1.rxLen++] = rxData;
Usart1.rxTimeOut = 0;
}
else
{
Usart1.rxLen = 0;
}
}
#ifdef USART1_DMA
void USART1_IRQHandler(void) //重写串口中断处理函数
{
uint32_t temp;
if ( (USART_GetIntStatus(USART1, USART_INT_OREF) != RESET) //Overrun error
|| (USART_GetIntStatus(USART1, USART_INT_NEF) != RESET) //Noise error flag
|| (USART_GetIntStatus(USART1, USART_INT_FEF) != RESET) //Framing error
)
{
temp = USART1->STS;
temp = USART1->DAT;
}
if((USART_GetIntStatus(USART1,USART_INT_IDLEF) != RESET))//IDLE line detected
{
temp = USART1->STS;//清IDLE标志
temp = USART1->DAT;
DMA_EnableChannel(DMA1_CH5,DISABLE);
temp = DMA_GetCurrDataCounter(DMA1_CH5); //应该是当前接收数据缓存器剩余空间长度
Usart1.rxLen = USART1_RX_LEN - temp; //计算出当前接收数据长度
DMA1_CH5->TXNUM=USART1_RX_LEN;
DMA_EnableChannel(DMA1_CH5,ENABLE);
if(Usart1.rxLen<=USART1_RX_LEN)
Usart1.rxOkFlag =1; //数据包接收完成标志
//printf("Usart1 data packet Usart1.rxLen = %d.",Usart1.rxLen);
}
}
#else
void USART1_IRQHandler(void)
{
u8 rec = 0;
if (USART_GetIntStatus(USART1, USART_INT_RXDNE) != RESET)
{
USART_ClrIntPendingBit(USART1, USART_INT_RXDNE);
rec = USART_ReceiveData(USART1);
usart1RxBuf(rec);
}
if (USART_GetIntStatus(USART1, USART_INT_TXDE) != RESET)
{
}
if(USART_GetIntStatus(USART1, USART_INT_OREF) != RESET)
{
/*Read the STS register first,and the read the DAT
register to clear the overflow interrupt*/
(void)USART1->STS;
(void)USART1->DAT;
USART_ClrIntPendingBit(USART1,USART_INT_OREF);
}
}
#endif
#ifdef USART1_DMA
void usart1Deal(void) //usart data deal,figure out whether it's data EC800 or data JT808.
{
if(Usart1.rxOkFlag == 1) //数据包接收完成标志
// if((Usart1.rxLen>1)&&(Usart1.rxTimeOut>100))
{
Usart1.rxOkFlag =0;
// if(Usart1.rxBuf[0]==0x7E && Usart1.rxBuf[Usart1.rxLen-1]==0x7E) //JT808数据包
// {
// memcpy(jt808.rxBuf,Usart1.rxBuf,Usart1.rxLen); //copy the data to buf
// jt808.rxLen = Usart1.rxLen; //
// jt808.rxOkFlag = OK; //jt808接收数据包完成标志置位
// }
// else //EC800 AT指令反馈或自动上传数据
{
memcpy(ec800.rxBuf,Usart1.rxBuf,Usart1.rxLen); //copy the data to buf
ec800.rxBufLen = Usart1.rxLen; //
ec800.rxOkFlag = OK;
//if(ec800.debug) log_debug("EC800 receive control CMD ********************************************************* \r\n"); //This code just for test.Edit by kevin.
}
// usartSendBuf(USART3,Usart1.rxBuf,Usart1.rxLen); //发送整包数据到log串口
memset(Usart1.rxBuf,0,Usart1.rxLen); //清零串口数据缓存
Usart1.rxTimeOut = 0;
Usart1.rxLen = 0;
}
}
#else
void usart1Deal(void) //usart data deal,figure out whether it's data EC800 or data JT808.
{
if((Usart1.rxLen>1)&&(Usart1.rxTimeOut>10))
{
Usart1.rxTimeOut = 0;
Usart1.rxOkFlag = 0;
atCmdParser(Usart1.rxBuf,Usart1.rxLen-1);
memset(Usart1.rxBuf,0,USART1_RX_LEN); //清零串口数据缓存
Usart1.rxLen = 0;
}
}
#endif
#ifndef AT_COMMAND_H__
#define AT_COMMAND_H__
#include "main.h"
#define RX_LEN 128 //接受数据缓存区长度
#define TX_LEN 128 //接受数据缓存区长度
struct AT_COMMAND // company AT command structure
{
// char rxBuf[RX_LEN]; //接收缓存区
// char txBuf[RX_LEN]; //发送缓存区
u16 rxLen; //串口1接收到的数据长度
u16 txLen; //串口1接收到的数据长度
u8 rxOkFlag; //RX 数据接收完成标志
u8 txOkFlag; // tx数据发送ready flag
};
// extern struct AT_COMMAND Command ; // company AT command structure.
void atCmdParser(char* rxBuf ,u16 rxLen); // company AT command parser
#endif //AT_COMMAND_H__
#include "at_command.h"
// struct AT_COMMAND Command ; // company AT command structure.
#define AT_ACK() printf("+OK\r\n"); // company AT command general ACK.
void atCmdParser(char* rxBuf ,u16 rxLen) // company AT command parser
{
logSend((u8*)rxBuf,rxLen);
if(strstr(rxBuf,"AT=TESTRESET")!=NULL) // device reset
{
// printf("系统立即重启--------------------测试."); //
GPS_POWER(FALSE); //Turn off the gps.
EC800_POWER_OFF(); //turn of the ec800 power
ODB_POWER(FALSE);//默认关闭ODB电源。
EX_POWER(0); //测试阶段默认打开外电12V电压。1:打开12V 0:关闭12V
delay_ms(100);
printf("系统立即重启---------------测试."); //
NVIC_SystemReset();
// AT_ACK(); // company AT command general ACK.
// NVIC_SystemReset();
}
else if(strstr(rxBuf,"AT=RESET")!=NULL) // device reset
{
printf("The system is ready to restart."); //
Device.reset = TRUE;
AT_ACK(); // company AT command general ACK.
// NVIC_SystemReset();
}
else if(strstr((const char *)rxBuf,"AT=SLEEP,")!=NULL) //AT set sleep and wake up time指令解析。
{
u32 workTime = 0;
u32 days = 0;
u32 sleepTime = 0;
char bufWorkTime[10];
char bufDay[10];
char bufSleepTime[10];
if(sscanf((const char *)rxBuf,"AT=SLEEP,%[^,]%*[,] %[^,]%*[,] %[^#]",bufWorkTime,bufDay,bufSleepTime) != 0)
{
workTime = atoi(bufWorkTime);
days = atoi(bufDay);
sleepTime = atoi(bufSleepTime);
Sleep.workTime = workTime; //Go to sleep after delay Time seconds later.
Sleep.days = days;
Sleep.sleepTime = sleepTime*60; //wakeupTime seconds later wake up.
Sleep.mode = SLEEP_MODE_LOG_SET; //1:4G set the wake up time mode. 2:Automatic timed wake up mode.0:No-sleep mode.
Sleep.step = 1;
printf("The current RTC is %d-%d-%d week:%d %d:%d:%d .\n",rtc.year,rtc.month,rtc.date,rtc.weekDay,rtc.hours,rtc.minutes,rtc.seconds);
printf("The Sleep.sleepTime = %d senconds.\n",Sleep.sleepTime);
printf("It will take to %d ms go into sleep mode.\n",Sleep.workTime);
printf("The sleep set mode source is %d.\n",Sleep.mode);
}
else
{
printf("AT command is error.");
}
}
// else if(strstr(rxBuf,"AT=SLEEPTEST")!=NULL) // Sleep mode test.
// {
// Sleep.sleepTime = 10; //10 seconds later wake up.
// Sleep.workTime = 3*1000; //Go to sleep after delay 3 seconds later.
// Sleep.mode = SLEEP_MODE_LOG_TEST;
// printf("The current RTC is %d-%d-%d week:%d %d:%d:%d .\n",rtc.year,rtc.month,rtc.date,rtc.weekDay,rtc.hours,rtc.minutes,rtc.seconds);
// printf("The Sleep.sleepTime = %d senconds.\n",Sleep.sleepTime);
// printf("It will take to %d ms go into sleep mode.\n",Sleep.workTime);
// printf("The sleep set mode source is %d.\n",Sleep.mode);
// AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
// }
// else if(strstr((const char *)rxBuf,"AT=ATLOGUP,")!=NULL) //log。
// {
// u32 logFlag = 0;
// u32 timeSeconds = 0;
// u32 byteNum = 0;
// u32 reportTime = 0;
// char buflogF[10];
// char bufSeconds[10];
// char bufByteNub[10];
// char bufReportTime[10];
// if(sscanf((const char *)rxBuf,"AT=ATLOGUP,%[^,]%*[,] %[^,]%*[,] %[^,]%*[,] %[^#]",buflogF,bufSeconds,bufByteNub,bufReportTime) != 0)
// {
// logFlag = atoi(buflogF);
// timeSeconds = atoi(bufSeconds);
// byteNum = atoi(bufByteNub);
// reportTime = atoi(bufReportTime);
// }
// else
// {
// printf("AT command is error.");
// }
// }
else if(strstr(rxBuf,"AT=LOG,1")!=NULL) // Sleep mode test.
{
Device.log = TRUE;
printf("AT=LOG=%d",Device.log);
AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
}
else if(strstr(rxBuf,"AT=LOG,0")!=NULL) // Sleep mode test.
{
Device.log = FALSE;
printf("AT=LOG=%d",Device.log);
AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
}
else if(strstr(rxBuf,"AT=LOG?")!=NULL) // Sleep mode test.
{
printf("AT=LOG,%d",Device.log);
AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
}
else if(strstr(rxBuf,"AT=TESTPASS,")!=NULL) //测试信息写入
{
char testBuf[128] = {0};
if(sscanf(rxBuf,"AT=TESTPASS,%[^#] ",testBuf) != 0)
{
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
sprintf(Parm.testBuf,testBuf); //
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=TESTPASS,%s",Parm.testBuf);
AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
}
else
{
printf("The parameter is wrong.\n");
}
}
else if(strstr(rxBuf,"AT=TESTPASS?")!=NULL) //信息查询
{
printf("AT=TESTPASS,%s",Parm.testBuf);
AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
}
//NETWORK AND SERVER
else if(strstr((const char *)rxBuf,"AT=SERVERLIST1,")!=NULL) //AT set sleep and wake up time指令解析。
{
u32 port = 0;
// char* portBuf;
// char* ipBuf;
char portBuf[10];
char ipBuf[SERVER_IP_LEN];
if(sscanf((const char *)rxBuf,"AT=SERVERLIST1,%[^:]%*[:] %[^#]",ipBuf,portBuf) != 0)
{
port = atoi(portBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
sprintf(Parm.serverIp[0].addr,ipBuf); //
Parm.serverIp[0].port = port;
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=SERVERLIST1,%s,%d .\n", Parm.serverIp[0].addr,Parm.serverIp[0].port);
AT_ACK(); // company AT command general ACK.
}
else
{
printf("AT command is error.");
}
}
else if(strstr((const char *)rxBuf,"AT=SERVERLIST1?")!=NULL) //
{
printf("AT=SERVERLIST1,%s,%d .\n", Parm.serverIp[0].addr,Parm.serverIp[0].port);
AT_ACK(); // company AT command general ACK.
}
// else if(strstr((const char *)rxBuf,"AT=SERVERLIST2,")!=NULL) //AT set sleep and wake up time指令解析。
// {
// u32 port = 0;
// char portBuf[10];
// char ipBuf[SERVER_IP_LEN];
// if(sscanf((const char *)rxBuf,"AT=SERVERLIST1,%[^:]%*[:] %[^#]",Parm.serverIp[1].addr,portBuf) != 0)
// {
// port = atoi(portBuf);
// u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
// w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
// sprintf(Parm.serverIp[1].addr,ipBuf); //
// Parm.serverIp[1].port = port;
// w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
// printf("The server IP :%s, port :%d .\n", Parm.serverIp[1].addr,Parm.serverIp[1].port);
// }
// else
// {
// printf("AT command is error.");
// }
// }
// else if(strstr((const char *)rxBuf,"AT=SERVERLIST2?")!=NULL) //
// {
// printf("The server IP :%s, port :%d .\n", Parm.serverIp[1].addr,Parm.serverIp[1].port);
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr((const char *)rxBuf,"AT=SERVERLIST3,")!=NULL) //AT set sleep and wake up time指令解析。
// {
// u32 port = 0;
// char portBuf[10];
// char ipBuf[SERVER_IP_LEN];
// if(sscanf((const char *)rxBuf,"AT=SERVERLIST1,%[^:]%*[:] %[^#]",Parm.serverIp[2].addr,portBuf) != 0)
// {
// port = atoi(portBuf);
// u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
// w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
// sprintf(Parm.serverIp[2].addr,ipBuf); //
// Parm.serverIp[2].port = port;
// w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
// printf("The server IP :%s, port :%d .\n", Parm.serverIp[2].addr,Parm.serverIp[2].port);
// }
// else
// {
// printf("AT command is error.");
// }
// }
// else if(strstr((const char *)rxBuf,"AT=SERVERLIST3?")!=NULL) //
// {
// printf("The server IP :%s, port :%d .\n", Parm.serverIp[2].addr,Parm.serverIp[2].port);
// AT_ACK(); // company AT command general ACK.
// }
//OTA SERVER
else if(strstr((const char *)rxBuf,"AT=OTASERVER1,")!=NULL) //AT set sleep and wake up time指令解析。
{
u32 port = 0;
char portBuf[10];
char ipBuf[SERVER_IP_LEN];
char filePath[128];
if(sscanf((const char *)rxBuf,"AT=OTASERVER1,%[^:]%*[:] %[^,]%*[,] %[^#]",ipBuf,portBuf,filePath) != 0)
{
port = atoi(portBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
sprintf(Parm.updateServerIp[0].addr,ipBuf); //
Parm.updateServerIp[0].port = port;
sprintf(Parm.binfilePath[0].name,filePath); //
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=OTASERVER1,%s:%d%s.\n", Parm.updateServerIp[0].addr,Parm.updateServerIp[0].port,Parm.binfilePath[0].name);
AT_ACK(); // company AT command general ACK.
}
else
{
printf("AT command is error.");
}
}
else if(strstr((const char *)rxBuf,"AT=OTASERVER1?")!=NULL) //
{
printf("AT=OTASERVER1,%s:%d%s.\n", Parm.updateServerIp[0].addr,Parm.updateServerIp[0].port,Parm.binfilePath[0].name);
AT_ACK(); // company AT command general ACK.
}
// else if(strstr((const char *)rxBuf,"AT=OTASERVER2,")!=NULL) //AT set sleep and wake up time指令解析。
// {
// u32 port = 0;
// char portBuf[10];
// char ipBuf[SERVER_IP_LEN];
// char filePath[128];
// if(sscanf((const char *)rxBuf,"AT=OTASERVER2,%[^:]%*[:] %[^,]%*[,] %[^#]",ipBuf,portBuf,filePath) != 0)
// {
// port = atoi(portBuf);
// u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
// w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
// sprintf(Parm.updateServerIp[1].addr,ipBuf); //
// Parm.updateServerIp[1].port = port;
// sprintf(Parm.binfilePath[1].name,filePath); //
// w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
// printf("%s:%d%s.\n", Parm.updateServerIp[1].addr,Parm.updateServerIp[1].port,Parm.binfilePath[1].name);
// AT_ACK(); // company AT command general ACK.
// }
// else
// {
// printf("AT command is error.");
// }
// }
// else if(strstr((const char *)rxBuf,"AT=OTASERVER2?")!=NULL) //
// {
// printf("%s:%d%s.\n", Parm.updateServerIp[1].addr,Parm.updateServerIp[1].port,Parm.binfilePath[1].name);
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr((const char *)rxBuf,"AT=OTASERVER3,")!=NULL) //AT set sleep and wake up time指令解析。
// {
// u32 port = 0;
// char portBuf[10];
// char ipBuf[SERVER_IP_LEN];
// char filePath[128];
// if(sscanf((const char *)rxBuf,"AT=OTASERVER3,%[^:]%*[:] %[^,]%*[,] %[^#]",ipBuf,portBuf,filePath) != 0)
// {
// port = atoi(portBuf);
// u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
// w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
// sprintf(Parm.updateServerIp[2].addr,ipBuf); //
// Parm.updateServerIp[2].port = port;
// sprintf(Parm.binfilePath[2].name,filePath); //
// w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
// printf("%s:%d%s.\n", Parm.updateServerIp[2].addr,Parm.updateServerIp[2].port,Parm.binfilePath[2].name);
// AT_ACK(); // company AT command general ACK.
// }
// else
// {
// printf("AT command is error.");
// }
// }
// else if(strstr((const char *)rxBuf,"AT=OTASERVER3?")!=NULL) //
// {
// printf("%s:%d%s.\n", Parm.updateServerIp[2].addr,Parm.updateServerIp[2].port,Parm.binfilePath[2].name);
// AT_ACK(); // company AT command general ACK.
// }
else if(strstr(rxBuf,"AT=OTAUPDATE")!=NULL) // device reset
{
printf("Ready to OTA update."); //
Device.reset = TRUE;
Device.otaFlag = TRUE;
app_flag_write(0x00000000 ,APP_UPDATE__DONE_FLAG_ADDR);//擦除APP标志,重新升级。
AT_ACK(); // company AT command general ACK.
// NVIC_SystemReset();
}
//DA215 /
else if(strstr(rxBuf,"AT=GSENSOR?")!=NULL) //inquire gsonser chip ID
{
printf("AT=GSENSOR,信号:%s,ID:0x%02X,采样时间:%dms,采样点:%d,阈值:%d,侧翻:%d.",da215.name,da215.id,Parm.da215.sampleTime,Parm.da215.sampleNumber,Parm.da215.shreshold,Parm.da215.rolloverTh);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GSENSORLOG,1")!=NULL) //enable GSENSOR debug log
{
da215.log = TRUE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GSENSORLOG,0")!=NULL) //disable GSENSOR debug log
{
da215.log = FALSE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GSENSORDEBUG?")!=NULL) //inquire gsonser debug log mode
{
printf("AT=GSENSORDEBUG=%d",da215.debug);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GSENSORDEBUG,1")!=NULL) //enable GSENSOR debug log
{
da215.debug = TRUE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GSENSORDEBUG,0")!=NULL) //disable GSENSOR debug log
{
da215.debug = FALSE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GSENSOROFFSET?")!=NULL) //GSENSOR Calibration
{
printf("AT=GSENSOROFFSET,parameter:offsetX=%d,offsetY=%d,offsetZ=%d",Parm.da215.offSetX,Parm.da215.offSetY,Parm.da215.offSetZ); //
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GSENSOROFFSET")!=NULL) //GSENSOR Calibration
{
da215.status = DA215_CALIBRATION; //进入校准模式
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=VIBRATE,")!=NULL) //GSENSOR vibrate set
{
u32 vibrateAlarmFlag = 0;
u32 shreshold = 0;
u32 wakeUpTimeLimit = 0;
int temp1 =sscanf(rxBuf,"AT=VIBRATE,%d%*[,]%d%*[,]%d",&vibrateAlarmFlag,&shreshold,&wakeUpTimeLimit);
//printf("AT=VIBRATE,%d,%d,%d temp1 = %d",reportFlag,shreshold,wakeUpTimeLimit,temp1); //
da215.vibrateAlarmFlag = vibrateAlarmFlag;
da215.shreshold = shreshold;
da215.wakeUpTimeLimit = wakeUpTimeLimit*1000;
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.da215.vibrateAlarmFlag = vibrateAlarmFlag;
Parm.da215.shreshold = shreshold;
Parm.da215.wakeUpTimeLimit = wakeUpTimeLimit;
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=VIBRATE?")!=NULL) //GSENSOR vibration parameter query
{
printf("AT=VIBRATE,%d,%d,%d",Parm.da215.vibrateAlarmFlag,Parm.da215.shreshold,Parm.da215.wakeUpTimeLimit); //AT=VIBRATE,A,B,C A :表示震动报警开关 B :表示震动强度数值 C :表示唤醒连续检测的次数, 范围1~60, 默认3次
printf(" da215.vibrateFlag = %d.",da215.vibrateFlag);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GSENSORTIMER,")!=NULL) //Gsensor work mode set
{
u8 reportFlag = 0;
char bufSh[10] = {0};
u8 shreshold = 0;
char bufSamT[10] = {0};
u16 sampleTime = 0;
char bufSamNumL[10] = {0};
u16 sampleNumber = 0; //Number of sampling points
int tmep = sscanf(rxBuf,"AT=GSENSORTIMER,%hhd%*[,]%[^,]%*[,]%[^,]%*[,]%[^#]",&reportFlag,bufSh,bufSamT,bufSamNumL);
shreshold = atoi(bufSh);
sampleTime = atoi(bufSamT);
sampleNumber = atoi(bufSamNumL);
da215.reportFlag = reportFlag;
da215.shreshold = shreshold;
// da215.sampleTime = sampleTime;
Parm.da215.sampleTime = sampleTime;
da215.sampleNumber = sampleNumber;
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.da215.reportFlag = da215.reportFlag;
Parm.da215.shreshold = da215.shreshold;
// Parm.da215.sampleTime = da215.sampleTime;
Parm.da215.sampleNumber = da215.sampleNumber;
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=GSENSORTIMER,report=%d,shreshold=%d,sampleTime=%d,smpleNum=%d",da215.reportFlag,da215.shreshold,da215.sampleTime,da215.sampleNumber); //
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GSENSORTIMER?")!=NULL) //GSENSOR work mode query
{
printf("AT=GSENSORTIMER,report=%d,shreshold=%d,sampleTime%d,sampleNum=%d",da215.reportFlag,da215.shreshold,da215.sampleTime,da215.sampleNumber); //
AT_ACK(); // company AT command general ACK.
}
//AHT20 //
// else if(strstr(rxBuf,"AT=AHT20DEBUG?")!=NULL) //inquire gsonser debug log mode
// {
// printf("AT=AHT20DEBUG=%d",da215.debug);
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=AHT20DEBUG,1")!=NULL) //enable AHT20 debug log
// {
// aht20.debug = TRUE;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=AHT20DEBUG,0")!=NULL) //disable AHT20 debug log
// {
// aht20.debug = FALSE;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=TEMPTHRESHOLD,")!=NULL) //
// {
// u8 alarmReportFlag = 0;
// char minTemBuf[10] = {0};
// double minTem = 0; //Minimum temperature
// char maxTemBuf[10] = {0};
// double maxTem = 0; //Maximum temperature
// u8 minHum = 0; //Minimum humidity
// u8 maxHum = 0; //Maximum humidity
// int temp = sscanf(rxBuf,"AT=TEMPTHRESHOLD,%hhd%*[,] %[^,]%*[,] %[^,]%*[,] %hhd%*[,] %hhd",&alarmReportFlag,minTemBuf,maxTemBuf,(char*)&minHum,(char*)&maxHum);
// minTem = atof(minTemBuf);
// maxTem = atof(maxTemBuf);
// aht20.alarmReportFlag = alarmReportFlag;
// aht20.minTem = minTem*10;
// aht20.maxTem = maxTem*10;
// aht20.minHum = minHum*10;
// aht20.maxHum = maxHum*10;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=TEMPTHRESHOLD?")!=NULL) //
// {
// printf("AT=TEMPTHRESHOLD,%d,%.1f,%.1f,%.1f,%.1f",aht20.alarmReportFlag,aht20.minTem/10.0,aht20.maxTem/10.0,aht20.minHum/10.0,aht20.maxHum/10.0); //
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=TME?")!=NULL) //查询温湿度数值
// {
// printf("AT=TME,%.1f °C,%.1f%%",aht20.tem/10.0,aht20.hum/10.0); //
// AT_ACK(); // company AT command general ACK.
// }
//FLASH //
else if(strstr(rxBuf,"AT=FLASHCHIP?")!=NULL) //inquire Flash debug log mode
{
printf("AT=FLASHCHIP,NAME=%s,ID=0X%08X,SIZE=%dMByte",w25qxx.name,w25qxx.id,w25qxx.size);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=FLASHCHIP,ERASE")!=NULL) //inquire Flash debug log mode
{
wq25xxEraseChip();
printf("AT=FLASHCHIP,ERASE");
printf("The system is ready to restart."); //
Device.reset = TRUE;
AT_ACK(); // company AT command general ACK.
}
// //EPD //
// else if(strstr(rxBuf,"AT=EPDDEBUG?")!=NULL) //inquire epd debug log mode
// {
// if(epd.debug == TRUE) //debug mode
// {
// printf("AT=EPDDEBUG,1");
// }
// else
// {
// printf("AT=EPDDEBUG,0");
// }
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=EPDDEBUG,1")!=NULL) //enable EPD debug log
// {
// epd.debug = TRUE;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=EPDDEBUG,0")!=NULL) //disable EPD debug log
// {
// epd.debug = FALSE;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=EPD?")!=NULL) //inquire epd debug log mode
// {
// printf("AT=EPD,");
// printf("Parm.image.fileId[0] = %08X.\n",Parm.image.fileId[0]); //This code just for testing.
// printf("Parm.image.fileId[1] = %08X.\n",Parm.image.fileId[1]); //This code just for testing.
// printf("Parm.image.fileId[2] = %08X.\n",Parm.image.fileId[2]); //This code just for testing.
// printf("Parm.image.fileId[3] = %08X.\n",Parm.image.fileId[3]); //This code just for testing.
// printf("Parm.image.fileId[4] = %08X.\n",Parm.image.fileId[4]); //This code just for testing.
// printf("Parm.image.fileId[5] = %08X.\n",Parm.image.fileId[5]); //This code just for testing.
// printf("Parm.image.fileId[6] = %08X.\n",Parm.image.fileId[6]); //This code just for testing.
// printf("Parm.image.totalNum = %08X.\n",Parm.image.totalNum); //
// printf("Parm.image.currentNum = %08X.\n",Parm.image.currentNum); //
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=EPD,")!=NULL) //inquire epd debug log mode
// {
// char buf[ATO_I_F_LEN] = {0};
// u32 imageNum = 0;
// if(sscanf(rxBuf,"AT=EPD,%[^#] ",buf) == 1)
// {
// imageNum = atoi(buf);
// epd.currentImage = imageNum;//显示图片号码.
// epd.currentImage &= 0X07;
// // epd.lastImage = epd.currentImage+1;
// printf("AT=EPD,%d",epd.currentImage);
// AT_ACK(); // company AT command general ACK.
// u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
// w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
// Parm.image.currentNum = epd.currentImage;
// w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
// }
// }
// else if(strstr(rxBuf,"AT=EPD=NEXT")!=NULL) //display the next image.
// {
// epd.currentImage++;//显示下一张图片.
// epd.currentImage &= 0X07;
// epd.lastImage = epd.currentImage+1;
// printf("AT=EPD=NEXT=%d",epd.currentImage);
// AT_ACK(); // company AT command general ACK.
// }
//EC800 //
// else if(strstr(rxBuf,"AT=ROAM,0")!=NULL) //inquire EC800 debug log mode
// {
// ec800.roamSetModeFlag = TRUE;
// ec800.roamMode = 0;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ROAM,1")!=NULL) //inquire EC800 debug log mode
// {
// ec800.roamSetModeFlag = TRUE;
// ec800.roamMode = 1;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ROAM?")!=NULL) //inquire EC800 debug log mode
// {
// printf("AT=ROAM,%d",ec800.roamMode);
// AT_ACK(); // company AT command general ACK.
// }
else if(strstr(rxBuf,"AT=EC800APN?")!=NULL) //inquire EC800 debug log mode
{
printf("AT=EC800APN,MODE=%d,APN0:%s,APN1:%s.",Parm.apnSetMode,Parm.apn[0].name,Parm.apn[1].name);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=EC800APNMODE,")!=NULL)
{
u32 mode = 0;
if(sscanf(rxBuf,"AT=EC800APNMODE,%d#",&mode) ==1)
{
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //w25qxxRead(u8* pBuffer,u32 ReadAddr,u16 NumByteToRead)
Parm.apnSetMode = mode;
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
AT_ACK(); // company AT command general ACK.
}
else
{
printf("The parameter is wrong.\n");
}
}
else if(strstr(rxBuf,"AT=EC800APN,")!=NULL)
{
char apn[128] ={0};
u32 number = 0;
if(sscanf(rxBuf,"AT=EC800APN,%d,%[^#]",&number,apn) ==2)
{
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //w25qxxRead(u8* pBuffer,u32 ReadAddr,u16 NumByteToRead)
sprintf(Parm.apn[number].name,apn); //默认APN
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
AT_ACK(); // company AT command general ACK.
}
else
{
printf("The parameter is wrong.\n");
}
}
else if(strstr(rxBuf,"AT=EC800ID?")!=NULL) //inquire EC800 debug log mode
{
printf("AT=EC800ID:%s,status:%d",ec800.mtId,ec800.status);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=EC800DEBUG?")!=NULL) //inquire EC800 debug log mode
{
if(ec800.debug == TRUE) //debug mode
{
printf("AT=EC800DEBUG,1");
}
else
{
printf("AT=EC800DEBUG,0");
}
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=EC800DEBUG,1")!=NULL) //enable EC800 debug log
{
ec800.debug = TRUE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=EC800DEBUG,0")!=NULL) //disable EC800 debug log
{
ec800.debug = FALSE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=EC800TXDEBUG,1")!=NULL) //enable EC800 txdebug log
{
ec800.txDebug = TRUE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=EC800TXDEBUG,0")!=NULL) //disable EC800 txdebug log
{
ec800.txDebug = FALSE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=EC800RXDEBUG,1")!=NULL) //enable EC800 rxdebug log
{
ec800.rxDebug = TRUE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=EC800RXDEBUG,0")!=NULL) //disable EC800 rxdebug log
{
ec800.rxDebug = FALSE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=EC800REVERSION?")!=NULL) //inquire EC800 debug log mode
{
printf("AT=EC800REVERSION:%s",ec800.mtRevison);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=SETIMEI,")!=NULL) //set SETIMEI
{
char imei[20] = {0};
int temp = sscanf(rxBuf,"AT=SETIMEI,%[^#]",imei);
if(strlen(imei) >= 10) //加上末尾的#
{
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.imeiFlag = 1; //IMEI号码获取方式,0:4G模块读取 1:串口自主设置。
memcpy(Parm.imei,imei,20); //copy the data to buf
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=IMEI:E:%s,F:%s,手动设置:%d",ec800.imei,Parm.imei,Parm.imeiFlag);
}
else
{
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.imeiFlag = 0; //IMEI号码获取方式,0:4G模块读取 1:串口自主设置。
memset(Parm.imei,0,20); //清零数据缓存
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=IMEI:E:%s,F:%s,手动设置:%d",ec800.imei,Parm.imei,Parm.imeiFlag);
printf("AT=SETIMEI:ERROR,THE LENGTH IS WRONG.");
}
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=IMEI?")!=NULL) //inquire IMEI
{
printf("AT=IMEI:E:%s,F:%s,手动设置:%d",ec800.imei,Parm.imei,Parm.imeiFlag);
AT_ACK(); // company AT command general ACK.
}
// else if(strstr(rxBuf,"AT=CONNECT?")!=NULL) //inquire network connections
// {
// printf("AT=CONNECT:%d",ec800.linkNetFlag);
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=EC800LOW=POWER")!=NULL) //EC800低功耗
// {
// ec800.lowPowerFlag = TRUE;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=EC800=WAKE")!=NULL) //EC800低功耗唤醒
// {
// ec800.wakeupFlag = TRUE;
// AT_ACK(); // company AT command general ACK.
// }
else if(strstr(rxBuf,"AT=4G+")!=NULL) //4G 数据透传。
{
char txBuf[128];
u16 txLen = 0;
sscanf(rxBuf,"AT=4G+%[^#]",txBuf);
txLen = rxLen-7;
ec800Send((u8*)txBuf,txLen);
printf(txBuf,txLen);
ec800.rxDebug = TRUE;
ec800.txDebug = TRUE;
// ec800.status = EC800_TEST_MOMOD;
// ec800.txDebug = TRUE;
// AT_ACK(); // company AT command general ACK.
}
//jt808 //
else if(strstr(rxBuf,"AT=JT808DEBUG?")!=NULL) //inquire JT808 debug log mode
{
printf("AT=JT808DEBUG=%d",jt808.debug);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=JT808DEBUG,1")!=NULL) //enable JT808 debug log
{
jt808.debug = TRUE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=JT808EBUG,0")!=NULL) //disable JT808 debug log
{
jt808.debug = FALSE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=JT808RXDEBUG,1")!=NULL) //enable JT808 debug log
{
jt808.rxDebug = TRUE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=JT808RXDEBUG,0")!=NULL) //disable JT808 debug log
{
jt808.rxDebug = FALSE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=JT808TXDEBUG,1")!=NULL) //enable JT808 debug log
{
jt808.txDebug = TRUE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=JT808TXDEBUG,0")!=NULL) //disable JT808 debug log
{
jt808.txDebug = FALSE;
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=NOWGNSS")!=NULL) //立即报警
{
jt808.alarmFlag = TRUE;
printf("AT=NOWGNSS"); //
AT_ACK(); // company AT command general ACK.
}
// else if(strstr(rxBuf,"AT=HEARBEAT,")!=NULL) //set jt808 heartbeat time
// {
// u16 heartBeatTimeLimit = 0;
// char bufH[10] = {0};
// if(sscanf(rxBuf,"AT=HEARBEAT,%[^#]",bufH) ==1)
// {
// heartBeatTimeLimit = atoi(bufH); //字符串转整数
// jt808.heartBeatTimeLimit = heartBeatTimeLimit*1000; //将秒换算成毫秒
// u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
// w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //w25qxxRead(u8* pBuffer,u32 ReadAddr,u16 NumByteToRead)
// Parm.wkMode[Parm.currentMode].heartBeatTimeLimit = heartBeatTimeLimit;
// w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
// AT_ACK(); // company AT command general ACK.
// }
// else
// {
// printf("The parameter is wrong.\n");
// }
// }
//ADC1 //
// else if(strstr(rxBuf,"AT=ADC1DEBUG?")!=NULL) //inquire gsonser debug log mode
// {
// if(adc1.debug == TRUE) //debug mode
// {
// printf("AT=ADC1DEBUG,1");
// }
// else
// {
// printf("AT=ADC1DEBUG,0");
// }
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ADC1DEBUG,1")!=NULL) //enable GSENSOR debug log
// {
// adc1.debug = TRUE;
// printf("AT=ADC1DEBUG,1");
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ADC1DEBUG,0")!=NULL) //enable GSENSOR debug log
// {
// adc1.debug = FALSE;
// printf("AT=ADC1DEBUG,0");
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=SYSVDD?")!=NULL) //查询系统主控电压
// {
// printf("AT=SYSVDD:3.3v,"); //
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=BATTERY?")!=NULL) //查询电池电压
// {
// printf("AT=BATTERY:%dmv,soc = %d%%",adc1.voltage,Power.soc); //
// AT_ACK(); // company AT command general ACK.
// }
else if(strstr(rxBuf,"AT=BATTERYLP,")!=NULL) //设置低电压阈值 单位:mv
{
char* tempP = strstr(rxBuf,"AT=BATTERYLP,");
char tempBuf0[10];
char tempBuf1[10];
u16 lowPowerVoltage = 0;
u16 recoverPowerVoltage = 0;
if(sscanf(tempP,"AT=BATTERYLP,%[^,]%*[,] %[^#] ",tempBuf0,tempBuf1) != 0)
{
lowPowerVoltage = atoi(tempBuf0);
recoverPowerVoltage = atoi(tempBuf1);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.lowPowerVoltage = lowPowerVoltage; //
Parm.recoverPowerVoltage = recoverPowerVoltage; //
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=BATTERYLP:%dmv,%dmv",Parm.lowPowerVoltage,Parm.recoverPowerVoltage); //
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=BATTERYLP?")!=NULL) //查询低电压阈值
{
printf("AT=BATTERYLP:%dmv,%dmv",Parm.lowPowerVoltage,Parm.recoverPowerVoltage); //
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=CHARGE,")!=NULL) //设置低电压阈值 单位:mv
{
char* tempP = strstr(rxBuf,"AT=CHARGE,");
char tempBuf0[10];
char tempBuf1[10];
char tempBuf2[10];
u8 chargeEnable = 0;
u32 chargeVoltage = 0;
u32 chargeTime = 0;
if(sscanf(tempP,"AT=CHARGE,%[^,]%*[,] %[^,]%*[,] %[^#] ",tempBuf0,tempBuf1,tempBuf2) != 0)
{
chargeEnable = atoi(tempBuf0);
chargeVoltage = atoi(tempBuf1);
chargeTime = atoi(tempBuf2);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.chargeEnable = chargeEnable; //
Parm.chargeVoltage = chargeVoltage; //
Parm.chargeTime = chargeTime; //
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=CHARGE:%d,%dmv,%dm",Parm.chargeEnable,Parm.chargeVoltage,Parm.chargeTime); //
AT_ACK(); // company AT command general ACK.
}
// else if(strstr(rxBuf,"AT=CHARGE?")!=NULL) //查询低电压阈值
// {
// printf("AT=CHARGE:%d,%dmv,%dm",Parm.chargeEnable,Parm.chargeVoltage,Parm.chargeTime); //
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ADC1?")!=NULL) //ADC 数据及采样频率
// {
// printf("AT+ADC1:%dmv,SAMPLETIME:%dms",adc1.voltage,adc1.sampleTime); //
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ADC1,")!=NULL) //查询电池电压
// {
// char sampleTimeBuf[ATO_I_F_LEN] = {0};
// u32 sampleTime = 0;
// sscanf(rxBuf,"AT=ADC1,%[^#]",sampleTimeBuf);
// sampleTime = atoi(sampleTimeBuf);
// adc1.sampleTime = sampleTime;
// //缺少参数flash保存、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
// AT_ACK(); // company AT command general ACK.
// }
// //ADC2 //
// else if(strstr(rxBuf,"AT=ADC2DEBUG?")!=NULL) //inquire gsonser debug log mode
// {
// if(adc2.debug == TRUE) //debug mode
// {
// printf("AT+ADC2DEBUG,1");
// }
// else
// {
// printf("AT+ADC2DEBUG,0");
// }
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ADC2DEBUG,1")!=NULL) //enable GSENSOR debug log
// {
// adc2.debug = TRUE;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ADC2DEBUG,0")!=NULL) //enable GSENSOR debug log
// {
// adc2.debug = FALSE;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ADC2?")!=NULL) //查询电池电压
// {
// printf("AT+ADC2:%d,SAMPLETIME:%d",adc2.voltage,adc2.sampleTime); //
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=ADC2,")!=NULL) //设置采样频率
// {
// char sampleTimeBuf[ATO_I_F_LEN] = {0};
// u32 sampleTime = 0;
// sscanf(rxBuf,"AT=ADC2,%[^#]",sampleTimeBuf);
// sampleTime = atoi(sampleTimeBuf);
// adc2.sampleTime = sampleTime;
// //缺少参数flash保存、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
// AT_ACK(); // company AT command general ACK.
// }
//work mode //
// else if(strstr(rxBuf,"AT=SETWORKMODE,")!=NULL) // work mode set
// {
// char mode = 0;
// if(sscanf(rxBuf,"AT=SETWORKMODE,%hhd",&mode) == 1)
// {
// if(mode<3)
// {
// u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
// w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
// Parm.currentMode = mode;
// w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.、
// printf("AT=workMode,%d,%d,%d,%d,%d,%d,%d",Parm.currentMode,Parm.wkMode[Parm.currentMode].heartBeatTimeLimit,Parm.wkMode[Parm.currentMode].positionReportTimeLimit,Parm.wkMode[Parm.currentMode].inflectionPointFlag,Parm.wkMode[Parm.currentMode].resetTime,Parm.wkMode[Parm.currentMode].sleepTime,Parm.wkMode[Parm.currentMode].workTime);
// AT_ACK(); // company AT command general ACK.
// }
// else
// {
// printf("The work mode is wrong.");
// }
// }
// else
// {
// printf("The work mode is wrong.");
// }
// }
else if(strstr(rxBuf,"AT=WORKMODE,0")!=NULL) // work mode parameter set
{
char mode = 0;
// u32 heartBeatTimeLimit = 0;
// u32 positionReportTime = 0;
// char inflectionPointFlag = 0;
u32 resetTime = 0;
u32 sleepTime = 0;
u32 workTime = 0;
// char bufH[10]; //heart beat time.
// char bufP[10]; //positionReportTime.
char bufR[10]; //resetTime.
char bufS[10]; //sleep time.
char bufW[10]; //work time.
if(sscanf(rxBuf,"AT=WORKMODE,%hhd%*[,] %[^,]%*[,] %[^,]%*[,] %[^#]",&mode,bufR,bufS,bufW) == 4)
{
// heartBeatTimeLimit = 0xffffffff; //字符串转整形
// positionReportTime = 0xffffffff;
// inflectionPointFlag = 0; //拐点上报关闭
resetTime = atoi(bufR);
sleepTime = atoi(bufS);
workTime = atoi(bufW);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.currentMode = mode;
// Parm.wkMode[mode].heartBeatTimeLimit = heartBeatTimeLimit; //unit:seconds 更新要修改的参数
// Parm.wkMode[mode].positionReportTimeLimit = positionReportTime; //unit:seconds
// Parm.wkMode[mode].inflectionPointFlag = inflectionPointFlag;
Parm.wkMode[mode].resetTime = resetTime; //unit:seconds
Parm.wkMode[mode].sleepTime = sleepTime;
Parm.wkMode[mode].workTime = workTime;
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=workMode,%d,%d,%d,%d",mode,Parm.wkMode[mode].resetTime,Parm.wkMode[mode].sleepTime,Parm.wkMode[mode].workTime);
AT_ACK(); // company AT command general ACK.
addSecondsRTC(&resetRtc,rtc,Parm.wkMode[Parm.currentMode].resetTime); //下次重启RTC时间
}
else
{
printf("The parameter is wrong.");
}
}
else if(strstr(rxBuf,"AT=WORKMODE,")!=NULL) // work mode parameter set
{
char mode = 0;
u32 heartBeatTimeLimit = 0;
u32 positionReportTime = 0;
char inflectionPointFlag = 0;
u32 resetTime = 0;
u32 sleepTime = 0;
u32 workTime = 0;
char bufH[10]; //heart beat time.
char bufP[10]; //positionReportTime.
char bufR[10]; //resetTime.
char bufS[10]; //sleep time.
char bufW[10]; //work time.
if(sscanf(rxBuf,"AT=WORKMODE,%hhd%*[,]%[^,]%*[,]%[^,]%*[,]%hhd%*[,]%[^,]%*[,]%[^,]%*[,]%[^#]",&mode,(char*)bufH,(char*)bufP,&inflectionPointFlag,(char*)bufR,bufS,bufW) == 7)
{
heartBeatTimeLimit = atoi(bufH) ; //字符串转整形
positionReportTime = atoi(bufP);
resetTime = atoi(bufR);
sleepTime = atoi(bufS);
workTime = atoi(bufW);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.currentMode = mode;
Parm.wkMode[mode].heartBeatTimeLimit = heartBeatTimeLimit; //unit:seconds 更新要修改的参数
Parm.wkMode[mode].positionReportTimeLimit = positionReportTime; //unit:seconds
Parm.wkMode[mode].inflectionPointFlag = inflectionPointFlag;
Parm.wkMode[mode].resetTime = resetTime; //unit:seconds
Parm.wkMode[mode].sleepTime = sleepTime;
Parm.wkMode[mode].workTime = workTime;
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=workMode,%d,%d,%d,%d,%d,%d,%d",mode,Parm.wkMode[mode].heartBeatTimeLimit,Parm.wkMode[mode].positionReportTimeLimit,Parm.wkMode[mode].inflectionPointFlag,Parm.wkMode[mode].resetTime,Parm.wkMode[mode].sleepTime,Parm.wkMode[mode].workTime);
AT_ACK(); // company AT command general ACK.
addSecondsRTC(&resetRtc,rtc,Parm.wkMode[Parm.currentMode].resetTime); //下次重启RTC时间
}
else
{
printf("The parameter is wrong.");
}
}
else if(strstr(rxBuf,"AT=WORKMODE?")!=NULL) // work mode query
{
printf("AT=workMode,%d,%d,%d,%d,%d,%d,%d",Parm.currentMode,Parm.wkMode[Parm.currentMode].heartBeatTimeLimit,Parm.wkMode[Parm.currentMode].positionReportTimeLimit,Parm.wkMode[Parm.currentMode].inflectionPointFlag,Parm.wkMode[Parm.currentMode].resetTime,Parm.wkMode[Parm.currentMode].sleepTime,Parm.wkMode[Parm.currentMode].workTime);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=INFO?")!=NULL) // device info
{
printf("AT=INFO:DEVICE:%s,",Device.id); //
printf("UPDATE TIME:%s %s,",Device.date,Device.time);
printf("E_IMEI:%s,",ec800.imei);
printf("F_IMEI:%s,",Parm.imei);
printf("IMEI自主设置:%d,",Parm.imeiFlag);
printf("ICCID:%s,",ec800.iccid);
printf("软件版本:%s.\n",Device.versionS); //Software version
printf("硬件版本:%s.\n",Device.versionH); //Hardware version
printf("参数长度:%d.\n",sizeof(Parm));
// txHeader.id = T_ATTR_ACK_ID; //发送给平台
// jt808.ackSendFlag = TRUE;
AT_ACK(); // company AT command general ACK.
}
// else if(strstr(rxBuf,"AT=PARM=LIST=SIZE?")!=NULL) // parameter data size
// {
// printf("AT=PARM=LIST=SIZE:%d byte,",sizeof(Parm)); //
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=SETLPNUM,")!=NULL) // set car number
// {
// char buf[30] = {0};
// int temp = sscanf(rxBuf,"AT=SETLPNUM,%s",buf);
// memcpy(buf,rxBuf+12,Command.rxLen-12); //copy the data to buf
// memcpy(Device.carNum,rxBuf+12,Command.rxLen-12); //copy the data to buf
// printf(buf,strlen(buf)); //
// //printf("AT=SETLPNUM, len:%d",sizeof("AT=SETLPNUM,"));
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=SETLPNUM?")!=NULL) // car number?
// {
// if(strlen(Device.carNum)<5)
// {
// printf("AT=SETLPNUM:EMPTY");
// }
// else
// {
// printf("AT=SETLPNUM:");
// printf(Device.carNum,8); //
// }
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=SETTYPE?")!=NULL) // T type,DEVICE
// {
// printf(Device.id,strlen(Device.id)); //
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=SETTYPE,")!=NULL) // T type,DEVICE
// {
// char buf[30] = {0};
// int temp = sscanf(rxBuf,"AT=SETTYPE,%[^#]",buf);
// if(strlen(buf)>2)
// {
// memcpy(Device.id,buf,30); //包括后面的空字符,如此就不用清除Device.id[]中的残余数据.
// }
// else
// {
// }
// AT_ACK(); // company AT command general ACK.
// }
else if(strstr(rxBuf,"AT=SETSFCODE?")!=NULL) // software code/version?
{
printf("AT=SETSFCODE:%s",Device.versionS);
AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
}
else if(strstr(rxBuf,"AT=SETHWCODE?")!=NULL) // hardware code/version?
{
printf("AT=SETHWCODE:%s",Parm.versionH);
AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
}
else if(strstr(rxBuf,"AT=SETHWCODE,")!=NULL) // Set hardware code/version.
{
char buf[30] = {0};
if(sscanf(rxBuf,"AT=SETHWCODE,%[^#]",buf) != 0)
{
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
sprintf(Parm.versionH,buf); //
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=SETHWCODE,%s",Parm.versionH);
AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
}
}
//Buzz //
// else if(strstr(rxBuf,"AT=BUZZSW,")!=NULL) //BUZZ开关。
// {
// char* tempP = strstr(rxBuf,"AT=BUZZSW,");
// char tempBuf[10];
// u8 buzzSw = 0;
// if(sscanf(tempP,"AT=BUZZSW,%[^#] ",tempBuf) != 0)
// {
// buzzSw = atoi(tempBuf);
// u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
// w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
// Parm.buzzSw = buzzSw; //BUZZ开关。
// w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
// if (Parm.buzzSw)
// {
// setBuzz(100,100,1); //buzz param set: T(on off) times
// }
// }
// printf("AT=BUZZSW,%d",Parm.buzzSw);
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=BUZZSW?")!=NULL) //BUZZ开关。
// {
// printf("AT=BUZZSW,%d",Parm.buzzSw);
// AT_ACK(); // company AT command general ACK.
// }
//RTC //
// else if(strstr(rxBuf,"AT=RTC?")!=NULL) //RTC 时间查询
// {
// printf("AT+RTC:offsetY:%d,UTC:%d,offset:%d,DATE:%d/%d/%d,WEEK:%d,time:%d:%d:%d\r\n",rtc.offsetY,rtc.utc,rtc.offSet,rtc.year+rtc.offsetY,rtc.month,rtc.date,rtc.weekDay,rtc.hours,rtc.minutes,rtc.seconds);
// AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
// }
// else if(strstr(rxBuf,"AT=RTCTIME,")!=NULL) //RTC 时间设置
// {
// char hourBuf[ATO_I_F_LEN] = {0};
// char nimuteBuf[ATO_I_F_LEN] = {0};
// char secondBuf[ATO_I_F_LEN] = {0};
// uint8_t Hours = 0;
// uint8_t Minutes = 0;
// uint8_t Seconds = 0;
// int temp = sscanf(rxBuf,"AT=RTCTIME,%[^,]%*[,] %[^,]%*[,] %[^#] ",hourBuf,nimuteBuf,secondBuf);
// Hours = atoi(hourBuf);
// Minutes = atoi(nimuteBuf);
// Seconds = atoi(secondBuf);
// rtcSetTime.Hours = Hours;
// rtcSetTime.Seconds = Seconds;
// rtcSetTime.Minutes = Minutes;
// rtc.setTime = 1; //设置RTC 时间
// AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
// }
// else if(strstr(rxBuf,"AT=RTCDATE,")!=NULL) //RTC 日期设置
// {
// char yearBuf[ATO_I_F_LEN] = {0};
// char monthBuf[ATO_I_F_LEN] = {0};
// char dayBuf[ATO_I_F_LEN] = {0};
// u16 Year = 0;
// uint8_t Month = 0;
// uint8_t Date = 0;
// int temp = sscanf(rxBuf,"AT=RTCDATE,%[^,]%*[,] %[^,]%*[,] %[^#] ",yearBuf,monthBuf,dayBuf);
// Year = atoi(yearBuf);
// Month = atoi(monthBuf);
// Date = atoi(dayBuf);
// rtcSetData.Year = Year-2000;
// rtcSetData.Month = Month;
// rtcSetData.Date = Date;
// rtcSetData.WeekDay = weekDay(rtcSetData.Year,rtcSetData.Month,rtcSetData.Date);
// rtc.setDate = 1; //设置RTC 日期
// printf("year = %d,month = %d,day =%d,weekDay = %d.\n",rtcSetData.Year,rtcSetData.Month,rtcSetData.Date, rtcSetData.WeekDay);
// AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
// }
// else if(strstr(rxBuf,"AT=GMT?")!=NULL) //时区查询
// {
// printf("AT+GMT:%d,%d",rtc.utc,rtc.offSet);
// AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
// }
// else if(strstr(rxBuf,"AT=GMT,")!=NULL) //RTC
// {
// char utcBuf[ATO_I_F_LEN] = {0};
// char offsetBuf[ATO_I_F_LEN] = {0};
// int16_t utc = 0;
// int16_t offset = 0;
// if(sscanf(rxBuf,"AT=GMT,%[^,]%*[,] %[^#] ",utcBuf,offsetBuf) == 2)
// {
// utc = atoi(utcBuf);
// offset = atoi(offsetBuf);
// rtc.utc = utc;
// rtc.offSet = offset;
// u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
// w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
// Parm.utc = rtc.utc; //默认北京时间,东八区
// Parm.offSet = rtc.offSet; //时差
// w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
// AT_ACK(); // company AT command general ACK. NVIC_SystemReset();
// }
// else
// {
// printf("The parameter is wrong.\n");
// }
// }
//GPS //
else if(strstr(rxBuf,"AT=GPSDEBUG?")!=NULL) //inquire gps debug log mode
{
if(Gps.debug == TRUE) //debug mode
{
printf("AT=GPSDEBUG,1");
}
else
{
printf("AT=GPSDEBUG,0");
}
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GPSDEBUG,1")!=NULL) //enable gps debug log
{
Gps.debug = TRUE;
printf("AT=GPSDEBUG,1");
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GPSDEBUG,0")!=NULL) //disable gps debug log
{
Gps.debug = FALSE;
printf("AT=GPSDEBUG,0");
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GPSPOWER,0")!=NULL) //disable gps debug log
{
GPS_POWER(FALSE); //Turn off the gps.
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=GPSPOWER,1")!=NULL) //disable gps debug log
{
GPS_POWER(TRUE); //Turn on the gps.
AT_ACK(); // company AT command general ACK.
}
// else if(strstr(rxBuf,"AT=GPS+")!=NULL) //4G 数据透传。
// {
// sscanf(rxBuf,"AT=GPS+%[^#]",usart4.txBuf);
// usart4.txLen = Command.rxLen-7;
// gpsSend((u8*)usart4.txBuf,usart4.txLen);
// printf(usart4.txBuf,usart4.txLen);
// Gps.debug = TRUE;
// // ec800.txDebug = TRUE;
// // AT_ACK(); // company AT command general ACK.
// }
else if(strstr(rxBuf,"AT=AGPSNOW")!=NULL) //4G 数据透传。
{
Gps.agpsFlag = TRUE;
Gps.txDebug = TRUE;
printf("手动开启AGPS------------------------.\r\n"); //
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=AGPSSW,")!=NULL) //AGPS开关。
{
char* tempP = strstr(rxBuf,"AT=AGPSSW,");
char tempBuf[10];
u8 agpsSwitch = 0;
if(sscanf(tempP,"AT=AGPSSW,%[^#] ",tempBuf) != 0)
{
agpsSwitch = atoi(tempBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.agpsSw = agpsSwitch; //AGPS开关。
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=AGPSSW,%d",Parm.agpsSw);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=AGPSNUM,")!=NULL) //AGPS有效星历阈值。
{
char* tempP = strstr(rxBuf,"AT=AGPSNUM,");
char tempBuf[10];
u8 agpsNumLimit = 0;
if(sscanf(tempP,"AT=AGPSNUM,%[^#] ",tempBuf) != 0)
{
agpsNumLimit = atoi(tempBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.agpsNumLimit = agpsNumLimit; //AGPS有效星历阈值。
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=AGPSNUM,%d",Parm.agpsNumLimit);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=AGPSNUM?")!=NULL) //AGPS有效星历阈值查询。
{
printf("AT=AGPSNUM,%d",Parm.agpsNumLimit);
AT_ACK(); // company AT command general ACK.
}
else if(strstr((const char *)rxBuf,"AT=AGPSLIST,")!=NULL) //AT set sleep and wake up time指令解析。
{
u32 port = 0;
// char* portBuf;
// char* ipBuf;
char type[40];
char ipBuf[SERVER_IP_LEN];
char portBuf[10];
char userNameBuf[SERVER_IP_LEN];
char userPwdBuf[20];
char timeOutBuf[20];
char typeListBuf[SERVER_IP_LEN];
// A ip port user name pwd 超时 包含的芯片型号
if(sscanf((const char *)rxBuf,"AT=AGPSLIST,%[^,]%*[,] %[^:]%*[:] %[^,]%*[,] %[^,]%*[,] %[^,]%*[,] %[^,]%*[,] %[^#]",type,ipBuf,portBuf,userNameBuf,userPwdBuf,timeOutBuf,typeListBuf) != 0)
{
port = atoi(portBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
sprintf(Parm.agpsIp[0].addr,ipBuf); //
Parm.agpsIp[0].port = port;
sprintf(Parm.agps0UserName,userNameBuf); //
sprintf(Parm.agps0Pwd,userPwdBuf); //
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("The server IP :%s, port :%d .\n", Parm.agpsIp[0].addr,Parm.agpsIp[0].port);
AT_ACK(); // company AT command general ACK.
}
}
else if(strstr(rxBuf,"AT=GPSCN,")!=NULL) //GPS低功耗设置。
{
char* tempP = strstr(rxBuf,"AT=GPSCN,");
char gpsCnBuf[ATO_I_F_LEN] = {0}; //gps CN值
char satelliteMinNumBuf[ATO_I_F_LEN] = {0}; //gps工作最小卫星颗数限制。
char gpsDetTimeLimitBuf[ATO_I_F_LEN] = {0}; //GPS检测时间,获取卫星数据,CN值的时间,不符合要求则直接中断GPS操作。
char gpsMaxWorkTimeBuf[ATO_I_F_LEN] = {0}; //最大工作时间,单位:秒
char spsLpTimeLimitBuf[ATO_I_F_LEN] = {0}; //低功耗模式开启时间限制,单位秒。
char gpsAdvanceTimeBuf[ATO_I_F_LEN] = {0}; //
char gpsAfter200WorkTimeBuf[ATO_I_F_LEN] = {0}; //定位上报后工作时间,单位:秒
if(sscanf(tempP,"AT=GPSCN,%[^,]%*[,] %[^,]%*[,] %[^,]%*[,] %[^,]%*[,] %[^,]%*[,] %[^,]%*[,] %[^#] ",gpsCnBuf,satelliteMinNumBuf,gpsDetTimeLimitBuf,gpsMaxWorkTimeBuf,spsLpTimeLimitBuf,gpsAdvanceTimeBuf,gpsAfter200WorkTimeBuf)!= 0)
{
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.gpsCn = atoi(gpsCnBuf); //gps CN值过滤参数。
Parm.satelliteMinNum = atoi(satelliteMinNumBuf); //gps工作最小卫星颗数限制。
Parm.gpsDetTimeLimit = atoi(gpsDetTimeLimitBuf); //GPS检测时间,获取卫星数据,CN值的时间,不符合要求则直接中断GPS操作。
Parm.gpsMaxWorkTime = atoi(gpsMaxWorkTimeBuf); //最大工作时间,单位:秒
Parm.gpsLpTimeLimit = atoi(spsLpTimeLimitBuf); //gps低功耗开启时间限制,单位秒。
Parm.gpsAdvanceTime = atoi(gpsAdvanceTimeBuf); //提前打开gps时间,单位:秒。
Parm.gpsAfter200WorkTime = atoi(gpsAfter200WorkTimeBuf); //最小工作时间,单位:秒
Parm.gpsMinWorkTime = Parm.gpsAdvanceTime+Parm.gpsAfter200WorkTime; //定位上报后工作时间,单位:秒
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
printf("AT=GPSCN,%d,%d,%d,%d,%d,%d,%d",Parm.gpsCn,Parm.satelliteMinNum,Parm.gpsDetTimeLimit,Parm.gpsMaxWorkTime,Parm.gpsLpTimeLimit,Parm.gpsAdvanceTime,Parm.gpsAfter200WorkTime);
AT_ACK(); // company AT command general ACK.
}
}
else if(strstr(rxBuf,"AT=GPSCN?")!=NULL) //
{
printf("AT=GPSCN,%d,%d,%d,%d,%d,%d,%d",Parm.gpsCn,Parm.satelliteMinNum,Parm.gpsDetTimeLimit,Parm.gpsMaxWorkTime,Parm.gpsLpTimeLimit,Parm.gpsAdvanceTime,Parm.gpsAfter200WorkTime);
AT_ACK(); // company AT command general ACK.
}
//OBD
else if(strstr(rxBuf,"AT=OBDCHARGE,")!=NULL) //打开充电
{
char* tempP = strstr(rxBuf,"AT=OBDCHARGE,");
char tempBuf[10];
u8 open = 0;
if(sscanf(tempP,"AT=OBDCHARGE,%[^#] ",tempBuf) != 0)
{
open = atoi(tempBuf);
if( open == 1)
{
EX_POWER(1); //打开12V充电电源。
Power.obdChargeFlag = TRUE;
addSecondsRTC(&chargeRtc,rtc,Parm.chargeTime*60); //
printf("打开充电电源,充电时长:%dS,充电关闭RTC:%d日%d:%d:%d.\n",Parm.chargeTime,chargeRtc.date,chargeRtc.hours,chargeRtc.minutes,chargeRtc.seconds);
}
else
{
EX_POWER(0); //关闭12V充电电源。
Power.obdChargeFlag = TRUE;
addSecondsRTC(&chargeRtc,rtc,0); //
printf("关闭充电电源,充电时长:%dS,充电关闭RTC:%d日%d:%d:%d.\n",Parm.chargeTime,chargeRtc.date,chargeRtc.hours,chargeRtc.minutes,chargeRtc.seconds);
}
}
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=CANVCCOPEN?")!=NULL) //OBD电压状态查询
{
printf("CANVCCOPEN,%d,%d",obd.sysPowerStatus,Sleep.doNotSleepTime);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=CANVCCOPEN,")!=NULL) //打开OBD系统电压。
{
char* tempP = strstr(rxBuf,"AT=CANVCCOPEN,");
char tempBuf0[10] = {0};
char tempBuf1[10] = {0};
u8 obdSysPowerStatus = 0; //OBD 系统电源。
u32 doNotSleepTime = 0;
if(sscanf(tempP,"AT=CANVCCOPEN,%[^,]%*[,] %[^#] ",tempBuf0,tempBuf1) != 0)
{
obdSysPowerStatus = atoi(tempBuf0);
doNotSleepTime = atoi(tempBuf1);
Sleep.enable = FALSE; //休眠使能关闭。
if( obdSysPowerStatus == 1)
{
ODB_POWER(TRUE); //OBD系统电压。1:打开 0:关闭
}
else
{
ODB_POWER(FALSE); //OBD系统电压。1:打开 0:关闭
}
Sleep.doNotSleepTime = doNotSleepTime;
}
printf("AT=CANVCCOPEN,%d,%d",obd.sysPowerStatus,Sleep.doNotSleepTime);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=READVIN")!=NULL) //重新读取VIN码
{
obd.accFlag = TRUE;
// obd.status = OBD_POWER_ON;
printf("重新读取VIN码");
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=VINCODE?")!=NULL) //查询VIN码
{
printf("AT=VINCODE,%s",obd.vinCodeBuf);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=VINCODECLEAR")!=NULL) //VIN CODE clear
{
for (u16 i = 0; i < 40; i++)
{
obd.vinCodeBuf[i] = 0;
}
printf("AT=VINCODE,%s",obd.vinCodeBuf);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=VCCLOW?")!=NULL) //12V OBD电压状态查询
{
printf("AT=VCCLOW,%dmv",Parm.exLowPower);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=VCCLOW,")!=NULL) //
{
char* tempP = strstr(rxBuf,"AT=VCCLOW,");
char tempBuf[10];
u32 exLowPower = 0; //OBD 外电源电压。
if(sscanf(tempP,"AT=VCCLOW,%[^#] ",tempBuf) != 0)
{
exLowPower = atoi(tempBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.exLowPower = exLowPower; //OBD外电压低压阈值。
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=VCCLOW,%dmv",Parm.exLowPower);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=OBDVCCCOMPENSTATE?")!=NULL) //OBD电压补偿参数补偿。
{
printf("AT=OBDVCCCOMPENSTATE,%dmv,%dmv",Parm.chargeCompenstateV,Parm.rsErrorCompenstateV);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=OBDVCCCOMPENSTATE,")!=NULL) //
{
char* tempP = strstr(rxBuf,"AT=OBDVCCCOMPENSTATE,");
char tempBuf0[10] = {0};
char tempBuf1[10] = {0};
u32 chargeCompenstateV = 0; //OBD 外电源充电状态拉低电压补偿。
s32 rsErrorCompenstateV = 0;
if(sscanf(tempP,"AT=OBDVCCCOMPENSTATE,%[^,]%*[,] %[^#] ",tempBuf0,tempBuf1) != 0)
{
chargeCompenstateV = atoi(tempBuf0);
rsErrorCompenstateV = atoi(tempBuf1);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.chargeCompenstateV = chargeCompenstateV; //OBD外电源充电状态拉低电压补偿。
Parm.rsErrorCompenstateV = rsErrorCompenstateV; //OBD外电ADC分压电阻误差补偿参数
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=OBDVCCCOMPENSTATE,%dmv,%dmv",Parm.chargeCompenstateV,Parm.rsErrorCompenstateV);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=OBDVERSON?")!=NULL) //OBD电压补偿参数补偿。
{
printf("AT=OBDVERSON,%s",obd.version);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=ACCVOLTAGE,")!=NULL) //设置ACC检测电压阈值 单位:mv
{
char* tempP = strstr(rxBuf,"AT=ACCVOLTAGE,");
char tempBuf0[10];
u32 accVoltage = 0;
if(sscanf(tempP,"AT=ACCVOLTAGE,%[^#] ",tempBuf0) != 0)
{
accVoltage = atoi(tempBuf0);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
Parm.accVoltage = accVoltage; //
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=ACCVOLTAGE:%dmv",Parm.accVoltage); //
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=ACCVOLTAGE?")!=NULL) //查询低电压阈值
{
printf("AT=ACCVOLTAGE:%dmv",Parm.accVoltage); //
AT_ACK(); // company AT command general ACK.
}
// //LOCK //
// else if(strstr(rxBuf,"AT=LOCKDEBUG?")!=NULL) //inquire gps debug log mode
// {
// if(lock.debug == TRUE) //debug mode
// {
// printf("AT=LOCKDEBUG,1");
// }
// else
// {
// printf("AT=LOCKDEBUG,0");
// }
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=LOCKDEBUG,1")!=NULL) //enable debug log
// {
// lock.debug = TRUE;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=LOCKDEBUG,0")!=NULL) //disable debug log
// {
// lock.debug = FALSE;
// AT_ACK(); // company AT command general ACK.
// }
// else if(strstr(rxBuf,"AT=UNLOCKOPEN,")!=NULL) //open lock
// {
// char modeBuf[10];
// char openTimeBuf[10];
// if(sscanf((const char *)rxBuf,"AT=UNLOCKOPEN,%[^,]%*[,] %[^#]",modeBuf,openTimeBuf) != 0)
// {
// lock.mode = atoi(modeBuf);
// lock.openTime = atoi(openTimeBuf);
// lock.openFlag = TRUE;
// AT_ACK(); // company AT command general ACK.
// }
// else
// {
// printf("The lock parameter is wrong.\n");
// }
// }
//开关信息设置
else if(strstr(rxBuf,"AT=LIGHT_F_WAKEUP_SW,")!=NULL) //前光感唤醒。
{
char* tempP = strstr(rxBuf,"AT=LIGHT_F_WAKEUP_SW,");
char tempBuf[10];
u8 switchStatus = 0; //开关信息
if(sscanf(tempP,"AT=LIGHT_F_WAKEUP_SW,%[^#] ",tempBuf) != 0)
{
switchStatus = atoi(tempBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
LIGHT_F_WAKEUP_SW = switchStatus; //BUZZ开关。
// Parm.crc = getParmCrc(); //计算校验和
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=LIGHT_F_WAKEUP_SW,%d",LIGHT_F_WAKEUP_SW);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=LIGHT_F_ALARM_SW,")!=NULL) //前光感报警
{
char* tempP = strstr(rxBuf,"AT=LIGHT_F_ALARM_SW,");
char tempBuf[10];
u8 switchStatus = 0; //开关信息
if(sscanf(tempP,"AT=LIGHT_F_ALARM_SW,%[^#] ",tempBuf) != 0)
{
switchStatus = atoi(tempBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
LIGHT_F_ALARM_SW = switchStatus; //BUZZ开关。
// Parm.crc = getParmCrc(); //计算校验和
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=LIGHT_F_ALARM_SW,%d",LIGHT_F_ALARM_SW);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=LIGHT_B_WAKEUP_SW,")!=NULL) //后光感唤醒
{
char* tempP = strstr(rxBuf,"AT=LIGHT_B_WAKEUP_SW,");
char tempBuf[10];
u8 switchStatus = 0; //开关信息
if(sscanf(tempP,"AT=LIGHT_B_WAKEUP_SW,%[^#] ",tempBuf) != 0)
{
switchStatus = atoi(tempBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
LIGHT_B_WAKEUP_SW = switchStatus; //BUZZ开关。
// Parm.crc = getParmCrc(); //计算校验和
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=LIGHT_B_WAKEUP_SW,%d",LIGHT_B_WAKEUP_SW);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=LIGHT_B_ALARM_SW,")!=NULL) //后光感报警
{
char* tempP = strstr(rxBuf,"AT=LIGHT_B_ALARM_SW,");
char tempBuf[10];
u8 switchStatus = 0; //开关信息
if(sscanf(tempP,"AT=LIGHT_B_ALARM_SW,%[^#] ",tempBuf) != 0)
{
switchStatus = atoi(tempBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
LIGHT_B_ALARM_SW = switchStatus; //BUZZ开关。
// Parm.crc = getParmCrc(); //计算校验和
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=LIGHT_B_ALARM_SW,%d",LIGHT_B_ALARM_SW);
AT_ACK(); // company AT command general ACK.
}
else if(strstr(rxBuf,"AT=VIBRATE_WAKEUP_SW,")!=NULL) //震动唤醒
{
char* tempP = strstr(rxBuf,"AT=VIBRATE_WAKEUP_SW,");
char tempBuf[10];
u8 switchStatus = 0; //开关信息
if(sscanf(tempP,"AT=VIBRATE_WAKEUP_SW,%[^#] ",tempBuf) != 0)
{
switchStatus = atoi(tempBuf);
u8 * parmP = (u8 *)(&Parm); //获取参数结构体地址。
w25qxxRead(parmP,PARAMETER_ADDR,sizeof(Parm)); //read back the flash parameter.
VIBRATE_WAKEUP_SW = switchStatus; //BUZZ开关。
// Parm.crc = getParmCrc(); //计算校验和
w25qxxWrite(parmP,PARAMETER_ADDR,sizeof(Parm)); //Write system parameters to FLASH.
}
printf("AT=VIBRATE_WAKEUP_SW,%d",VIBRATE_WAKEUP_SW);
AT_ACK(); // company AT command general ACK.
}
//absent command deal /
else //absent AT command.
{
printf("AT command maybe absent.\r\n"); //This code just for testing.
}
}