Vodafone K3770 dongle enabled receipt printer.
Dependencies: AdafruitThermalPrinter VodafoneK3770LibArchive mbed
Fork of 3GPrinter by
main.cpp@1:59abeafd95d2, 2012-06-29 (annotated)
- Committer:
- ashleymills
- Date:
- Fri Jun 29 08:47:09 2012 +0000
- Revision:
- 1:59abeafd95d2
- Parent:
- 0:76691d4f3960
Initial;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:76691d4f3960 | 1 | #define __DEBUG__ 4 //Maximum verbosity |
ashleymills | 0:76691d4f3960 | 2 | #ifndef __MODULE__ |
ashleymills | 0:76691d4f3960 | 3 | #define __MODULE__ "net_3g_basic_http_test.cpp" |
ashleymills | 0:76691d4f3960 | 4 | #endif |
ashleymills | 0:76691d4f3960 | 5 | |
ashleymills | 0:76691d4f3960 | 6 | #include "core/fwk.h" |
ashleymills | 0:76691d4f3960 | 7 | #include "mbed.h" |
ashleymills | 0:76691d4f3960 | 8 | #include "rtos.h" |
ashleymills | 0:76691d4f3960 | 9 | #include "if/VodafoneK3770.h" |
ashleymills | 0:76691d4f3960 | 10 | #include "AdafruitThermal.h" |
ashleymills | 0:76691d4f3960 | 11 | |
ashleymills | 0:76691d4f3960 | 12 | DigitalOut led1(LED1); |
ashleymills | 0:76691d4f3960 | 13 | |
ashleymills | 0:76691d4f3960 | 14 | extern "C" void HardFault_Handler() { |
ashleymills | 1:59abeafd95d2 | 15 | error("Hard Fault!\n"); |
ashleymills | 0:76691d4f3960 | 16 | } |
ashleymills | 0:76691d4f3960 | 17 | |
ashleymills | 1:59abeafd95d2 | 18 | // this is the main thread which checks for messages and sends them to the printer |
ashleymills | 1:59abeafd95d2 | 19 | void printerLoop(void const*) { |
ashleymills | 1:59abeafd95d2 | 20 | VodafoneK3770 modem; // setup modem |
ashleymills | 1:59abeafd95d2 | 21 | AdafruitThermal printer(p13,p14); // setup printer |
ashleymills | 1:59abeafd95d2 | 22 | printer.begin(); // and init it |
ashleymills | 0:76691d4f3960 | 23 | |
ashleymills | 1:59abeafd95d2 | 24 | // declare space for phone number and message storage |
ashleymills | 1:59abeafd95d2 | 25 | char numBuffer[20], msgBuffer[256]; |
ashleymills | 1:59abeafd95d2 | 26 | size_t numSMS; // variable to track number of received messages |
ashleymills | 1:59abeafd95d2 | 27 | |
ashleymills | 1:59abeafd95d2 | 28 | //modem.sendSM("07825608771","this is a test"); |
ashleymills | 1:59abeafd95d2 | 29 | |
ashleymills | 1:59abeafd95d2 | 30 | // loop forever |
ashleymills | 1:59abeafd95d2 | 31 | while(1) { |
ashleymills | 1:59abeafd95d2 | 32 | DBG("Checking SM count"); |
ashleymills | 0:76691d4f3960 | 33 | |
ashleymills | 1:59abeafd95d2 | 34 | // retrieve the short message count into numSMS |
ashleymills | 1:59abeafd95d2 | 35 | if(modem.getSMCount(&numSMS)==OK) { |
ashleymills | 1:59abeafd95d2 | 36 | DBG("getSMCount success"); |
ashleymills | 1:59abeafd95d2 | 37 | DBG("numSMS: %d",numSMS); |
ashleymills | 1:59abeafd95d2 | 38 | // check if any short messages have been received |
ashleymills | 1:59abeafd95d2 | 39 | if(numSMS>0) { |
ashleymills | 1:59abeafd95d2 | 40 | DBG("SM count > 0"); |
ashleymills | 1:59abeafd95d2 | 41 | // get the oldest short message in the queue |
ashleymills | 1:59abeafd95d2 | 42 | if(modem.getSM(numBuffer,msgBuffer,256)==OK) { |
ashleymills | 1:59abeafd95d2 | 43 | DBG("message received"); |
ashleymills | 1:59abeafd95d2 | 44 | DBG("num: %s",numBuffer); |
ashleymills | 1:59abeafd95d2 | 45 | DBG("msg: %s",msgBuffer); |
ashleymills | 1:59abeafd95d2 | 46 | // send it to the printer |
ashleymills | 1:59abeafd95d2 | 47 | printer.print(msgBuffer); |
ashleymills | 1:59abeafd95d2 | 48 | printer.print("\r\n"); |
ashleymills | 1:59abeafd95d2 | 49 | // linefeed a couple of times |
ashleymills | 1:59abeafd95d2 | 50 | printer.feed(2); |
ashleymills | 1:59abeafd95d2 | 51 | } |
ashleymills | 1:59abeafd95d2 | 52 | } |
ashleymills | 1:59abeafd95d2 | 53 | } |
ashleymills | 1:59abeafd95d2 | 54 | // wait 500ms |
ashleymills | 1:59abeafd95d2 | 55 | Thread::wait(500); |
ashleymills | 0:76691d4f3960 | 56 | } |
ashleymills | 0:76691d4f3960 | 57 | } |
ashleymills | 0:76691d4f3960 | 58 | |
ashleymills | 1:59abeafd95d2 | 59 | // this is the main thread |
ashleymills | 0:76691d4f3960 | 60 | int main() { |
ashleymills | 1:59abeafd95d2 | 61 | // init the debug macros |
ashleymills | 1:59abeafd95d2 | 62 | DBG_INIT(); |
ashleymills | 0:76691d4f3960 | 63 | |
ashleymills | 1:59abeafd95d2 | 64 | // create and launch printer thread |
ashleymills | 1:59abeafd95d2 | 65 | Thread testTask( |
ashleymills | 1:59abeafd95d2 | 66 | printerLoop, // function name |
ashleymills | 1:59abeafd95d2 | 67 | NULL, osPriorityNormal, 1024 * 4); |
ashleymills | 1:59abeafd95d2 | 68 | |
ashleymills | 1:59abeafd95d2 | 69 | // loop forever, relinquish thread every 500ms |
ashleymills | 1:59abeafd95d2 | 70 | while(1) { |
ashleymills | 1:59abeafd95d2 | 71 | // toggle led1 |
ashleymills | 1:59abeafd95d2 | 72 | led1 = !led1; |
ashleymills | 1:59abeafd95d2 | 73 | // wait 500ms |
ashleymills | 1:59abeafd95d2 | 74 | Thread::wait(500); |
ashleymills | 1:59abeafd95d2 | 75 | } |
ashleymills | 0:76691d4f3960 | 76 | |
ashleymills | 1:59abeafd95d2 | 77 | return 0; |
ashleymills | 0:76691d4f3960 | 78 | } |