Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
src/main.cpp@49:0456ee2271be, 2016-09-13 (annotated)
- Committer:
- davidjhoward
- Date:
- Tue Sep 13 19:25:13 2016 +0000
- Revision:
- 49:0456ee2271be
- Parent:
- 45:3b9e1923cb15
- Child:
- 50:6924b1a2c769
- Child:
- 52:e25c857451b6
Cloud Data Handler updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmarkel44 | 0:65cfa4873284 | 1 | /****************************************************************************** |
jmarkel44 | 3:8ea4db957749 | 2 | * |
jmarkel44 | 0:65cfa4873284 | 3 | * File: main.cpp |
jmarkel44 | 0:65cfa4873284 | 4 | * Desciption: main ICE driver routine |
jmarkel44 | 0:65cfa4873284 | 5 | * |
jmarkel44 | 0:65cfa4873284 | 6 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 7 | #include "mbed.h" |
jmarkel44 | 0:65cfa4873284 | 8 | #include "rtos.h" |
jmarkel44 | 0:65cfa4873284 | 9 | #include <stdio.h> |
jmarkel44 | 0:65cfa4873284 | 10 | #include "mDot.h" |
jmarkel44 | 0:65cfa4873284 | 11 | #include "global.h" |
jmarkel44 | 0:65cfa4873284 | 12 | #include "ConfigurationHandler.h" |
jmarkel44 | 0:65cfa4873284 | 13 | #include "AnalyticsLogger.h" |
jmarkel44 | 0:65cfa4873284 | 14 | #include "ModbusMaster.h" |
jmarkel44 | 0:65cfa4873284 | 15 | #include "BLEDataHandler.h" |
davidjhoward | 16:7f6599312962 | 16 | #include "LoRaInit.h" |
jmarkel44 | 20:653923c2f37a | 17 | #include "ControlTask.h" |
jmarkel44 | 20:653923c2f37a | 18 | #include "CloudDataHandler.h" |
jmarkel44 | 0:65cfa4873284 | 19 | |
jmarkel44 | 0:65cfa4873284 | 20 | // main thread identifier (for signaling) |
jmarkel44 | 0:65cfa4873284 | 21 | osThreadId mainThreadId = NULL; |
jmarkel44 | 0:65cfa4873284 | 22 | int sig_continue = 0x1; |
jmarkel44 | 0:65cfa4873284 | 23 | |
jmarkel44 | 0:65cfa4873284 | 24 | // data handler to configuration hanlder mailbox |
jmarkel44 | 0:65cfa4873284 | 25 | Mail<Message_t, 16> MailBox; |
davidjhoward | 31:4b1587034318 | 26 | Mail<Message_t, 16> ModbusMasterMailBox; |
jmarkel44 | 0:65cfa4873284 | 27 | |
jmarkel44 | 0:65cfa4873284 | 28 | // local function prototypes |
jmarkel44 | 0:65cfa4873284 | 29 | static void banner(void); |
jmarkel44 | 0:65cfa4873284 | 30 | |
davidjhoward | 7:c0c03193612d | 31 | // for file system access outside of main() |
jmarkel44 | 13:c80c283f9db2 | 32 | mDot *GLOBAL_mdot; |
jmarkel44 | 13:c80c283f9db2 | 33 | |
jmarkel44 | 34:f345fdec711d | 34 | Thread *GLOBAL_analyticsLogger_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 35 | Thread *GLOBAL_modbusMaster_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 36 | Thread *GLOBAL_BLE_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 37 | Thread *GLOBAL_CDH_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 38 | Thread *GLOBAL_configHandler_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 39 | Thread *GLOBAL_controlTask_thread = NULL; |
jmarkel44 | 34:f345fdec711d | 40 | |
jmarkel44 | 13:c80c283f9db2 | 41 | // store modbus register information |
jmarkel44 | 13:c80c283f9db2 | 42 | std::map<std::string,ModbusRegister> ModbusRegisterMap; |
davidjhoward | 7:c0c03193612d | 43 | |
jmarkel44 | 0:65cfa4873284 | 44 | /***************************************************************************** |
jmarkel44 | 0:65cfa4873284 | 45 | * Function: banner() |
jmarkel44 | 0:65cfa4873284 | 46 | * Description: Display the application boot banner |
jmarkel44 | 0:65cfa4873284 | 47 | * |
jmarkel44 | 0:65cfa4873284 | 48 | * @param none |
jmarkel44 | 0:65cfa4873284 | 49 | * @return none |
jmarkel44 | 0:65cfa4873284 | 50 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 51 | static void banner( void ) |
jmarkel44 | 0:65cfa4873284 | 52 | { |
jmarkel44 | 35:6235ef67faa1 | 53 | printf("\n\n\r\nWelcome to Project: ICE v0.0.35\n"); |
jmarkel44 | 0:65cfa4873284 | 54 | printf("\rThe Intelligent Connected Experience\n"); |
jmarkel44 | 0:65cfa4873284 | 55 | printf("\rCopyright 2016 Nalco Water, an Ecolab Company\n"); |
jmarkel44 | 0:65cfa4873284 | 56 | |
jmarkel44 | 0:65cfa4873284 | 57 | printf("\r\t _____ _____ ______ \n"); |
jmarkel44 | 0:65cfa4873284 | 58 | printf("\r\t |_ _| / ____| | ____|\n"); |
jmarkel44 | 0:65cfa4873284 | 59 | printf("\r\t | | | | | |__ \n"); |
jmarkel44 | 0:65cfa4873284 | 60 | printf("\r\t | | | | | __| \n"); |
jmarkel44 | 0:65cfa4873284 | 61 | printf("\r\t _| |_ | |____ | |____ \n"); |
jmarkel44 | 0:65cfa4873284 | 62 | printf("\r\t |_____| \\_____| |______|\n"); |
jmarkel44 | 0:65cfa4873284 | 63 | |
jmarkel44 | 0:65cfa4873284 | 64 | printf("\r\n\r\n\r\r\n"); |
jmarkel44 | 0:65cfa4873284 | 65 | } |
jmarkel44 | 0:65cfa4873284 | 66 | |
jmarkel44 | 0:65cfa4873284 | 67 | /***************************************************************************** |
jmarkel44 | 0:65cfa4873284 | 68 | * Function: banner() |
jmarkel44 | 0:65cfa4873284 | 69 | * Description: Display the application boot banner |
jmarkel44 | 0:65cfa4873284 | 70 | * |
jmarkel44 | 0:65cfa4873284 | 71 | * @param none |
jmarkel44 | 0:65cfa4873284 | 72 | * @return none |
jmarkel44 | 0:65cfa4873284 | 73 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 74 | int main( void ) |
jmarkel44 | 0:65cfa4873284 | 75 | { |
jmarkel44 | 0:65cfa4873284 | 76 | mDot *dot; |
davidjhoward | 16:7f6599312962 | 77 | |
davidjhoward | 21:85c69494c0ff | 78 | GLOBAL_mdot = dot = mDot::getInstance(); |
davidjhoward | 21:85c69494c0ff | 79 | mDotRadioInit( dot ); |
davidjhoward | 21:85c69494c0ff | 80 | |
jmarkel44 | 13:c80c283f9db2 | 81 | // for signaling from the configuration handler |
jmarkel44 | 0:65cfa4873284 | 82 | mainThreadId = osThreadGetId(); |
jmarkel44 | 3:8ea4db957749 | 83 | |
jmarkel44 | 0:65cfa4873284 | 84 | banner(); |
jmarkel44 | 0:65cfa4873284 | 85 | printf("\rMultiTech mDot library version: %s\n", dot->getId().c_str()); |
jmarkel44 | 3:8ea4db957749 | 86 | |
jmarkel44 | 3:8ea4db957749 | 87 | // start the configuration handler |
jmarkel44 | 35:6235ef67faa1 | 88 | Thread configHandler_thread(ConfigurationHandler, NULL, osPriorityNormal, 3072, NULL); |
jmarkel44 | 20:653923c2f37a | 89 | Thread controlTask_thread(ControlTask); |
jmarkel44 | 3:8ea4db957749 | 90 | |
jmarkel44 | 0:65cfa4873284 | 91 | // wait for the configuration handler to signal us |
jmarkel44 | 0:65cfa4873284 | 92 | osSignalWait(sig_continue, osWaitForever); |
jmarkel44 | 3:8ea4db957749 | 93 | |
jmarkel44 | 0:65cfa4873284 | 94 | printf("\r%s: continuing to initialize...\n", __func__); |
jmarkel44 | 3:8ea4db957749 | 95 | |
jmarkel44 | 34:f345fdec711d | 96 | Thread analyticsLoggerThread(AnalyticsLogger); |
davidjhoward | 49:0456ee2271be | 97 | Thread modbusMaster_thread(ModbusMaster, NULL, osPriorityNormal, 10000, NULL); |
jmarkel44 | 3:8ea4db957749 | 98 | Thread BLE_thread(BLEDataHandler); |
davidjhoward | 49:0456ee2271be | 99 | Thread CDH_thread(CloudDataHandler, NULL, osPriorityNormal, 8000, NULL); |
jmarkel44 | 34:f345fdec711d | 100 | |
jmarkel44 | 35:6235ef67faa1 | 101 | // assign globals |
jmarkel44 | 34:f345fdec711d | 102 | GLOBAL_analyticsLogger_thread = &analyticsLoggerThread; |
jmarkel44 | 34:f345fdec711d | 103 | GLOBAL_modbusMaster_thread = &modbusMaster_thread; |
jmarkel44 | 34:f345fdec711d | 104 | GLOBAL_BLE_thread = & BLE_thread; |
jmarkel44 | 34:f345fdec711d | 105 | GLOBAL_CDH_thread = & CDH_thread; |
jmarkel44 | 34:f345fdec711d | 106 | GLOBAL_configHandler_thread = &configHandler_thread; |
jmarkel44 | 34:f345fdec711d | 107 | GLOBAL_controlTask_thread = &controlTask_thread; |
jmarkel44 | 3:8ea4db957749 | 108 | |
jmarkel44 | 1:057d8fc6cb2f | 109 | Thread::wait(1000); |
jmarkel44 | 3:8ea4db957749 | 110 | |
jmarkel44 | 3:8ea4db957749 | 111 | // display free memory on the heap |
jmarkel44 | 18:9cf694a764c0 | 112 | printf("\r\n"); |
jmarkel44 | 3:8ea4db957749 | 113 | __heapstats((__heapprt)fprintf,stdout); |
jmarkel44 | 3:8ea4db957749 | 114 | |
jmarkel44 | 3:8ea4db957749 | 115 | printf("\r\n"); |
jmarkel44 | 13:c80c283f9db2 | 116 | Thread::wait(1000); |
jmarkel44 | 0:65cfa4873284 | 117 | printf("\r\n"); |
jmarkel44 | 20:653923c2f37a | 118 | |
jmarkel44 | 3:8ea4db957749 | 119 | // start the command shell |
jmarkel44 | 0:65cfa4873284 | 120 | ntshell_execute(&ntshell, func_read, func_write, func_cb_ntshell); |
jmarkel44 | 3:8ea4db957749 | 121 | } |