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:
Mon Oct 06 03:15:01 2014 +0000
Revision:
21:2b85d1442d34
Parent:
19:1cf0bad37c62
Child:
22:dcc1ade67468
Child:
23:17da4f0985dc
updates for DF

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 21:2b85d1442d34 28 // Temperature sensor - The TMP36 sensor uses A3 in the shield.. See Definitions.h for the define.
ansond 21:2b85d1442d34 29 // AnalogIn tmp36_temp_sensor(TEMP_PIN);
ansond 21:2b85d1442d34 30
ansond 21:2b85d1442d34 31 // ****************** DreamForce 2014 ******************//
ansond 16:d196d812f651 32
ansond 19:1cf0bad37c62 33 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 34 this->m_logger = logger;
ansond 0:ba3327ba3a04 35 }
ansond 0:ba3327ba3a04 36
ansond 0:ba3327ba3a04 37 StatusReporter::~StatusReporter() {
ansond 0:ba3327ba3a04 38 }
ansond 0:ba3327ba3a04 39
ansond 19:1cf0bad37c62 40 Logger *StatusReporter::logger() { return this->m_logger; }
ansond 19:1cf0bad37c62 41
ansond 16:d196d812f651 42 // Calculate the ambient temperature of the TMP36 sensor in C...
ansond 16:d196d812f651 43 int StatusReporter::getLocalTemperature() {
ansond 21:2b85d1442d34 44 // Temperature sensor output voltage per TMP36 data sheet
ansond 21:2b85d1442d34 45 //
ansond 21:2b85d1442d34 46 // Celcius temperature is calulated as follows:
ansond 21:2b85d1442d34 47 // tempC = ((temperature_sensor_voltage*3.3) - 0.6) * 100.0;
ansond 21:2b85d1442d34 48 //
ansond 21:2b85d1442d34 49 // Example: float tempC = (float)(((float)tmp36_temp_sensor*3.3)-0.600)*100.0;
ansond 21:2b85d1442d34 50 //
ansond 21:2b85d1442d34 51
ansond 21:2b85d1442d34 52 float tempC = 0.0;
ansond 16:d196d812f651 53
ansond 16:d196d812f651 54 // DEBUG
ansond 19:1cf0bad37c62 55 LOG_CONSOLE("Ambient Temp: %.1f C",tempC);
ansond 16:d196d812f651 56
ansond 16:d196d812f651 57 // convert to int for brevity...
ansond 16:d196d812f651 58 return (int)tempC;
ansond 16:d196d812f651 59 }
ansond 16:d196d812f651 60
ansond 0:ba3327ba3a04 61 void StatusReporter::checkAndReportOnStatus() {
ansond 0:ba3327ba3a04 62 // look for a readable RFID tag
ansond 0:ba3327ba3a04 63 if(this->m_rfid_reader.readable()) {
ansond 0:ba3327ba3a04 64 // capture the RFID id...
ansond 19:1cf0bad37c62 65 LOG_CONSOLE("RFID: Found RFID.\r\nReading...");
ansond 0:ba3327ba3a04 66 int rfid = this->m_rfid_reader.read();
ansond 19:1cf0bad37c62 67 LOG_CONSOLE("RFID: ID %d found...\r\nProcessing...",rfid);
ansond 0:ba3327ba3a04 68
ansond 16:d196d812f651 69 // look it up in our ReportDB... proceed only if we find something we know about...
ansond 16:d196d812f651 70 char *name = this->m_db.lookupReportName(rfid);
ansond 0:ba3327ba3a04 71 if (name != NULL) {
ansond 0:ba3327ba3a04 72 // build out a simple subject for the case
ansond 4:cfa87685c859 73 char subject[DB_MAX_NAME_LENGTH+1];
ansond 4:cfa87685c859 74 memset(subject,0,DB_MAX_NAME_LENGTH+1);
ansond 0:ba3327ba3a04 75 sprintf(subject,"%s case update",name);
ansond 0:ba3327ba3a04 76
ansond 0:ba3327ba3a04 77 // create and dispatch a case
ansond 14:f4ab5c7abc50 78 this->m_logger->turnLEDPurple();
ansond 16:d196d812f651 79 char *description = this->m_db.lookupReportDescription(rfid);
ansond 16:d196d812f651 80 char *condition = this->m_db.lookupReportCondition(rfid);
ansond 16:d196d812f651 81 int temperature = this->getLocalTemperature();
ansond 16:d196d812f651 82 char *latitude = this->m_db.lookupReportLatitude(rfid);
ansond 16:d196d812f651 83 char *longitude = this->m_db.lookupReportLongitude(rfid);
ansond 19:1cf0bad37c62 84 bool success = this->m_case_generator.createAnonymousCase(subject,description,condition,temperature,latitude,longitude);
ansond 0:ba3327ba3a04 85 if (success == true) {
ansond 19:1cf0bad37c62 86 LOG_CONSOLE("Case Generated!\r\nScanning...");
ansond 14:f4ab5c7abc50 87 this->m_logger->turnLEDGreen();
ansond 0:ba3327ba3a04 88 }
ansond 0:ba3327ba3a04 89 else {
ansond 19:1cf0bad37c62 90 LOG_CONSOLE("Case Generation FAILED\r\nScanning...");
ansond 14:f4ab5c7abc50 91 this->m_logger->turnLEDYellow();
ansond 0:ba3327ba3a04 92 }
ansond 0:ba3327ba3a04 93 }
ansond 0:ba3327ba3a04 94 else {
ansond 0:ba3327ba3a04 95 // unrecognized RFID
ansond 19:1cf0bad37c62 96 LOG_CONSOLE("RFID %d unknown.\r\nScanning...",rfid);
ansond 0:ba3327ba3a04 97 }
ansond 0:ba3327ba3a04 98 }
ansond 0:ba3327ba3a04 99 }