iowfehu;gdbjwHJAOPIHO?L
Fork of X_NUCLEO_IDW01M1 by
Diff: SPWFInterface.h
- Revision:
- 0:dc55f40eb04f
- Child:
- 3:fd9d20c4d3f0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SPWFInterface.h Wed Apr 13 11:34:07 2016 +0000 @@ -0,0 +1,94 @@ +/* SpwfSAInterface implementation of NetworkInterfaceAPI + * Copyright (c) 2015 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SPWFSA_INTERFACE_H +#define SPWFSA_INTERFACE_H + +#include <vector> +#include <map> +#include "WiFiInterface.h" +#include "SpwfSADevice.h" + +#define SPWFSA_SOCKET_COUNT 8 + +/** SpwfSAInterface class + * Implementation of the NetworkInterface for the SPWF Device + */ +class SpwfSAInterface : public WiFiInterface +{ +public: + + SpwfSAInterface(PinName tx, PinName rx, PinName rst, PinName wkup, PinName rts, bool debug = false); + virtual ~SpwfSAInterface(); + + // Implementation of WiFiInterface + virtual int32_t connect( + const char *ssid, + const char *pass, + ns_security_t security = NS_SECURITY_NONE); + + virtual int32_t disconnect(); + + // Implementation of NetworkInterface + virtual const char *getIPAddress(); + virtual const char *getMACAddress(); + + virtual SocketInterface *createSocket(ns_protocol_t proto); + virtual void destroySocket(SocketInterface *socket); + + int32_t init(void); + void debug(const char * string); + void setid(bool set, int id); + +private: + + SpwfSADevice _spwf; + bool _ids[SPWFSA_SOCKET_COUNT]; + multimap <char *, vector <uint16_t> > c_table; + + // Implementation of the SocketInterface for the SpwfSA + class SpwfSASocket : public SocketInterface + { + public: + + // SpwfSA specific details + SpwfSADevice *__spwf; + SpwfSAInterface *_itf; + ns_protocol_t _proto; + int _id; + + SpwfSASocket(SpwfSAInterface *itf, SpwfSADevice *spwf, ns_protocol_t proto) + : __spwf(spwf), _itf(itf), _proto(proto) {} + + virtual ~SpwfSASocket() { + _itf = 0; + __spwf = 0; + } + + // Implementation of SocketInterface + virtual int32_t open(const char *ip, uint16_t port); + virtual int32_t close(); + + virtual int32_t send(const void *data, uint32_t size); + virtual int32_t recv(void *data, uint32_t size); + }; + +}; + +/*Function to export singleton instance*/ +SpwfSAInterface *createSPWFInstance(void); + +#endif