Bläddra i källkod

Restart main board if no connection. Limiter switches swap.

Bartosz Jakubski 1 månad sedan
förälder
incheckning
9a200062cc
5 ändrade filer med 76893 tillägg och 76851 borttagningar
  1. 7 0
      OZE_Main/Core/Src/mqtt_client.c
  2. 37 36
      OZE_Main/Core/Src/uart_tasks.c
  3. 74486 74453
      OZE_Main/Debug/OZE_Main.list
  4. 2357 2357
      OZE_Main/Debug/OZE_Main.map
  5. 6 5
      OZE_Sensor/Core/Src/meas_tasks.c

+ 7 - 0
OZE_Main/Core/Src/mqtt_client.c

@@ -98,6 +98,7 @@ uint32_t MqttConnectBroker (void);          // mqtt broker connect function
 void MqttMessageArrived (MessageData* msg); // mqtt message callback function
 
 void MqttClientSubTask (void* argument) {
+    uint8_t connectionTryCounter = 0;
     while (1) {
         // waiting for valid ip address
         if (gnetif.ip_addr.addr == 0 || gnetif.netmask.addr == 0 || gnetif.gw.addr == 0) // system has no valid ip address
@@ -115,8 +116,14 @@ void MqttClientSubTask (void* argument) {
             // try to connect to the broker
             if (MqttConnectBroker () != MQTT_SUCCESS) {
                 osDelay (pdMS_TO_TICKS (1000));
+                connectionTryCounter++;
+                if (connectionTryCounter > 10) {
+                    __disable_irq ();
+                    NVIC_SystemReset ();
+                }
             }
         } else {
+            connectionTryCounter = 0;
             MQTTYield (&mqttClient, 500); // handle timer
             osDelay (pdMS_TO_TICKS (100));
         }

+ 37 - 36
OZE_Main/Core/Src/uart_tasks.c

@@ -387,7 +387,6 @@ void UartTxTask (void* argument) {
             case spSetPositonY:
                 WriteDataToBuffer (outputDataBuffer, &outputDataBufferPos, &data.values.flaotValues.value[0], sizeof (float));
                 break;
-                break;
             default: continue; break;
             }
 
@@ -412,43 +411,45 @@ void UartTxTask (void* argument) {
                     slaveLastSeen[boardNumber] = 0;
                     switch (frameData.frameHeader.frameCommand) {
                     case spGetElectricalMeasurments:
-                        osMutexAcquire (resMeasurementsMutex, osWaitForever);
-                        RESMeasurements* resMeas = &resMeasurements[boardNumber];
-                        inputDataBufferPos       = 0;
-                        ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->voltageRMS);
-                        ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->voltagePeak);
-                        ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->currentRMS);
-                        ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->currentPeak);
-                        ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->power);
-                        osMutexRelease (resMeasurementsMutex);
+                        if (osMutexAcquire (resMeasurementsMutex, osWaitForever) == osOK) {
+                            RESMeasurements* resMeas = &resMeasurements[boardNumber];
+                            inputDataBufferPos       = 0;
+                            ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->voltageRMS);
+                            ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->voltagePeak);
+                            ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->currentRMS);
+                            ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->currentPeak);
+                            ReadMeasSetFromBuffer (frameData.dataBuffer, &inputDataBufferPos, resMeas->power);
+                            osMutexRelease (resMeasurementsMutex);
+                        }
                         break;
                     case spGetSensorMeasurments:
