|
@@ -24,9 +24,9 @@
|
|
#define MQTT_BUFSIZE 1024
|
|
#define MQTT_BUFSIZE 1024
|
|
|
|
|
|
char* const subscribeTopicNames[MASTER_BOARD + SLAVES_COUNT] = { "Set/0", "Set/1", "Set/2", "Set/3", "Set/4" };
|
|
char* const subscribeTopicNames[MASTER_BOARD + SLAVES_COUNT] = { "Set/0", "Set/1", "Set/2", "Set/3", "Set/4" };
|
|
-#define MAX_COMMANDS_IN_MQTT_PAYLOAD 14
|
|
|
|
|
|
+#define MAX_COMMANDS_IN_MQTT_PAYLOAD 15
|
|
char* const topicCommands[MAX_COMMANDS_IN_MQTT_PAYLOAD] = { "fanSpeed", "motorXon", "motorYon", "diode", "motorXMaxCurrent", "motorYMaxCurrent", "clearPeakElectricalMeasurements", "mainBoardRelay",
|
|
char* const topicCommands[MAX_COMMANDS_IN_MQTT_PAYLOAD] = { "fanSpeed", "motorXon", "motorYon", "diode", "motorXMaxCurrent", "motorYMaxCurrent", "clearPeakElectricalMeasurements", "mainBoardRelay",
|
|
- "setEncoderXValue", "setEncoderYValue", "setVoltageMeasGains", "setVoltageMeasOffsets", "setCurrentMeasGains", "setCurrentMeasOffsets" };
|
|
|
|
|
|
+ "setEncoderXValue", "setEncoderYValue", "setVoltageMeasGains", "setVoltageMeasOffsets", "setCurrentMeasGains", "setCurrentMeasOffsets", "resetSystem" };
|
|
|
|
|
|
enum _Topics
|
|
enum _Topics
|
|
{
|
|
{
|
|
@@ -43,7 +43,8 @@ enum _Topics
|
|
setVoltageMeasGains,
|
|
setVoltageMeasGains,
|
|
setVoltageMeasOffsets,
|
|
setVoltageMeasOffsets,
|
|
setCurrentMeasGains,
|
|
setCurrentMeasGains,
|
|
- setCurrentMeasOffsets
|
|
|
|
|
|
+ setCurrentMeasOffsets,
|
|
|
|
+ resetSystem,
|
|
};
|
|
};
|
|
|
|
|
|
enum _BoardNoOverTopic
|
|
enum _BoardNoOverTopic
|
|
@@ -295,141 +296,174 @@ void MqttMessageArrived (MessageData* msg) {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (topicForBoard == unknownBoard) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
cJSON* json = cJSON_Parse (message->payload);
|
|
cJSON* json = cJSON_Parse (message->payload);
|
|
const cJSON* objectItem = NULL;
|
|
const cJSON* objectItem = NULL;
|
|
InterProcessData data = { 0 };
|
|
InterProcessData data = { 0 };
|
|
uint32_t arraySize = 0;
|
|
uint32_t arraySize = 0;
|
|
- for (int topicCmdNumber = 0; topicCmdNumber < MAX_COMMANDS_IN_MQTT_PAYLOAD; topicCmdNumber++) {
|
|
|
|
- spCommand = spUnknown;
|
|
|
|
- objectItem = cJSON_GetObjectItemCaseSensitive (json, topicCommands[topicCmdNumber]);
|
|
|
|
- if (objectItem != NULL) {
|
|
|
|
- switch (topicCmdNumber) {
|
|
|
|
- case fanSpeedTopic: spCommand = spSetFanSpeed;
|
|
|
|
- case motorXonTopic:
|
|
|
|
- if (spCommand == spUnknown) {
|
|
|
|
- spCommand = spSetMotorXOn;
|
|
|
|
- }
|
|
|
|
- case motorYonTopic:
|
|
|
|
- if (spCommand == spUnknown) {
|
|
|
|
- spCommand = spSetMotorYOn;
|
|
|
|
- }
|
|
|
|
- if (cJSON_IsArray (objectItem)) {
|
|
|
|
- data.spCommand = spCommand;
|
|
|
|
- arraySize = cJSON_GetArraySize (objectItem);
|
|
|
|
- if (arraySize == 2) {
|
|
|
|
- for (int i = 0; i < arraySize; i++) {
|
|
|
|
- cJSON* item = cJSON_GetArrayItem (objectItem, i);
|
|
|
|
- if (cJSON_IsNumber (item)) {
|
|
|
|
- data.values.integerValues.value[i] = item->valueint;
|
|
|
|
|
|
+ if (topicForBoard != main_board) {
|
|
|
|
+ for (int topicCmdNumber = 0; topicCmdNumber < MAX_COMMANDS_IN_MQTT_PAYLOAD; topicCmdNumber++) {
|
|
|
|
+ spCommand = spUnknown;
|
|
|
|
+ objectItem = cJSON_GetObjectItemCaseSensitive (json, topicCommands[topicCmdNumber]);
|
|
|
|
+ if (objectItem != NULL) {
|
|
|
|
+ switch (topicCmdNumber) {
|
|
|
|
+ case fanSpeedTopic: spCommand = spSetFanSpeed;
|
|
|
|
+ case motorXonTopic:
|
|
|
|
+ if (spCommand == spUnknown) {
|
|
|
|
+ spCommand = spSetMotorXOn;
|
|
|
|
+ }
|
|
|
|
+ case motorYonTopic:
|
|
|
|
+ if (spCommand == spUnknown) {
|
|
|
|
+ spCommand = spSetMotorYOn;
|
|
|
|
+ }
|
|
|
|
+ if (cJSON_IsArray (objectItem)) {
|
|
|
|
+ data.spCommand = spCommand;
|
|
|
|
+ arraySize = cJSON_GetArraySize (objectItem);
|
|
|
|
+ if (arraySize == 2) {
|
|
|
|
+ for (int i = 0; i < arraySize; i++) {
|
|
|
|
+ cJSON* item = cJSON_GetArrayItem (objectItem, i);
|
|
|
|
+ if (cJSON_IsNumber (item)) {
|
|
|
|
+ data.values.integerValues.value[i] = item->valueint;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- break;
|
|
|
|
- case diodeTopic:
|
|
|
|
- data.spCommand = spSetDiodeOn;
|
|
|
|
- data.values.integerValues.value[0] = objectItem->valueint;
|
|
|
|
- data.values.integerValues.value[1] = 0;
|
|
|
|
- break;
|
|
|
|
- case motorXMaxCurrentTopic: spCommand = spSetmotorXMaxCurrent;
|
|
|
|
- case motorYMaxCurrentTopic:
|
|
|
|
- if (spCommand == spUnknown) {
|
|
|
|
- spCommand = spSetmotorYMaxCurrent;
|
|
|
|
- }
|
|
|
|
- data.spCommand = spCommand;
|
|
|
|
- data.values.flaotValues.value[0] = objectItem->valuedouble;
|
|
|
|
- data.values.flaotValues.value[1] = 0.0;
|
|
|
|
- break;
|
|
|
|
- case clearPeakElectricalMeasurementsTopic: data.spCommand = spClearPeakMeasurments; break;
|
|
|
|
- case mainBoardRelayTopic:
|
|
|
|
- if (cJSON_IsArray (objectItem)) {
|
|
|
|
- arraySize = cJSON_GetArraySize (objectItem);
|
|
|
|
- if (arraySize == 2) {
|
|
|
|
- int32_t relayNumber = -1;
|
|
|
|
- cJSON* item = cJSON_GetArrayItem (objectItem, 0);
|
|
|
|
- if (cJSON_IsNumber (item)) {
|
|
|
|
- relayNumber = item->valueint;
|
|
|
|
|
|
+ break;
|
|
|
|
+ case diodeTopic:
|
|
|
|
+ if (cJSON_IsNumber (objectItem)) {
|
|
|
|
+ data.spCommand = spSetDiodeOn;
|
|
|
|
+ data.values.integerValues.value[0] = objectItem->valueint;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case motorXMaxCurrentTopic: spCommand = spSetmotorXMaxCurrent;
|
|
|
|
+ case motorYMaxCurrentTopic:
|
|
|
|
+ if (cJSON_IsNumber (objectItem)) {
|
|
|
|
+ if (spCommand == spUnknown) {
|
|
|
|
+ spCommand = spSetmotorYMaxCurrent;
|
|
}
|
|
}
|
|
- int32_t relayTimeOn = 0;
|
|
|
|
- item = cJSON_GetArrayItem (objectItem, 1);
|
|
|
|
- if (cJSON_IsNumber (item)) {
|
|
|
|
- relayTimeOn = item->valueint;
|
|
|
|
|
|
+ data.spCommand = spCommand;
|
|
|
|
+ data.values.flaotValues.value[0] = objectItem->valuedouble;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case clearPeakElectricalMeasurementsTopic:
|
|
|
|
+ if (cJSON_IsNumber (objectItem)) {
|
|
|
|
+ if (objectItem->valueint == 1) {
|
|
|
|
+ data.spCommand = spClearPeakMeasurments;
|
|
}
|
|
}
|
|
- RelayCtrl (relayNumber, relayTimeOn);
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
- break;
|
|
|
|
- case setEncoderXValue:
|
|
|
|
- data.spCommand = spSetEncoderXValue;
|
|
|
|
- data.values.flaotValues.value[0] = objectItem->valuedouble;
|
|
|
|
- data.values.flaotValues.value[1] = 0;
|
|
|
|
- break;
|
|
|
|
- case setEncoderYValue:
|
|
|
|
- data.spCommand = spSetEncoderYValue;
|
|
|
|
- data.values.flaotValues.value[0] = objectItem->valuedouble;
|
|
|
|
- data.values.flaotValues.value[1] = 0;
|
|
|
|
- break;
|
|
|
|
- case setVoltageMeasGains:
|
|
|
|
- spCommand = spSetVoltageMeasGains;
|
|
|
|
- case setVoltageMeasOffsets:
|
|
|
|
- if (spCommand == spUnknown) {
|
|
|
|
- spCommand = spSetVoltageMeasOffsets;
|
|
|
|
- }
|
|
|
|
- case setCurrentMeasGains:
|
|
|
|
- if (spCommand == spUnknown) {
|
|
|
|
- spCommand = spSetCurrentMeasGains;
|
|
|
|
- }
|
|
|
|
- case setCurrentMeasOffsets:
|
|
|
|
- if (spCommand == spUnknown) {
|
|
|
|
- spCommand = spSetCurrentMeasOffsets;
|
|
|
|
- }
|
|
|
|
- if (cJSON_IsArray (objectItem)) {
|
|
|
|
- data.spCommand = spCommand;
|
|
|
|
- arraySize = cJSON_GetArraySize (objectItem);
|
|
|
|
- if (arraySize == 3) {
|
|
|
|
- for (int i = 0; i < arraySize; i++) {
|
|
|
|
- cJSON* item = cJSON_GetArrayItem (objectItem, i);
|
|
|
|
|
|
+ break;
|
|
|
|
+ case mainBoardRelayTopic:
|
|
|
|
+ if (cJSON_IsArray (objectItem)) {
|
|
|
|
+ arraySize = cJSON_GetArraySize (objectItem);
|
|
|
|
+ if (arraySize == 2) {
|
|
|
|
+ int32_t relayNumber = -1;
|
|
|
|
+ cJSON* item = cJSON_GetArrayItem (objectItem, 0);
|
|
if (cJSON_IsNumber (item)) {
|
|
if (cJSON_IsNumber (item)) {
|
|
- data.values.flaotValues.value[i] = item->valuedouble;
|
|
|
|
|
|
+ relayNumber = item->valueint;
|
|
}
|
|
}
|
|
|
|
+ int32_t relayTimeOn = 0;
|
|
|
|
+ item = cJSON_GetArrayItem (objectItem, 1);
|
|
|
|
+ if (cJSON_IsNumber (item)) {
|
|
|
|
+ relayTimeOn = item->valueint;
|
|
|
|
+ }
|
|
|
|
+ RelayCtrl (relayNumber, relayTimeOn);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ break;
|
|
|
|
+ case setEncoderXValue:
|
|
|
|
+ if (cJSON_IsNumber (objectItem)) {
|
|
|
|
+ data.spCommand = spSetEncoderXValue;
|
|
|
|
+ data.values.flaotValues.value[0] = objectItem->valuedouble;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case setEncoderYValue:
|
|
|
|
+ if (cJSON_IsNumber (objectItem)) {
|
|
|
|
+ data.spCommand = spSetEncoderYValue;
|
|
|
|
+ data.values.flaotValues.value[0] = objectItem->valuedouble;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case setVoltageMeasGains: spCommand = spSetVoltageMeasGains;
|
|
|
|
+ case setVoltageMeasOffsets:
|
|
|
|
+ if (spCommand == spUnknown) {
|
|
|
|
+ spCommand = spSetVoltageMeasOffsets;
|
|
|
|
+ }
|
|
|
|
+ case setCurrentMeasGains:
|
|
|
|
+ if (spCommand == spUnknown) {
|
|
|
|
+ spCommand = spSetCurrentMeasGains;
|
|
|
|
+ }
|
|
|
|
+ case setCurrentMeasOffsets:
|
|
|
|
+ if (spCommand == spUnknown) {
|
|
|
|
+ spCommand = spSetCurrentMeasOffsets;
|
|
|
|
+ }
|
|
|
|
+ if (cJSON_IsArray (objectItem)) {
|
|
|
|
+ data.spCommand = spCommand;
|
|
|
|
+ arraySize = cJSON_GetArraySize (objectItem);
|
|
|
|
+ if (arraySize == 3) {
|
|
|
|
+ for (int i = 0; i < arraySize; i++) {
|
|
|
|
+ cJSON* item = cJSON_GetArrayItem (objectItem, i);
|
|
|
|
+ if (cJSON_IsNumber (item)) {
|
|
|
|
+ data.values.flaotValues.value[i] = item->valuedouble;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case resetSystem:
|
|
|
|
+ if (cJSON_IsNumber (objectItem)) {
|
|
|
|
+ if (objectItem->valueint == 1) {
|
|
|
|
+ data.spCommand = spResetSystem;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ default: break;
|
|
}
|
|
}
|
|
- break;
|
|
|
|
- default: break;
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- switch (topicForBoard) {
|
|
|
|
- case main_board: break;
|
|
|
|
- case board_1:
|
|
|
|
- if (uart1TaskData.sendCmdToSlaveQueue != NULL) {
|
|
|
|
- osMessageQueuePut (uart1TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
|
|
|
|
- }
|
|
|
|
- printf ("Send cmd to board 1\n");
|
|
|
|
- break;
|
|
|
|
- case board_2:
|
|
|
|
- if (uart3TaskData.sendCmdToSlaveQueue != NULL) {
|
|
|
|
- osMessageQueuePut (uart3TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
|
|
|
|
- }
|
|
|
|
- printf ("Send cmd to board 2\n");
|
|
|
|
- break;
|
|
|
|
- case board_3:
|
|
|
|
- if (uart6TaskData.sendCmdToSlaveQueue != NULL) {
|
|
|
|
- osMessageQueuePut (uart6TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
|
|
|
|
- }
|
|
|
|
- printf ("Send cmd to board 3\n");
|
|
|
|
- break;
|
|
|
|
- case board_4:
|
|
|
|
- if (uart2TaskData.sendCmdToSlaveQueue != NULL) {
|
|
|
|
- osMessageQueuePut (uart2TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
|
|
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ for (int topicCmdNumber = 0; topicCmdNumber < MAX_COMMANDS_IN_MQTT_PAYLOAD; topicCmdNumber++) {
|
|
|
|
+ objectItem = cJSON_GetObjectItemCaseSensitive (json, topicCommands[topicCmdNumber]);
|
|
|
|
+ if (objectItem != NULL) {
|
|
|
|
+ if (topicCmdNumber == resetSystem) {
|
|
|
|
+ __disable_irq ();
|
|
|
|
+ NVIC_SystemReset ();
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
- printf ("Send cmd to board 4\n");
|
|
|
|
- break;
|
|
|
|
- default: break;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ switch (topicForBoard) {
|
|
|
|
+ case main_board: break;
|
|
|
|
+ case board_1:
|
|
|
|
+ if (uart1TaskData.sendCmdToSlaveQueue != NULL) {
|
|
|
|
+ osMessageQueuePut (uart1TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
|
|
|
|
+ }
|
|
|
|
+ printf ("Send cmd to board 1\n");
|
|
|
|
+ break;
|
|
|
|
+ case board_2:
|
|
|
|
+ if (uart3TaskData.sendCmdToSlaveQueue != NULL) {
|
|
|
|
+ osMessageQueuePut (uart3TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
|
|
|
|
+ }
|
|
|
|
+ printf ("Send cmd to board 2\n");
|
|
|
|
+ break;
|
|
|
|
+ case board_3:
|
|
|
|
+ if (uart6TaskData.sendCmdToSlaveQueue != NULL) {
|
|
|
|
+ osMessageQueuePut (uart6TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
|
|
|
|
+ }
|
|
|
|
+ printf ("Send cmd to board 3\n");
|
|
|
|
+ break;
|
|
|
|
+ case board_4:
|
|
|
|
+ if (uart2TaskData.sendCmdToSlaveQueue != NULL) {
|
|
|
|
+ osMessageQueuePut (uart2TaskData.sendCmdToSlaveQueue, &data, 0, (TickType_t)100);
|
|
|
|
+ }
|
|
|
|
+ printf ("Send cmd to board 4\n");
|
|
|
|
+ break;
|
|
|
|
+ default: break;
|
|
|
|
+ }
|
|
|
|
+
|
|
cJSON_Delete (json);
|
|
cJSON_Delete (json);
|
|
printf ("MQTT Topic:%s, MSG[%d]:%s\n", topicName, (int)message->payloadlen, (char*)message->payload);
|
|
printf ("MQTT Topic:%s, MSG[%d]:%s\n", topicName, (int)message->payloadlen, (char*)message->payload);
|
|
}
|
|
}
|