Murata Type YD Wi-Fi driver
Dependents: easy-connect-type-yd
SNICInterface/Socket/SNIC_Socket.h@0:35a2186cf186, 2017-07-12 (annotated)
- Committer:
- MACRUM
- Date:
- Wed Jul 12 10:49:10 2017 +0000
- Revision:
- 0:35a2186cf186
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:35a2186cf186 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
MACRUM | 0:35a2186cf186 | 2 | * |
MACRUM | 0:35a2186cf186 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
MACRUM | 0:35a2186cf186 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
MACRUM | 0:35a2186cf186 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
MACRUM | 0:35a2186cf186 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
MACRUM | 0:35a2186cf186 | 7 | * furnished to do so, subject to the following conditions: |
MACRUM | 0:35a2186cf186 | 8 | * |
MACRUM | 0:35a2186cf186 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
MACRUM | 0:35a2186cf186 | 10 | * substantial portions of the Software. |
MACRUM | 0:35a2186cf186 | 11 | * |
MACRUM | 0:35a2186cf186 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
MACRUM | 0:35a2186cf186 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
MACRUM | 0:35a2186cf186 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
MACRUM | 0:35a2186cf186 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MACRUM | 0:35a2186cf186 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
MACRUM | 0:35a2186cf186 | 17 | */ |
MACRUM | 0:35a2186cf186 | 18 | /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License |
MACRUM | 0:35a2186cf186 | 19 | * port to the muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART. |
MACRUM | 0:35a2186cf186 | 20 | */ |
MACRUM | 0:35a2186cf186 | 21 | #ifndef SNIC_SOCKET_H_ |
MACRUM | 0:35a2186cf186 | 22 | #define SNIC_SOCKET_H_ |
MACRUM | 0:35a2186cf186 | 23 | |
MACRUM | 0:35a2186cf186 | 24 | #include "SNICInterface/SNIC/SNIC_Core.h" |
MACRUM | 0:35a2186cf186 | 25 | #include "SNICInterface/SNIC/SNIC_UartMsgUtil.h" |
MACRUM | 0:35a2186cf186 | 26 | |
MACRUM | 0:35a2186cf186 | 27 | #define htons(x) __REV16(x) |
MACRUM | 0:35a2186cf186 | 28 | #define ntohs(x) __REV16(x) |
MACRUM | 0:35a2186cf186 | 29 | #define htonl(x) __REV(x) |
MACRUM | 0:35a2186cf186 | 30 | #define ntohl(x) __REV(x) |
MACRUM | 0:35a2186cf186 | 31 | |
MACRUM | 0:35a2186cf186 | 32 | typedef unsigned long socklen_t; |
MACRUM | 0:35a2186cf186 | 33 | |
MACRUM | 0:35a2186cf186 | 34 | /** Socket file descriptor and select wrapper |
MACRUM | 0:35a2186cf186 | 35 | */ |
MACRUM | 0:35a2186cf186 | 36 | class SnicSocket { |
MACRUM | 0:35a2186cf186 | 37 | public: |
MACRUM | 0:35a2186cf186 | 38 | /** Socket |
MACRUM | 0:35a2186cf186 | 39 | */ |
MACRUM | 0:35a2186cf186 | 40 | SnicSocket(); |
MACRUM | 0:35a2186cf186 | 41 | |
MACRUM | 0:35a2186cf186 | 42 | /** Set blocking or non-blocking mode of the socket and a timeout on |
MACRUM | 0:35a2186cf186 | 43 | blocking socket operations |
MACRUM | 0:35a2186cf186 | 44 | \param blocking true for blocking mode, false for non-blocking mode. |
MACRUM | 0:35a2186cf186 | 45 | \param timeout timeout in ms [Default: (1500)ms]. |
MACRUM | 0:35a2186cf186 | 46 | */ |
MACRUM | 0:35a2186cf186 | 47 | void set_blocking(bool blocking, unsigned int timeout=1500); |
MACRUM | 0:35a2186cf186 | 48 | |
MACRUM | 0:35a2186cf186 | 49 | /** Set socket options |
MACRUM | 0:35a2186cf186 | 50 | @param level stack level (see: lwip/sockets.h) |
MACRUM | 0:35a2186cf186 | 51 | @param optname option ID |
MACRUM | 0:35a2186cf186 | 52 | @param optval option value |
MACRUM | 0:35a2186cf186 | 53 | @param socklen_t length of the option value |
MACRUM | 0:35a2186cf186 | 54 | @return 0 on success, -1 on failure |
MACRUM | 0:35a2186cf186 | 55 | */ |
MACRUM | 0:35a2186cf186 | 56 | int set_option(int level, int optname, const void *optval, socklen_t optlen); |
MACRUM | 0:35a2186cf186 | 57 | |
MACRUM | 0:35a2186cf186 | 58 | /** Get socket options |
MACRUM | 0:35a2186cf186 | 59 | @param level stack level (see: lwip/sockets.h) |
MACRUM | 0:35a2186cf186 | 60 | @param optname option ID |
MACRUM | 0:35a2186cf186 | 61 | \param optval buffer pointer where to write the option value |
MACRUM | 0:35a2186cf186 | 62 | \param socklen_t length of the option value |
MACRUM | 0:35a2186cf186 | 63 | \return 0 on success, -1 on failure |
MACRUM | 0:35a2186cf186 | 64 | */ |
MACRUM | 0:35a2186cf186 | 65 | int get_option(int level, int optname, void *optval, socklen_t *optlen); |
MACRUM | 0:35a2186cf186 | 66 | |
MACRUM | 0:35a2186cf186 | 67 | /** Close the socket |
MACRUM | 0:35a2186cf186 | 68 | \param shutdown free the left-over data in message queues |
MACRUM | 0:35a2186cf186 | 69 | */ |
MACRUM | 0:35a2186cf186 | 70 | int close(bool shutdown=true); |
MACRUM | 0:35a2186cf186 | 71 | |
MACRUM | 0:35a2186cf186 | 72 | virtual ~SnicSocket(); |
MACRUM | 0:35a2186cf186 | 73 | |
MACRUM | 0:35a2186cf186 | 74 | int createSocket( unsigned char bind = 0, unsigned int local_addr = 0, unsigned short port = 0 ); |
MACRUM | 0:35a2186cf186 | 75 | |
MACRUM | 0:35a2186cf186 | 76 | void socket_attach(void (*callback)(void *), void *data); |
MACRUM | 0:35a2186cf186 | 77 | |
MACRUM | 0:35a2186cf186 | 78 | void event(); |
MACRUM | 0:35a2186cf186 | 79 | |
MACRUM | 0:35a2186cf186 | 80 | protected: |
MACRUM | 0:35a2186cf186 | 81 | int resolveHostName( const char *host_p ); |
MACRUM | 0:35a2186cf186 | 82 | |
MACRUM | 0:35a2186cf186 | 83 | protected: |
MACRUM | 0:35a2186cf186 | 84 | int mSocketID; |
MACRUM | 0:35a2186cf186 | 85 | bool _blocking; |
MACRUM | 0:35a2186cf186 | 86 | int _timeout; |
MACRUM | 0:35a2186cf186 | 87 | char *getSocketSendBuf(); |
MACRUM | 0:35a2186cf186 | 88 | public: |
MACRUM | 0:35a2186cf186 | 89 | void (*_callback)(void *); |
MACRUM | 0:35a2186cf186 | 90 | void *_data; |
MACRUM | 0:35a2186cf186 | 91 | |
MACRUM | 0:35a2186cf186 | 92 | private: |
MACRUM | 0:35a2186cf186 | 93 | |
MACRUM | 0:35a2186cf186 | 94 | // int select(struct timeval *timeout, bool read, bool write); |
MACRUM | 0:35a2186cf186 | 95 | |
MACRUM | 0:35a2186cf186 | 96 | }; |
MACRUM | 0:35a2186cf186 | 97 | |
MACRUM | 0:35a2186cf186 | 98 | #endif /* SNIC_SOCKET_H_ */ |
MACRUM | 0:35a2186cf186 | 99 |