A library for talking to Multi-Tech's Cellular SocketModem Devices.

Dependents:   M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more

wifi/Wifi.h

Committer:
jengbrecht
Date:
2013-12-27
Revision:
79:f356009dbc12
Parent:
76:371aab9902a4
Child:
93:aa7a48e65974

File content as of revision 79:f356009dbc12:

#ifndef WIFI_H
#define WIFI_H

#include "IPStack.h"
#include "MTSBufferedIO.h"
#include "mbed.h"
#include "Cellular.h"
#include <string>
#include <vector>

using namespace mts;

class Wifi : public IPStack
{
public:
    enum SecurityType {
        NONE, WEP64, WEP128, WPA, WPA2
    };

    ~Wifi();

    static Wifi* getInstance();
    bool init(MTSBufferedIO* io);

    virtual bool connect();
    virtual void disconnect();
    virtual bool isConnected();

    // TCP and UDP Socket related commands
    // For behavior of the following methods refer to IPStack.h documentation
    virtual bool bind(unsigned int port);
    virtual bool open(const std::string& address, unsigned int port, Mode mode);
    virtual bool isOpen();
    virtual bool close();
    virtual int read(char* data, int max, int timeout = -1);
    virtual int write(const char* data, int length, int timeout = -1);
    virtual unsigned int readable();
    virtual unsigned int writeable();

    virtual void reset();

    std::string sendCommand(std::string command, int timeoutMillis, char esc = CR);
    Code sendBasicCommand(std::string command, int timeoutMillis, char esc = CR);

    Code setNetwork(const std::string& ssid, const std::string& key, SecurityType type);
    int getSignalStrength();
    bool setCmdMode(bool on);

private:
    static Wifi* instance; //Static pointer to the single Cellular object.

    MTSBufferedIO* io; //IO interface obect that the radio is accessed through.
    bool echoMode; //Specifies if the echo mode is currently enabled.

    bool wifiConnected; //Specifies if a Wifi network session is currently connected.
    std::string _ssid; //A string that holds the SSID for the Wifi module.

    Mode mode; //The current socket Mode.
    bool socketOpened; //Specifies if a Socket is presently opened.
    bool socketCloseable; //Specifies is a Socket can be closed.
    unsigned int local_port; //Holds the local port for socket connections.
    std::string local_address; //Holds the local address for socket connections.
    unsigned int host_port; //Holds the remote port for socket connections.
    std::string host_address; //Holds the remote address for socket connections.
    bool cmdOn;

    Wifi(); //Private constructor, use the getInstance() method.
    Wifi(MTSBufferedIO* io); //Private constructor, use the getInstance() method.
};

#endif /* WIFI_H */