123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #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<read_size;i++){
- snprintf(temp,3,"%02x",r_buffer[i]);
- strcat(ShowBuf,temp);
- }
- usbOutPut(ShowBuf,strlen(ShowBuf));
- MSG_INFO(1,"uart1: read: {%s}", ShowBuf);
- BLE_at_process(r_buffer,read_size);
- read_size=0;
- memset(ShowBuf,0,sizeof(ShowBuf));
-
- }
- }
- }
-
- }
- void CreateUART1_Thread(void)
- {
- gUart1Td=LSAPI_OSI_ThreadCreate("UserUart1", UART1_Thread, NULL, LSAPI_OSI_PRIORITY_NORMAL, 1024*4, 4);
- if(gUart1Td==NULL){
- MSG_INFO(1,"uart1 thread create err");
- LSAPI_OSI_ThreadSleep(500);
- }
- }
|