Core Base Classes for the Light Endpoints
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more
main.cpp@18:bc165829bb88, 2014-02-26 (annotated)
- Committer:
- ansond
- Date:
- Wed Feb 26 05:45:38 2014 +0000
- Revision:
- 18:bc165829bb88
- Parent:
- 0:4c9bfcb3e759
- Child:
- 20:f2dbbd852e08
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:4c9bfcb3e759 | 1 | /* Copyright C2013 Doug Anson, MIT License |
ansond | 0:4c9bfcb3e759 | 2 | * |
ansond | 0:4c9bfcb3e759 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:4c9bfcb3e759 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:4c9bfcb3e759 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:4c9bfcb3e759 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:4c9bfcb3e759 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 0:4c9bfcb3e759 | 8 | * |
ansond | 0:4c9bfcb3e759 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:4c9bfcb3e759 | 10 | * substantial portions of the Software. |
ansond | 0:4c9bfcb3e759 | 11 | * |
ansond | 0:4c9bfcb3e759 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:4c9bfcb3e759 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:4c9bfcb3e759 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:4c9bfcb3e759 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:4c9bfcb3e759 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:4c9bfcb3e759 | 17 | */ |
ansond | 0:4c9bfcb3e759 | 18 | |
ansond | 0:4c9bfcb3e759 | 19 | #include "MBEDEndpoint.h" |
ansond | 0:4c9bfcb3e759 | 20 | |
ansond | 18:bc165829bb88 | 21 | #include <string.h> |
ansond | 18:bc165829bb88 | 22 | #include <stdlib.h> |
ansond | 18:bc165829bb88 | 23 | |
ansond | 0:4c9bfcb3e759 | 24 | // Ethernet Interface |
ansond | 0:4c9bfcb3e759 | 25 | EthernetInterface ethernet; |
ansond | 0:4c9bfcb3e759 | 26 | |
ansond | 0:4c9bfcb3e759 | 27 | // Serial Console Support |
ansond | 0:4c9bfcb3e759 | 28 | #include "MODSERIAL.h" |
ansond | 0:4c9bfcb3e759 | 29 | MODSERIAL pc(USBTX, USBRX); |
ansond | 0:4c9bfcb3e759 | 30 | |
ansond | 0:4c9bfcb3e759 | 31 | // LCD Support |
ansond | 0:4c9bfcb3e759 | 32 | #include "C12832_lcd.h" |
ansond | 0:4c9bfcb3e759 | 33 | C12832_LCD lcd; |
ansond | 0:4c9bfcb3e759 | 34 | |
ansond | 0:4c9bfcb3e759 | 35 | // Instances for the Endpoint |
ansond | 0:4c9bfcb3e759 | 36 | ErrorHandler *error_handler = NULL; |
ansond | 0:4c9bfcb3e759 | 37 | MBEDEndpoint *endpoint = NULL; |
ansond | 18:bc165829bb88 | 38 | |
ansond | 18:bc165829bb88 | 39 | // cannot seem to find strdup() anywhere.. |
ansond | 18:bc165829bb88 | 40 | char* strdup (const char *str) { |
ansond | 18:bc165829bb88 | 41 | char *result = (char*)(malloc (strlen (str) + 1)); |
ansond | 18:bc165829bb88 | 42 | if (result != NULL) |
ansond | 18:bc165829bb88 | 43 | strcpy (result,str); |
ansond | 18:bc165829bb88 | 44 | return result; |
ansond | 18:bc165829bb88 | 45 | } |
ansond | 0:4c9bfcb3e759 | 46 | |
ansond | 0:4c9bfcb3e759 | 47 | // ErrorHandler (logger) |
ansond | 0:4c9bfcb3e759 | 48 | ErrorHandler *logger() { return error_handler; } |
ansond | 0:4c9bfcb3e759 | 49 | |
ansond | 0:4c9bfcb3e759 | 50 | // close down the application and exit |
ansond | 0:4c9bfcb3e759 | 51 | void closedown() { |
ansond | 0:4c9bfcb3e759 | 52 | if (endpoint != NULL) { |
ansond | 0:4c9bfcb3e759 | 53 | error_handler->log("Closing down Endpoint..."); |
ansond | 0:4c9bfcb3e759 | 54 | delete endpoint; |
ansond | 0:4c9bfcb3e759 | 55 | } |
ansond | 0:4c9bfcb3e759 | 56 | |
ansond | 0:4c9bfcb3e759 | 57 | pc.printf("Exiting...\r\n"); |
ansond | 0:4c9bfcb3e759 | 58 | lcd.locate(0,0); |
ansond | 0:4c9bfcb3e759 | 59 | lcd.printf("Shutdown Complete"); |
ansond | 0:4c9bfcb3e759 | 60 | delete error_handler; |
ansond | 0:4c9bfcb3e759 | 61 | exit(1); |
ansond | 0:4c9bfcb3e759 | 62 | } |
ansond | 0:4c9bfcb3e759 | 63 | |
ansond | 0:4c9bfcb3e759 | 64 | // Main Entry |
ansond | 0:4c9bfcb3e759 | 65 | int main() { |
ansond | 0:4c9bfcb3e759 | 66 | error_handler = new ErrorHandler(&pc,&lcd); |
ansond | 0:4c9bfcb3e759 | 67 | endpoint = new MBEDEndpoint(error_handler,ðernet); |
ansond | 0:4c9bfcb3e759 | 68 | if (endpoint != NULL) endpoint->run(); |
ansond | 0:4c9bfcb3e759 | 69 | } |