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

YDwifi/YDwifi.h

Committer:
kishino
Date:
2014-03-13
Revision:
6:70f522934032
Parent:
5:ef3befe3edad

File content as of revision 6:70f522934032:

#ifndef _YD_WIFI_H_
#define _YD_WIFI_H_

#include "mbed.h"
#include "rtos.h"
#include "RawSerial.h"

#include "YDwifiUartCommand.h"
//#include "CBuffer.h"

namespace murata_wifi
{

/** C_YDwifi class
 */
class C_YDwifi
{

public:
    /** Wi-Fi security
     */
    typedef enum SECURITY {
        /** Securiry Open */
        e_SEC_OPEN       = 0x00,
        /** Securiry WEP */
        e_SEC_WEP        = 0x01,
        /** Securiry WPA-PSK(TKIP) */
        e_SEC_WPA_TKIP   = 0x02,
        /** Securiry WPA2-PSK(AES) */
        e_SEC_WPA2_AES   = 0x04,
        /** Securiry WPA2-PSK(TKIP/AES) */
        e_SEC_WPA2_MIXED = 0x06,
        /** Securiry WPA-PSK(AES) */
        e_SEC_WPA_AES    = 0x07
    }E_SECURITY;

    /** Wi-Fi Network type
     */
    typedef enum NETWORK_TYPE {
        /** Infrastructure */
        e_INFRA = 0,
        /** Adhoc */
        e_ADHOC = 1
    }E_NETWORK_TYPE;

    /** Wi-Fi status
     */
    typedef enum WIFI_STATUS {
        /** Wi-Fi OFF */
        e_STATUS_OFF = 0,
        /** No network */
        e_NO_NETWORK,
        /** Connected to AP (STA mode) */
        e_STA_JOINED,
        /** Started  on AP mode */
        e_AP_STARTED
    }E_WIFI_STATUS;

protected:
    /** GEN_FW_VER_GET_REQ Command */
    typedef struct 
    {
        unsigned char cmd_sid;
        unsigned char seq;
    }tagGEN_FW_VER_GET_REQ_T;

    /** WIFI_ON_REQ Command */
    typedef struct 
    {
        unsigned char cmd_sid;
        unsigned char seq;
        char country[COUNTRYC_CODE_LENTH];
    }tagWIFI_ON_REQ_T;

    /** WIFI_OFF_REQ Command */
    typedef struct 
    {
        unsigned char cmd_sid;
        unsigned char seq;
    }tagWIFI_OFF_REQ_T;

    /** WIFI_DISCONNECT_REQ Command */
    typedef struct 
    {
        unsigned char cmd_sid;
        unsigned char seq;
    }tagWIFI_DISCONNECT_REQ_T;

    /** WIFI_GET_STA_RSSI_REQ Command */
    typedef struct 
    {
        unsigned char cmd_sid;
        unsigned char seq;
    }tagWIFI_GET_STA_RSSI_REQ_T;

    /** WIFI_GET_STATUS_REQ Command */
    typedef struct 
    {
        unsigned char cmd_sid;
        unsigned char seq;
        unsigned char interface;
    }tagWIFI_GET_STATUS_REQ_T;

    /** WIFI_SCAN_REQ Command */
    typedef struct 
    {
        unsigned char cmd_sid;
        unsigned char seq;
        unsigned char scan_type;
        unsigned char bss_type;
        unsigned char bssid[BSSID_MAC_LENTH];
        unsigned char chan_list;
        unsigned char ssid[SSID_MAX_LENGTH+1];
    }tagWIFI_SCAN_REQ_T;

    static C_YDwifi     *mInstance_p;
    Thread              *mUartRecvThread_p;
    Mutex               mUartMutex;
//    DigitalInOut        mModuleReset;
    C_YDwifiUartCommand mUartCommand;
    RawSerial           mUart;
    
    /** Constructor
     * \param tx mbed pin to use for tx line of Serial interface
     * \param rx mbed pin to use for rx line of Serial interface
     * \param cts mbed pin to use for cts line of Serial interface
     * \param rts mbed pin to use for rts line of Serial interface
     * \param reset reset pin of the wifi module
     * \param alarm alarm pin of the wifi module
     * \param baud baud rate of Serial interface
     */
    C_YDwifi (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud);

    /** Initialize UART
    */
    int initUart();

    static C_YDwifi * getInstance() {
        return mInstance_p;
    };

    /** Send data to UART
        @param len  Length of send data
        @param data Pointer of send data
        @return 0:success/other:fail
    */
    int sendUart( unsigned int len, unsigned char *data );

    /** Receiving thread of UART
    */
    static void uartRecvThread( void const *args_p );
    
};
}

#endif