Library for inclusion of main.cpp

Committer:
ansond
Date:
Fri Sep 26 04:44:25 2014 +0000
Revision:
4:582f7ce2f930
Parent:
3:acea67392757
updates for new logger

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 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 3:acea67392757 19 #include "Definitions.h"
ansond 4:582f7ce2f930 20 #include "Logger.h"
ansond 3:acea67392757 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 3:acea67392757 45 extern "C" void HardFault_Handler() { NVIC_SystemReset(); }
ansond 0:8f99b3f2c3a8 46
ansond 3:acea67392757 47 #ifdef MAC_ADDRESS
ansond 3:acea67392757 48 char mac[6] = {MAC_ADDRESS};
ansond 3:acea67392757 49 extern "C" void mbed_mac_address(char *s) { for(int i=0;i<6;++i) s[i] = mac[i]; }
ansond 3:acea67392757 50 char fmt_mac[RESOURCE_VALUE_LEN+1];
ansond 3:acea67392757 51 #endif
ansond 3:acea67392757 52
ansond 0:8f99b3f2c3a8 53 // Main Task...
ansond 0:8f99b3f2c3a8 54 void mainTask(void const *v) {
ansond 0:8f99b3f2c3a8 55 // create our object instances
ansond 4:582f7ce2f930 56 #if _NXP_PLATFORM
ansond 4:582f7ce2f930 57 Logger logger(&pc,&lcd);
ansond 4:582f7ce2f930 58 #endif
ansond 4:582f7ce2f930 59 #if _UBLOX_PLATFORM
ansond 4:582f7ce2f930 60 Logger logger(&pc,&lcd);
ansond 0:8f99b3f2c3a8 61 #endif
ansond 0:8f99b3f2c3a8 62 #if _K64F_PLATFORM
ansond 4:582f7ce2f930 63 Logger logger(&pc,NULL);
ansond 0:8f99b3f2c3a8 64 #endif
ansond 0:8f99b3f2c3a8 65
ansond 0:8f99b3f2c3a8 66 // announce
ansond 3:acea67392757 67 logger.log("ARM/DreamForce 2014 Hello salesforce v%s",APP_VERSION);
ansond 0:8f99b3f2c3a8 68 logger.turnLEDBlue();
ansond 0:8f99b3f2c3a8 69
ansond 0:8f99b3f2c3a8 70 // initialize Ethernet
ansond 0:8f99b3f2c3a8 71 logger.log("Initializing Ethernet...");
ansond 0:8f99b3f2c3a8 72 ethernet.init();
ansond 0:8f99b3f2c3a8 73
ansond 0:8f99b3f2c3a8 74 // get a DHCP address and bring the network interface up
ansond 0:8f99b3f2c3a8 75 logger.log("Getting IP Address...");
ansond 0:8f99b3f2c3a8 76 logger.turnLEDOrange();
ansond 0:8f99b3f2c3a8 77 if (ethernet.connect() == 0) {
ansond 0:8f99b3f2c3a8 78 // log our IP address (DHCP)
ansond 0:8f99b3f2c3a8 79 logger.log("IP Address: %s",ethernet.getIPAddress());
ansond 0:8f99b3f2c3a8 80
ansond 3:acea67392757 81 // allocate something here...
ansond 0:8f99b3f2c3a8 82
ansond 0:8f99b3f2c3a8 83 // entering main loop
ansond 3:acea67392757 84 logger.log("Entering Main Loop...\r\nStarting main loop...");
ansond 0:8f99b3f2c3a8 85 logger.turnLEDGreen();
ansond 0:8f99b3f2c3a8 86
ansond 0:8f99b3f2c3a8 87 // Enter the main loop
ansond 0:8f99b3f2c3a8 88 while(true) {
ansond 3:acea67392757 89 // Do work with something here...
ansond 3:acea67392757 90 Thread::wait(10*WAIT_TIME_MS);;
ansond 0:8f99b3f2c3a8 91 }
ansond 0:8f99b3f2c3a8 92 }
ansond 0:8f99b3f2c3a8 93 else {
ansond 0:8f99b3f2c3a8 94 logger.log("No Network... Exiting...");
ansond 0:8f99b3f2c3a8 95 logger.turnLEDRed();
ansond 0:8f99b3f2c3a8 96 exit(1);
ansond 0:8f99b3f2c3a8 97 }
ansond 0:8f99b3f2c3a8 98
ansond 0:8f99b3f2c3a8 99 // disconnect
ansond 0:8f99b3f2c3a8 100 logger.log("Disconnecting...");
ansond 0:8f99b3f2c3a8 101 logger.turnLEDOrange();
ansond 0:8f99b3f2c3a8 102 ethernet.disconnect();
ansond 0:8f99b3f2c3a8 103
ansond 0:8f99b3f2c3a8 104 // Exit
ansond 0:8f99b3f2c3a8 105 logger.log("Exiting...");
ansond 0:8f99b3f2c3a8 106 logger.turnLEDBlue();
ansond 0:8f99b3f2c3a8 107 exit(1);
ansond 0:8f99b3f2c3a8 108 }
ansond 0:8f99b3f2c3a8 109
ansond 0:8f99b3f2c3a8 110 // main entry
ansond 0:8f99b3f2c3a8 111 int main() {
ansond 0:8f99b3f2c3a8 112 #if _K64F_PLATFORM
ansond 0:8f99b3f2c3a8 113 Thread workerTask(mainTask, NULL, osPriorityNormal, STACK_SIZE);
ansond 0:8f99b3f2c3a8 114 while (true) {
ansond 0:8f99b3f2c3a8 115 Thread::wait(10*WAIT_TIME_MS);
ansond 0:8f99b3f2c3a8 116 }
ansond 0:8f99b3f2c3a8 117 #else
ansond 0:8f99b3f2c3a8 118 mainTask(NULL);
ansond 0:8f99b3f2c3a8 119 #endif
ansond 0:8f99b3f2c3a8 120 }