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 Copyright (c) 2010 Andy Kirkham
mafischl 0:d9266031f832 3
mafischl 0:d9266031f832 4 Permission is hereby granted, free of charge, to any person obtaining a copy
mafischl 0:d9266031f832 5 of this software and associated documentation files (the "Software"), to deal
mafischl 0:d9266031f832 6 in the Software without restriction, including without limitation the rights
mafischl 0:d9266031f832 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mafischl 0:d9266031f832 8 copies of the Software, and to permit persons to whom the Software is
mafischl 0:d9266031f832 9 furnished to do so, subject to the following conditions:
mafischl 0:d9266031f832 10
mafischl 0:d9266031f832 11 The above copyright notice and this permission notice shall be included in
mafischl 0:d9266031f832 12 all copies or substantial portions of the Software.
mafischl 0:d9266031f832 13
mafischl 0:d9266031f832 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mafischl 0:d9266031f832 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mafischl 0:d9266031f832 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mafischl 0:d9266031f832 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mafischl 0:d9266031f832 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mafischl 0:d9266031f832 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mafischl 0:d9266031f832 20 THE SOFTWARE.
mafischl 0:d9266031f832 21 */
mafischl 0:d9266031f832 22
mafischl 0:d9266031f832 23 #include "MODSERIAL.h"
mafischl 0:d9266031f832 24 #include "MACROS.h"
mafischl 0:d9266031f832 25
mafischl 0:d9266031f832 26 namespace AjK {
mafischl 0:d9266031f832 27
mafischl 0:d9266031f832 28 int
mafischl 0:d9266031f832 29 MODSERIAL::resizeBuffer(int size, IrqType type, bool memory_check)
mafischl 0:d9266031f832 30 {
mafischl 0:d9266031f832 31 int rval = Ok;
mafischl 0:d9266031f832 32
mafischl 0:d9266031f832 33 // If the requested size is the same as the current size there's nothing to do,
mafischl 0:d9266031f832 34 // just continue to use the same buffer as it's fine as it is.
mafischl 0:d9266031f832 35 if (buffer_size[type] == size) return rval;
mafischl 0:d9266031f832 36
mafischl 0:d9266031f832 37 // Make sure the ISR cannot use the buffers while we are manipulating them.
mafischl 0:d9266031f832 38 disableIrq();
mafischl 0:d9266031f832 39
mafischl 0:d9266031f832 40 // If the requested buffer size is larger than the current size,
mafischl 0:d9266031f832 41 // attempt to create a new buffer and use it.
mafischl 0:d9266031f832 42 if (buffer_size[type] < size) {
mafischl 0:d9266031f832 43 rval = upSizeBuffer(size, type, memory_check);
mafischl 0:d9266031f832 44 }
mafischl 0:d9266031f832 45 else if (buffer_size[type] > size) {
mafischl 0:d9266031f832 46 rval = downSizeBuffer(size, type, memory_check);
mafischl 0:d9266031f832 47 }
mafischl 0:d9266031f832 48
mafischl 0:d9266031f832 49 // Start the ISR system again with the new buffers.
mafischl 0:d9266031f832 50 enableIrq();
mafischl 0:d9266031f832 51
mafischl 0:d9266031f832 52 return rval;
mafischl 0:d9266031f832 53 }
mafischl 0:d9266031f832 54
mafischl 0:d9266031f832 55 int
mafischl 0:d9266031f832 56 MODSERIAL::downSizeBuffer(int size, IrqType type, bool memory_check)
mafischl 0:d9266031f832 57 {
mafischl 0:d9266031f832 58 if (size >= buffer_count[type]) {
mafischl 0:d9266031f832 59 return BufferOversize;
mafischl 0:d9266031f832 60 }
mafischl 0:d9266031f832 61
mafischl 0:d9266031f832 62 char *s = (char *)malloc(size);
mafischl 0:d9266031f832 63
mafischl 0:d9266031f832 64 if (s == (char *)NULL) {
mafischl 0:d9266031f832 65 if (memory_check) {
mafischl 0:d9266031f832 66 error("Failed to allocate memory for %s buffer", type == TxIrq ? "TX" : "RX");
mafischl 0:d9266031f832 67 }
mafischl 0:d9266031f832 68 return NoMemory;
mafischl 0:d9266031f832 69 }
mafischl 0:d9266031f832 70
mafischl 0:d9266031f832 71 int c, new_in = 0;
mafischl 0:d9266031f832 72
mafischl 0:d9266031f832 73 do {
mafischl 0:d9266031f832 74 c = __getc(false);
mafischl 0:d9266031f832 75 if (c != -1) s[new_in++] = (char)c;
mafischl 0:d9266031f832 76 if (new_in >= size) new_in = 0;
mafischl 0:d9266031f832 77 }
mafischl 0:d9266031f832 78 while (c != -1);
mafischl 0:d9266031f832 79
mafischl 0:d9266031f832 80 free((char *)buffer[type]);
mafischl 0:d9266031f832 81 buffer[type] = s;
mafischl 0:d9266031f832 82 buffer_in[type] = new_in;
mafischl 0:d9266031f832 83 buffer_out[type] = 0;
mafischl 0:d9266031f832 84 return Ok;
mafischl 0:d9266031f832 85 }
mafischl 0:d9266031f832 86
mafischl 0:d9266031f832 87 int
mafischl 0:d9266031f832 88 MODSERIAL::upSizeBuffer(int size, IrqType type, bool memory_check)
mafischl 0:d9266031f832 89 {
mafischl 0:d9266031f832 90 char *s = (char *)malloc(size);
mafischl 0:d9266031f832 91
mafischl 0:d9266031f832 92 if (s == (char *)NULL) {
mafischl 0:d9266031f832 93 if (memory_check) {
mafischl 0:d9266031f832 94 error("Failed to allocate memory for %s buffer", type == TxIrq ? "TX" : "RX");
mafischl 0:d9266031f832 95 }
mafischl 0:d9266031f832 96 return NoMemory;
mafischl 0:d9266031f832 97 }
mafischl 0:d9266031f832 98
mafischl 0:d9266031f832 99 if (buffer_count[type] == 0) { // Current buffer empty?
mafischl 0:d9266031f832 100 free((char *)buffer[type]);
mafischl 0:d9266031f832 101 buffer[type] = s;
mafischl 0:d9266031f832 102 buffer_in[type] = 0;
mafischl 0:d9266031f832 103 buffer_out[type] = 0;
mafischl 0:d9266031f832 104 }
mafischl 0:d9266031f832 105 else { // Copy the current contents into the new buffer.
mafischl 0:d9266031f832 106 int c, new_in = 0;
mafischl 0:d9266031f832 107 do {
mafischl 0:d9266031f832 108 c = __getc(false);
mafischl 0:d9266031f832 109 if (c != -1) s[new_in++] = (char)c;
mafischl 0:d9266031f832 110 if (new_in >= size) new_in = 0; // Shouldn't happen, but be sure.
mafischl 0:d9266031f832 111 }
mafischl 0:d9266031f832 112 while (c != -1);
mafischl 0:d9266031f832 113 free((char *)buffer[type]);
mafischl 0:d9266031f832 114 buffer[type] = s;
mafischl 0:d9266031f832 115 buffer_in[type] = new_in;
mafischl 0:d9266031f832 116 buffer_out[type] = 0;
mafischl 0:d9266031f832 117 }
mafischl 0:d9266031f832 118
mafischl 0:d9266031f832 119 buffer_size[type] = size;
mafischl 0:d9266031f832 120 return Ok;
mafischl 0:d9266031f832 121 }
mafischl 0:d9266031f832 122
mafischl 0:d9266031f832 123 }; // namespace AjK ends