TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.
http/server/HttpSocket.h@1:e448e81c416f, 2015-09-11 (annotated)
- Committer:
- dflet
- Date:
- Fri Sep 11 15:38:33 2015 +0000
- Revision:
- 1:e448e81c416f
- Parent:
- 0:400d8e75a8d0
Removed some debud.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 0:400d8e75a8d0 | 1 | //***************************************************************************** |
dflet | 0:400d8e75a8d0 | 2 | // Copyright (C) 2014 Texas Instruments Incorporated |
dflet | 0:400d8e75a8d0 | 3 | // |
dflet | 0:400d8e75a8d0 | 4 | // All rights reserved. Property of Texas Instruments Incorporated. |
dflet | 0:400d8e75a8d0 | 5 | // Restricted rights to use, duplicate or disclose this code are |
dflet | 0:400d8e75a8d0 | 6 | // granted through contract. |
dflet | 0:400d8e75a8d0 | 7 | // The program may not be used without the written permission of |
dflet | 0:400d8e75a8d0 | 8 | // Texas Instruments Incorporated or against the terms and conditions |
dflet | 0:400d8e75a8d0 | 9 | // stipulated in the agreement under which this program has been supplied, |
dflet | 0:400d8e75a8d0 | 10 | // and under no circumstances can it be used with non-TI connectivity device. |
dflet | 0:400d8e75a8d0 | 11 | // |
dflet | 0:400d8e75a8d0 | 12 | //***************************************************************************** |
dflet | 0:400d8e75a8d0 | 13 | |
dflet | 0:400d8e75a8d0 | 14 | |
dflet | 0:400d8e75a8d0 | 15 | #ifndef HTTPSOCKET_H_ |
dflet | 0:400d8e75a8d0 | 16 | #define HTTPSOCKET_H_ |
dflet | 0:400d8e75a8d0 | 17 | |
dflet | 0:400d8e75a8d0 | 18 | /** |
dflet | 0:400d8e75a8d0 | 19 | * @defgroup HttpSocket |
dflet | 0:400d8e75a8d0 | 20 | * This module performs all HTTP socket operations |
dflet | 0:400d8e75a8d0 | 21 | * |
dflet | 0:400d8e75a8d0 | 22 | * @{ |
dflet | 0:400d8e75a8d0 | 23 | */ |
dflet | 0:400d8e75a8d0 | 24 | |
dflet | 0:400d8e75a8d0 | 25 | |
dflet | 0:400d8e75a8d0 | 26 | #include "HttpCore.h" |
dflet | 0:400d8e75a8d0 | 27 | |
dflet | 0:400d8e75a8d0 | 28 | // Max number of times server must retry to setup connection |
dflet | 0:400d8e75a8d0 | 29 | #define SERVER_MAX_SETUP_RETRY_COUNT 3 |
dflet | 0:400d8e75a8d0 | 30 | |
dflet | 0:400d8e75a8d0 | 31 | #define SL_SSL_SRV_KEY "/cert/serverkey.der" /* Server key file ID */ |
dflet | 0:400d8e75a8d0 | 32 | #define SL_SSL_SRV_CERT "/cert/servercert.der" /* Server certificate file ID */ |
dflet | 0:400d8e75a8d0 | 33 | |
dflet | 0:400d8e75a8d0 | 34 | #ifdef __cplusplus |
dflet | 0:400d8e75a8d0 | 35 | extern "C" { |
dflet | 0:400d8e75a8d0 | 36 | #endif |
dflet | 0:400d8e75a8d0 | 37 | |
dflet | 0:400d8e75a8d0 | 38 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 39 | // |
dflet | 0:400d8e75a8d0 | 40 | //! Creates a TCP server socket. It calls OpenTCPServerSocket. |
dflet | 0:400d8e75a8d0 | 41 | //! |
dflet | 0:400d8e75a8d0 | 42 | //! \param uiPortNum is the port number to bind to |
dflet | 0:400d8e75a8d0 | 43 | //! |
dflet | 0:400d8e75a8d0 | 44 | //! This function |
dflet | 0:400d8e75a8d0 | 45 | //! 1. Creates a TCP socket and binds to it |
dflet | 0:400d8e75a8d0 | 46 | //! 2. Sets the socket options |
dflet | 0:400d8e75a8d0 | 47 | //! |
dflet | 0:400d8e75a8d0 | 48 | //! \return Soceket Descriptor, < 1 if error. |
dflet | 0:400d8e75a8d0 | 49 | // |
dflet | 0:400d8e75a8d0 | 50 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 51 | int CreateTCPServerSocket(unsigned int uiPortNum); |
dflet | 0:400d8e75a8d0 | 52 | |
dflet | 0:400d8e75a8d0 | 53 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 54 | // |
dflet | 0:400d8e75a8d0 | 55 | //! Creates a TCP socket and binds to it |
dflet | 0:400d8e75a8d0 | 56 | //! |
dflet | 0:400d8e75a8d0 | 57 | //! \param uiPortNum is the port number to bind to |
dflet | 0:400d8e75a8d0 | 58 | //! |
dflet | 0:400d8e75a8d0 | 59 | //! This function |
dflet | 0:400d8e75a8d0 | 60 | //! 1. Creates a TCP socket and binds to it |
dflet | 0:400d8e75a8d0 | 61 | //! |
dflet | 0:400d8e75a8d0 | 62 | //! \return Soceket Descriptor, < 1 if error. |
dflet | 0:400d8e75a8d0 | 63 | // |
dflet | 0:400d8e75a8d0 | 64 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 65 | int OpenTCPServerSocket(unsigned int uiPortNum); |
dflet | 0:400d8e75a8d0 | 66 | |
dflet | 0:400d8e75a8d0 | 67 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 68 | // |
dflet | 0:400d8e75a8d0 | 69 | //! Accepts the client socket. Sets it to blocking with receive timeout. |
dflet | 0:400d8e75a8d0 | 70 | //! |
dflet | 0:400d8e75a8d0 | 71 | //! \param iSockDesc is the socket ID obtained from CreateTCPServerSocket |
dflet | 0:400d8e75a8d0 | 72 | //! |
dflet | 0:400d8e75a8d0 | 73 | //! This function |
dflet | 0:400d8e75a8d0 | 74 | //! 1. Accepts the client socket. |
dflet | 0:400d8e75a8d0 | 75 | //! 2. Sets to blocking mode with RECV timeout |
dflet | 0:400d8e75a8d0 | 76 | //! |
dflet | 0:400d8e75a8d0 | 77 | //! \return socket handler is returned after the SockID is put in listening state |
dflet | 0:400d8e75a8d0 | 78 | // |
dflet | 0:400d8e75a8d0 | 79 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 80 | int CreateTCPClientSocket(int iSockDesc); |
dflet | 0:400d8e75a8d0 | 81 | |
dflet | 0:400d8e75a8d0 | 82 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 83 | // |
dflet | 0:400d8e75a8d0 | 84 | //! Closes TCP client socket when the Http connection with that client is closed. |
dflet | 0:400d8e75a8d0 | 85 | //! |
dflet | 0:400d8e75a8d0 | 86 | //! \param iSockDesc is the socket ID obtained from CreateTCPServerSocket |
dflet | 0:400d8e75a8d0 | 87 | //! |
dflet | 0:400d8e75a8d0 | 88 | //! This function |
dflet | 0:400d8e75a8d0 | 89 | //! 1. Calls sl_close. Tries 3 times before returning error |
dflet | 0:400d8e75a8d0 | 90 | //! |
dflet | 0:400d8e75a8d0 | 91 | //! \return 0 if success |
dflet | 0:400d8e75a8d0 | 92 | //! -1 if error |
dflet | 0:400d8e75a8d0 | 93 | // |
dflet | 0:400d8e75a8d0 | 94 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 95 | int CloseTCPClientSocket(int iSockDesc); |
dflet | 0:400d8e75a8d0 | 96 | |
dflet | 0:400d8e75a8d0 | 97 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 98 | // |
dflet | 0:400d8e75a8d0 | 99 | //! Sends over the socket to a specific client. In non blocking socket type, it keeps looping till send is success |
dflet | 0:400d8e75a8d0 | 100 | //! |
dflet | 0:400d8e75a8d0 | 101 | //! \param socket is the handle obtained from CreateTCPClientSocket |
dflet | 0:400d8e75a8d0 | 102 | //! buffer is the pointer to the data to be sent |
dflet | 0:400d8e75a8d0 | 103 | //! len is the length of the data to be sent |
dflet | 0:400d8e75a8d0 | 104 | //! |
dflet | 0:400d8e75a8d0 | 105 | //! This function |
dflet | 0:400d8e75a8d0 | 106 | //! 1. Calls send and keeps trying as long as the return is SL_EAGAIN. |
dflet | 0:400d8e75a8d0 | 107 | //! |
dflet | 0:400d8e75a8d0 | 108 | //! \return length successfully sent if it was a success |
dflet | 0:400d8e75a8d0 | 109 | //! error code if there was a failure. |
dflet | 0:400d8e75a8d0 | 110 | //! |
dflet | 0:400d8e75a8d0 | 111 | //! It will not return an error if simplelink returns SL_EAGAIN. Instead it will keep trying till it succeeds. |
dflet | 0:400d8e75a8d0 | 112 | // |
dflet | 0:400d8e75a8d0 | 113 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 114 | int ClientSocketSend(long socket, char * buffer, unsigned int len); |
dflet | 0:400d8e75a8d0 | 115 | |
dflet | 0:400d8e75a8d0 | 116 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 117 | // |
dflet | 0:400d8e75a8d0 | 118 | //! Closes TCP server socket. |
dflet | 0:400d8e75a8d0 | 119 | //! |
dflet | 0:400d8e75a8d0 | 120 | //! \param iSockDesc is the socket ID obtained from CreateTCPServerSocket |
dflet | 0:400d8e75a8d0 | 121 | //! |
dflet | 0:400d8e75a8d0 | 122 | //! This function |
dflet | 0:400d8e75a8d0 | 123 | //! 1. Calls sl_close. Tries 3 times before returning error |
dflet | 0:400d8e75a8d0 | 124 | //! |
dflet | 0:400d8e75a8d0 | 125 | //! \return 0 if success |
dflet | 0:400d8e75a8d0 | 126 | //! -1 if error |
dflet | 0:400d8e75a8d0 | 127 | // |
dflet | 0:400d8e75a8d0 | 128 | //**************************************************************************** |
dflet | 0:400d8e75a8d0 | 129 | int CloseTCPServerSocket(int iSockDesc); |
dflet | 0:400d8e75a8d0 | 130 | |
dflet | 0:400d8e75a8d0 | 131 | |
dflet | 0:400d8e75a8d0 | 132 | #ifdef __cplusplus |
dflet | 0:400d8e75a8d0 | 133 | } |
dflet | 0:400d8e75a8d0 | 134 | #endif /* __cplusplus */ |
dflet | 0:400d8e75a8d0 | 135 | |
dflet | 0:400d8e75a8d0 | 136 | #endif /* HTTPSOCKET_H_ */ |
dflet | 0:400d8e75a8d0 | 137 | |
dflet | 0:400d8e75a8d0 | 138 | //***************************************************************************** |
dflet | 0:400d8e75a8d0 | 139 | // |
dflet | 0:400d8e75a8d0 | 140 | // Close the Doxygen group. |
dflet | 0:400d8e75a8d0 | 141 | //! @} |
dflet | 0:400d8e75a8d0 | 142 | // |
dflet | 0:400d8e75a8d0 | 143 | //***************************************************************************** |
dflet | 0:400d8e75a8d0 | 144 |