SRK Version of mDot LoRa_Sensormode_SRK
Dependencies: libmDot mbed-rtos mbed
Fork of mDot_LoRa_Sensornode by
Application.cpp
00001 /* 00002 * Application.cpp 00003 * 00004 * Created on: Jun 3, 2016 00005 * Author: Adrian 00006 */ 00007 00008 #include "Application.h" 00009 00010 Application::Application() { 00011 initInterfaces(); 00012 initSensors(); 00013 initMutexes(); 00014 initQueueBundle(); 00015 initTasks(); 00016 initApplicationConfig(); 00017 } 00018 00019 Application::~Application() { 00020 delete uart; 00021 delete debugSerial; 00022 delete i2c_rt; 00023 00024 delete gpsSensor; 00025 delete max44009; 00026 delete bme280; 00027 delete mpu9250; 00028 delete si1143; 00029 00030 delete taskLight; 00031 delete taskTemperature; 00032 delete taskPressure; 00033 delete taskHumidity; 00034 delete taskAcceleration; 00035 delete taskGyroscope; 00036 delete taskTesla; 00037 delete taskProximity; 00038 delete taskGps; 00039 } 00040 00041 void Application::init(APPLICATION_MODE desiredMode){ 00042 config->build(desiredMode); 00043 stopAllRunningSensorTasks(); 00044 configureSensors(); 00045 configureLora(); 00046 startRunnableSensorTasks(); 00047 } 00048 00049 void Application::stopAllRunningSensorTasks(){ 00050 if(taskLight->getState() == RUNNING){ 00051 taskLight->stop(); 00052 } 00053 if(taskTemperature->getState() == RUNNING){ 00054 taskTemperature->stop(); 00055 } 00056 if(taskPressure->getState() == RUNNING){ 00057 taskPressure->stop(); 00058 } 00059 if(taskHumidity->getState() == RUNNING){ 00060 taskHumidity->stop(); 00061 } 00062 if(taskAcceleration->getState() == RUNNING){ 00063 taskAcceleration->stop(); 00064 } 00065 if(taskGyroscope->getState() == RUNNING){ 00066 taskGyroscope->stop(); 00067 } 00068 if(taskTesla->getState() == RUNNING){ 00069 taskTesla->stop(); 00070 } 00071 if(taskProximity->getState() == RUNNING){ 00072 taskProximity->stop(); 00073 } 00074 if(taskGps->getState() == RUNNING){ 00075 taskGps->stop(); 00076 } 00077 if(taskLoRaMeasurement->getState() == RUNNING){ 00078 taskLoRaMeasurement->stop(); 00079 } 00080 if(taskDataHandler->getState() == RUNNING){ 00081 taskDataHandler->stop(); 00082 } 00083 00084 osDelay(100); 00085 } 00086 00087 void Application::initInterfaces(){ 00088 uart = new RawSerial(XBEE_DOUT,XBEE_DIN); 00089 debugSerial = new RawSerial(USBTX,USBRX); 00090 i2c_rt = new I2C_RT(); 00091 dot = mDot::getInstance(); 00092 lora = new LoRa(dot,debugSerial); 00093 00094 uart->baud(BAUD_UART); 00095 uart->format(8,SerialBase::None,1); 00096 debugSerial->baud(BAUD_USB); 00097 debugSerial->format(8,SerialBase::None,1); 00098 } 00099 00100 void Application::initSensors(){ 00101 gpsSensor = new uBlox(uart); 00102 max44009 = new MAX44009(i2c_rt); 00103 bme280 = new BME280(i2c_rt); 00104 mpu9250 = new MPU9250(i2c_rt); 00105 si1143 = new SI1143(i2c_rt); 00106 } 00107 00108 void Application::initTasks(){ 00109 taskLight = new TaskLight(max44009,mutexI2C,&queueLight,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00110 taskTemperature = new TaskTemperature(bme280,mutexI2C,&queueTemperature,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00111 taskHumidity = new TaskHumidity(bme280,mutexI2C,&queueHumidity,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00112 taskPressure = new TaskPressure(bme280,mutexI2C,&queuePressure,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00113 taskAcceleration = new TaskAcceleration(mpu9250,mutexI2C,&queueAcceleration,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00114 taskGyroscope = new TaskGyroscope(mpu9250,mutexI2C,&queueGyro,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00115 taskTesla = new TaskTesla(mpu9250,mutexI2C,&queueTesla,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00116 taskProximity = new TaskProximity(si1143,mutexI2C,&queueProximity,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00117 taskGps = new TaskGPS(gpsSensor,mutexUART1,&queueGps,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00118 taskLoRaMeasurement = new TaskLoRaMeasurement(lora,mutexLoRa,&queueLoRaMeasurements,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00119 taskDataHandler = new TaskDatahandler(lora,mutexLoRa,queueBundle,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); 00120 taskDataHandler->setDebugSerial(debugSerial); 00121 } 00122 00123 void Application::startRunnableSensorTasks(){ 00124 if(config->getStateTaskLight() == RUNNING){ 00125 taskLight->start(); 00126 } 00127 if(config->getStateTaskTemperature() == RUNNING){ 00128 taskTemperature->start(); 00129 } 00130 if(config->getStateTaskPressure() == RUNNING){ 00131 taskPressure->start(); 00132 } 00133 if(config->getStateTaskHumidity() == RUNNING){ 00134 taskHumidity->start(); 00135 } 00136 if(config->getStateTaskAcceleration() == RUNNING){ 00137 taskAcceleration->start(); 00138 } 00139 if(config->getStateTaskGyroscope() == RUNNING){ 00140 taskGyroscope->start(); 00141 } 00142 if(config->getStateTaskTesla() == RUNNING){ 00143 taskTesla->start(); 00144 } 00145 if(config->getStateTaskProximity() == RUNNING){ 00146 taskProximity->start(); 00147 } 00148 if(config->getStateTaskGPS() == RUNNING){ 00149 taskGps->start(); 00150 } 00151 if(config->getStateTaskLoRaMeasurement() == RUNNING){ 00152 taskLoRaMeasurement->start(); 00153 } 00154 00155 taskDataHandler->start(); 00156 } 00157 00158 void Application::configureSensors(){ 00159 max44009->init(config->getMAX44009_MODE()); 00160 bme280->init(config->getBME280_MODE()); 00161 mpu9250->init(config->getMPU9250_MODE()); 00162 // si1143->init(config->getSI1143_MODE()); 00163 gpsSensor->init(config->getuBlox_MODE()); 00164 } 00165 00166 void Application::configureLora(){ 00167 lora->init(config->getLORA_MODE()); 00168 } 00169 00170 void Application::initMutexes(){ 00171 this->mutexI2C = new Mutex(); 00172 this->mutexUART1 = new Mutex(); 00173 this->mutexLoRa = new Mutex(); 00174 } 00175 00176 void Application::initApplicationConfig(){ 00177 config = new ApplicationConfig(); 00178 } 00179 00180 void Application::initQueueBundle(){ 00181 this->queueBundle.queueAcceleration = &queueAcceleration; 00182 this->queueBundle.queueCommands = &queueCommands; 00183 this->queueBundle.queueGps = &queueGps; 00184 this->queueBundle.queueGyro = &queueGyro; 00185 this->queueBundle.queueHumidity = &queueHumidity; 00186 this->queueBundle.queueLight = &queueLight; 00187 this->queueBundle.queueLoRaMeasurments = &queueLoRaMeasurements; 00188 this->queueBundle.queuePressure = &queuePressure; 00189 this->queueBundle.queueProximity = &queueProximity; 00190 this->queueBundle.queueTemperature = &queueTemperature; 00191 this->queueBundle.queueTesla = &queueTesla; 00192 }
Generated on Wed Jul 13 2022 09:23:47 by 1.7.2