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 18:01:31 2011 +0000
Revision:
1:5a7cce9994a3
Parent:
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 #ifndef NETUDPSOCKET_H
mafischl 0:d9266031f832 25 #define NETUDPSOCKET_H
mafischl 0:d9266031f832 26
mafischl 0:d9266031f832 27 #include "net.h"
mafischl 0:d9266031f832 28 #include "host.h"
mafischl 0:d9266031f832 29
mafischl 0:d9266031f832 30 #include <queue>
mafischl 0:d9266031f832 31 using std::queue;
mafischl 0:d9266031f832 32
mafischl 0:d9266031f832 33 //Implements a Berkeley-like socket if
mafischl 0:d9266031f832 34 //Can be interfaced either to lwip or a Telit module
mafischl 0:d9266031f832 35
mafischl 0:d9266031f832 36 enum NetUdpSocketErr
mafischl 0:d9266031f832 37 {
mafischl 0:d9266031f832 38 __NETUDPSOCKET_MIN = -0xFFFF,
mafischl 0:d9266031f832 39 NETUDPSOCKET_SETUP, //NetUdpSocket not properly configured
mafischl 0:d9266031f832 40 NETUDPSOCKET_IF, //If has problems
mafischl 0:d9266031f832 41 NETUDPSOCKET_MEM, //Not enough mem
mafischl 0:d9266031f832 42 NETUDPSOCKET_INUSE, //If/Port is in use
mafischl 0:d9266031f832 43 //...
mafischl 0:d9266031f832 44 NETUDPSOCKET_OK = 0
mafischl 0:d9266031f832 45 };
mafischl 0:d9266031f832 46
mafischl 0:d9266031f832 47 enum NetUdpSocketEvent //Only one lonely event here... but who knows, maybe some day there'll be another one!
mafischl 0:d9266031f832 48 {
mafischl 0:d9266031f832 49 NETUDPSOCKET_READABLE, //Data in buf
mafischl 0:d9266031f832 50 };
mafischl 0:d9266031f832 51
mafischl 0:d9266031f832 52
mafischl 0:d9266031f832 53 class NetUdpSocket
mafischl 0:d9266031f832 54 {
mafischl 0:d9266031f832 55 public:
mafischl 0:d9266031f832 56 NetUdpSocket();
mafischl 0:d9266031f832 57 virtual ~NetUdpSocket(); //close()
mafischl 0:d9266031f832 58
mafischl 0:d9266031f832 59 virtual NetUdpSocketErr bind(const Host& me) = 0;
mafischl 0:d9266031f832 60
mafischl 0:d9266031f832 61 virtual int /*if < 0 : NetUdpSocketErr*/ sendto(const char* buf, int len, Host* pHost) = 0;
mafischl 0:d9266031f832 62 virtual int /*if < 0 : NetUdpSocketErr*/ recvfrom(char* buf, int len, Host* pHost) = 0;
mafischl 0:d9266031f832 63
mafischl 0:d9266031f832 64 /* TODO NTH : printf / scanf helpers that call send/recv */
mafischl 0:d9266031f832 65
mafischl 0:d9266031f832 66 virtual NetUdpSocketErr close() = 0;
mafischl 0:d9266031f832 67
mafischl 0:d9266031f832 68 virtual NetUdpSocketErr poll() = 0;
mafischl 0:d9266031f832 69
mafischl 0:d9266031f832 70 class CDummy;
mafischl 0:d9266031f832 71 //Callbacks
mafischl 0:d9266031f832 72 template<class T>
mafischl 0:d9266031f832 73 //Linker bug : Must be defined here :(
mafischl 0:d9266031f832 74 void setOnEvent( T* pItem, void (T::*pMethod)(NetUdpSocketEvent) )
mafischl 0:d9266031f832 75 {
mafischl 0:d9266031f832 76 m_pCbItem = (CDummy*) pItem;
mafischl 0:d9266031f832 77 m_pCbMeth = (void (CDummy::*)(NetUdpSocketEvent)) pMethod;
mafischl 0:d9266031f832 78 }
mafischl 0:d9266031f832 79
mafischl 0:d9266031f832 80 void resetOnEvent(); //Disable callback
mafischl 0:d9266031f832 81
mafischl 0:d9266031f832 82 protected:
mafischl 0:d9266031f832 83 void queueEvent(NetUdpSocketEvent e);
mafischl 0:d9266031f832 84 void discardEvents();
mafischl 0:d9266031f832 85 void flushEvents(); //to be called during polling
mafischl 0:d9266031f832 86
mafischl 0:d9266031f832 87 Host m_host;
mafischl 0:d9266031f832 88 Host m_client;
mafischl 0:d9266031f832 89
mafischl 0:d9266031f832 90 friend class Net;
mafischl 0:d9266031f832 91 int m_refs;
mafischl 0:d9266031f832 92
mafischl 0:d9266031f832 93 bool m_closed;
mafischl 0:d9266031f832 94 bool m_removed;
mafischl 0:d9266031f832 95
mafischl 0:d9266031f832 96 private:
mafischl 0:d9266031f832 97 //We do not want to execute user code in interrupt routines, so we queue events until the server is polled
mafischl 0:d9266031f832 98 //If we port this to a multithreaded OS, we could avoid this (however some functions here are not thread-safe, so beware ;) )
mafischl 0:d9266031f832 99 void onEvent(NetUdpSocketEvent e); //To be called on poll
mafischl 0:d9266031f832 100 CDummy* m_pCbItem;
mafischl 0:d9266031f832 101 void (CDummy::*m_pCbMeth)(NetUdpSocketEvent);
mafischl 0:d9266031f832 102 queue<NetUdpSocketEvent> m_events;
mafischl 0:d9266031f832 103
mafischl 0:d9266031f832 104 };
mafischl 0:d9266031f832 105
mafischl 0:d9266031f832 106 #endif