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: DmTftLibrary eeprom SX1280Lib filesystem mbed
Fork of MSNV2-Terminal_V1-5 by
Application.cpp@10:1b37e3b41947, 2018-08-22 (annotated)
- Committer:
- FCH_31
- Date:
- Wed Aug 22 21:22:43 2018 +0000
- Revision:
- 10:1b37e3b41947
- Parent:
- 8:cd489b7c49a0
- Child:
- 12:e9ec35413787
3
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| FCH_31 | 8:cd489b7c49a0 | 1 | /* |
| FCH_31 | 8:cd489b7c49a0 | 2 | * MISNet |
| FCH_31 | 8:cd489b7c49a0 | 3 | * |
| FCH_31 | 8:cd489b7c49a0 | 4 | * Application.cpp |
| FCH_31 | 8:cd489b7c49a0 | 5 | * |
| FCH_31 | 8:cd489b7c49a0 | 6 | * Created on: August 17, 2018 |
| FCH_31 | 8:cd489b7c49a0 | 7 | * Author: Francis CHATAIN |
| FCH_31 | 8:cd489b7c49a0 | 8 | * |
| FCH_31 | 8:cd489b7c49a0 | 9 | */ |
| FCH_31 | 8:cd489b7c49a0 | 10 | |
| FCH_31 | 8:cd489b7c49a0 | 11 | #include "main.h" |
| FCH_31 | 8:cd489b7c49a0 | 12 | #include "Application.h" |
| FCH_31 | 10:1b37e3b41947 | 13 | |
| FCH_31 | 8:cd489b7c49a0 | 14 | #include "DataBase.h" |
| FCH_31 | 8:cd489b7c49a0 | 15 | #include "Messages.h" |
| FCH_31 | 10:1b37e3b41947 | 16 | #include "ExtMemory.h" |
| FCH_31 | 10:1b37e3b41947 | 17 | |
| FCH_31 | 10:1b37e3b41947 | 18 | #include "Tftlcd.h" |
| FCH_31 | 10:1b37e3b41947 | 19 | #include "Lora.h" |
| FCH_31 | 8:cd489b7c49a0 | 20 | #include "Sensor.h" |
| FCH_31 | 8:cd489b7c49a0 | 21 | |
| FCH_31 | 10:1b37e3b41947 | 22 | |
| FCH_31 | 10:1b37e3b41947 | 23 | static DataBase dataBase ; // Database creation |
| FCH_31 | 8:cd489b7c49a0 | 24 | static Messages messages ; // Messages Maker (Sensors, Config, Synchro ...) |
| FCH_31 | 10:1b37e3b41947 | 25 | static ExtMemory extMemory ; // Memoire ext |
| FCH_31 | 10:1b37e3b41947 | 26 | |
| FCH_31 | 10:1b37e3b41947 | 27 | |
| FCH_31 | 10:1b37e3b41947 | 28 | Tftlcd tftlcd ; // eventuellement a déplacer (uniquement valable sur les conf nucléo) |
| FCH_31 | 10:1b37e3b41947 | 29 | Sensor sensor ; // eventuellement a déplacer |
| FCH_31 | 8:cd489b7c49a0 | 30 | |
| FCH_31 | 8:cd489b7c49a0 | 31 | |
| FCH_31 | 8:cd489b7c49a0 | 32 | Application::Application() { // constructeur |
| FCH_31 | 8:cd489b7c49a0 | 33 | // Basic instance |
| FCH_31 | 8:cd489b7c49a0 | 34 | //this.dataBase = DataBase; |
| FCH_31 | 8:cd489b7c49a0 | 35 | //this.messages = Messages ; // Messages Maker (Sensors, Config, Synchro ...) |
| FCH_31 | 8:cd489b7c49a0 | 36 | } |
| FCH_31 | 8:cd489b7c49a0 | 37 | |
| FCH_31 | 8:cd489b7c49a0 | 38 | Application::~Application() { } // delete xxx; |
| FCH_31 | 8:cd489b7c49a0 | 39 | |
| FCH_31 | 8:cd489b7c49a0 | 40 | |
| FCH_31 | 8:cd489b7c49a0 | 41 | void Application::start (){ // @brief Start the Application |
| FCH_31 | 8:cd489b7c49a0 | 42 | initInterfaces () ; // Primary interface uart, i2c, spi ... |
| FCH_31 | 10:1b37e3b41947 | 43 | extMemory.read (&dataBase) ; // Read memory to know the list of sensor availables, fill DataBase |
| FCH_31 | 8:cd489b7c49a0 | 44 | initSensors () ; // Depend of the list of sensors launch each |
| FCH_31 | 8:cd489b7c49a0 | 45 | initActuators () ; // Depend of the list of actuator launch each |
| FCH_31 | 8:cd489b7c49a0 | 46 | |
| FCH_31 | 8:cd489b7c49a0 | 47 | // Read Radio parameter in Database for Lora interface (example) |
| FCH_31 | 8:cd489b7c49a0 | 48 | uint32_t freq ; |
| FCH_31 | 8:cd489b7c49a0 | 49 | RadioLoRaBandwidths_t bw ; |
| FCH_31 | 8:cd489b7c49a0 | 50 | RadioLoRaSpreadingFactors_t sf ; |
| FCH_31 | 8:cd489b7c49a0 | 51 | int8_t pwr ; |
| FCH_31 | 8:cd489b7c49a0 | 52 | uint8_t bsz ; |
| FCH_31 | 8:cd489b7c49a0 | 53 | int16_t time ; |
| FCH_31 | 8:cd489b7c49a0 | 54 | dataBase.getRadioParameter ( freq, bw, sf, pwr, bsz, time) ; |
| FCH_31 | 8:cd489b7c49a0 | 55 | |
| FCH_31 | 8:cd489b7c49a0 | 56 | initLora ( freq, bw, sf, pwr ) ; // Initialise the radio module |
| FCH_31 | 8:cd489b7c49a0 | 57 | |
| FCH_31 | 10:1b37e3b41947 | 58 | printf( "*** APP *** start %ld %d %d %d %d %d \r\n",freq, bw, sf, pwr, bsz, time) ; |
| FCH_31 | 10:1b37e3b41947 | 59 | |
| FCH_31 | 10:1b37e3b41947 | 60 | tftlcd.Update ( freq, bw, sf, pwr, bsz, time ) ; // Show information |
| FCH_31 | 8:cd489b7c49a0 | 61 | |
| FCH_31 | 10:1b37e3b41947 | 62 | printf( "*** APP_ *** Start Application (Send message GoodHealth)\r\n"); |
| FCH_31 | 10:1b37e3b41947 | 63 | messages.buildGoodhealth () ; |
| FCH_31 | 8:cd489b7c49a0 | 64 | //sendMessageLora () ; |
| FCH_31 | 8:cd489b7c49a0 | 65 | } |
| FCH_31 | 8:cd489b7c49a0 | 66 | |
| FCH_31 | 10:1b37e3b41947 | 67 | void Application::initInterfaces () { |
| FCH_31 | 10:1b37e3b41947 | 68 | // Depend of the configuration read on DataBase (memory origin) |
| FCH_31 | 10:1b37e3b41947 | 69 | |
| FCH_31 | 10:1b37e3b41947 | 70 | debugSerial = new RawSerial (USBTX,USBRX, 230400); // Debug Link |
| FCH_31 | 10:1b37e3b41947 | 71 | tftlcd.Init () ; |
| FCH_31 | 10:1b37e3b41947 | 72 | |
| FCH_31 | 10:1b37e3b41947 | 73 | // I2C, SPI, UART .... |
| FCH_31 | 10:1b37e3b41947 | 74 | |
| FCH_31 | 10:1b37e3b41947 | 75 | } |
| FCH_31 | 10:1b37e3b41947 | 76 | |
| FCH_31 | 10:1b37e3b41947 | 77 | |
| FCH_31 | 10:1b37e3b41947 | 78 | void Application::initSensors(){ |
| FCH_31 | 10:1b37e3b41947 | 79 | printf( "*** APPP *** initSensors \r\n"); |
| FCH_31 | 10:1b37e3b41947 | 80 | // depend of the list identified (example) |
| FCH_31 | 10:1b37e3b41947 | 81 | //bme280 = new BME280(i2c_rt); |
| FCH_31 | 10:1b37e3b41947 | 82 | // depend of the list identified |
| FCH_31 | 10:1b37e3b41947 | 83 | //bme280->init(config->getBME280_MODE()); |
| FCH_31 | 10:1b37e3b41947 | 84 | } |
| FCH_31 | 10:1b37e3b41947 | 85 | |
| FCH_31 | 10:1b37e3b41947 | 86 | void Application::initActuators(){ |
| FCH_31 | 10:1b37e3b41947 | 87 | // depend of the list identified (example) |
| FCH_31 | 10:1b37e3b41947 | 88 | //bme280 = new BME280(i2c_rt); |
| FCH_31 | 10:1b37e3b41947 | 89 | // depend of the list identified |
| FCH_31 | 10:1b37e3b41947 | 90 | //bme280->init(config->getBME280_MODE()); |
| FCH_31 | 10:1b37e3b41947 | 91 | } |
| FCH_31 | 10:1b37e3b41947 | 92 | |
| FCH_31 | 10:1b37e3b41947 | 93 | void Application::manageSensors () { |
| FCH_31 | 10:1b37e3b41947 | 94 | readSensors (); |
| FCH_31 | 10:1b37e3b41947 | 95 | messages.buildSensors () ; |
| FCH_31 | 10:1b37e3b41947 | 96 | sendMessage () ; |
| FCH_31 | 10:1b37e3b41947 | 97 | } |
| FCH_31 | 10:1b37e3b41947 | 98 | |
| FCH_31 | 10:1b37e3b41947 | 99 | void Application::manageGoodhealth () { |
| FCH_31 | 10:1b37e3b41947 | 100 | readSensors (); |
| FCH_31 | 10:1b37e3b41947 | 101 | messages.buildGoodhealth () ; |
| FCH_31 | 10:1b37e3b41947 | 102 | //sendMessage () ; |
| FCH_31 | 10:1b37e3b41947 | 103 | } |
| FCH_31 | 10:1b37e3b41947 | 104 | |
| FCH_31 | 10:1b37e3b41947 | 105 | void Application::manageSynchro () { |
| FCH_31 | 10:1b37e3b41947 | 106 | messages.buildSynchro () ; |
| FCH_31 | 10:1b37e3b41947 | 107 | //sendMessage () ; |
| FCH_31 | 10:1b37e3b41947 | 108 | } |
| FCH_31 | 10:1b37e3b41947 | 109 | |
| FCH_31 | 10:1b37e3b41947 | 110 | void Application::manageConfiguration () { |
| FCH_31 | 10:1b37e3b41947 | 111 | messages.buildConfiguration () ; |
| FCH_31 | 10:1b37e3b41947 | 112 | //sendMessage () ; |
| FCH_31 | 10:1b37e3b41947 | 113 | } |
| FCH_31 | 10:1b37e3b41947 | 114 | |
| FCH_31 | 10:1b37e3b41947 | 115 | void Application::manageListening () { |
| FCH_31 | 10:1b37e3b41947 | 116 | } |
| FCH_31 | 10:1b37e3b41947 | 117 | |
| FCH_31 | 10:1b37e3b41947 | 118 | |
| FCH_31 | 8:cd489b7c49a0 | 119 | void Application::getScheduling (uint16_t &TimerPayload, uint16_t &TimerGoodhealth, uint16_t &TimerSynchro, uint16_t &TimerListening ) { |
| FCH_31 | 8:cd489b7c49a0 | 120 | |
| FCH_31 | 8:cd489b7c49a0 | 121 | TimerPayload = 1L ; // TODO Dépend de la lecture de la memoire (ici simulé) |
| FCH_31 | 8:cd489b7c49a0 | 122 | TimerGoodhealth = 60L ; |
| FCH_31 | 8:cd489b7c49a0 | 123 | TimerSynchro = 0L ; |
| FCH_31 | 8:cd489b7c49a0 | 124 | TimerListening = 0L ; |
| FCH_31 | 8:cd489b7c49a0 | 125 | } |
| FCH_31 | 8:cd489b7c49a0 | 126 | |
| FCH_31 | 10:1b37e3b41947 | 127 | void Application::sendMessage () { |
| FCH_31 | 8:cd489b7c49a0 | 128 | printf( "*** APP_ *** sendMessage \r\n"); |
| FCH_31 | 8:cd489b7c49a0 | 129 | sendMessageLora () ; |
| FCH_31 | 8:cd489b7c49a0 | 130 | } |
| FCH_31 | 8:cd489b7c49a0 | 131 | |
| FCH_31 | 8:cd489b7c49a0 | 132 | |
| FCH_31 | 10:1b37e3b41947 | 133 | void Application::readSensors () { |
| FCH_31 | 8:cd489b7c49a0 | 134 | printf( "*** APP_ *** readSensors \r\n"); |
| FCH_31 | 8:cd489b7c49a0 | 135 | // depend of the list identified |
| FCH_31 | 8:cd489b7c49a0 | 136 | // Each sensor send can put a event in the db |
| FCH_31 | 8:cd489b7c49a0 | 137 | } |
| FCH_31 | 8:cd489b7c49a0 | 138 | |
| FCH_31 | 8:cd489b7c49a0 | 139 | void Application::writeActuators () { |
| FCH_31 | 8:cd489b7c49a0 | 140 | // depend of the list identified |
| FCH_31 | 8:cd489b7c49a0 | 141 | // Each sensor send can put a event in the queu |
| FCH_31 | 8:cd489b7c49a0 | 142 | } |
| FCH_31 | 8:cd489b7c49a0 | 143 | |
| FCH_31 | 8:cd489b7c49a0 | 144 | |
| FCH_31 | 8:cd489b7c49a0 | 145 |
