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