fork of StatusReporter with specific changes for the changeover to the support personnel database

Dependencies:   ID12RFID SalesforceCaseGenerator-df2014 SalesforceInterface SupportPersonnelDB

Dependents:   df-2014-rfid-case-gen-k64f-complete df-2014-rfid-case-gen-k64f-exercise

Fork of StatusReporter by Doug Anson

Committer:
ansond
Date:
Tue Oct 07 22:12:19 2014 +0000
Revision:
24:324d739f9a22
Parent:
23:17da4f0985dc
Child:
25:4a49843cd881
reset for exercise

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:ba3327ba3a04 1 /* Copyright C2014 ARM, MIT License
ansond 0:ba3327ba3a04 2 *
ansond 19:1cf0bad37c62 3 * Author: Doug Anson (doug.anson@arm.com)
ansond 19:1cf0bad37c62 4 *
ansond 0:ba3327ba3a04 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:ba3327ba3a04 6 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:ba3327ba3a04 7 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:ba3327ba3a04 8 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:ba3327ba3a04 9 * furnished to do so, subject to the following conditions:
ansond 0:ba3327ba3a04 10 *
ansond 0:ba3327ba3a04 11 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:ba3327ba3a04 12 * substantial portions of the Software.
ansond 0:ba3327ba3a04 13 *
ansond 0:ba3327ba3a04 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:ba3327ba3a04 15 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:ba3327ba3a04 16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:ba3327ba3a04 17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:ba3327ba3a04 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:ba3327ba3a04 19 */
ansond 0:ba3327ba3a04 20
ansond 0:ba3327ba3a04 21 #include "StatusReporter.h"
ansond 0:ba3327ba3a04 22
ansond 19:1cf0bad37c62 23 // Logging
ansond 19:1cf0bad37c62 24 #define LOG_CONSOLE(...) { if (this->logger() != NULL) { this->logger()->logConsole(__VA_ARGS__); } }
ansond 19:1cf0bad37c62 25
ansond 21:2b85d1442d34 26 // ****************** DreamForce 2014 ******************//
ansond 21:2b85d1442d34 27
ansond 24:324d739f9a22 28 // TEMP SENSOR - The TMP36 sensor uses A3 in the shield.. See Definitions.h for the define.
ansond 24:324d739f9a22 29 //
ansond 24:324d739f9a22 30 // Uncommnent the following line to bind to the TMP36 temperature sensor
ansond 24:324d739f9a22 31 //
ansond 24:324d739f9a22 32 // AnalogIn tmp36_temp_sensor(TEMP_PIN);
ansond 21:2b85d1442d34 33
ansond 21:2b85d1442d34 34 // ****************** DreamForce 2014 ******************//
ansond 16:d196d812f651 35
ansond 19:1cf0bad37c62 36 StatusReporter::StatusReporter(HTTPClient *http,Logger *logger) : m_case_generator(http,logger), m_db(), m_rfid_reader(RFID_TX_PIN,RFID_RX_PIN) {
ansond 0:ba3327ba3a04 37 this->m_logger = logger;
ansond 0:ba3327ba3a04 38 }
ansond 0:ba3327ba3a04 39
ansond 0:ba3327ba3a04 40 StatusReporter::~StatusReporter() {
ansond 0:ba3327ba3a04 41 }
ansond 0:ba3327ba3a04 42
ansond 19:1cf0bad37c62 43 Logger *StatusReporter::logger() { return this->m_logger; }
ansond 19:1cf0bad37c62 44
ansond 16:d196d812f651 45 // Calculate the ambient temperature of the TMP36 sensor in C...
ansond 16:d196d812f651 46 int StatusReporter::getLocalTemperature() {
ansond 24:324d739f9a22 47 // TEMP SENSOR: temperature calculation per TMP36 data sheet
ansond 21:2b85d1442d34 48 //
ansond 24:324d739f9a22 49 // Celcius temperature is calculated as follows (with 3.3V input):
ansond 24:324d739f9a22 50 //
ansond 21:2b85d1442d34 51 // tempC = ((temperature_sensor_voltage*3.3) - 0.6) * 100.0;
ansond 21:2b85d1442d34 52 //
ansond 24:324d739f9a22 53 // You can use the following code snippet:
ansond 24:324d739f9a22 54 //
ansond 24:324d739f9a22 55 // float tempC = (float)(((float)tmp36_temp_sensor*3.3)-0.600)*100.0;
ansond 24:324d739f9a22 56 //
ansond 24:324d739f9a22 57 // in place of:
ansond 24:324d739f9a22 58 //
ansond 24:324d739f9a22 59 // float tempC = 0.0;
ansond 24:324d739f9a22 60 //
ansond 24:324d739f9a22 61 // to calculate the ambient temperature via the TMP36 sensor (in Celcius)
ansond 21:2b85d1442d34 62 //
ansond 21:2b85d1442d34 63
ansond 24:324d739f9a22 64 float tempC = 0.0;
ansond 16:d196d812f651 65
ansond 16:d196d812f651 66 // DEBUG
ansond 19:1cf0bad37c62 67 LOG_CONSOLE("Ambient Temp: %.1f C",tempC);
ansond 16:d196d812f651 68
ansond 16:d196d812f651 69 // convert to int for brevity...
ansond 16:d196d812f651 70 return (int)tempC;
ansond 16:d196d812f651 71 }
ansond 16:d196d812f651 72
ansond 0:ba3327ba3a04 73 void StatusReporter::checkAndReportOnStatus() {
ansond 0:ba3327ba3a04 74 // look for a readable RFID tag
ansond 0:ba3327ba3a04 75 if(this->m_rfid_reader.readable()) {
ansond 0:ba3327ba3a04 76 // capture the RFID id...
ansond 19:1cf0bad37c62 77 LOG_CONSOLE("RFID: Found RFID.\r\nReading...");
ansond 0:ba3327ba3a04 78 int rfid = this->m_rfid_reader.read();
ansond 19:1cf0bad37c62 79 LOG_CONSOLE("RFID: ID %d found...\r\nProcessing...",rfid);
ansond 0:ba3327ba3a04 80
ansond 16:d196d812f651 81 // look it up in our ReportDB... proceed only if we find something we know about...
ansond 16:d196d812f651 82 char *name = this->m_db.lookupReportName(rfid);
ansond 0:ba3327ba3a04 83 if (name != NULL) {
ansond 0:ba3327ba3a04 84 // build out a simple subject for the case
ansond 4:cfa87685c859 85 char subject[DB_MAX_NAME_LENGTH+1];
ansond 4:cfa87685c859 86 memset(subject,0,DB_MAX_NAME_LENGTH+1);
ansond 0:ba3327ba3a04 87 sprintf(subject,"%s case update",name);
ansond 0:ba3327ba3a04 88
ansond 0:ba3327ba3a04 89 // create and dispatch a case
ansond 14:f4ab5c7abc50 90 this->m_logger->turnLEDPurple();
ansond 16:d196d812f651 91 char *description = this->m_db.lookupReportDescription(rfid);
ansond 16:d196d812f651 92 char *condition = this->m_db.lookupReportCondition(rfid);
ansond 16:d196d812f651 93 int temperature = this->getLocalTemperature();
ansond 16:d196d812f651 94 char *latitude = this->m_db.lookupReportLatitude(rfid);
ansond 16:d196d812f651 95 char *longitude = this->m_db.lookupReportLongitude(rfid);
ansond 19:1cf0bad37c62 96 bool success = this->m_case_generator.createAnonymousCase(subject,description,condition,temperature,latitude,longitude);
ansond 0:ba3327ba3a04 97 if (success == true) {
ansond 19:1cf0bad37c62 98 LOG_CONSOLE("Case Generated!\r\nScanning...");
ansond 14:f4ab5c7abc50 99 this->m_logger->turnLEDGreen();
ansond 0:ba3327ba3a04 100 }
ansond 0:ba3327ba3a04 101 else {
ansond 19:1cf0bad37c62 102 LOG_CONSOLE("Case Generation FAILED\r\nScanning...");
ansond 14:f4ab5c7abc50 103 this->m_logger->turnLEDYellow();
ansond 0:ba3327ba3a04 104 }
ansond 0:ba3327ba3a04 105 }
ansond 0:ba3327ba3a04 106 else {
ansond 0:ba3327ba3a04 107 // unrecognized RFID
ansond 19:1cf0bad37c62 108 LOG_CONSOLE("RFID %d unknown.\r\nScanning...",rfid);
ansond 0:ba3327ba3a04 109 }
ansond 0:ba3327ba3a04 110 }
ansond 0:ba3327ba3a04 111 }