Dreamforce 2014 Workshop RFID Case Generator - Completed Exercise

Dependencies:   BufferedSerial C12832 EndpointMain-rfid EthernetInterface Logger StatusReporter-df2014 mbed-rtos mbed

Fork of df-2014-workshop-rfid-case-generator-k64f by Doug Anson

Committer:
ansond
Date:
Wed Aug 27 05:40:16 2014 +0000
Revision:
3:03108e424931
Parent:
0:df2aa79c64f2
Child:
4:46459ed734f3
using heroku service to map to SF http reqs

Who changed what in which revision?

UserRevisionLine numberNew 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 0:df2aa79c64f2 22 // RFID Reader - on P14 pin
ansond 3:03108e424931 23 //#include "ID12RFID.h"
ansond 3:03108e424931 24 //ID12RFID rfid_reader(p14);
ansond 0:df2aa79c64f2 25
ansond 0:df2aa79c64f2 26 // Salesforce Case Generator
ansond 0:df2aa79c64f2 27 #include "SalesForceCaseGenerator.h"
ansond 0:df2aa79c64f2 28
ansond 0:df2aa79c64f2 29 // our Logger
ansond 0:df2aa79c64f2 30 #include "Logger.h"
ansond 0:df2aa79c64f2 31
ansond 0:df2aa79c64f2 32 // our WidgetDB
ansond 0:df2aa79c64f2 33 #include "WidgetDB.h"
ansond 0:df2aa79c64f2 34
ansond 0:df2aa79c64f2 35 // our LCD Panel
ansond 0:df2aa79c64f2 36 #include "C12832_lcd.h"
ansond 0:df2aa79c64f2 37 C12832_LCD lcd;
ansond 0:df2aa79c64f2 38
ansond 0:df2aa79c64f2 39 // our Serial port
ansond 0:df2aa79c64f2 40 #include "Serial.h"
ansond 0:df2aa79c64f2 41 Serial pc(USBTX, USBRX);
ansond 0:df2aa79c64f2 42
ansond 3:03108e424931 43 // Ethernet
ansond 3:03108e424931 44 #include "EthernetInterface.h"
ansond 3:03108e424931 45 EthernetInterface ethernet;
ansond 3:03108e424931 46
ansond 0:df2aa79c64f2 47 // Main Entry...
ansond 0:df2aa79c64f2 48 int main() {
ansond 0:df2aa79c64f2 49 // create our object instances
ansond 0:df2aa79c64f2 50 Logger logger(&pc,&lcd);
ansond 0:df2aa79c64f2 51
ansond 0:df2aa79c64f2 52 // announce
ansond 0:df2aa79c64f2 53 logger.log("DF 2014 RFID Reader\r\nVersion: %s",APP_VERSION);
ansond 0:df2aa79c64f2 54
ansond 3:03108e424931 55 // initialize Ethernet
ansond 3:03108e424931 56 logger.log("Initializing Ethernet...");
ansond 3:03108e424931 57 ethernet.init();
ansond 0:df2aa79c64f2 58
ansond 3:03108e424931 59 // get a DHCP address and bring the network interface up
ansond 3:03108e424931 60 logger.log("Getting IP Address...");
ansond 3:03108e424931 61 if (ethernet.connect() == 0) {
ansond 3:03108e424931 62 // log our IP address (DHCP)
ansond 3:03108e424931 63 logger.log("IP Address: %s",ethernet.getIPAddress());
ansond 3:03108e424931 64
ansond 3:03108e424931 65 // create the WidgetDB
ansond 3:03108e424931 66 WidgetDB db;
ansond 3:03108e424931 67
ansond 3:03108e424931 68 // create the Salesforce Case Generator
ansond 3:03108e424931 69 SalesForceCaseGenerator case_generator(&logger);
ansond 3:03108e424931 70
ansond 3:03108e424931 71 /*
ansond 3:03108e424931 72 // Enter the main loop
ansond 3:03108e424931 73 while(true) {
ansond 3:03108e424931 74 // look for a readable RFID tag
ansond 3:03108e424931 75 if(rfid_reader.readable()) {
ansond 3:03108e424931 76 // capture the RFID id...
ansond 3:03108e424931 77 int rfid = rfid_reader.read();
ansond 3:03108e424931 78 logger.log("RFID: %d found...\r\nProcessing...",rfid);
ansond 0:df2aa79c64f2 79
ansond 3:03108e424931 80 // look it up in our WidgetDB... proceed only if we find something we know about...
ansond 3:03108e424931 81 //char *name = db.lookupWidgetName(rfid);
ansond 3:03108e424931 82 if (name != NULL) {
ansond 3:03108e424931 83 // build out a simple subject for the case
ansond 3:03108e424931 84 char subject[MAX_NAME_LENGTH+1];
ansond 3:03108e424931 85 memset(subject,0,MAX_NAME_LENGTH+1);
ansond 3:03108e424931 86 sprintf(subject,"Widget %s detected",name);
ansond 3:03108e424931 87
ansond 3:03108e424931 88 // create and dispatch a case
ansond 3:03108e424931 89 bool success = case_generator.createCase(subject,db.lookupWidgetDescription(rfid));
ansond 3:03108e424931 90 if (success == true) {
ansond 3:03108e424931 91 logger.log("Case Generated!");
ansond 3:03108e424931 92 }
ansond 3:03108e424931 93 else {
ansond 3:03108e424931 94 logger.log("Case Generation FAILED");
ansond 3:03108e424931 95 }
ansond 0:df2aa79c64f2 96 }
ansond 0:df2aa79c64f2 97 else {
ansond 3:03108e424931 98 // unrecognized RFID
ansond 3:03108e424931 99 logger.log("RFID unknown. Ignoring...");
ansond 0:df2aa79c64f2 100 }
ansond 3:03108e424931 101 }
ansond 3:03108e424931 102
ansond 3:03108e424931 103 // wait a bit and look again
ansond 3:03108e424931 104 wait_ms(WAIT_TIME_MS);
ansond 3:03108e424931 105 }
ansond 3:03108e424931 106
ansond 3:03108e424931 107 */
ansond 3:03108e424931 108
ansond 3:03108e424931 109 logger.log("Generating Sample Case...");
ansond 3:03108e424931 110 bool success = case_generator.createCase("hello doug","this is a mbed case dispatch");
ansond 3:03108e424931 111 if (success == true) {
ansond 3:03108e424931 112 logger.log("Case Generated!");
ansond 3:03108e424931 113 }
ansond 3:03108e424931 114 else {
ansond 3:03108e424931 115 logger.log("Case Generation FAILED");
ansond 3:03108e424931 116 }
ansond 3:03108e424931 117 }
ansond 3:03108e424931 118 else {
ansond 3:03108e424931 119 logger.log("No Network... Exiting...");
ansond 3:03108e424931 120 }
ansond 3:03108e424931 121
ansond 3:03108e424931 122 // disconnect
ansond 3:03108e424931 123 ethernet.disconnect();
ansond 0:df2aa79c64f2 124 }