Dreamforce 2014 Workshop RFID Case Generator - FRDM-K64F
Dependencies: EndpointMain-rfid EthernetInterface StatusReporter BufferedSerial mbed-rtos mbed Logger C12832
Fork of df-2014-workshop-rfid-case-generator-ublox by
main.cpp@8:fefcecb66463, 2014-08-27 (annotated)
- Committer:
- ansond
- Date:
- Wed Aug 27 20:30:37 2014 +0000
- Revision:
- 8:fefcecb66463
- Parent:
- 7:5d6e03557246
- Child:
- 13:2561e3855a81
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:df2aa79c64f2 | 1 | /* Copyright C2014 ARM, MIT License |
ansond | 0:df2aa79c64f2 | 2 | * |
ansond | 0:df2aa79c64f2 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:df2aa79c64f2 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:df2aa79c64f2 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:df2aa79c64f2 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:df2aa79c64f2 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 0:df2aa79c64f2 | 8 | * |
ansond | 0:df2aa79c64f2 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:df2aa79c64f2 | 10 | * substantial portions of the Software. |
ansond | 0:df2aa79c64f2 | 11 | * |
ansond | 0:df2aa79c64f2 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:df2aa79c64f2 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:df2aa79c64f2 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:df2aa79c64f2 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:df2aa79c64f2 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:df2aa79c64f2 | 17 | */ |
ansond | 0:df2aa79c64f2 | 18 | |
ansond | 0:df2aa79c64f2 | 19 | // our definitions |
ansond | 0:df2aa79c64f2 | 20 | #include "Definitions.h" |
ansond | 0:df2aa79c64f2 | 21 | |
ansond | 6:427c387b10e7 | 22 | // RFID Reader - on P14 pin |
ansond | 6:427c387b10e7 | 23 | #if ID12_ENABLE |
ansond | 6:427c387b10e7 | 24 | #include "ID12RFID.h" |
ansond | 7:5d6e03557246 | 25 | ID12RFID rfid_reader(p13,p14); |
ansond | 6:427c387b10e7 | 26 | #endif |
ansond | 0:df2aa79c64f2 | 27 | |
ansond | 0:df2aa79c64f2 | 28 | // Salesforce Case Generator |
ansond | 0:df2aa79c64f2 | 29 | #include "SalesForceCaseGenerator.h" |
ansond | 0:df2aa79c64f2 | 30 | |
ansond | 0:df2aa79c64f2 | 31 | // our Logger |
ansond | 0:df2aa79c64f2 | 32 | #include "Logger.h" |
ansond | 0:df2aa79c64f2 | 33 | |
ansond | 0:df2aa79c64f2 | 34 | // our WidgetDB |
ansond | 0:df2aa79c64f2 | 35 | #include "WidgetDB.h" |
ansond | 0:df2aa79c64f2 | 36 | |
ansond | 0:df2aa79c64f2 | 37 | // our LCD Panel |
ansond | 0:df2aa79c64f2 | 38 | #include "C12832_lcd.h" |
ansond | 0:df2aa79c64f2 | 39 | C12832_LCD lcd; |
ansond | 0:df2aa79c64f2 | 40 | |
ansond | 0:df2aa79c64f2 | 41 | // our Serial port |
ansond | 0:df2aa79c64f2 | 42 | #include "Serial.h" |
ansond | 0:df2aa79c64f2 | 43 | Serial pc(USBTX, USBRX); |
ansond | 0:df2aa79c64f2 | 44 | |
ansond | 3:03108e424931 | 45 | // Ethernet |
ansond | 3:03108e424931 | 46 | #include "EthernetInterface.h" |
ansond | 3:03108e424931 | 47 | EthernetInterface ethernet; |
ansond | 3:03108e424931 | 48 | |
ansond | 6:427c387b10e7 | 49 | // HARD RESET |
ansond | 6:427c387b10e7 | 50 | extern "C" void HardFault_Handler() { NVIC_SystemReset(); } |
ansond | 6:427c387b10e7 | 51 | |
ansond | 0:df2aa79c64f2 | 52 | // Main Entry... |
ansond | 0:df2aa79c64f2 | 53 | int main() { |
ansond | 0:df2aa79c64f2 | 54 | // create our object instances |
ansond | 0:df2aa79c64f2 | 55 | Logger logger(&pc,&lcd); |
ansond | 0:df2aa79c64f2 | 56 | |
ansond | 0:df2aa79c64f2 | 57 | // announce |
ansond | 0:df2aa79c64f2 | 58 | logger.log("DF 2014 RFID Reader\r\nVersion: %s",APP_VERSION); |
ansond | 0:df2aa79c64f2 | 59 | |
ansond | 3:03108e424931 | 60 | // initialize Ethernet |
ansond | 3:03108e424931 | 61 | logger.log("Initializing Ethernet..."); |
ansond | 3:03108e424931 | 62 | ethernet.init(); |
ansond | 0:df2aa79c64f2 | 63 | |
ansond | 3:03108e424931 | 64 | // get a DHCP address and bring the network interface up |
ansond | 3:03108e424931 | 65 | logger.log("Getting IP Address..."); |
ansond | 3:03108e424931 | 66 | if (ethernet.connect() == 0) { |
ansond | 3:03108e424931 | 67 | // log our IP address (DHCP) |
ansond | 3:03108e424931 | 68 | logger.log("IP Address: %s",ethernet.getIPAddress()); |
ansond | 3:03108e424931 | 69 | |
ansond | 3:03108e424931 | 70 | // create the WidgetDB |
ansond | 3:03108e424931 | 71 | WidgetDB db; |
ansond | 3:03108e424931 | 72 | |
ansond | 3:03108e424931 | 73 | // create the Salesforce Case Generator |
ansond | 3:03108e424931 | 74 | SalesForceCaseGenerator case_generator(&logger); |
ansond | 3:03108e424931 | 75 | |
ansond | 8:fefcecb66463 | 76 | // entering main loop |
ansond | 8:fefcecb66463 | 77 | logger.log("Entering Main Loop...\r\nScanning..."); |
ansond | 8:fefcecb66463 | 78 | |
ansond | 3:03108e424931 | 79 | // Enter the main loop |
ansond | 3:03108e424931 | 80 | while(true) { |
ansond | 6:427c387b10e7 | 81 | #if ID12_ENABLE |
ansond | 3:03108e424931 | 82 | // look for a readable RFID tag |
ansond | 8:fefcecb66463 | 83 | //logger.log("RFID: Scanning..."); |
ansond | 3:03108e424931 | 84 | if(rfid_reader.readable()) { |
ansond | 3:03108e424931 | 85 | // capture the RFID id... |
ansond | 6:427c387b10e7 | 86 | logger.log("RFID: Found RFID.\r\nReading..."); |
ansond | 3:03108e424931 | 87 | int rfid = rfid_reader.read(); |
ansond | 6:427c387b10e7 | 88 | logger.log("RFID: ID %d found...\r\nProcessing...",rfid); |
ansond | 0:df2aa79c64f2 | 89 | |
ansond | 3:03108e424931 | 90 | // look it up in our WidgetDB... proceed only if we find something we know about... |
ansond | 6:427c387b10e7 | 91 | char *name = db.lookupWidgetName(rfid); |
ansond | 3:03108e424931 | 92 | if (name != NULL) { |
ansond | 3:03108e424931 | 93 | // build out a simple subject for the case |
ansond | 3:03108e424931 | 94 | char subject[MAX_NAME_LENGTH+1]; |
ansond | 3:03108e424931 | 95 | memset(subject,0,MAX_NAME_LENGTH+1); |
ansond | 8:fefcecb66463 | 96 | sprintf(subject,"%s case update",name); |
ansond | 3:03108e424931 | 97 | |
ansond | 3:03108e424931 | 98 | // create and dispatch a case |
ansond | 3:03108e424931 | 99 | bool success = case_generator.createCase(subject,db.lookupWidgetDescription(rfid)); |
ansond | 3:03108e424931 | 100 | if (success == true) { |
ansond | 8:fefcecb66463 | 101 | logger.log("Case Generated!\r\nScanning..."); |
ansond | 3:03108e424931 | 102 | } |
ansond | 3:03108e424931 | 103 | else { |
ansond | 8:fefcecb66463 | 104 | logger.log("Case Generation FAILED\r\nScanning..."); |
ansond | 3:03108e424931 | 105 | } |
ansond | 0:df2aa79c64f2 | 106 | } |
ansond | 0:df2aa79c64f2 | 107 | else { |
ansond | 3:03108e424931 | 108 | // unrecognized RFID |
ansond | 8:fefcecb66463 | 109 | logger.log("RFID unk-ignored.\r\nScanning..."); |
ansond | 0:df2aa79c64f2 | 110 | } |
ansond | 3:03108e424931 | 111 | } |
ansond | 6:427c387b10e7 | 112 | #else |
ansond | 6:427c387b10e7 | 113 | // simply create and dispatch a single case |
ansond | 6:427c387b10e7 | 114 | logger.log("Creating Case..."); |
ansond | 6:427c387b10e7 | 115 | bool success = case_generator.createCase("sample mbed case","this is a sample mbed case"); |
ansond | 6:427c387b10e7 | 116 | if (success == true) { |
ansond | 6:427c387b10e7 | 117 | logger.log("Case Generated!"); |
ansond | 6:427c387b10e7 | 118 | logger.log("Exiting..."); |
ansond | 6:427c387b10e7 | 119 | exit(1); |
ansond | 6:427c387b10e7 | 120 | } |
ansond | 6:427c387b10e7 | 121 | else { |
ansond | 6:427c387b10e7 | 122 | logger.log("Case Generation FAILED"); |
ansond | 6:427c387b10e7 | 123 | logger.log("Exiting..."); |
ansond | 6:427c387b10e7 | 124 | exit(1); |
ansond | 6:427c387b10e7 | 125 | } |
ansond | 6:427c387b10e7 | 126 | #endif |
ansond | 3:03108e424931 | 127 | |
ansond | 3:03108e424931 | 128 | // wait a bit and look again |
ansond | 3:03108e424931 | 129 | wait_ms(WAIT_TIME_MS); |
ansond | 3:03108e424931 | 130 | } |
ansond | 3:03108e424931 | 131 | } |
ansond | 3:03108e424931 | 132 | else { |
ansond | 3:03108e424931 | 133 | logger.log("No Network... Exiting..."); |
ansond | 6:427c387b10e7 | 134 | exit(1); |
ansond | 3:03108e424931 | 135 | } |
ansond | 3:03108e424931 | 136 | |
ansond | 3:03108e424931 | 137 | // disconnect |
ansond | 4:46459ed734f3 | 138 | logger.log("Disconnecting..."); |
ansond | 3:03108e424931 | 139 | ethernet.disconnect(); |
ansond | 4:46459ed734f3 | 140 | |
ansond | 4:46459ed734f3 | 141 | // Exit |
ansond | 6:427c387b10e7 | 142 | logger.log("Exiting..."); |
ansond | 6:427c387b10e7 | 143 | exit(1); |
ansond | 0:df2aa79c64f2 | 144 | } |