TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.
fPtr_func.cpp
00001 /* 00002 * - CC31xx/CC32xx Host Driver Implementation 00003 * 00004 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ 00005 * 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 00014 * Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the 00017 * distribution. 00018 * 00019 * Neither the name of Texas Instruments Incorporated nor the names of 00020 * its contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00026 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00027 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00031 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 */ 00036 00037 #include "simplelink/cc3100_simplelink.h" 00038 00039 #include "simplelink/cc3100.h" 00040 #include "simplelink/cc3100_driver.h" 00041 #include "simplelink/G_functions/fPtr_func.h" 00042 #include "simplelink/cc3100_nonos.h" 00043 #include "cli_uart.h" 00044 #include "Led_config.h" 00045 00046 #include "cc3100_trace.h" 00047 #include "myBoardInit.h" 00048 00049 using namespace mbed_cc3100; 00050 00051 cc3100 _cc3100_(NC, NC, p9, p10, p8, SPI(p5, p6, p7));//LPC1768 irq, nHib, cs, mosi, miso, sck 00052 00053 #ifdef __cplusplus 00054 extern "C" { 00055 #endif 00056 00057 unsigned char POST_token[] = "__SL_P_ULD"; 00058 unsigned char GET_token[] = "__SL_G_ULD"; 00059 00060 00061 #define PRINT_BUF_LEN 128 00062 extern int8_t print_buf[PRINT_BUF_LEN]; 00063 00064 #define LED_STRING "LED" 00065 #define LED1_STRING "LED1_" 00066 #define LED2_STRING ",LED2_" 00067 #define LED_ON_STRING "ON" 00068 #define LED_OFF_STRING "OFF" 00069 00070 /* General Events handling*/ 00071 #if defined (EXT_LIB_REGISTERED_GENERAL_EVENTS) 00072 00073 typedef _SlEventPropogationStatus_e (*general_callback) (SlDeviceEvent_t *); 00074 00075 static const general_callback general_callbacks[] = 00076 { 00077 #ifdef SlExtLib1GeneralEventHandler 00078 SlExtLib1GeneralEventHandler, 00079 #endif 00080 00081 #ifdef SlExtLib2GeneralEventHandler 00082 SlExtLib2GeneralEventHandler, 00083 #endif 00084 00085 #ifdef SlExtLib3GeneralEventHandler 00086 SlExtLib3GeneralEventHandler, 00087 #endif 00088 00089 #ifdef SlExtLib4GeneralEventHandler 00090 SlExtLib4GeneralEventHandler, 00091 #endif 00092 00093 #ifdef SlExtLib5GeneralEventHandler 00094 SlExtLib5GeneralEventHandler, 00095 #endif 00096 }; 00097 00098 #undef _SlDrvHandleGeneralEvents 00099 00100 /******************************************************************** 00101 _SlDrvHandleGeneralEvents 00102 Iterates through all the general(device) event handlers which are 00103 registered by the external libs/user application. 00104 *********************************************************************/ 00105 void _SlDrvHandleGeneralEvents(SlDeviceEvent_t *slGeneralEvent) 00106 { 00107 uint8_t i; 00108 00109 /* Iterate over all the extenal libs handlers */ 00110 for ( i = 0 ; i < sizeof(general_callbacks)/sizeof(general_callbacks[0]) ; i++ ) 00111 { 00112 if (EVENT_PROPAGATION_BLOCK == general_callbacks[i](slGeneralEvent) ) 00113 { 00114 /* exit immediately and do not call the user specific handler as well */ 00115 return; 00116 } 00117 } 00118 00119 /* At last call the Application specific handler if registered */ 00120 #ifdef sl_GeneralEvtHdlr 00121 sl_GeneralEvtHdlr(slGeneralEvent); 00122 #endif 00123 00124 } 00125 #endif 00126 00127 00128 00129 /* WLAN Events handling*/ 00130 00131 #if defined (EXT_LIB_REGISTERED_WLAN_EVENTS) 00132 00133 typedef _SlEventPropogationStatus_e (*wlan_callback) (SlWlanEvent_t *); 00134 00135 static wlan_callback wlan_callbacks[] = 00136 { 00137 #ifdef SlExtLib1WlanEventHandler 00138 SlExtLib1WlanEventHandler, 00139 #endif 00140 00141 #ifdef SlExtLib2WlanEventHandler 00142 SlExtLib2WlanEventHandler, 00143 #endif 00144 00145 #ifdef SlExtLib3WlanEventHandler 00146 SlExtLib3WlanEventHandler, 00147 #endif 00148 00149 #ifdef SlExtLib4WlanEventHandler 00150 SlExtLib4WlanEventHandler, 00151 #endif 00152 00153 #ifdef SlExtLib5WlanEventHandler 00154 SlExtLib5WlanEventHandler, 00155 #endif 00156 }; 00157 00158 #undef _SlDrvHandleWlanEvents 00159 00160 /*********************************************************** 00161 _SlDrvHandleWlanEvents 00162 Iterates through all the wlan event handlers which are 00163 registered by the external libs/user application. 00164 ************************************************************/ 00165 void _SlDrvHandleWlanEvents(SlWlanEvent_t *slWlanEvent) 00166 { 00167 uint8_t i; 00168 00169 /* Iterate over all the extenal libs handlers */ 00170 for ( i = 0 ; i < sizeof(wlan_callbacks)/sizeof(wlan_callbacks[0]) ; i++ ) 00171 { 00172 if ( EVENT_PROPAGATION_BLOCK == wlan_callbacks[i](slWlanEvent) ) 00173 { 00174 /* exit immediately and do not call the user specific handler as well */ 00175 return; 00176 } 00177 } 00178 00179 /* At last call the Application specific handler if registered */ 00180 #ifdef sl_WlanEvtHdlr 00181 sl_WlanEvtHdlr(slWlanEvent); 00182 #endif 00183 00184 } 00185 #endif 00186 00187 00188 /* NetApp Events handling */ 00189 #if defined (EXT_LIB_REGISTERED_NETAPP_EVENTS) 00190 00191 typedef _SlEventPropogationStatus_e (*netApp_callback) (SlNetAppEvent_t *); 00192 00193 static const netApp_callback netApp_callbacks[] = 00194 { 00195 #ifdef SlExtLib1NetAppEventHandler 00196 SlExtLib1NetAppEventHandler, 00197 #endif 00198 00199 #ifdef SlExtLib2NetAppEventHandler 00200 SlExtLib2NetAppEventHandler, 00201 #endif 00202 00203 #ifdef SlExtLib3NetAppEventHandler 00204 SlExtLib3NetAppEventHandler, 00205 #endif 00206 00207 #ifdef SlExtLib4NetAppEventHandler 00208 SlExtLib4NetAppEventHandler, 00209 #endif 00210 00211 #ifdef SlExtLib5NetAppEventHandler 00212 SlExtLib5NetAppEventHandler, 00213 #endif 00214 }; 00215 00216 #undef _SlDrvHandleNetAppEvents 00217 00218 /************************************************************ 00219 _SlDrvHandleNetAppEvents 00220 Iterates through all the net app event handlers which are 00221 registered by the external libs/user application. 00222 ************************************************************/ 00223 void _SlDrvHandleNetAppEvents(SlNetAppEvent_t *slNetAppEvent) 00224 { 00225 uint8_t i; 00226 00227 /* Iterate over all the extenal libs handlers */ 00228 for ( i = 0 ; i < sizeof(netApp_callbacks)/sizeof(netApp_callbacks[0]) ; i++ ) 00229 { 00230 if (EVENT_PROPAGATION_BLOCK == netApp_callbacks[i](slNetAppEvent) ) 00231 { 00232 /* exit immediately and do not call the user specific handler as well */ 00233 return; 00234 } 00235 } 00236 00237 /* At last call the Application specific handler if registered */ 00238 #ifdef sl_NetAppEvtHdlr 00239 sl_NetAppEvtHdlr(slNetAppEvent); 00240 #endif 00241 00242 } 00243 #endif 00244 00245 00246 /* Http Server Events handling */ 00247 #if defined (EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS) 00248 00249 typedef _SlEventPropogationStatus_e (*httpServer_callback) (SlHttpServerEvent_t*, SlHttpServerResponse_t*); 00250 00251 static const httpServer_callback httpServer_callbacks[] = 00252 { 00253 #ifdef SlExtLib1HttpServerEventHandler 00254 SlExtLib1HttpServerEventHandler, 00255 #endif 00256 00257 #ifdef SlExtLib2HttpServerEventHandler 00258 SlExtLib2HttpServerEventHandler, 00259 #endif 00260 00261 #ifdef SlExtLib3HttpServerEventHandler 00262 SlExtLib3HttpServerEventHandler, 00263 #endif 00264 00265 #ifdef SlExtLib4HttpServerEventHandler 00266 SlExtLib4HttpServerEventHandler, 00267 #endif 00268 00269 #ifdef SlExtLib5HttpServerEventHandler 00270 SlExtLib5HttpServerEventHandler, 00271 #endif 00272 }; 00273 00274 #undef _SlDrvHandleHttpServerEvents 00275 00276 /******************************************************************* 00277 _SlDrvHandleHttpServerEvents 00278 Iterates through all the http server event handlers which are 00279 registered by the external libs/user application. 00280 ********************************************************************/ 00281 void _SlDrvHandleHttpServerEvents(SlHttpServerEvent_t *slHttpServerEvent, SlHttpServerResponse_t *slHttpServerResponse) 00282 { 00283 _u8 i; 00284 00285 /* Iterate over all the external libs handlers */ 00286 for ( i = 0 ; i < sizeof(httpServer_callbacks)/sizeof(httpServer_callbacks[0]) ; i++ ) 00287 { 00288 if ( EVENT_PROPAGATION_BLOCK == httpServer_callbacks[i](slHttpServerEvent, slHttpServerResponse) ) 00289 { 00290 /* exit immediately and do not call the user specific handler as well */ 00291 return; 00292 } 00293 } 00294 00295 /* At last call the Application specific handler if registered */ 00296 #ifdef sl_HttpServerCallback 00297 sl_HttpServerCallback(slHttpServerEvent, slHttpServerResponse); 00298 #endif 00299 00300 } 00301 #endif 00302 00303 00304 /* Socket Events */ 00305 #if defined (EXT_LIB_REGISTERED_SOCK_EVENTS) 00306 00307 typedef _SlEventPropogationStatus_e (*sock_callback) (SlSockEvent_t *); 00308 00309 static const sock_callback sock_callbacks[] = 00310 { 00311 #ifdef SlExtLib1SockEventHandler 00312 SlExtLib1SockEventHandler, 00313 #endif 00314 00315 #ifdef SlExtLib2SockEventHandler 00316 SlExtLib2SockEventHandler, 00317 #endif 00318 00319 #ifdef SlExtLib3SockEventHandler 00320 SlExtLib3SockEventHandler, 00321 #endif 00322 00323 #ifdef SlExtLib4SockEventHandler 00324 SlExtLib4SockEventHandler, 00325 #endif 00326 00327 #ifdef SlExtLib5SockEventHandler 00328 SlExtLib5SockEventHandler, 00329 #endif 00330 }; 00331 00332 /************************************************************* 00333 _SlDrvHandleSockEvents 00334 Iterates through all the socket event handlers which are 00335 registered by the external libs/user application. 00336 **************************************************************/ 00337 void _SlDrvHandleSockEvents(SlSockEvent_t *slSockEvent) 00338 { 00339 uint8_t i; 00340 00341 /* Iterate over all the external libs handlers */ 00342 for ( i = 0 ; i < sizeof(sock_callbacks)/sizeof(sock_callbacks[0]) ; i++ ) 00343 { 00344 if ( EVENT_PROPAGATION_BLOCK == sock_callbacks[i](slSockEvent) ) 00345 { 00346 /* exit immediately and do not call the user specific handler as well */ 00347 return; 00348 } 00349 } 00350 00351 /* At last call the Application specific handler if registered */ 00352 #ifdef sl_SockEvtHdlr 00353 sl_SockEvtHdlr(slSockEvent); 00354 #endif 00355 00356 } 00357 00358 #endif 00359 00360 /*! 00361 \brief This function handles ping report events 00362 00363 \param[in] pPingReport holds the ping report statistics 00364 00365 \return None 00366 00367 \note 00368 00369 \warning 00370 */ 00371 void SimpleLinkPingReport(SlPingReport_t *pPingReport) 00372 { 00373 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_PING_DONE); 00374 00375 if(pPingReport == NULL) 00376 Uart_Write((uint8_t *)" [PING REPORT] NULL Pointer Error\r\n"); 00377 00378 g_PingPacketsRecv = pPingReport->PacketsReceived; 00379 } 00380 00381 00382 /*******************************************************************************/ 00383 /* _sl_HandleAsync_Accept */ 00384 /*******************************************************************************/ 00385 #ifndef SL_TINY_EXT 00386 void _sl_HandleAsync_Accept(void *pVoidBuf) 00387 { 00388 _SocketAddrResponse_u *pMsgArgs = (_SocketAddrResponse_u *)_SL_RESP_ARGS_START(pVoidBuf); 00389 00390 _cc3100_._driver._SlDrvProtectionObjLockWaitForever(); 00391 00392 VERIFY_PROTOCOL(( pMsgArgs->IpV4.sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS); 00393 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); 00394 00395 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs,sizeof(_SocketAddrResponse_u)); 00396 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj); 00397 00398 _cc3100_._driver._SlDrvProtectionObjUnLock(); 00399 return; 00400 } 00401 00402 /*******************************************************************************/ 00403 /* _sl_HandleAsync_Connect */ 00404 /*******************************************************************************/ 00405 void _sl_HandleAsync_Connect(void *pVoidBuf) 00406 { 00407 _SocketResponse_t *pMsgArgs = (_SocketResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); 00408 00409 _cc3100_._driver._SlDrvProtectionObjLockWaitForever(); 00410 00411 VERIFY_PROTOCOL((pMsgArgs->sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS); 00412 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); 00413 00414 ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->sd = pMsgArgs->sd; 00415 ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->statusOrLen = pMsgArgs->statusOrLen; 00416 00417 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj); 00418 _cc3100_._driver._SlDrvProtectionObjUnLock(); 00419 return; 00420 } 00421 00422 /*******************************************************************************/ 00423 /* _sl_HandleAsync_Select */ 00424 /*******************************************************************************/ 00425 void _sl_HandleAsync_Select(void *pVoidBuf) 00426 { 00427 _SelectAsyncResponse_t *pMsgArgs = (_SelectAsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); 00428 00429 _cc3100_._driver._SlDrvProtectionObjLockWaitForever(); 00430 00431 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); 00432 00433 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_SelectAsyncResponse_t)); 00434 00435 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj); 00436 _cc3100_._driver._SlDrvProtectionObjUnLock(); 00437 00438 return; 00439 } 00440 00441 #endif 00442 00443 /******************************************************************************/ 00444 /* _sl_HandleAsync_DnsGetHostByName */ 00445 /******************************************************************************/ 00446 void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf) 00447 { 00448 _GetHostByNameIPv4AsyncResponse_t *pMsgArgs = (_GetHostByNameIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); 00449 00450 _cc3100_._driver._SlDrvProtectionObjLockWaitForever(); 00451 00452 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); 00453 00454 /*IPv6 */ 00455 if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) { 00456 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv6AsyncResponse_t)); 00457 } 00458 /*IPv4 */ 00459 else 00460 { 00461 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv4AsyncResponse_t)); 00462 } 00463 00464 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj); 00465 _cc3100_._driver._SlDrvProtectionObjUnLock(); 00466 00467 return; 00468 } 00469 00470 /******************************************************************************/ 00471 00472 /****************************************************************************** 00473 _sl_HandleAsync_DnsGetHostByService 00474 00475 CALLER NWP - Async event on sl_DnsGetHostByService with IPv4 Family 00476 00477 00478 DESCRIPTION: 00479 00480 Async event on sl_DnsGetHostByService command with IPv4 Family. 00481 Return service attributes like IP address, port and text according to service name. 00482 The user sets a service name Full/Part (see example below), and should get the: 00483 1. IP of the service 00484 2. The port of service. 00485 3. The text of service. 00486 00487 Hence it can make a connection to the specific service and use it. 00488 It is similar to get host by name method. 00489 00490 It is done by a single shot query with PTR type on the service name. 00491 00492 00493 00494 Note: 00495 1. The return's attributes are belonged to first service that is found. 00496 It can be other services with the same service name will response to 00497 the query. The results of these responses are saved in the peer cache of the NWP, and 00498 should be read by another API. 00499 00500 00501 PARAMETERS: 00502 00503 pVoidBuf - is point to opcode of the event. 00504 it contains the outputs that are given to the user 00505 00506 outputs description: 00507 00508 1.out_pAddr[] - output: Contain the IP address of the service. 00509 2.out_pPort - output: Contain the port of the service. 00510 3.inout_TextLen - Input: Contain the max length of the text that the user wants to get. 00511 it means that if the test of service is bigger that its value than 00512 the text is cut to inout_TextLen value. 00513 Output: Contain the length of the text that is returned. Can be full text or part 00514 of the text (see above). 00515 00516 4.out_pText - Contain the text of the service (full or part see above- inout_TextLen description). 00517 00518 * 00519 00520 00521 RETURNS: success or fail. 00522 00523 ******************************************************************************/ 00524 #ifndef SL_TINY_EXT 00525 void _sl_HandleAsync_DnsGetHostByService(void *pVoidBuf) 00526 { 00527 _GetHostByServiceAsyncResponse_t* Res; 00528 uint16_t TextLen; 00529 uint16_t UserTextLen; 00530 00531 /*pVoidBuf - is point to opcode of the event.*/ 00532 00533 /*set pMsgArgs to point to the attribute of the event.*/ 00534 _GetHostByServiceIPv4AsyncResponse_t *pMsgArgs = (_GetHostByServiceIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); 00535 00536 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs); 00537 00538 /*IPv6*/ 00539 if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) { 00540 return; 00541 } 00542 /*IPv4*/ 00543 else { 00544 /************************************************************************************************* 00545 00546 1. Copy the attribute part of the evnt to the attribute part of the response 00547 memcpy(g_pCB->GetHostByServiceCB.pAsyncRsp, pMsgArgs, sizeof(_GetHostByServiceIPv4AsyncResponse_t)); 00548 00549 set to TextLen the text length of the service.*/ 00550 TextLen = pMsgArgs->TextLen; 00551 00552 /*Res pointed to mDNS global object struct */ 00553 Res = (_GetHostByServiceAsyncResponse_t*)g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs; 00554 00555 00556 00557 /*It is 4 bytes so we avoid from memcpy*/ 00558 Res->out_pAddr[0] = pMsgArgs->Address; 00559 Res->out_pPort[0] = pMsgArgs->Port; 00560 Res->Status = pMsgArgs->Status; 00561 00562 /*set to TextLen the text length of the user (input fromthe user).*/ 00563 UserTextLen = Res->inout_TextLen[0]; 00564 00565 /*Cut the service text if the user requested for smaller text.*/ 00566 UserTextLen = (TextLen <= UserTextLen) ? TextLen : UserTextLen; 00567 Res->inout_TextLen[0] = UserTextLen ; 00568 00569 /************************************************************************************************** 00570 00571 2. Copy the payload part of the evnt (the text) to the payload part of the response 00572 the lenght of the copy is according to the text length in the attribute part. */ 00573 00574 00575 memcpy(Res->out_pText, 00576 (int8_t *)(& pMsgArgs[1]), /* & pMsgArgs[1] -> 1st byte after the fixed header = 1st byte of variable text.*/ 00577 UserTextLen); 00578 00579 00580 /**************************************************************************************************/ 00581 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj); 00582 return; 00583 } 00584 } 00585 #endif 00586 00587 /*****************************************************************************/ 00588 /* _sl_HandleAsync_PingResponse */ 00589 /*****************************************************************************/ 00590 #ifndef SL_TINY_EXT 00591 void _sl_HandleAsync_PingResponse(void *pVoidBuf) 00592 { 00593 _PingReportResponse_t *pMsgArgs = (_PingReportResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); 00594 SlPingReport_t pingReport; 00595 00596 if(pPingCallBackFunc) { 00597 _cc3100_._netapp.CopyPingResultsToReport(pMsgArgs,&pingReport); 00598 pPingCallBackFunc(&pingReport); 00599 } else { 00600 00601 _cc3100_._driver._SlDrvProtectionObjLockWaitForever(); 00602 VERIFY_SOCKET_CB(NULL != g_pCB->PingCB.PingAsync.pAsyncRsp); 00603 00604 if (NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs) { 00605 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_PingReportResponse_t)); 00606 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj); 00607 } 00608 _cc3100_._driver._SlDrvProtectionObjUnLock(); 00609 } 00610 return; 00611 } 00612 #endif 00613 00614 /* ******************************************************************************/ 00615 /* _SlDrvMsgReadSpawnCtx */ 00616 /* ******************************************************************************/ 00617 _SlReturnVal_t _SlDrvMsgReadSpawnCtx(void *pValue) 00618 { 00619 00620 #ifdef SL_POLLING_MODE_USED 00621 int16_t retCode = OSI_OK; 00622 /* for polling based systems */ 00623 do { 00624 retCode = _cc3100_._nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, 0); 00625 if ( OSI_OK != retCode ) { 00626 if (TRUE == g_pCB->IsCmdRespWaited) { 00627 OSI_RET_OK_CHECK( _cc3100_._nonos.sl_SyncObjSignal(&g_pCB->CmdSyncObj) ); 00628 return SL_RET_CODE_OK; 00629 } 00630 } 00631 00632 } while (OSI_OK != retCode); 00633 00634 #else 00635 #ifndef SL_PLATFORM_MULTI_THREADED 00636 _cc3100_._driver._SlDrvObjLockWaitForever(&g_pCB->GlobalLockObj); 00637 // OSI_RET_OK_CHECK(_cc3100_._nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, SL_OS_WAIT_FOREVER) ); 00638 #else 00639 OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->GlobalLockObj, SL_OS_WAIT_FOREVER) ); 00640 #endif 00641 #endif 00642 g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;/* buffer must be allocated by _SlDrvMsgRead */ 00643 g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler= NULL; 00644 g_pCB->FunctionParams.AsyncExt.RxMsgClass = CMD_RESP_CLASS;/* init to illegal value and verify it's overwritten with the valid one */ 00645 00646 /* Messages might have been read by CmdResp context. Therefore after */ 00647 /* getting LockObj, check again where the Pending Rx Msg is still present. */ 00648 if(FALSE == (_cc3100_._driver._SL_PENDING_RX_MSG(g_pCB))) { 00649 #ifndef SL_PLATFORM_MULTI_THREADED 00650 _cc3100_._driver._SlDrvObjUnLock(&g_pCB->GlobalLockObj); 00651 // OSI_RET_OK_CHECK(_cc3100_._nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj)); 00652 #else 00653 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj)); 00654 #endif 00655 return SL_RET_CODE_OK; 00656 } 00657 00658 VERIFY_RET_OK(_cc3100_._driver._SlDrvMsgRead()); 00659 00660 g_pCB->RxDoneCnt++; 00661 00662 switch(g_pCB->FunctionParams.AsyncExt.RxMsgClass) { 00663 case ASYNC_EVT_CLASS: 00664 /* If got here and protected by LockObj a message is waiting */ 00665 /* to be read */ 00666 VERIFY_PROTOCOL(NULL != g_pCB->FunctionParams.AsyncExt.pAsyncBuf); 00667 00668 _cc3100_._driver._SlAsyncEventGenericHandler(); 00669 00670 #if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) 00671 g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL; 00672 #else 00673 free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); 00674 #endif 00675 break; 00676 case DUMMY_MSG_CLASS: 00677 case RECV_RESP_CLASS: 00678 /* These types are legal in this context. Do nothing */ 00679 break; 00680 case CMD_RESP_CLASS: 00681 /* Command response is illegal in this context. */ 00682 /* No 'break' here: Assert! */ 00683 default: 00684 VERIFY_PROTOCOL(0); 00685 } 00686 #ifndef SL_PLATFORM_MULTI_THREADED 00687 _cc3100_._driver._SlDrvObjUnLock(&g_pCB->GlobalLockObj); 00688 // OSI_RET_OK_CHECK(_cc3100_._nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj)); 00689 #else 00690 OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj)); 00691 #endif 00692 return(SL_RET_CODE_OK); 00693 00694 } 00695 00696 /*************************************************************************** 00697 _sl_HandleAsync_Stop - handles stop signalling to 00698 a waiting object 00699 ****************************************************************************/ 00700 void _sl_HandleAsync_Stop(void *pVoidBuf) 00701 { 00702 _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pVoidBuf); 00703 00704 VERIFY_SOCKET_CB(NULL != g_pCB->StopCB.pAsyncRsp); 00705 00706 _cc3100_._driver._SlDrvProtectionObjLockWaitForever(); 00707 00708 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_BasicResponse_t)); 00709 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj); 00710 _cc3100_._driver._SlDrvProtectionObjUnLock(); 00711 return; 00712 } 00713 00714 /****************************************************************************** 00715 _SlDrvDeviceEventHandler - handles internally device async events 00716 ******************************************************************************/ 00717 void _SlDrvDeviceEventHandler(void *pArgs) 00718 { 00719 _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs; 00720 00721 switch(pHdr->GenHeader.Opcode) { 00722 case SL_OPCODE_DEVICE_INITCOMPLETE: 00723 _cc3100_._sl_HandleAsync_InitComplete(pHdr); 00724 00725 break; 00726 case SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE: 00727 _sl_HandleAsync_Stop(pHdr); 00728 00729 break; 00730 00731 00732 case SL_OPCODE_DEVICE_ABORT: 00733 { 00734 #if defined (sl_GeneralEvtHdlr) || defined(EXT_LIB_REGISTERED_GENERAL_EVENTS) 00735 SlDeviceEvent_t devHandler; 00736 devHandler.Event = SL_DEVICE_ABORT_ERROR_EVENT; 00737 devHandler.EventData.deviceReport.AbortType = *((uint32_t*)pArgs + 2); 00738 devHandler.EventData.deviceReport.AbortData = *((uint32_t*)pArgs + 3); 00739 _SlDrvHandleGeneralEvents(&devHandler); 00740 #endif 00741 } 00742 break; 00743 case SL_OPCODE_DEVICE_DEVICEASYNCFATALERROR: 00744 #if defined (sl_GeneralEvtHdlr) || defined(EXT_LIB_REGISTERED_GENERAL_EVENTS) 00745 { 00746 _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pHdr); 00747 SlDeviceEvent_t devHandler; 00748 devHandler.Event = SL_DEVICE_FATAL_ERROR_EVENT; 00749 devHandler.EventData.deviceEvent.status = pMsgArgs->status & 0xFF; 00750 devHandler.EventData.deviceEvent.sender = (SlErrorSender_e)((pMsgArgs->status >> 8) & 0xFF); 00751 _SlDrvHandleGeneralEvents(&devHandler); 00752 } 00753 #endif 00754 break; 00755 default: 00756 SL_ERROR_TRACE2(MSG_306, "ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode); 00757 //printf("ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode); 00758 00759 } 00760 } 00761 00762 /*****************************************************************************/ 00763 /* _SlDrvNetAppEventHandler */ 00764 /*****************************************************************************/ 00765 void _SlDrvNetAppEventHandler(void *pArgs) 00766 { 00767 _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs; 00768 #if defined(sl_HttpServerCallback) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS) 00769 SlHttpServerEvent_t httpServerEvent; 00770 SlHttpServerResponse_t httpServerResponse; 00771 #endif 00772 switch(pHdr->GenHeader.Opcode) { 00773 case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE: 00774 case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE_V6: 00775 _sl_HandleAsync_DnsGetHostByName(pArgs); 00776 break; 00777 #ifndef SL_TINY_EXT 00778 case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE: 00779 case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE_V6: 00780 _sl_HandleAsync_DnsGetHostByService(pArgs); 00781 break; 00782 case SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE: 00783 _sl_HandleAsync_PingResponse(pArgs); 00784 break; 00785 #endif 00786 00787 #if defined(sl_HttpServerCallback) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS) 00788 case SL_OPCODE_NETAPP_HTTPGETTOKENVALUE: { 00789 00790 uint8_t *pTokenName; 00791 slHttpServerData_t Token_value; 00792 sl_NetAppHttpServerGetToken_t *httpGetToken = (sl_NetAppHttpServerGetToken_t *)_SL_RESP_ARGS_START(pHdr); 00793 pTokenName = (uint8_t *)((sl_NetAppHttpServerGetToken_t *)httpGetToken + 1); 00794 00795 httpServerResponse.Response = SL_NETAPP_HTTPSETTOKENVALUE; 00796 httpServerResponse.ResponseData.token_value.len = MAX_TOKEN_VALUE_LEN; 00797 00798 /* Reuse the async buffer for getting the token value response from the user */ 00799 httpServerResponse.ResponseData.token_value.data = (uint8_t *)_SL_RESP_ARGS_START(pHdr) + MAX_TOKEN_NAME_LEN; 00800 httpServerEvent.Event = SL_NETAPP_HTTPGETTOKENVALUE_EVENT; 00801 00802 httpServerEvent.EventData.httpTokenName.len = httpGetToken->token_name_len; 00803 httpServerEvent.EventData.httpTokenName.data = pTokenName; 00804 00805 Token_value.token_name = pTokenName; 00806 00807 _SlDrvHandleHttpServerEvents (&httpServerEvent, &httpServerResponse); 00808 00809 Token_value.value_len = httpServerResponse.ResponseData.token_value.len; 00810 Token_value.name_len = httpServerEvent.EventData.httpTokenName.len; 00811 00812 Token_value.token_value = httpServerResponse.ResponseData.token_value.data; 00813 00814 00815 _cc3100_._netapp.sl_NetAppSendTokenValue(&Token_value); 00816 #endif 00817 } 00818 break; 00819 00820 case SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE: { 00821 #ifdef sl_HttpServerCallback 00822 uint8_t *pPostParams; 00823 00824 sl_NetAppHttpServerPostToken_t *httpPostTokenArgs = (sl_NetAppHttpServerPostToken_t *)_SL_RESP_ARGS_START(pHdr); 00825 pPostParams = (uint8_t *)((sl_NetAppHttpServerPostToken_t *)httpPostTokenArgs + 1); 00826 00827 httpServerEvent.Event = SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT; 00828 00829 httpServerEvent.EventData.httpPostData.action.len = httpPostTokenArgs->post_action_len; 00830 httpServerEvent.EventData.httpPostData.action.data = pPostParams; 00831 pPostParams+=httpPostTokenArgs->post_action_len; 00832 00833 httpServerEvent.EventData.httpPostData.token_name.len = httpPostTokenArgs->token_name_len; 00834 httpServerEvent.EventData.httpPostData.token_name.data = pPostParams; 00835 pPostParams+=httpPostTokenArgs->token_name_len; 00836 00837 httpServerEvent.EventData.httpPostData.token_value.len = httpPostTokenArgs->token_value_len; 00838 httpServerEvent.EventData.httpPostData.token_value.data = pPostParams; 00839 00840 httpServerResponse.Response = SL_NETAPP_RESPONSE_NONE; 00841 00842 00843 _SlDrvHandleHttpServerEvents (&httpServerEvent, &httpServerResponse); 00844 } 00845 break; 00846 #endif 00847 default: 00848 SL_ERROR_TRACE2(MSG_305, "ASSERT: _SlDrvNetAppEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode); 00849 VERIFY_PROTOCOL(0); 00850 } 00851 } 00852 00853 /* 00854 * ASYNCHRONOUS EVENT HANDLERS -- Start 00855 */ 00856 00857 /*! 00858 \brief This function handles WLAN events 00859 00860 \param[in] pWlanEvent is the event passed to the handler 00861 00862 \return None 00863 00864 \note 00865 00866 \warning 00867 */ 00868 #if (defined(sl_WlanEvtHdlr)) 00869 void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) 00870 { 00871 unsigned char g_ucConnectionSSID[32+1]; //Connection SSID 00872 unsigned char g_ucConnectionBSSID[6]; //Connection BSSID 00873 00874 if(pWlanEvent == NULL) 00875 Uart_Write((uint8_t *)" [WLAN EVENT] NULL Pointer Error \n\r"); 00876 00877 switch(pWlanEvent->Event) { 00878 case SL_WLAN_CONNECT_EVENT: { 00879 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION); 00880 00881 // Copy new connection SSID and BSSID to global parameters 00882 memcpy(g_ucConnectionSSID,pWlanEvent->EventData. 00883 STAandP2PModeWlanConnected.ssid_name, 00884 pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_len); 00885 memcpy(g_ucConnectionBSSID, 00886 pWlanEvent->EventData.STAandP2PModeWlanConnected.bssid, 00887 SL_BSSID_LENGTH); 00888 memset(print_buf, 0x00, PRINT_BUF_LEN); 00889 sprintf((char*) print_buf, "[WLAN EVENT] STA Connected to the AP: %s ,""BSSID: %x:%x:%x:%x:%x:%x\n\r", 00890 g_ucConnectionSSID,g_ucConnectionBSSID[0], 00891 g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], 00892 g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], 00893 g_ucConnectionBSSID[5]); 00894 Uart_Write((uint8_t *) print_buf); 00895 /* 00896 * Information about the connected AP (like name, MAC etc) will be 00897 * available in 'slWlanConnectAsyncResponse_t' - Applications 00898 * can use it if required 00899 * 00900 * slWlanConnectAsyncResponse_t *pEventData = NULL; 00901 * pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected; 00902 * 00903 */ 00904 } 00905 break; 00906 00907 case SL_WLAN_DISCONNECT_EVENT: { 00908 slWlanConnectAsyncResponse_t* pEventData = NULL; 00909 00910 _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION); 00911 _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED); 00912 00913 pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected; 00914 00915 /* If the user has initiated 'Disconnect' request, 'reason_code' is SL_USER_INITIATED_DISCONNECTION */ 00916 if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) { 00917 memset(print_buf, 0x00, PRINT_BUF_LEN); 00918 sprintf((char*) print_buf, "[WLAN EVENT]Device disconnected from the AP: %s," 00919 "BSSID: %x:%x:%x:%x:%x:%x on application's request \n\r", 00920 g_ucConnectionSSID,g_ucConnectionBSSID[0], 00921 g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], 00922 g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], 00923 g_ucConnectionBSSID[5]); 00924 Uart_Write((uint8_t *) print_buf); 00925 } else { 00926 memset(print_buf, 0x00, PRINT_BUF_LEN); 00927 sprintf((char*) print_buf, "[WLAN ERROR]Device disconnected from the AP AP: %s," 00928 "BSSID: %x:%x:%x:%x:%x:%x on an ERROR..!! \n\r", 00929 g_ucConnectionSSID,g_ucConnectionBSSID[0], 00930 g_ucConnectionBSSID[1],g_ucConnectionBSSID[2], 00931 g_ucConnectionBSSID[3],g_ucConnectionBSSID[4], 00932 g_ucConnectionBSSID[5]); 00933 Uart_Write((uint8_t *) print_buf); 00934 } 00935 memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID)); 00936 memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID)); 00937 } 00938 break; 00939 00940 case SL_WLAN_STA_CONNECTED_EVENT: { 00941 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_STA_CONNECTED); 00942 } 00943 break; 00944 00945 case SL_WLAN_STA_DISCONNECTED_EVENT: { 00946 _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_STA_CONNECTED); 00947 _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_LEASED); 00948 } 00949 break; 00950 00951 default: { 00952 memset(print_buf, 0x00, PRINT_BUF_LEN); 00953 sprintf((char*) print_buf, "[WLAN EVENT] Unexpected event [0x%x]\n\r",pWlanEvent->Event); 00954 Uart_Write((uint8_t *) print_buf); 00955 } 00956 break; 00957 } 00958 } 00959 #endif 00960 00961 /*! 00962 \brief This function handles events for IP address acquisition via DHCP 00963 indication 00964 00965 \param[in] pNetAppEvent is the event passed to the handler 00966 00967 \return None 00968 00969 \note 00970 00971 \warning 00972 */ 00973 #if (defined(sl_NetAppEvtHdlr)) 00974 void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) 00975 { 00976 00977 if(pNetAppEvent == NULL){ 00978 Uart_Write((uint8_t *)" [NETAPP EVENT] NULL Pointer Error \n\r"); 00979 } 00980 00981 switch(pNetAppEvent->Event) { 00982 case SL_NETAPP_IPV4_IPACQUIRED_EVENT: { 00983 SlIpV4AcquiredAsync_t *pEventData = NULL; 00984 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED); 00985 pEventData = &pNetAppEvent->EventData.ipAcquiredV4; 00986 g_GatewayIP = pEventData->gateway; 00987 00988 memset(print_buf, 0x00, PRINT_BUF_LEN); 00989 sprintf((char*) print_buf, "[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , ""Gateway=%d.%d.%d.%d\n\r", 00990 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,3), 00991 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,2), 00992 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,1), 00993 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,0), 00994 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,3), 00995 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,2), 00996 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,1), 00997 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,0)); 00998 Uart_Write((uint8_t *) print_buf); 00999 } 01000 break; 01001 01002 case SL_NETAPP_IP_LEASED_EVENT: { 01003 g_StationIP = pNetAppEvent->EventData.ipLeased.ip_address; 01004 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_IP_LEASED); 01005 01006 } 01007 break; 01008 01009 default: { 01010 memset(print_buf, 0x00, PRINT_BUF_LEN); 01011 sprintf((char*) print_buf, "[NETAPP EVENT] Unexpected event [0x%x] \n\r",pNetAppEvent->Event); 01012 Uart_Write((uint8_t *) print_buf); 01013 } 01014 break; 01015 } 01016 } 01017 #endif 01018 01019 /*! 01020 \brief This function handles socket events indication 01021 01022 \param[in] pSock is the event passed to the handler 01023 01024 \return None 01025 */ 01026 #if (defined(sl_SockEvtHdlr)) 01027 void SimpleLinkSockEventHandler(SlSockEvent_t *pSock) 01028 { 01029 if(pSock == NULL) 01030 Uart_Write((uint8_t *)" [SOCK EVENT] NULL Pointer Error \n\r"); 01031 01032 switch( pSock->Event ) 01033 { 01034 case SL_SOCKET_TX_FAILED_EVENT: 01035 /* 01036 * TX Failed 01037 * 01038 * Information about the socket descriptor and status will be 01039 * available in 'SlSockEventData_t' - Applications can use it if 01040 * required 01041 * 01042 * SlSockEventData_t *pEventData = NULL; 01043 * pEventData = & pSock->EventData; 01044 */ 01045 01046 switch( pSock->socketAsyncEvent.SockTxFailData.status ) 01047 { 01048 case SL_ECLOSE: 01049 Uart_Write((uint8_t *)" [SOCK EVENT] Close socket operation, failed to transmit all queued packets\n\r"); 01050 break; 01051 default: 01052 memset(print_buf, 0x00, PRINT_BUF_LEN); 01053 sprintf((char*) print_buf, "[SOCK ERROR] - TX FAILED : socket %d , reason""(%d) \n\n", pSock->socketAsyncEvent.SockTxFailData.sd, pSock->socketAsyncEvent.SockTxFailData.status); 01054 Uart_Write((uint8_t *) print_buf); 01055 01056 break; 01057 } 01058 break; 01059 01060 default: 01061 memset(print_buf, 0x00, PRINT_BUF_LEN); 01062 sprintf((char*) print_buf, "[SOCK EVENT] - Unexpected Event [%x0x]\n\n",pSock->Event); 01063 Uart_Write((uint8_t *) print_buf); 01064 break; 01065 } 01066 } 01067 #endif 01068 01069 /*! 01070 \brief This function handles callback for the HTTP server events 01071 01072 \param[in] pHttpEvent - Contains the relevant event information 01073 \param[in] pHttpResponse - Should be filled by the user with the 01074 relevant response information 01075 01076 \return None 01077 01078 \note 01079 01080 \warning 01081 */ 01082 #if (defined(sl_HttpServerCallback)) 01083 void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pSlHttpServerEvent, SlHttpServerResponse_t *pSlHttpServerResponse) 01084 { 01085 unsigned char strLenVal = 0; 01086 01087 if(!pSlHttpServerEvent || !pSlHttpServerResponse) 01088 { 01089 return; 01090 } 01091 01092 switch (pSlHttpServerEvent->Event) 01093 { 01094 case SL_NETAPP_HTTPGETTOKENVALUE_EVENT: 01095 { 01096 unsigned char status, *ptr; 01097 01098 ptr = pSlHttpServerResponse->ResponseData.token_value.data; 01099 pSlHttpServerResponse->ResponseData.token_value.len = 0; 01100 if(memcmp(pSlHttpServerEvent->EventData.httpTokenName.data, GET_token, 01101 strlen((const char *)GET_token)) == 0) 01102 { 01103 status = GPIO_IF_LedStatus(MCU_RED_LED_GPIO); 01104 strLenVal = strlen(LED1_STRING); 01105 memcpy(ptr, LED1_STRING, strLenVal); 01106 ptr += strLenVal; 01107 pSlHttpServerResponse->ResponseData.token_value.len += strLenVal; 01108 if(status & 0x01) 01109 { 01110 strLenVal = strlen(LED_ON_STRING); 01111 memcpy(ptr, LED_ON_STRING, strLenVal); 01112 ptr += strLenVal; 01113 pSlHttpServerResponse->ResponseData.token_value.len += strLenVal; 01114 } 01115 else 01116 { 01117 strLenVal = strlen(LED_OFF_STRING); 01118 memcpy(ptr, LED_OFF_STRING, strLenVal); 01119 ptr += strLenVal; 01120 pSlHttpServerResponse->ResponseData.token_value.len += strLenVal; 01121 } 01122 status = GPIO_IF_LedStatus(MCU_GREEN_LED_GPIO); 01123 strLenVal = strlen(LED2_STRING); 01124 memcpy(ptr, LED2_STRING, strLenVal); 01125 ptr += strLenVal; 01126 pSlHttpServerResponse->ResponseData.token_value.len += strLenVal; 01127 if(status & 0x01) 01128 { 01129 strLenVal = strlen(LED_ON_STRING); 01130 memcpy(ptr, LED_ON_STRING, strLenVal); 01131 ptr += strLenVal; 01132 pSlHttpServerResponse->ResponseData.token_value.len += strLenVal; 01133 } 01134 else 01135 { 01136 strLenVal = strlen(LED_OFF_STRING); 01137 memcpy(ptr, LED_OFF_STRING, strLenVal); 01138 ptr += strLenVal; 01139 pSlHttpServerResponse->ResponseData.token_value.len += strLenVal; 01140 } 01141 *ptr = '\0'; 01142 } 01143 01144 } 01145 break; 01146 01147 case SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT: 01148 { 01149 unsigned char led; 01150 unsigned char *ptr = pSlHttpServerEvent->EventData.httpPostData.token_name.data; 01151 01152 if(memcmp(ptr, POST_token, strlen((const char *)POST_token)) == 0) 01153 { 01154 ptr = pSlHttpServerEvent->EventData.httpPostData.token_value.data; 01155 strLenVal = strlen(LED_STRING); 01156 if(memcmp(ptr, LED_STRING, strLenVal) != 0) 01157 break; 01158 ptr += strLenVal; 01159 led = *ptr; 01160 strLenVal = strlen(LED_ON_STRING); 01161 ptr += strLenVal; 01162 if(led == '1') 01163 { 01164 if(memcmp(ptr, LED_ON_STRING, strLenVal) == 0) 01165 { 01166 GPIO_IF_LedOn(MCU_RED_LED_GPIO); 01167 } 01168 else 01169 { 01170 GPIO_IF_LedOff(MCU_RED_LED_GPIO); 01171 } 01172 } 01173 else if(led == '2') 01174 { 01175 if(memcmp(ptr, LED_ON_STRING, strLenVal) == 0) 01176 { 01177 GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); 01178 } 01179 else 01180 { 01181 GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); 01182 } 01183 } 01184 01185 } 01186 } 01187 break; 01188 default: 01189 break; 01190 } 01191 } 01192 #endif 01193 /*! 01194 \brief This function handles general error events indication 01195 01196 \param[in] pDevEvent is the event passed to the handler 01197 01198 \return None 01199 */ 01200 #if (defined(sl_GeneralEvtHdlr)) 01201 void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent) 01202 { 01203 /* 01204 * Most of the general errors are not FATAL are are to be handled 01205 * appropriately by the application 01206 */ 01207 memset(print_buf, 0x00, PRINT_BUF_LEN); 01208 sprintf((char*) print_buf, "[GENERAL EVENT] - ID=[%d] Sender=[%d]\n\n", pDevEvent->EventData.deviceEvent.status, pDevEvent->EventData.deviceEvent.sender); 01209 Uart_Write((uint8_t *) print_buf); 01210 } 01211 #endif 01212 01213 #ifdef __cplusplus 01214 } 01215 #endif /* __cplusplus */ 01216 01217 //}//namespace
Generated on Wed Jul 13 2022 15:58:45 by 1.7.2