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 "UDPSocket.h"
mafischl 0:d9266031f832 25 #include "if/net/netudpsocket.h"
mafischl 0:d9266031f832 26
mafischl 0:d9266031f832 27 UDPSocket::UDPSocket() : m_pNetUdpSocket(NULL), m_pCbItem(NULL), m_pCbMeth(NULL), m_pCb(NULL)
mafischl 0:d9266031f832 28 {
mafischl 0:d9266031f832 29
mafischl 0:d9266031f832 30 }
mafischl 0:d9266031f832 31
mafischl 0:d9266031f832 32 UDPSocket::~UDPSocket() //close()
mafischl 0:d9266031f832 33 {
mafischl 0:d9266031f832 34 close();
mafischl 0:d9266031f832 35 }
mafischl 0:d9266031f832 36
mafischl 0:d9266031f832 37 UDPSocketErr UDPSocket::bind(const Host& me)
mafischl 0:d9266031f832 38 {
mafischl 0:d9266031f832 39 UDPSocketErr udpSocketErr = checkInst();
mafischl 0:d9266031f832 40 if(udpSocketErr)
mafischl 0:d9266031f832 41 return udpSocketErr;
mafischl 0:d9266031f832 42 return (UDPSocketErr) m_pNetUdpSocket->bind(me);
mafischl 0:d9266031f832 43 }
mafischl 0:d9266031f832 44
mafischl 0:d9266031f832 45 int /*if < 0 : UDPSocketErr*/ UDPSocket::sendto(const char* buf, int len, Host* pHost)
mafischl 0:d9266031f832 46 {
mafischl 0:d9266031f832 47 UDPSocketErr udpSocketErr = checkInst();
mafischl 0:d9266031f832 48 if(udpSocketErr)
mafischl 0:d9266031f832 49 return udpSocketErr;
mafischl 0:d9266031f832 50 return m_pNetUdpSocket->sendto(buf, len, pHost);
mafischl 0:d9266031f832 51 }
mafischl 0:d9266031f832 52
mafischl 0:d9266031f832 53 int /*if < 0 : UDPSocketErr*/ UDPSocket::recvfrom(char* buf, int len, Host* pHost)
mafischl 0:d9266031f832 54 {
mafischl 0:d9266031f832 55 UDPSocketErr udpSocketErr = checkInst();
mafischl 0:d9266031f832 56 if(udpSocketErr)
mafischl 0:d9266031f832 57 return udpSocketErr;
mafischl 0:d9266031f832 58 return m_pNetUdpSocket->recvfrom(buf, len, pHost);
mafischl 0:d9266031f832 59 }
mafischl 0:d9266031f832 60
mafischl 0:d9266031f832 61 UDPSocketErr UDPSocket::close()
mafischl 0:d9266031f832 62 {
mafischl 0:d9266031f832 63 if(!m_pNetUdpSocket)
mafischl 0:d9266031f832 64 return UDPSOCKET_SETUP;
mafischl 0:d9266031f832 65 m_pNetUdpSocket->resetOnEvent();
mafischl 0:d9266031f832 66 UDPSocketErr udpSocketErr = (UDPSocketErr) m_pNetUdpSocket->close(); //Close (can already be closed)
mafischl 0:d9266031f832 67 Net::releaseUdpSocket(m_pNetUdpSocket); //And release it so it can be freed when properly removed
mafischl 0:d9266031f832 68 m_pNetUdpSocket = NULL;
mafischl 0:d9266031f832 69 return udpSocketErr;
mafischl 0:d9266031f832 70 }
mafischl 0:d9266031f832 71
mafischl 0:d9266031f832 72 //Callbacks
mafischl 0:d9266031f832 73 void UDPSocket::setOnEvent( void (*pMethod)(UDPSocketEvent) )
mafischl 0:d9266031f832 74 {
mafischl 0:d9266031f832 75 m_pCb = pMethod;
mafischl 0:d9266031f832 76 }
mafischl 0:d9266031f832 77
mafischl 0:d9266031f832 78 #if 0 //For info only
mafischl 0:d9266031f832 79 template<class T>
mafischl 0:d9266031f832 80 void UDPSocket::setOnEvent( T* pItem, void (T::*pMethod)(UDPSocketEvent) )
mafischl 0:d9266031f832 81 {
mafischl 0:d9266031f832 82 m_pCbItem = (CDummy*) pItem;
mafischl 0:d9266031f832 83 m_pCbMeth = (void (CDummy::*)(UDPSocketEvent)) pMethod;
mafischl 0:d9266031f832 84 }
mafischl 0:d9266031f832 85 #endif
mafischl 0:d9266031f832 86
mafischl 0:d9266031f832 87 void UDPSocket::resetOnEvent() //Disable callback
mafischl 0:d9266031f832 88 {
mafischl 0:d9266031f832 89 m_pCb = NULL;
mafischl 0:d9266031f832 90 m_pCbItem = NULL;
mafischl 0:d9266031f832 91 m_pCbMeth = NULL;
mafischl 0:d9266031f832 92 }
mafischl 0:d9266031f832 93
mafischl 0:d9266031f832 94 void UDPSocket::onNetUdpSocketEvent(NetUdpSocketEvent e)
mafischl 0:d9266031f832 95 {
mafischl 0:d9266031f832 96 if(m_pCbItem && m_pCbMeth)
mafischl 0:d9266031f832 97 (m_pCbItem->*m_pCbMeth)((UDPSocketEvent) e);
mafischl 0:d9266031f832 98 else if(m_pCb)
mafischl 0:d9266031f832 99 m_pCb((UDPSocketEvent) e);
mafischl 0:d9266031f832 100 }
mafischl 0:d9266031f832 101
mafischl 0:d9266031f832 102 UDPSocketErr UDPSocket::checkInst()
mafischl 0:d9266031f832 103 {
mafischl 0:d9266031f832 104 if(!m_pNetUdpSocket)
mafischl 0:d9266031f832 105 {
mafischl 0:d9266031f832 106 m_pNetUdpSocket = Net::udpSocket();
mafischl 0:d9266031f832 107 if(!m_pNetUdpSocket)
mafischl 0:d9266031f832 108 {
mafischl 0:d9266031f832 109 return UDPSOCKET_IF; //Interface did not return a socket (usually because a default interface does not exist)
mafischl 0:d9266031f832 110 }
mafischl 0:d9266031f832 111 m_pNetUdpSocket->setOnEvent(this, &UDPSocket::onNetUdpSocketEvent);
mafischl 0:d9266031f832 112 }
mafischl 0:d9266031f832 113 return UDPSOCKET_OK;
mafischl 0:d9266031f832 114 }