Library for inclusion of main.cpp -forked

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

Fork of EndpointMain by Doug Anson

Committer:
ansond
Date:
Fri Sep 26 04:34:23 2014 +0000
Revision:
2:55b1877a3a14
Parent:
1:8364052fbe84
Child:
3:1d8589377a86
revamped to use new salesforce interface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:8f99b3f2c3a8 1 /* Copyright C2014 ARM, MIT License
ansond 0:8f99b3f2c3a8 2 *
ansond 2:55b1877a3a14 3 * Author: Doug Anson (doug.anson@arm.com)
ansond 2:55b1877a3a14 4 *
ansond 0:8f99b3f2c3a8 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:8f99b3f2c3a8 6 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:8f99b3f2c3a8 7 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:8f99b3f2c3a8 8 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:8f99b3f2c3a8 9 * furnished to do so, subject to the following conditions:
ansond 0:8f99b3f2c3a8 10 *
ansond 0:8f99b3f2c3a8 11 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:8f99b3f2c3a8 12 * substantial portions of the Software.
ansond 0:8f99b3f2c3a8 13 *
ansond 0:8f99b3f2c3a8 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:8f99b3f2c3a8 15 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:8f99b3f2c3a8 16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:8f99b3f2c3a8 17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:8f99b3f2c3a8 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:8f99b3f2c3a8 19 */
ansond 2:55b1877a3a14 20
ansond 0:8f99b3f2c3a8 21 // our Serial port
ansond 0:8f99b3f2c3a8 22 #include "BufferedSerial.h"
ansond 0:8f99b3f2c3a8 23 BufferedSerial pc(USBTX, USBRX);
ansond 0:8f99b3f2c3a8 24
ansond 0:8f99b3f2c3a8 25 // Ethernet
ansond 0:8f99b3f2c3a8 26 #include "EthernetInterface.h"
ansond 0:8f99b3f2c3a8 27 EthernetInterface ethernet;
ansond 0:8f99b3f2c3a8 28
ansond 0:8f99b3f2c3a8 29 // HTTP
ansond 0:8f99b3f2c3a8 30 #include "HTTPClient.h"
ansond 0:8f99b3f2c3a8 31 HTTPClient http;
ansond 0:8f99b3f2c3a8 32
ansond 2:55b1877a3a14 33 // StatusReporter
ansond 2:55b1877a3a14 34 #include "StatusReporter.h"
ansond 2:55b1877a3a14 35
ansond 0:8f99b3f2c3a8 36 // Main Task...
ansond 0:8f99b3f2c3a8 37 void mainTask(void const *v) {
ansond 0:8f99b3f2c3a8 38 // create our object instances
ansond 2:55b1877a3a14 39 Logger logger(&pc,NULL);
ansond 0:8f99b3f2c3a8 40
ansond 0:8f99b3f2c3a8 41 // announce
ansond 0:8f99b3f2c3a8 42 logger.log("ARM/DreamForce 2014 mbed Status Reporter v%s",APP_VERSION);
ansond 0:8f99b3f2c3a8 43 logger.turnLEDBlue();
ansond 0:8f99b3f2c3a8 44
ansond 0:8f99b3f2c3a8 45 // initialize Ethernet
ansond 0:8f99b3f2c3a8 46 logger.log("Initializing Ethernet...");
ansond 0:8f99b3f2c3a8 47 ethernet.init();
ansond 0:8f99b3f2c3a8 48
ansond 0:8f99b3f2c3a8 49 // get a DHCP address and bring the network interface up
ansond 0:8f99b3f2c3a8 50 logger.log("Getting IP Address...");
ansond 0:8f99b3f2c3a8 51 logger.turnLEDOrange();
ansond 0:8f99b3f2c3a8 52 if (ethernet.connect() == 0) {
ansond 0:8f99b3f2c3a8 53 // log our IP address (DHCP)
ansond 0:8f99b3f2c3a8 54 logger.log("IP Address: %s",ethernet.getIPAddress());
ansond 0:8f99b3f2c3a8 55
ansond 0:8f99b3f2c3a8 56 // create the StatusReporter
ansond 2:55b1877a3a14 57 StatusReporter status_reporter(&http,&logger);
ansond 0:8f99b3f2c3a8 58
ansond 0:8f99b3f2c3a8 59 // entering main loop
ansond 0:8f99b3f2c3a8 60 logger.log("Entering Main Loop...\r\nScanning...");
ansond 0:8f99b3f2c3a8 61 logger.turnLEDGreen();
ansond 0:8f99b3f2c3a8 62
ansond 0:8f99b3f2c3a8 63 // Enter the main loop
ansond 0:8f99b3f2c3a8 64 while(true) {
ansond 0:8f99b3f2c3a8 65 // check and report on status updates
ansond 0:8f99b3f2c3a8 66 status_reporter.checkAndReportOnStatus();
ansond 2:55b1877a3a14 67 }
ansond 0:8f99b3f2c3a8 68 }
ansond 0:8f99b3f2c3a8 69 else {
ansond 0:8f99b3f2c3a8 70 logger.log("No Network... Exiting...");
ansond 0:8f99b3f2c3a8 71 logger.turnLEDRed();
ansond 0:8f99b3f2c3a8 72 exit(1);
ansond 0:8f99b3f2c3a8 73 }
ansond 0:8f99b3f2c3a8 74
ansond 0:8f99b3f2c3a8 75 // disconnect
ansond 0:8f99b3f2c3a8 76 logger.log("Disconnecting...");
ansond 0:8f99b3f2c3a8 77 logger.turnLEDOrange();
ansond 0:8f99b3f2c3a8 78 ethernet.disconnect();
ansond 0:8f99b3f2c3a8 79
ansond 0:8f99b3f2c3a8 80 // Exit
ansond 0:8f99b3f2c3a8 81 logger.log("Exiting...");
ansond 0:8f99b3f2c3a8 82 logger.turnLEDBlue();
ansond 0:8f99b3f2c3a8 83 exit(1);
ansond 0:8f99b3f2c3a8 84 }
ansond 0:8f99b3f2c3a8 85
ansond 0:8f99b3f2c3a8 86 // main entry
ansond 0:8f99b3f2c3a8 87 int main() {
ansond 2:55b1877a3a14 88 Thread workerTask(mainTask, NULL, osPriorityNormal, STACK_SIZE);
ansond 2:55b1877a3a14 89 while (true) {
ansond 0:8f99b3f2c3a8 90 Thread::wait(10*WAIT_TIME_MS);
ansond 2:55b1877a3a14 91 }
ansond 0:8f99b3f2c3a8 92 }