SNIC UART Interface library: Serial to Wi-Fi library for Murata TypeYD Wi-Fi module. For more information about TypeYD: http://www.murata.co.jp/products/microwave/module/lbwb1zzydz/index.html

Dependents:   SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more

Fork of YDwifiInterface by Takao Kishino

Committer:
kishino
Date:
Mon Mar 17 11:40:56 2014 +0000
Revision:
8:50d2509479cd
Child:
9:a98b45e766c8
Prefix of class name and file name was changed from 'YD' to 'SNIC'.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 8:50d2509479cd 1 #ifndef _SNIC_WIFI_H_
kishino 8:50d2509479cd 2 #define _SNIC_WIFI_H_
kishino 8:50d2509479cd 3
kishino 8:50d2509479cd 4 #include "mbed.h"
kishino 8:50d2509479cd 5 #include "rtos.h"
kishino 8:50d2509479cd 6 #include "RawSerial.h"
kishino 8:50d2509479cd 7
kishino 8:50d2509479cd 8 #include "SNICwifiUartCommand.h"
kishino 8:50d2509479cd 9 //#include "CBuffer.h"
kishino 8:50d2509479cd 10
kishino 8:50d2509479cd 11 namespace murata_wifi
kishino 8:50d2509479cd 12 {
kishino 8:50d2509479cd 13
kishino 8:50d2509479cd 14 /** C_SNICwifi class
kishino 8:50d2509479cd 15 */
kishino 8:50d2509479cd 16 class C_SNICwifi
kishino 8:50d2509479cd 17 {
kishino 8:50d2509479cd 18
kishino 8:50d2509479cd 19 public:
kishino 8:50d2509479cd 20 /** Wi-Fi security
kishino 8:50d2509479cd 21 */
kishino 8:50d2509479cd 22 typedef enum SECURITY {
kishino 8:50d2509479cd 23 /** Securiry Open */
kishino 8:50d2509479cd 24 e_SEC_OPEN = 0x00,
kishino 8:50d2509479cd 25 /** Securiry WEP */
kishino 8:50d2509479cd 26 e_SEC_WEP = 0x01,
kishino 8:50d2509479cd 27 /** Securiry WPA-PSK(TKIP) */
kishino 8:50d2509479cd 28 e_SEC_WPA_TKIP = 0x02,
kishino 8:50d2509479cd 29 /** Securiry WPA2-PSK(AES) */
kishino 8:50d2509479cd 30 e_SEC_WPA2_AES = 0x04,
kishino 8:50d2509479cd 31 /** Securiry WPA2-PSK(TKIP/AES) */
kishino 8:50d2509479cd 32 e_SEC_WPA2_MIXED = 0x06,
kishino 8:50d2509479cd 33 /** Securiry WPA-PSK(AES) */
kishino 8:50d2509479cd 34 e_SEC_WPA_AES = 0x07
kishino 8:50d2509479cd 35 }E_SECURITY;
kishino 8:50d2509479cd 36
kishino 8:50d2509479cd 37 /** Wi-Fi Network type
kishino 8:50d2509479cd 38 */
kishino 8:50d2509479cd 39 typedef enum NETWORK_TYPE {
kishino 8:50d2509479cd 40 /** Infrastructure */
kishino 8:50d2509479cd 41 e_INFRA = 0,
kishino 8:50d2509479cd 42 /** Adhoc */
kishino 8:50d2509479cd 43 e_ADHOC = 1
kishino 8:50d2509479cd 44 }E_NETWORK_TYPE;
kishino 8:50d2509479cd 45
kishino 8:50d2509479cd 46 /** Wi-Fi status
kishino 8:50d2509479cd 47 */
kishino 8:50d2509479cd 48 typedef enum WIFI_STATUS {
kishino 8:50d2509479cd 49 /** Wi-Fi OFF */
kishino 8:50d2509479cd 50 e_STATUS_OFF = 0,
kishino 8:50d2509479cd 51 /** No network */
kishino 8:50d2509479cd 52 e_NO_NETWORK,
kishino 8:50d2509479cd 53 /** Connected to AP (STA mode) */
kishino 8:50d2509479cd 54 e_STA_JOINED,
kishino 8:50d2509479cd 55 /** Started on AP mode */
kishino 8:50d2509479cd 56 e_AP_STARTED
kishino 8:50d2509479cd 57 }E_WIFI_STATUS;
kishino 8:50d2509479cd 58
kishino 8:50d2509479cd 59 protected:
kishino 8:50d2509479cd 60 /** GEN_FW_VER_GET_REQ Command */
kishino 8:50d2509479cd 61 typedef struct
kishino 8:50d2509479cd 62 {
kishino 8:50d2509479cd 63 unsigned char cmd_sid;
kishino 8:50d2509479cd 64 unsigned char seq;
kishino 8:50d2509479cd 65 }tagGEN_FW_VER_GET_REQ_T;
kishino 8:50d2509479cd 66
kishino 8:50d2509479cd 67 /** SNIC_INIT_REQ */
kishino 8:50d2509479cd 68 typedef struct
kishino 8:50d2509479cd 69 {
kishino 8:50d2509479cd 70 unsigned char cmd_sid;
kishino 8:50d2509479cd 71 unsigned char seq;
kishino 8:50d2509479cd 72 unsigned short buf_size;
kishino 8:50d2509479cd 73 }tagSNIC_INIT_REQ_T;
kishino 8:50d2509479cd 74
kishino 8:50d2509479cd 75 /** WIFI_ON_REQ Command */
kishino 8:50d2509479cd 76 typedef struct
kishino 8:50d2509479cd 77 {
kishino 8:50d2509479cd 78 unsigned char cmd_sid;
kishino 8:50d2509479cd 79 unsigned char seq;
kishino 8:50d2509479cd 80 char country[COUNTRYC_CODE_LENTH];
kishino 8:50d2509479cd 81 }tagWIFI_ON_REQ_T;
kishino 8:50d2509479cd 82
kishino 8:50d2509479cd 83 /** WIFI_OFF_REQ Command */
kishino 8:50d2509479cd 84 typedef struct
kishino 8:50d2509479cd 85 {
kishino 8:50d2509479cd 86 unsigned char cmd_sid;
kishino 8:50d2509479cd 87 unsigned char seq;
kishino 8:50d2509479cd 88 }tagWIFI_OFF_REQ_T;
kishino 8:50d2509479cd 89
kishino 8:50d2509479cd 90 /** WIFI_DISCONNECT_REQ Command */
kishino 8:50d2509479cd 91 typedef struct
kishino 8:50d2509479cd 92 {
kishino 8:50d2509479cd 93 unsigned char cmd_sid;
kishino 8:50d2509479cd 94 unsigned char seq;
kishino 8:50d2509479cd 95 }tagWIFI_DISCONNECT_REQ_T;
kishino 8:50d2509479cd 96
kishino 8:50d2509479cd 97 /** WIFI_GET_STA_RSSI_REQ Command */
kishino 8:50d2509479cd 98 typedef struct
kishino 8:50d2509479cd 99 {
kishino 8:50d2509479cd 100 unsigned char cmd_sid;
kishino 8:50d2509479cd 101 unsigned char seq;
kishino 8:50d2509479cd 102 }tagWIFI_GET_STA_RSSI_REQ_T;
kishino 8:50d2509479cd 103
kishino 8:50d2509479cd 104 /** WIFI_GET_STATUS_REQ Command */
kishino 8:50d2509479cd 105 typedef struct
kishino 8:50d2509479cd 106 {
kishino 8:50d2509479cd 107 unsigned char cmd_sid;
kishino 8:50d2509479cd 108 unsigned char seq;
kishino 8:50d2509479cd 109 unsigned char interface;
kishino 8:50d2509479cd 110 }tagWIFI_GET_STATUS_REQ_T;
kishino 8:50d2509479cd 111
kishino 8:50d2509479cd 112 /** WIFI_SCAN_REQ Command */
kishino 8:50d2509479cd 113 typedef struct
kishino 8:50d2509479cd 114 {
kishino 8:50d2509479cd 115 unsigned char cmd_sid;
kishino 8:50d2509479cd 116 unsigned char seq;
kishino 8:50d2509479cd 117 unsigned char scan_type;
kishino 8:50d2509479cd 118 unsigned char bss_type;
kishino 8:50d2509479cd 119 unsigned char bssid[BSSID_MAC_LENTH];
kishino 8:50d2509479cd 120 unsigned char chan_list;
kishino 8:50d2509479cd 121 unsigned char ssid[SSID_MAX_LENGTH+1];
kishino 8:50d2509479cd 122 }tagWIFI_SCAN_REQ_T;
kishino 8:50d2509479cd 123
kishino 8:50d2509479cd 124 static C_SNICwifi *mInstance_p;
kishino 8:50d2509479cd 125 Thread *mUartRecvThread_p;
kishino 8:50d2509479cd 126 Mutex mUartMutex;
kishino 8:50d2509479cd 127 // DigitalInOut mModuleReset;
kishino 8:50d2509479cd 128 C_SNICwifiUartCommand mUartCommand;
kishino 8:50d2509479cd 129 RawSerial mUart;
kishino 8:50d2509479cd 130
kishino 8:50d2509479cd 131 /** Constructor
kishino 8:50d2509479cd 132 * \param tx mbed pin to use for tx line of Serial interface
kishino 8:50d2509479cd 133 * \param rx mbed pin to use for rx line of Serial interface
kishino 8:50d2509479cd 134 * \param cts mbed pin to use for cts line of Serial interface
kishino 8:50d2509479cd 135 * \param rts mbed pin to use for rts line of Serial interface
kishino 8:50d2509479cd 136 * \param reset reset pin of the wifi module
kishino 8:50d2509479cd 137 * \param alarm alarm pin of the wifi module
kishino 8:50d2509479cd 138 * \param baud baud rate of Serial interface
kishino 8:50d2509479cd 139 */
kishino 8:50d2509479cd 140 C_SNICwifi (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud);
kishino 8:50d2509479cd 141
kishino 8:50d2509479cd 142 /** Initialize UART
kishino 8:50d2509479cd 143 */
kishino 8:50d2509479cd 144 int initUart();
kishino 8:50d2509479cd 145
kishino 8:50d2509479cd 146 static C_SNICwifi * getInstance() {
kishino 8:50d2509479cd 147 return mInstance_p;
kishino 8:50d2509479cd 148 };
kishino 8:50d2509479cd 149
kishino 8:50d2509479cd 150 /** Send data to UART
kishino 8:50d2509479cd 151 @param len Length of send data
kishino 8:50d2509479cd 152 @param data Pointer of send data
kishino 8:50d2509479cd 153 @return 0:success/other:fail
kishino 8:50d2509479cd 154 */
kishino 8:50d2509479cd 155 int sendUart( unsigned int len, unsigned char *data );
kishino 8:50d2509479cd 156
kishino 8:50d2509479cd 157 /** Receiving thread of UART
kishino 8:50d2509479cd 158 */
kishino 8:50d2509479cd 159 static void uartRecvThread( void const *args_p );
kishino 8:50d2509479cd 160
kishino 8:50d2509479cd 161 };
kishino 8:50d2509479cd 162 }
kishino 8:50d2509479cd 163
kishino 8:50d2509479cd 164 #endif