TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.
httpserverapp.cpp
00001 //***************************************************************************** 00002 // httpserver_app.c 00003 // 00004 // camera application macro & APIs 00005 // 00006 // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ 00007 // 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions 00011 // are met: 00012 // 00013 // Redistributions of source code must retain the above copyright 00014 // notice, this list of conditions and the following disclaimer. 00015 // 00016 // Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the 00019 // distribution. 00020 // 00021 // Neither the name of Texas Instruments Incorporated nor the names of 00022 // its contributors may be used to endorse or promote products derived 00023 // from this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00026 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00027 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00028 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00029 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00030 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00031 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00032 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00033 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00034 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00035 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 //***************************************************************************** 00038 //***************************************************************************** 00039 // 00040 //! \addtogroup Httpserverapp 00041 //! @{ 00042 // 00043 //***************************************************************************** 00044 00045 #include <string.h> 00046 #include <stdlib.h> 00047 00048 // SimpleLink include 00049 #include "cc3100_simplelink.h" 00050 #include "cc3100_sl_common.h" 00051 00052 // Free-RTOS/TI-RTOS include 00053 #include "osi.h" 00054 00055 // HTTP lib includes 00056 #include "HttpCore.h" 00057 #include "HttpRequest.h" 00058 00059 #include "websocketapp.h" 00060 #include "httpserverapp.h" 00061 #include "camera_app.h" 00062 00063 #include "ArduCAM.h" 00064 #include "cli_uart.h" 00065 #include "app_config.h" 00066 #include "myBoardInit.h" 00067 #include "HttpDebug.h" 00068 00069 using namespace mbed_cc3100; 00070 00071 cc3100 _cc3100_Mod(NC, NC, p9, p10, p8, SPI(p5, p6, p7));//LPC1768 irq, nHib, cs, mosi, miso, sck 00072 00073 ArduCAM CAM(OV5642, p14, SPI(p11, p12, p13), I2C(p28, p27)); 00074 00075 /****************************************************************************/ 00076 /* MACROS */ 00077 /****************************************************************************/ 00078 00079 00080 /**************************************************************************** 00081 Global variables 00082 ****************************************************************************/ 00083 char *g_Buffer; 00084 UINT8 g_success = 0; 00085 int g_close = 0; 00086 UINT16 g_uConnection; 00087 OsiTaskHandle g_iCameraTaskHdl = 0; 00088 00089 00090 void WebSocketCloseSessionHandler() 00091 { 00092 g_close = 1; 00093 } 00094 00095 void CameraAppTask(void *param) 00096 { 00097 UINT8 Opcode = 0x02; 00098 struct HttpBlob Write; 00099 00100 /* Reset cam */ 00101 // CAM.set_bit(ARDUCHIP_GPIO,GPIO_RESET_MASK); 00102 // wait_ms(50); 00103 // CAM.clear_bit(ARDUCHIP_GPIO,GPIO_RESET_MASK); 00104 // wait(1); 00105 CAM.write_reg(ARDUCHIP_MODE, 0x00); 00106 00107 00108 #ifdef ENABLE_JPEG 00109 InitCameraComponents(320, 240); 00110 #else 00111 InitCameraComponents(240, 256); 00112 #endif 00113 00114 while(1) 00115 { 00116 if(g_close == 0) 00117 { 00118 Write.uLength = StartCamera((char **)&Write.pData); 00119 if(!sl_WebSocketSend(g_uConnection, Write, Opcode)) 00120 { 00121 Uart_Write((uint8_t*)"sl_WebSocketSend failed.\n\r"); 00122 while(1); 00123 } 00124 } 00125 } 00126 00127 } 00128 00129 00130 /*! 00131 * \brief This websocket Event is called when WebSocket Server receives data 00132 * from client. 00133 * 00134 * 00135 * \param[in] uConnection Websocket Client Id 00136 * \param[in] *ReadBuffer Pointer to the buffer that holds the payload. 00137 * 00138 * \return none. 00139 * 00140 */ 00141 void WebSocketRecvEventHandler(UINT16 uConnection, char *ReadBuffer) 00142 { 00143 char *camera = "capture"; 00144 00145 /* 00146 * UINT8 Opcode; 00147 * struct HttpBlob Write; 00148 */ 00149 00150 g_uConnection = uConnection; 00151 00152 g_Buffer = ReadBuffer; 00153 g_close = 0; 00154 if (!strcmp(ReadBuffer,camera)) 00155 { 00156 if(!g_iCameraTaskHdl) 00157 { 00158 osi_TaskCreate(CameraAppTask, 00159 "CameraApp", 00160 1024, 00161 NULL, 00162 CAMERA_SERVICE_PRIORITY, 00163 &g_iCameraTaskHdl); 00164 } 00165 00166 } 00167 //Free memory as we are not using anywhere later 00168 free(g_Buffer); 00169 g_Buffer = NULL; 00170 /* Enter websocket application code here */ 00171 return; 00172 } 00173 00174 00175 /*! 00176 * \brief This websocket Event indicates successful handshake with client 00177 * Once this is called the server can start sending data packets over websocket using 00178 * the sl_WebSocketSend API. 00179 * 00180 * 00181 * \param[in] uConnection Websocket Client Id 00182 * 00183 * \return none 00184 */ 00185 void WebSocketHandshakeEventHandler(UINT16 uConnection) 00186 { 00187 g_success = 1; 00188 g_uConnection = uConnection; 00189 } 00190 00191 00192 //**************************************************************************** 00193 // 00194 //! Task function start the device and crete a TCP server showcasing the smart 00195 //! plug 00196 //! 00197 //**************************************************************************** 00198 00199 00200 void HttpServerAppTask(void * param) 00201 { 00202 int32_t lRetVal = -1; 00203 Uart_Write((uint8_t*)"Start SimpleLink in AP Mode \n\r"); 00204 //Start SimpleLink in AP Mode 00205 lRetVal = _cc3100_Mod.Network_IF_InitDriver(ROLE_AP); 00206 if(lRetVal < 0) 00207 { 00208 Uart_Write((uint8_t*)"Start SimpleLink in AP Mode Failed \n\r"); 00209 LOOP_FOREVER(); 00210 } 00211 00212 //Stop Internal HTTP Server 00213 lRetVal = _cc3100_Mod._netapp.sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID); 00214 if(lRetVal < 0) 00215 { 00216 Uart_Write((uint8_t*)"Stop Internal HTTP Server Failed \n\r"); 00217 LOOP_FOREVER(); 00218 } 00219 Uart_Write((uint8_t*)"HttpServerAppTask \n\r"); 00220 //Run APPS HTTP Server 00221 HttpServerInitAndRun(NULL); 00222 00223 Uart_Write((uint8_t*)"HttpServerAppTask has returned for some reason\n\r"); 00224 LOOP_FOREVER(); 00225 00226 } 00227 00228 //***************************************************************************** 00229 // 00230 // Close the Doxygen group. 00231 //! @} 00232 // 00233 //***************************************************************************** 00234 00235 00236 00237
Generated on Wed Jul 13 2022 15:58:45 by 1.7.2