-                        osMutexAcquire (sensorsInfoMutex, osWaitForever);
-                        inputDataBufferPos   = 0;
-                        SesnorsInfo* sensors = &sensorsInfo[boardNumber];
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->pvTemperature[0]);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->pvTemperature[1]);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->fanVoltage);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->pvEncoderX);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->pvEncoderY);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorXStatus);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorYStatus);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorXAveCurrent);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorYAveCurrent);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorXPeakCurrent);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorYPeakCurrent);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitXSwitchUp);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitXSwitchDown);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitXSwitchCenter);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitYSwitchUp);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitYSwitchDown);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitYSwitchCenter);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->powerSupplyFailMask);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->currentXPosition);
-                        ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->currentYPosition);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->positionXWeak);
-                        ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->positionYWeak);
-                        osMutexRelease (sensorsInfoMutex);
+                        if (osMutexAcquire (sensorsInfoMutex, osWaitForever) == osOK) {
+                            inputDataBufferPos   = 0;
+                            SesnorsInfo* sensors = &sensorsInfo[boardNumber];
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->pvTemperature[0]);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->pvTemperature[1]);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->fanVoltage);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->pvEncoderX);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->pvEncoderY);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorXStatus);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorYStatus);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorXAveCurrent);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorYAveCurrent);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorXPeakCurrent);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->motorYPeakCurrent);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitXSwitchUp);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitXSwitchDown);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitXSwitchCenter);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitYSwitchUp);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitYSwitchDown);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->limitYSwitchCenter);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->powerSupplyFailMask);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->currentXPosition);
+                            ReadFloatFromBuffer (frameData.dataBuffer, &inputDataBufferPos, &sensors->currentYPosition);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->positionXWeak);
+                            ReadByteFromBufer (frameData.dataBuffer, &inputDataBufferPos, &sensors->positionYWeak);
+                            osMutexRelease (sensorsInfoMutex);
+                        }
                         break;
                     default: break;
                     }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 74486 - 74453
OZE_Main/Debug/OZE_Main.list


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 2357 - 2357
OZE_Main/Debug/OZE_Main.map


+ 6 - 5
OZE_Sensor/Core/Src/meas_tasks.c

@@ -287,7 +287,7 @@ void LimiterSwitchTask (void* arg) {
     while (pdTRUE) {
         osDelay (pdMS_TO_TICKS (100));
         if (osMutexAcquire (sensorsInfoMutex, osWaitForever) == osOK) {
-            sensorsInfo.limitXSwitchDown = HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_13);
+            sensorsInfo.limitXSwitchDown = HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_12);
             pinStates                    = (limitXSwitchDownPrevState << 1) | sensorsInfo.limitXSwitchDown;
             if ((pinStates & 0x3) == 0x1) {
                 limiterXTriggered            = 1;
@@ -296,7 +296,7 @@ void LimiterSwitchTask (void* arg) {
             }
             limitXSwitchDownPrevState = sensorsInfo.limitXSwitchDown;
 
-            sensorsInfo.limitXSwitchUp = HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_12);
+            sensorsInfo.limitXSwitchUp = HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_13);
             pinStates                  = (limitXSwitchUpPrevState << 1) | sensorsInfo.limitXSwitchUp;
             if ((pinStates & 0x3) == 0x1) {
                 limiterXTriggered            = 1;
@@ -313,7 +313,7 @@ void LimiterSwitchTask (void* arg) {
             }
             limitXSwitchCenterPrevState = sensorsInfo.limitXSwitchCenter;
 
-            sensorsInfo.limitYSwitchDown = HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_9);
+            sensorsInfo.limitYSwitchDown = HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_11);
             pinStates                    = (limitYSwitchDownPrevState << 1) | sensorsInfo.limitYSwitchDown;
             if ((pinStates & 0x3) == 0x1) {
                 limiterYTriggered            = 1;
@@ -322,7 +322,7 @@ void LimiterSwitchTask (void* arg) {
             }
             limitYSwitchDownPrevState = sensorsInfo.limitYSwitchDown;
 
-            sensorsInfo.limitYSwitchUp = HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_11);
+            sensorsInfo.limitYSwitchUp = HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_9);
             pinStates                  = (limitYSwitchUpPrevState << 1) | sensorsInfo.limitYSwitchUp;
             if ((pinStates & 0x3) == 0x1) {
                 limiterYTriggered            = 1;
@@ -382,7 +382,8 @@ void EncoderTask (void* arg) {
 				printf ("Forbidden\n");
 			}
 			step                             = step % 4;
-			*encoderTaskArg->pvEncoder       = fmodf (encoderValue, 360.0);
+//			*encoderTaskArg->pvEncoder       = fmodf (encoderValue, 360.0);
+			*encoderTaskArg->pvEncoder       = encoderValue;
 			*encoderTaskArg->currentPosition = 100 * (*encoderTaskArg->pvEncoder) / MAX_X_AXE_ANGLE;
 			osMutexRelease (sensorsInfoMutex);
 		}