SMS Scheduler that will automatically send and receive text messages using the Enfora 1308 GSM Modem. Please note that it uses a modified NetServices library and to set the baud rate for the GSM Modem to 19.2K.

Dependencies:   mbed

Committer:
mafischl
Date:
Thu Oct 13 17:02:29 2011 +0000
Revision:
0:d9266031f832

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mafischl 0:d9266031f832 1
mafischl 0:d9266031f832 2 /*
mafischl 0:d9266031f832 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
mafischl 0:d9266031f832 4
mafischl 0:d9266031f832 5 Permission is hereby granted, free of charge, to any person obtaining a copy
mafischl 0:d9266031f832 6 of this software and associated documentation files (the "Software"), to deal
mafischl 0:d9266031f832 7 in the Software without restriction, including without limitation the rights
mafischl 0:d9266031f832 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mafischl 0:d9266031f832 9 copies of the Software, and to permit persons to whom the Software is
mafischl 0:d9266031f832 10 furnished to do so, subject to the following conditions:
mafischl 0:d9266031f832 11
mafischl 0:d9266031f832 12 The above copyright notice and this permission notice shall be included in
mafischl 0:d9266031f832 13 all copies or substantial portions of the Software.
mafischl 0:d9266031f832 14
mafischl 0:d9266031f832 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mafischl 0:d9266031f832 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mafischl 0:d9266031f832 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mafischl 0:d9266031f832 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mafischl 0:d9266031f832 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mafischl 0:d9266031f832 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mafischl 0:d9266031f832 21 THE SOFTWARE.
mafischl 0:d9266031f832 22 */
mafischl 0:d9266031f832 23
mafischl 0:d9266031f832 24 /** \file
mafischl 0:d9266031f832 25 TCP Socket header file
mafischl 0:d9266031f832 26 */
mafischl 0:d9266031f832 27
mafischl 0:d9266031f832 28 #ifndef TCPSOCKET_H
mafischl 0:d9266031f832 29 #define TCPSOCKET_H
mafischl 0:d9266031f832 30
mafischl 0:d9266031f832 31 #include "core/net.h"
mafischl 0:d9266031f832 32 #include "core/host.h"
mafischl 0:d9266031f832 33 //Essentially it is a safe interface to NetTcpSocket
mafischl 0:d9266031f832 34
mafischl 0:d9266031f832 35 ///TCP Socket error codes
mafischl 0:d9266031f832 36 enum TCPSocketErr
mafischl 0:d9266031f832 37 {
mafischl 0:d9266031f832 38 __TCPSOCKET_MIN = -0xFFFF,
mafischl 0:d9266031f832 39 TCPSOCKET_SETUP, ///<TCPSocket not properly configured
mafischl 0:d9266031f832 40 TCPSOCKET_TIMEOUT, ///<Connection timed out
mafischl 0:d9266031f832 41 TCPSOCKET_IF, ///<Interface has problems, does not exist or is not initialized
mafischl 0:d9266031f832 42 TCPSOCKET_MEM, ///<Not enough mem
mafischl 0:d9266031f832 43 TCPSOCKET_INUSE, ///<Interface / Port is in use
mafischl 0:d9266031f832 44 TCPSOCKET_EMPTY, ///<Connections queue is empty
mafischl 0:d9266031f832 45 TCPSOCKET_RST, ///<Connection was reset by remote host
mafischl 0:d9266031f832 46 //...
mafischl 0:d9266031f832 47 TCPSOCKET_OK = 0 ///<Success
mafischl 0:d9266031f832 48 };
mafischl 0:d9266031f832 49
mafischl 0:d9266031f832 50 ///TCP Socket Events
mafischl 0:d9266031f832 51 enum TCPSocketEvent
mafischl 0:d9266031f832 52 {
mafischl 0:d9266031f832 53 TCPSOCKET_CONNECTED, ///<Connected to host
mafischl 0:d9266031f832 54 TCPSOCKET_ACCEPT, ///<Client is connected, must call accept() to get a new Socket
mafischl 0:d9266031f832 55 TCPSOCKET_READABLE, ///<Data in buf
mafischl 0:d9266031f832 56 TCPSOCKET_WRITEABLE, ///<Can write data to buf
mafischl 0:d9266031f832 57 TCPSOCKET_CONTIMEOUT, ///<Connection timed out
mafischl 0:d9266031f832 58 TCPSOCKET_CONRST, ///<Connection was reset by remote host
mafischl 0:d9266031f832 59 TCPSOCKET_CONABRT, ///<Connection was aborted
mafischl 0:d9266031f832 60 TCPSOCKET_ERROR, ///<Unknown error
mafischl 0:d9266031f832 61 TCPSOCKET_DISCONNECTED ///<Disconnected
mafischl 0:d9266031f832 62 };
mafischl 0:d9266031f832 63
mafischl 0:d9266031f832 64 class NetTcpSocket;
mafischl 0:d9266031f832 65 enum NetTcpSocketEvent;
mafischl 0:d9266031f832 66
mafischl 0:d9266031f832 67 ///This is a simple TCP Socket class
mafischl 0:d9266031f832 68 /**
mafischl 0:d9266031f832 69 This class exposes an API to deal with TCP Sockets
mafischl 0:d9266031f832 70 */
mafischl 0:d9266031f832 71 class TCPSocket
mafischl 0:d9266031f832 72 {
mafischl 0:d9266031f832 73 public:
mafischl 0:d9266031f832 74 ///Creates a new socket
mafischl 0:d9266031f832 75 TCPSocket();
mafischl 0:d9266031f832 76 protected:
mafischl 0:d9266031f832 77 TCPSocket(NetTcpSocket* pNetTcpSocket);
mafischl 0:d9266031f832 78 public:
mafischl 0:d9266031f832 79 ///Closes if needed and destroys the socket
mafischl 0:d9266031f832 80 ~TCPSocket(); //close()
mafischl 0:d9266031f832 81
mafischl 0:d9266031f832 82 ///Binds the socket to (local) host
mafischl 0:d9266031f832 83 TCPSocketErr bind(const Host& me);
mafischl 0:d9266031f832 84
mafischl 0:d9266031f832 85 ///Starts listening
mafischl 0:d9266031f832 86 TCPSocketErr listen();
mafischl 0:d9266031f832 87
mafischl 0:d9266031f832 88 ///Connects socket to host
mafischl 0:d9266031f832 89 TCPSocketErr connect(const Host& host);
mafischl 0:d9266031f832 90
mafischl 0:d9266031f832 91 ///Accepts connection from client and gets connected socket
mafischl 0:d9266031f832 92 TCPSocketErr accept(Host* pClient, TCPSocket** ppNewTcpSocket);
mafischl 0:d9266031f832 93
mafischl 0:d9266031f832 94 ///Sends data
mafischl 0:d9266031f832 95 /*
mafischl 0:d9266031f832 96 @return a negative error code or the number of bytes transmitted
mafischl 0:d9266031f832 97 */
mafischl 0:d9266031f832 98 int /*if < 0 : TCPSocketErr*/ send(const char* buf, int len);
mafischl 0:d9266031f832 99
mafischl 0:d9266031f832 100 ///Receives data
mafischl 0:d9266031f832 101 /*
mafischl 0:d9266031f832 102 @return a negative error code or the number of bytes received
mafischl 0:d9266031f832 103 */
mafischl 0:d9266031f832 104 int /*if < 0 : TCPSocketErr*/ recv(char* buf, int len);
mafischl 0:d9266031f832 105
mafischl 0:d9266031f832 106 /* TODO NTH : printf / scanf helpers that call send/recv */
mafischl 0:d9266031f832 107
mafischl 0:d9266031f832 108 ///Closes socket
mafischl 0:d9266031f832 109 TCPSocketErr close();
mafischl 0:d9266031f832 110
mafischl 0:d9266031f832 111 //Callbacks
mafischl 0:d9266031f832 112 ///Setups callback
mafischl 0:d9266031f832 113 /**
mafischl 0:d9266031f832 114 @param pMethod : callback function
mafischl 0:d9266031f832 115 */
mafischl 0:d9266031f832 116 void setOnEvent( void (*pMethod)(TCPSocketEvent) );
mafischl 0:d9266031f832 117
mafischl 0:d9266031f832 118 class CDummy;
mafischl 0:d9266031f832 119 ///Setups callback
mafischl 0:d9266031f832 120 /**
mafischl 0:d9266031f832 121 @param pItem : instance of class on which to execute the callback method
mafischl 0:d9266031f832 122 @param pMethod : callback method
mafischl 0:d9266031f832 123 */
mafischl 0:d9266031f832 124 template<class T>
mafischl 0:d9266031f832 125 void setOnEvent( T* pItem, void (T::*pMethod)(TCPSocketEvent) )
mafischl 0:d9266031f832 126 {
mafischl 0:d9266031f832 127 m_pCbItem = (CDummy*) pItem;
mafischl 0:d9266031f832 128 m_pCbMeth = (void (CDummy::*)(TCPSocketEvent)) pMethod;
mafischl 0:d9266031f832 129 }
mafischl 0:d9266031f832 130
mafischl 0:d9266031f832 131 ///Disables callback
mafischl 0:d9266031f832 132 void resetOnEvent();
mafischl 0:d9266031f832 133
mafischl 0:d9266031f832 134 protected:
mafischl 0:d9266031f832 135 void onNetTcpSocketEvent(NetTcpSocketEvent e);
mafischl 0:d9266031f832 136 TCPSocketErr checkInst();
mafischl 0:d9266031f832 137
mafischl 0:d9266031f832 138 private:
mafischl 0:d9266031f832 139 NetTcpSocket* m_pNetTcpSocket;
mafischl 0:d9266031f832 140
mafischl 0:d9266031f832 141 CDummy* m_pCbItem;
mafischl 0:d9266031f832 142 void (CDummy::*m_pCbMeth)(TCPSocketEvent);
mafischl 0:d9266031f832 143
mafischl 0:d9266031f832 144 void (*m_pCb)(TCPSocketEvent);
mafischl 0:d9266031f832 145
mafischl 0:d9266031f832 146 };
mafischl 0:d9266031f832 147
mafischl 0:d9266031f832 148 #endif