Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Committer:
FCH_31
Date:
Mon Oct 22 09:37:50 2018 +0000
Revision:
41:5a436163dddf
Parent:
23:d7df2e2d28de
avec radio;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
patrick_duc 21:8524d815c587 1 /*
patrick_duc 21:8524d815c587 2 * MISNet
patrick_duc 21:8524d815c587 3 *
patrick_duc 21:8524d815c587 4 * Controller.cpp
patrick_duc 21:8524d815c587 5 *
patrick_duc 21:8524d815c587 6 * Created on: August 17, 2018
patrick_duc 21:8524d815c587 7 * Author: Francis CHATAIN
patrick_duc 21:8524d815c587 8 *
patrick_duc 21:8524d815c587 9 */
patrick_duc 21:8524d815c587 10
patrick_duc 23:d7df2e2d28de 11 /*
patrick_duc 23:d7df2e2d28de 12 #include <sstream>
patrick_duc 23:d7df2e2d28de 13 #include <iostream>
patrick_duc 23:d7df2e2d28de 14 #include <iomanip>
patrick_duc 23:d7df2e2d28de 15 #include <string>
patrick_duc 23:d7df2e2d28de 16 */
patrick_duc 23:d7df2e2d28de 17
patrick_duc 21:8524d815c587 18 #include "Context.h"
patrick_duc 21:8524d815c587 19
patrick_duc 21:8524d815c587 20 #ifndef TEST_ENVIRONMENT
patrick_duc 21:8524d815c587 21 #include "Tftlcd.h"
patrick_duc 21:8524d815c587 22 #endif
patrick_duc 21:8524d815c587 23
patrick_duc 21:8524d815c587 24
patrick_duc 21:8524d815c587 25 #include "main.h"
patrick_duc 21:8524d815c587 26 #include "Controller.hpp"
patrick_duc 21:8524d815c587 27
patrick_duc 21:8524d815c587 28 #include "DataBase.hpp"
patrick_duc 21:8524d815c587 29 #include "MessageFactory.hpp"
patrick_duc 21:8524d815c587 30 #include "ExtMemory.hpp"
patrick_duc 21:8524d815c587 31
patrick_duc 21:8524d815c587 32
patrick_duc 21:8524d815c587 33 using namespace misnet;
patrick_duc 21:8524d815c587 34
patrick_duc 21:8524d815c587 35
FCH_31 41:5a436163dddf 36 static DataBase dataBase ; // Database creation
FCH_31 41:5a436163dddf 37 static MessageFactory messageFactory ; // Messages Maker (Sensors, Config, Synchro ...)
FCH_31 41:5a436163dddf 38 static ExtMemory extMemory ; // Memoire externe
patrick_duc 21:8524d815c587 39
patrick_duc 21:8524d815c587 40 #ifndef TEST_ENVIRONMENT
patrick_duc 21:8524d815c587 41 Tftlcd tftlcd ; // eventuellement a déplacer (uniquement valable sur les conf nucléo)
patrick_duc 21:8524d815c587 42 #endif
patrick_duc 21:8524d815c587 43
patrick_duc 21:8524d815c587 44
patrick_duc 21:8524d815c587 45
patrick_duc 21:8524d815c587 46 Controller::Controller() { // constructeur
patrick_duc 21:8524d815c587 47 // Basic instance
patrick_duc 21:8524d815c587 48 //this.dataBase = DataBase;
patrick_duc 21:8524d815c587 49 //this.messageFactory = Message ; // Messages Maker (Sensors, Config, Synchro ...)
patrick_duc 23:d7df2e2d28de 50 uint32_t aValue = 65985;
patrick_duc 23:d7df2e2d28de 51 std::cout << "0x" << std::hex << aValue << std::endl;
patrick_duc 23:d7df2e2d28de 52
patrick_duc 23:d7df2e2d28de 53 std::stringstream stream;
patrick_duc 23:d7df2e2d28de 54
patrick_duc 23:d7df2e2d28de 55 stream << "0x" << std::hex << aValue;
patrick_duc 23:d7df2e2d28de 56 std::string result(stream.str());
patrick_duc 23:d7df2e2d28de 57
patrick_duc 23:d7df2e2d28de 58 std::cout << result.c_str() << std::endl;
patrick_duc 23:d7df2e2d28de 59
patrick_duc 21:8524d815c587 60 }
patrick_duc 21:8524d815c587 61
patrick_duc 21:8524d815c587 62 Controller::~Controller() { } // delete xxx;
patrick_duc 21:8524d815c587 63
patrick_duc 21:8524d815c587 64
patrick_duc 21:8524d815c587 65 #ifndef TEST_ENVIRONMENT
patrick_duc 21:8524d815c587 66 void Controller::start (){ // @brief Start the Controller
FCH_31 41:5a436163dddf 67
FCH_31 41:5a436163dddf 68 initInterfaces () ; // Primary interface uart, i2c, spi ...
FCH_31 41:5a436163dddf 69 extMemory.read (&dataBase) ; // Read memory to know the list of sensor availables, fill DataBase
FCH_31 41:5a436163dddf 70 initSensors () ; // Depend of the list of sensors launch each
FCH_31 41:5a436163dddf 71 initActuators () ; // Depend of the list of actuator launch each
patrick_duc 21:8524d815c587 72
patrick_duc 21:8524d815c587 73 // Read Radio parameter in Database for Lora interface (example)
patrick_duc 21:8524d815c587 74 uint32_t freq ;
patrick_duc 21:8524d815c587 75 RadioLoRaBandwidths_t bw ;
patrick_duc 21:8524d815c587 76 RadioLoRaSpreadingFactors_t sf ;
patrick_duc 21:8524d815c587 77 int8_t pwr ;
patrick_duc 21:8524d815c587 78 uint8_t bsz ;
patrick_duc 21:8524d815c587 79 int16_t terminal_heartbeat_period;
patrick_duc 21:8524d815c587 80 int16_t payload_heartbeat_period;
patrick_duc 21:8524d815c587 81 dataBase.getRadioParameter ( freq, bw, sf, pwr, bsz, terminal_heartbeat_period, payload_heartbeat_period) ;
patrick_duc 21:8524d815c587 82
FCH_31 41:5a436163dddf 83 //initLora ( freq, bw, sf, pwr ) ; // Initialise the radio module
patrick_duc 21:8524d815c587 84
FCH_31 41:5a436163dddf 85 printf( "*** CTRL *** start %ld %d %d %d %d %d \r\n",freq, bw, sf, pwr, bsz, time) ;
patrick_duc 21:8524d815c587 86
patrick_duc 21:8524d815c587 87 tftlcd.Update ( freq, bw, sf, pwr, bsz, payload_heartbeat_period ) ; // Show information
patrick_duc 21:8524d815c587 88
FCH_31 41:5a436163dddf 89 printf( "*** CTRL *** Start Controller (Send message GoodHealth)\r\n");
FCH_31 41:5a436163dddf 90
patrick_duc 21:8524d815c587 91 messageFactory.buildGoodhealth () ;
FCH_31 41:5a436163dddf 92
patrick_duc 21:8524d815c587 93 //sendMessageLora () ;
patrick_duc 21:8524d815c587 94 }
patrick_duc 21:8524d815c587 95
patrick_duc 21:8524d815c587 96 void Controller::initInterfaces () {
patrick_duc 21:8524d815c587 97 // Depend of the configuration read on DataBase (memory origin)
patrick_duc 21:8524d815c587 98
patrick_duc 21:8524d815c587 99 debugSerial = new RawSerial (USBTX,USBRX, 230400); // Debug Link
patrick_duc 21:8524d815c587 100 tftlcd.Init () ;
patrick_duc 21:8524d815c587 101 // I2C, SPI, UART ....
FCH_31 41:5a436163dddf 102
FCH_31 41:5a436163dddf 103 printf( "*** CTRL *** End of Init Interface \r\n");
patrick_duc 21:8524d815c587 104 }
patrick_duc 21:8524d815c587 105
patrick_duc 21:8524d815c587 106
patrick_duc 21:8524d815c587 107 void Controller::initSensors(){
FCH_31 41:5a436163dddf 108 printf( "*** CTRL *** initSensors \r\n");
patrick_duc 21:8524d815c587 109 // depend of the list identified (example)
patrick_duc 21:8524d815c587 110 //bme280 = new BME280(i2c_rt);
patrick_duc 21:8524d815c587 111 // depend of the list identified
patrick_duc 21:8524d815c587 112 //bme280->init(config->getBME280_MODE());
patrick_duc 21:8524d815c587 113 // iks01a2.read () ;
patrick_duc 21:8524d815c587 114 }
patrick_duc 21:8524d815c587 115
patrick_duc 21:8524d815c587 116 void Controller::initActuators(){
patrick_duc 21:8524d815c587 117 // depend of the list identified (example)
patrick_duc 21:8524d815c587 118 //bme280 = new BME280(i2c_rt);
patrick_duc 21:8524d815c587 119 // depend of the list identified
patrick_duc 21:8524d815c587 120 //bme280->init(config->getBME280_MODE());
patrick_duc 21:8524d815c587 121 }
patrick_duc 21:8524d815c587 122
patrick_duc 21:8524d815c587 123 void Controller::manageSensors () {
patrick_duc 21:8524d815c587 124 readSensors () ;
FCH_31 41:5a436163dddf 125 messageFactory.buildSensors () ;
patrick_duc 21:8524d815c587 126 sendMessage () ;
patrick_duc 21:8524d815c587 127 }
patrick_duc 21:8524d815c587 128
patrick_duc 21:8524d815c587 129 void Controller::manageGoodhealth () {
patrick_duc 21:8524d815c587 130 readSensors () ;
patrick_duc 21:8524d815c587 131 messageFactory.buildGoodhealth () ;
patrick_duc 21:8524d815c587 132 //sendMessage () ;
patrick_duc 21:8524d815c587 133 }
patrick_duc 21:8524d815c587 134
patrick_duc 21:8524d815c587 135 void Controller::manageSynchro () {
patrick_duc 21:8524d815c587 136 messageFactory.buildSynchro () ;
patrick_duc 21:8524d815c587 137 //sendMessage () ;
patrick_duc 21:8524d815c587 138 }
patrick_duc 21:8524d815c587 139
patrick_duc 21:8524d815c587 140 void Controller::manageConfiguration () {
patrick_duc 21:8524d815c587 141 messageFactory.buildConfiguration () ;
patrick_duc 21:8524d815c587 142 //sendMessage () ;
patrick_duc 21:8524d815c587 143 }
patrick_duc 21:8524d815c587 144
patrick_duc 21:8524d815c587 145 void Controller::manageListening () {
patrick_duc 21:8524d815c587 146 }
patrick_duc 21:8524d815c587 147
patrick_duc 21:8524d815c587 148
patrick_duc 21:8524d815c587 149 void Controller::getScheduling (uint16_t &TimerPayload, uint16_t &TimerGoodhealth, uint16_t &TimerSynchro, uint16_t &TimerListening ) {
patrick_duc 21:8524d815c587 150
FCH_31 41:5a436163dddf 151 TimerPayload = 5L ; // TODO Dépend de la lecture de la memoire (ici simulé)
patrick_duc 21:8524d815c587 152 TimerGoodhealth = 60L ;
patrick_duc 21:8524d815c587 153 TimerSynchro = 0L ;
patrick_duc 21:8524d815c587 154 TimerListening = 0L ;
patrick_duc 21:8524d815c587 155 }
patrick_duc 21:8524d815c587 156
patrick_duc 21:8524d815c587 157 void Controller::sendMessage () {
FCH_31 41:5a436163dddf 158 printf( "*** CTRL *** sendMessage \r\n");
FCH_31 41:5a436163dddf 159 //sendMessageLora () ;
patrick_duc 21:8524d815c587 160 }
patrick_duc 21:8524d815c587 161
patrick_duc 21:8524d815c587 162
patrick_duc 21:8524d815c587 163 void Controller::readSensors () {
FCH_31 41:5a436163dddf 164 printf("*** CTRL *** readSensors \r\n");
FCH_31 41:5a436163dddf 165 printf("*** CTRL *** loop on all channels\r\n");
patrick_duc 21:8524d815c587 166 short nbSensors = dataBase.getNbService(Service::SENSOR);
FCH_31 41:5a436163dddf 167 printf("*** CTRL *** there are %d sensors in this payload\r\n", nbSensors);
patrick_duc 21:8524d815c587 168 // depend of the list identified
patrick_duc 21:8524d815c587 169 // Each sensor sends an event in the db
patrick_duc 21:8524d815c587 170 //iks01a2.read () ;
patrick_duc 21:8524d815c587 171 }
patrick_duc 21:8524d815c587 172
patrick_duc 21:8524d815c587 173 void Controller::writeActuators () {
patrick_duc 21:8524d815c587 174 // depend of the list identified
patrick_duc 21:8524d815c587 175 // Each sensor send can put a event in the queu
patrick_duc 21:8524d815c587 176 }
patrick_duc 21:8524d815c587 177
patrick_duc 21:8524d815c587 178 #endif