#include "includes.h" #define VIR_WAIT_FOREVER (-1U) LSAPI_OSI_Thread_t *gUart1Td=NULL; LSAPI_OSI_Pipe_t *at_rx_pipe = NULL; LSAPI_OSI_Pipe_t *at_tx_pipe = NULL; void vir_at_process(char *buf,unsigned int len) { if(sutApp.gtTMode==1)MSG_INFO(1,"vir_at--->%s",buf); // if(msgCmp(buf, "SV")) { // strcpy(sutApp.modemVer, buf); // sutApp.modemVer[strlen(buf)-2]=0; // } pocCmdHandler(buf,len);// } //模块应答 static void prvVirtAtRespCallback(void *param, unsigned event) { LSAPI_OSI_Pipe_t *pipe = (LSAPI_OSI_Pipe_t *)param; char buf[256]; for (;;) { int bytes = LSAPI_OSI_PipeRead(pipe, buf, sizeof(buf)-1); if (bytes <= 0) break; buf[bytes] = '\0'; // MSG_INFO(1,"VAT1:%d,%s",bytes,buf); vir_at_process(buf,bytes); } //MSG_INFO(1,"prvVirtAtRespCallback"); } void makeupsample(void *param){ at_rx_pipe = LSAPI_OSI_PipeCreate(1024); at_tx_pipe = LSAPI_OSI_PipeCreate(1024);//1024 LSAPI_OSI_PipeSetReaderCallback(at_tx_pipe, LSAPI_PIPE_EVENT_RX_ARRIVED, prvVirtAtRespCallback, at_tx_pipe); LSAPI_Device_AtVirtConfig_t cfg = { .name = LSAPI_MAKE_TAG('V', 'A', 'T', '1'), .rx_pipe = at_rx_pipe, .tx_pipe = at_tx_pipe, }; LSAPI_Device_t *device = LSAPI_Device_AtVirtCreate(&cfg); LSAPI_Device_AtDispatch_t *dispatch = LSAPI_Device_AtDispatchCreate(device); LSAPI_Device_AtSetDispatch(device, dispatch); LSAPI_Device_Open(device); LSAPI_OSI_ThreadExit(); } void CreateSerialAtThead() { if(NULL==LSAPI_OSI_ThreadCreate("virat", makeupsample, NULL, LSAPI_OSI_PRIORITY_NORMAL, 1024, 4)) MSG_INFO(1,"virat thread create err"); LSAPI_OSI_ThreadSleep(500); } /* innerInfo 发送数据到内部(module)API */ void innerInfo(unsigned char *info, unsigned int len){ if(len>0){ if(0>LSAPI_OSI_PipeWriteAll(at_rx_pipe, info, len, VIR_WAIT_FOREVER)) MSG_INFO(1,"LSAPI_OSI_PipeWriteAll write failed"); } } void ModemSendAt(char *p) { int len; len=strlen(p); innerInfo(p,len); } /********************************************************************* ӲUART1 DET ********************************************************************/ static LSAPI_Device_t *gDeviceUart = NULL; void Ble_SendAT(char *data,int len){ LSAPI_Device_Write(gDeviceUart, data, len); } void *userUart1EventCB_t(void *param, uint32_t evt){ LSAPI_OSI_Event_t uart_event; //wlog_info("usartCallBack(evt:%d)>> enter",evt); uart_event.id = OHPOC_EVENT_UART1_RNE; uart_event.param1 = evt; /*Note: must use osiEventTrySend, not to use osiEventSend*/ if(osiEventTrySend((LSAPI_OSI_Thread_t *)param, &uart_event, 0) == FALSE)MSG_INFO(1,"uart send event failed"); } static void UART1_Thread(void *param){ uint8_t r_buffer[256] = {0x00}; unsigned ShowBuf[100]={0}; unsigned char temp[3]={0}; int ret,i = 0; LSAPI_OSI_Event_t waitevent = {0}; LSAPI_Device_UartConfig_t uart_cfg = { .name = LSAPI_DEV_UART1, .baud = 9600, .format = LSAPI_DEVICE_FORMAT_8N1, .parity = LSAPI_DEVICE_PARITY_ODD, }; uart_cfg.event_cb = userUart1EventCB_t ; uart_cfg.event_cb_ctx=gUart1Td; gDeviceUart = LSAPI_Device_UartCreate(&uart_cfg); if(gDeviceUart == NULL) { MSG_INFO(1,"uart: creat uart faild!"); return ; } ret = LSAPI_Device_Open(gDeviceUart); if(!ret){ MSG_INFO(1,"uart: Open uart Failed"); return ; } while (1) { LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &waitevent); int read_avail_size = LSAPI_Device_ReadAvail(gDeviceUart); if (read_avail_size > 0) { int read_size = LSAPI_Device_Read(gDeviceUart, r_buffer, sizeof(r_buffer)); if (read_size > 0) { for(i=0;i