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 #include "netservice.h"
mafischl 0:d9266031f832 25 #include "net.h"
mafischl 0:d9266031f832 26
mafischl 0:d9266031f832 27 //#define __DEBUG
mafischl 0:d9266031f832 28 #include "dbg/dbg.h"
mafischl 0:d9266031f832 29
mafischl 0:d9266031f832 30 NetService::NetService(bool owned /*= true*/) : m_closed(false), m_removed(false), m_owned(owned)
mafischl 0:d9266031f832 31 {
mafischl 0:d9266031f832 32 NetService::lpServices().push_back(this);
mafischl 0:d9266031f832 33 DBG("\r\n[ + %p ] %d\r\n", (void*)this, lpServices().size());
mafischl 0:d9266031f832 34 }
mafischl 0:d9266031f832 35
mafischl 0:d9266031f832 36 NetService::~NetService()
mafischl 0:d9266031f832 37 {
mafischl 0:d9266031f832 38 // DBG("\r\nService removed\r\n");
mafischl 0:d9266031f832 39 // DBG("\r\nNow %d services running\r\n", lpServices().size()-1);
mafischl 0:d9266031f832 40 DBG("\r\n[ - %p ] %d\r\n", (void*)this, lpServices().size()-1);
mafischl 0:d9266031f832 41 if((!m_owned) || (!m_removed)) //Destructor was not called by servicesPoll()
mafischl 0:d9266031f832 42 {
mafischl 0:d9266031f832 43 if(m_owned)
mafischl 0:d9266031f832 44 DBG("\r\nWARN!!!Service removed in dtor!!!\r\n");
mafischl 0:d9266031f832 45 NetService::lpServices().remove(this);
mafischl 0:d9266031f832 46 }
mafischl 0:d9266031f832 47 }
mafischl 0:d9266031f832 48
mafischl 0:d9266031f832 49 void NetService::poll()
mafischl 0:d9266031f832 50 {
mafischl 0:d9266031f832 51
mafischl 0:d9266031f832 52 }
mafischl 0:d9266031f832 53
mafischl 0:d9266031f832 54 void NetService::servicesPoll() //Poll all registered services & destroy closed ones
mafischl 0:d9266031f832 55 {
mafischl 0:d9266031f832 56 list<NetService*>::iterator it;
mafischl 0:d9266031f832 57 DBG("\r\nServices polling over %d services\r\n", lpServices().size());
mafischl 0:d9266031f832 58 for( it = lpServices().begin(); it != lpServices().end(); )
mafischl 0:d9266031f832 59 {
mafischl 0:d9266031f832 60 if( (*it)->m_owned && (*it)->m_closed )
mafischl 0:d9266031f832 61 {
mafischl 0:d9266031f832 62 DBG("\r\nService %p is flagged as closed\r\n", (*it));
mafischl 0:d9266031f832 63 (*it)->m_removed = true;
mafischl 0:d9266031f832 64 delete (*it);
mafischl 0:d9266031f832 65 it = lpServices().erase(it);
mafischl 0:d9266031f832 66 }
mafischl 0:d9266031f832 67 else
mafischl 0:d9266031f832 68 {
mafischl 0:d9266031f832 69 //DBG("Service %p polling start\n", (*it));
mafischl 0:d9266031f832 70 (*it)->poll();
mafischl 0:d9266031f832 71 //DBG("Service %p polling end\n", (*it));
mafischl 0:d9266031f832 72 it++;
mafischl 0:d9266031f832 73 }
mafischl 0:d9266031f832 74 }
mafischl 0:d9266031f832 75
mafischl 0:d9266031f832 76 }
mafischl 0:d9266031f832 77
mafischl 0:d9266031f832 78 void NetService::close()
mafischl 0:d9266031f832 79 {
mafischl 0:d9266031f832 80 DBG("\r\nService %p to be closed (owned = %d)\r\n", this, m_owned);
mafischl 0:d9266031f832 81 m_closed = true;
mafischl 0:d9266031f832 82 }
mafischl 0:d9266031f832 83
mafischl 0:d9266031f832 84 list<NetService*>& NetService::lpServices()
mafischl 0:d9266031f832 85 {
mafischl 0:d9266031f832 86 static list<NetService*>* pInst = new list<NetService*>(); //Called only once
mafischl 0:d9266031f832 87 return *pInst;
mafischl 0:d9266031f832 88 }