123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- /*
- * mock_tasks.c
- *
- * Created on: Aug 23, 2024
- * Author: jakubski
- */
- #include "FreeRTOS.h"
- #include "task.h"
- #include "main.h"
- #include "cmsis_os.h"
- #include "mock_tasks.h"
- #include "measurements.h"
- #include "node-red-config.h"
- extern RESMeasurements resMeasurements[SLAVES_COUNT];
- extern SesnorsInfo sensorsInfo[SLAVES_COUNT];
- extern osMutexId_t resMeasurementsMutex;
- extern osMutexId_t sensorsInfoMutex;
- #ifdef USER_MOCKS
- extern RNG_HandleTypeDef hrng;
- float rndflt (float rng) {
- uint32_t rndVal = 0;
- HAL_RNG_GenerateRandomNumber (&hrng, &rndVal);
- return ((float)rndVal / (float)(RAND_MAX)) * rng;
- }
- #else
- float rndflt (float rng)
- {
- (void)rng;
- return 0.0;
- }
- #endif
- void MockMeasurmetsTaskInit(void) {
- osThreadAttr_t osThreadAttrMockMeasTask = { 0 };
- // osThreadId_t osThreadMockMeasurmetsTaskId;
- osThreadAttrMockMeasTask.name = "os_thread_mock_measurmets";
- osThreadAttrMockMeasTask.stack_size = configMINIMAL_STACK_SIZE * 2;
- osThreadAttrMockMeasTask.priority = (osPriority_t)osPriorityNormal;
- // osThreadMockMeasurmetsTaskId = osThreadNew (MockMeasurmetsTask, NULL, &osThreadAttrMockMeasTask);
- osThreadNew (MockMeasurmetsTask, NULL, &osThreadAttrMockMeasTask);
- }
- void MockMeasurmetsTask (void* argument) {
- uint8_t boardNumber = 0;
- uint16_t counter = 0;
- while (pdTRUE) {
- for( boardNumber = 0; boardNumber < SLAVES_COUNT; boardNumber++)
- {
- osMutexAcquire (resMeasurementsMutex, osWaitForever);
- RESMeasurements *resMeas = &resMeasurements[boardNumber];
- resMeas->voltagePeak[0] = 60 + (0.01 * (counter % 100));
- resMeas->voltagePeak[1] = 61 + (0.01 * (counter % 100));
- resMeas->voltagePeak[2] = 62 + (0.01 * (counter % 100));
- resMeas->voltageRMS[0] = 46 + (0.01 * (counter % 100));
- resMeas->voltageRMS[1] = 47 + (0.01 * (counter % 100));
- resMeas->voltageRMS[2] = 48 + (0.01 * (counter % 100));
- resMeas->currentPeak[0] = 3 + (0.01 * (counter % 100));
- resMeas->currentPeak[1] = 4 + (0.01 * (counter % 100));
- resMeas->currentPeak[2] = 5 + (0.01 * (counter % 100));
- resMeas->currentRMS[0] = 1 + (0.01 * (counter % 100));
- resMeas->currentRMS[1] = 2 + (0.01 * (counter % 100));
- resMeas->currentRMS[2] = 3 + (0.01 * (counter % 100));
- resMeas->power[0] = resMeas->voltagePeak[0] * resMeas->currentRMS[0];
- resMeas->power[1] = resMeas->voltagePeak[1] * resMeas->currentRMS[1];
- resMeas->power[2] = resMeas->voltagePeak[2] * resMeas->currentRMS[2];
- osMutexRelease(resMeasurementsMutex);
- osMutexAcquire (sensorsInfoMutex, osWaitForever);
- SesnorsInfo* sensors = &sensorsInfo[boardNumber];
- sensors->pvTemperature[0] = 50 + (0.01 * (counter % 100));
- sensors->pvTemperature[1] = 51 + (0.01 * (counter % 100));
- sensors->fanVoltage = 12 + (0.01 * (counter % 100));
- sensors->pvEncoderXraw = 15 + (0.01 * (counter % 100));
- sensors->pvEncoderYraw = 10 + (0.01 * (counter % 100));
- sensors->motorXStatus = (counter % 100) > 50 ? 1 : 0;
- sensors->motorYStatus = (counter % 100) > 75 ? 1 : 0;
- sensors->motorXAveCurrent = 3 + (0.01 * (counter % 100));
- sensors->motorYAveCurrent = 3 + (0.01 * (counter % 100));
- sensors->motorXPeakCurrent = 6 + (0.01 * (counter % 100));
- sensors->motorYPeakCurrent = 6 + (0.01 * (counter % 100));
- sensors->limitXSwitchUp = (counter % 100) > 50 ? 1 : 0;
- sensors->limitXSwitchDown = (counter % 100) < 25 ? 1 : 0;
- sensors->limitXSwitchCenter = (counter % 100) > 35 ? 1 : 0;
- sensors->limitYSwitchUp = (counter % 100) > 50 ? 1 : 0;
- sensors->limitYSwitchDown = (counter % 100) < 25 ? 1 : 0;
- sensors->limitYSwitchCenter = (counter % 100) > 35 ? 1 : 0;
- sensors->powerSupplyFailMask = 0;
- osMutexRelease(sensorsInfoMutex);
- }
- counter++;
- osDelay (pdMS_TO_TICKS (1000));
- }
- }
|