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
main.cpp@0:8f99b3f2c3a8, 2014-09-09 (annotated)
- Committer:
- ansond
- Date:
- Tue Sep 09 20:45:08 2014 +0000
- Revision:
- 0:8f99b3f2c3a8
- Child:
- 1:8364052fbe84
relocated main.cpp to make StatusReporter portable
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:8f99b3f2c3a8 | 1 | /* Copyright C2014 ARM, MIT License |
ansond | 0:8f99b3f2c3a8 | 2 | * |
ansond | 0:8f99b3f2c3a8 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:8f99b3f2c3a8 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:8f99b3f2c3a8 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:8f99b3f2c3a8 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:8f99b3f2c3a8 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 0:8f99b3f2c3a8 | 8 | * |
ansond | 0:8f99b3f2c3a8 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:8f99b3f2c3a8 | 10 | * substantial portions of the Software. |
ansond | 0:8f99b3f2c3a8 | 11 | * |
ansond | 0:8f99b3f2c3a8 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:8f99b3f2c3a8 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:8f99b3f2c3a8 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:8f99b3f2c3a8 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:8f99b3f2c3a8 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:8f99b3f2c3a8 | 17 | */ |
ansond | 0:8f99b3f2c3a8 | 18 | |
ansond | 0:8f99b3f2c3a8 | 19 | // StatusReporter |
ansond | 0:8f99b3f2c3a8 | 20 | #include "StatusReporter.h" |
ansond | 0:8f99b3f2c3a8 | 21 | |
ansond | 0:8f99b3f2c3a8 | 22 | // appboard LCD Panel |
ansond | 0:8f99b3f2c3a8 | 23 | #if _NXP_PLATFORM |
ansond | 0:8f99b3f2c3a8 | 24 | #include "C12832_lcd.h" |
ansond | 0:8f99b3f2c3a8 | 25 | C12832_LCD lcd; |
ansond | 0:8f99b3f2c3a8 | 26 | #endif |
ansond | 0:8f99b3f2c3a8 | 27 | #if _UBLOX_PLATFORM |
ansond | 0:8f99b3f2c3a8 | 28 | #include "C12832.h" |
ansond | 0:8f99b3f2c3a8 | 29 | C12832 lcd(D11, D13, D12, D7, D10); |
ansond | 0:8f99b3f2c3a8 | 30 | #endif |
ansond | 0:8f99b3f2c3a8 | 31 | |
ansond | 0:8f99b3f2c3a8 | 32 | // our Serial port |
ansond | 0:8f99b3f2c3a8 | 33 | #include "BufferedSerial.h" |
ansond | 0:8f99b3f2c3a8 | 34 | BufferedSerial pc(USBTX, USBRX); |
ansond | 0:8f99b3f2c3a8 | 35 | |
ansond | 0:8f99b3f2c3a8 | 36 | // Ethernet |
ansond | 0:8f99b3f2c3a8 | 37 | #include "EthernetInterface.h" |
ansond | 0:8f99b3f2c3a8 | 38 | EthernetInterface ethernet; |
ansond | 0:8f99b3f2c3a8 | 39 | |
ansond | 0:8f99b3f2c3a8 | 40 | // HTTP |
ansond | 0:8f99b3f2c3a8 | 41 | #include "HTTPClient.h" |
ansond | 0:8f99b3f2c3a8 | 42 | HTTPClient http; |
ansond | 0:8f99b3f2c3a8 | 43 | |
ansond | 0:8f99b3f2c3a8 | 44 | // HARD RESET |
ansond | 0:8f99b3f2c3a8 | 45 | extern "C" void HardFault_Handler() { NVIC_SystemReset(); } |
ansond | 0:8f99b3f2c3a8 | 46 | |
ansond | 0:8f99b3f2c3a8 | 47 | // Main Task... |
ansond | 0:8f99b3f2c3a8 | 48 | void mainTask(void const *v) { |
ansond | 0:8f99b3f2c3a8 | 49 | // create our object instances |
ansond | 0:8f99b3f2c3a8 | 50 | #if _NXP_PLATFORM || _UBLOX_PLATFORM |
ansond | 0:8f99b3f2c3a8 | 51 | ErrorHandler logger(&pc,&lcd); |
ansond | 0:8f99b3f2c3a8 | 52 | #endif |
ansond | 0:8f99b3f2c3a8 | 53 | #if _K64F_PLATFORM |
ansond | 0:8f99b3f2c3a8 | 54 | ErrorHandler logger(&pc,NULL); |
ansond | 0:8f99b3f2c3a8 | 55 | #endif |
ansond | 0:8f99b3f2c3a8 | 56 | |
ansond | 0:8f99b3f2c3a8 | 57 | // announce |
ansond | 0:8f99b3f2c3a8 | 58 | logger.log("ARM/DreamForce 2014 mbed Status Reporter v%s",APP_VERSION); |
ansond | 0:8f99b3f2c3a8 | 59 | logger.turnLEDBlue(); |
ansond | 0:8f99b3f2c3a8 | 60 | |
ansond | 0:8f99b3f2c3a8 | 61 | // initialize Ethernet |
ansond | 0:8f99b3f2c3a8 | 62 | logger.log("Initializing Ethernet..."); |
ansond | 0:8f99b3f2c3a8 | 63 | ethernet.init(); |
ansond | 0:8f99b3f2c3a8 | 64 | |
ansond | 0:8f99b3f2c3a8 | 65 | // get a DHCP address and bring the network interface up |
ansond | 0:8f99b3f2c3a8 | 66 | logger.log("Getting IP Address..."); |
ansond | 0:8f99b3f2c3a8 | 67 | logger.turnLEDOrange(); |
ansond | 0:8f99b3f2c3a8 | 68 | if (ethernet.connect() == 0) { |
ansond | 0:8f99b3f2c3a8 | 69 | // log our IP address (DHCP) |
ansond | 0:8f99b3f2c3a8 | 70 | logger.log("IP Address: %s",ethernet.getIPAddress()); |
ansond | 0:8f99b3f2c3a8 | 71 | |
ansond | 0:8f99b3f2c3a8 | 72 | // create the StatusReporter |
ansond | 0:8f99b3f2c3a8 | 73 | StatusReporter status_reporter(&logger,(void *)&http); |
ansond | 0:8f99b3f2c3a8 | 74 | |
ansond | 0:8f99b3f2c3a8 | 75 | // entering main loop |
ansond | 0:8f99b3f2c3a8 | 76 | logger.log("Entering Main Loop...\r\nScanning..."); |
ansond | 0:8f99b3f2c3a8 | 77 | logger.turnLEDGreen(); |
ansond | 0:8f99b3f2c3a8 | 78 | |
ansond | 0:8f99b3f2c3a8 | 79 | // Enter the main loop |
ansond | 0:8f99b3f2c3a8 | 80 | while(true) { |
ansond | 0:8f99b3f2c3a8 | 81 | // check and report on status updates |
ansond | 0:8f99b3f2c3a8 | 82 | status_reporter.checkAndReportOnStatus(); |
ansond | 0:8f99b3f2c3a8 | 83 | } |
ansond | 0:8f99b3f2c3a8 | 84 | } |
ansond | 0:8f99b3f2c3a8 | 85 | else { |
ansond | 0:8f99b3f2c3a8 | 86 | logger.log("No Network... Exiting..."); |
ansond | 0:8f99b3f2c3a8 | 87 | logger.turnLEDRed(); |
ansond | 0:8f99b3f2c3a8 | 88 | exit(1); |
ansond | 0:8f99b3f2c3a8 | 89 | } |
ansond | 0:8f99b3f2c3a8 | 90 | |
ansond | 0:8f99b3f2c3a8 | 91 | // disconnect |
ansond | 0:8f99b3f2c3a8 | 92 | logger.log("Disconnecting..."); |
ansond | 0:8f99b3f2c3a8 | 93 | logger.turnLEDOrange(); |
ansond | 0:8f99b3f2c3a8 | 94 | ethernet.disconnect(); |
ansond | 0:8f99b3f2c3a8 | 95 | |
ansond | 0:8f99b3f2c3a8 | 96 | // Exit |
ansond | 0:8f99b3f2c3a8 | 97 | logger.log("Exiting..."); |
ansond | 0:8f99b3f2c3a8 | 98 | logger.turnLEDBlue(); |
ansond | 0:8f99b3f2c3a8 | 99 | exit(1); |
ansond | 0:8f99b3f2c3a8 | 100 | } |
ansond | 0:8f99b3f2c3a8 | 101 | |
ansond | 0:8f99b3f2c3a8 | 102 | // main entry |
ansond | 0:8f99b3f2c3a8 | 103 | int main() { |
ansond | 0:8f99b3f2c3a8 | 104 | #if _K64F_PLATFORM |
ansond | 0:8f99b3f2c3a8 | 105 | Thread workerTask(mainTask, NULL, osPriorityNormal, STACK_SIZE); |
ansond | 0:8f99b3f2c3a8 | 106 | while (true) { |
ansond | 0:8f99b3f2c3a8 | 107 | Thread::wait(10*WAIT_TIME_MS); |
ansond | 0:8f99b3f2c3a8 | 108 | } |
ansond | 0:8f99b3f2c3a8 | 109 | #else |
ansond | 0:8f99b3f2c3a8 | 110 | mainTask(NULL); |
ansond | 0:8f99b3f2c3a8 | 111 | #endif |
ansond | 0:8f99b3f2c3a8 | 112 | } |