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.
NetServices/if/gprsmodule/GPRSModuleNetIf.cpp@1:5a7cce9994a3, 2011-10-13 (annotated)
- Committer:
- mafischl
- Date:
- Thu Oct 13 18:01:31 2011 +0000
- Revision:
- 1:5a7cce9994a3
- Parent:
- 0:d9266031f832
Who changed what in which revision?
User | Revision | Line number | New 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 "netCfg.h" |
mafischl | 0:d9266031f832 | 25 | #if NET_GPRS_MODULE |
mafischl | 0:d9266031f832 | 26 | |
mafischl | 0:d9266031f832 | 27 | #include "GPRSModuleNetIf.h" |
mafischl | 0:d9266031f832 | 28 | |
mafischl | 0:d9266031f832 | 29 | #define __DEBUG |
mafischl | 0:d9266031f832 | 30 | #include "dbg/dbg.h" |
mafischl | 0:d9266031f832 | 31 | |
mafischl | 0:d9266031f832 | 32 | GPRSModuleNetIf::GPRSModuleNetIf(PinName tx, PinName rx, int baud /*= 115200*/) : PPPNetIf(NULL), m_serial(tx, rx) |
mafischl | 0:d9266031f832 | 33 | { |
mafischl | 0:d9266031f832 | 34 | PPPNetIf::m_pIf = new GPRSModem(); |
mafischl | 0:d9266031f832 | 35 | m_serial.baud(baud); |
mafischl | 0:d9266031f832 | 36 | } |
mafischl | 0:d9266031f832 | 37 | |
mafischl | 0:d9266031f832 | 38 | GPRSModuleNetIf::~GPRSModuleNetIf() |
mafischl | 0:d9266031f832 | 39 | { |
mafischl | 0:d9266031f832 | 40 | delete PPPNetIf::m_pIf; |
mafischl | 0:d9266031f832 | 41 | } |
mafischl | 0:d9266031f832 | 42 | |
mafischl | 0:d9266031f832 | 43 | PPPErr GPRSModuleNetIf::connect(const char* apn /*= NULL*/, const char* userId /*= NULL*/, const char* password /*= NULL*/) //Connect using GPRS |
mafischl | 0:d9266031f832 | 44 | { |
mafischl | 0:d9266031f832 | 45 | |
mafischl | 0:d9266031f832 | 46 | DBG("Powering on module.\n") |
mafischl | 0:d9266031f832 | 47 | if(!setOn()) //Could not power on module |
mafischl | 0:d9266031f832 | 48 | { |
mafischl | 0:d9266031f832 | 49 | DBG("Could not power on module.\n"); |
mafischl | 0:d9266031f832 | 50 | return PPP_MODEM; |
mafischl | 0:d9266031f832 | 51 | } |
mafischl | 0:d9266031f832 | 52 | |
mafischl | 0:d9266031f832 | 53 | //wait(10); //Wait for module to init. |
mafischl | 0:d9266031f832 | 54 | |
mafischl | 0:d9266031f832 | 55 | ATErr atErr; |
mafischl | 0:d9266031f832 | 56 | for(int i=0; i<3; i++) |
mafischl | 0:d9266031f832 | 57 | { |
mafischl | 0:d9266031f832 | 58 | atErr = m_pIf->open(&m_serial); //3 tries |
mafischl | 0:d9266031f832 | 59 | if(!atErr) |
mafischl | 0:d9266031f832 | 60 | break; |
mafischl | 0:d9266031f832 | 61 | DBG("Could not open AT If, trying again.\n"); |
mafischl | 0:d9266031f832 | 62 | wait(4); |
mafischl | 0:d9266031f832 | 63 | } |
mafischl | 0:d9266031f832 | 64 | |
mafischl | 0:d9266031f832 | 65 | if(atErr) |
mafischl | 0:d9266031f832 | 66 | { |
mafischl | 0:d9266031f832 | 67 | setOff(); |
mafischl | 0:d9266031f832 | 68 | return PPP_MODEM; |
mafischl | 0:d9266031f832 | 69 | } |
mafischl | 0:d9266031f832 | 70 | |
mafischl | 0:d9266031f832 | 71 | DBG("AT If opened.\n"); |
mafischl | 0:d9266031f832 | 72 | |
mafischl | 0:d9266031f832 | 73 | PPPErr pppErr; |
mafischl | 0:d9266031f832 | 74 | for(int i=0; i<3; i++) |
mafischl | 0:d9266031f832 | 75 | { |
mafischl | 0:d9266031f832 | 76 | DBG("Trying to connect.\n"); |
mafischl | 0:d9266031f832 | 77 | pppErr = PPPNetIf::GPRSConnect(apn, userId, password); |
mafischl | 0:d9266031f832 | 78 | if(!pppErr) |
mafischl | 0:d9266031f832 | 79 | break; |
mafischl | 0:d9266031f832 | 80 | DBG("Could not connect.\n"); |
mafischl | 0:d9266031f832 | 81 | wait(4); |
mafischl | 0:d9266031f832 | 82 | } |
mafischl | 0:d9266031f832 | 83 | if(pppErr) |
mafischl | 0:d9266031f832 | 84 | { |
mafischl | 0:d9266031f832 | 85 | setOff(); |
mafischl | 0:d9266031f832 | 86 | return pppErr; |
mafischl | 0:d9266031f832 | 87 | } |
mafischl | 0:d9266031f832 | 88 | |
mafischl | 0:d9266031f832 | 89 | DBG("Connected.\n"); |
mafischl | 0:d9266031f832 | 90 | |
mafischl | 0:d9266031f832 | 91 | return PPP_OK; |
mafischl | 0:d9266031f832 | 92 | } |
mafischl | 0:d9266031f832 | 93 | |
mafischl | 0:d9266031f832 | 94 | PPPErr GPRSModuleNetIf::disconnect() |
mafischl | 0:d9266031f832 | 95 | { |
mafischl | 0:d9266031f832 | 96 | DBG("Disconnecting...\n"); |
mafischl | 0:d9266031f832 | 97 | PPPErr pppErr = PPPNetIf::disconnect(); |
mafischl | 0:d9266031f832 | 98 | if(pppErr) |
mafischl | 0:d9266031f832 | 99 | return pppErr; |
mafischl | 0:d9266031f832 | 100 | |
mafischl | 0:d9266031f832 | 101 | m_pIf->close(); |
mafischl | 0:d9266031f832 | 102 | |
mafischl | 0:d9266031f832 | 103 | DBG("Powering off module.\n") |
mafischl | 0:d9266031f832 | 104 | setOff(); //Power off module |
mafischl | 0:d9266031f832 | 105 | |
mafischl | 0:d9266031f832 | 106 | DBG("Off.\n") |
mafischl | 0:d9266031f832 | 107 | |
mafischl | 0:d9266031f832 | 108 | return PPP_OK; |
mafischl | 0:d9266031f832 | 109 | } |
mafischl | 0:d9266031f832 | 110 | |
mafischl | 0:d9266031f832 | 111 | |
mafischl | 0:d9266031f832 | 112 | #endif |