Merge branch 'main' of gitlab.enterpriselab.ch:adis_team_gueti_roaster/adis_hs2022_team_4 into main

main
Simon Frei 4 years ago
commit 9f30eaaf90
  1. 4
      ADIS_ESP32_Eclipse/main/challenge_app.c
  2. 39
      ADIS_ESP32_Eclipse/main/challenge_com.c
  3. 15
      ADIS_ESP32_Eclipse/main/splitflap_wrapper.c
  4. 4
      ADIS_tinyK22_SplitFlap/source/shell.c

@ -58,7 +58,7 @@ static void appTask(void *pv){
// endless loop
for(;;){
MyMqtt_Publish("scada/status", "Testmessage from ESP");
//MyMqtt_Publish("scada/status", "Testmessage from ESP");
vTaskDelay(pdMS_TO_TICKS(10000));
}
@ -109,6 +109,8 @@ static uint8_t PrintStatus(const McuShell_StdIOType *io) {
static uint8_t PrintHelp(const McuShell_StdIOType *io) {
McuShell_SendHelpStr((unsigned char*)"challenge", (unsigned char*)"Group of ESP32 Challenge commands\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" help|status", (unsigned char*)"Shows Challenge help or status\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" setMode s(tationary)", (unsigned char*)"Sets the mode of this robot to stationary\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" setMode m(mobile)", (unsigned char*)"Sets the mode of this robot to mobile\r\n", io->stdOut);
return ERR_OK;
}

@ -26,14 +26,19 @@ const char MQTT_TOPIC_SF_CONFIG_SETUP[] = "/splitFlap/config/setup/";
void Challenge_Com_ParseMqtt(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data){
/* INFO
* TOPIC: event->topic
* TOPIC: event->topic ==> do not directly use, string is not limited
* TOPIC LENGTH: event->topic_len
* DATA: event->data
* DATA: event->data ==> do not directly use, string is not limited
* DATA LENGTH: event->data_len
* CLIENT: event->client
*/
esp_mqtt_event_handle_t event = event_data;
// cut strings to length
char topic[event->topic_len+1]; char data[event->data_len+1];
McuUtility_strcpy((unsigned char*)topic, sizeof(topic), (unsigned char*)event->topic);
McuUtility_strcpy((unsigned char*)data, sizeof(data), (unsigned char*)event->data);
bool handled = false;
// check if event id is MQTT_EVENT_DATA => break if not
@ -46,7 +51,7 @@ void Challenge_Com_ParseMqtt(void *handler_args, esp_event_base_t base, int32_t
/* stationary robot allowed commands */
if(Challenge_App_GetRobotMode() == true) {
// CMD: CONFIG SETUP
if(McuUtility_strcmp((char*)event->topic, MQTT_TOPIC_SF_CONFIG_SETUP)==0){
if(McuUtility_strcmp(topic, MQTT_TOPIC_SF_CONFIG_SETUP)==0){
handled = true;
// parse json
int setupId = 0;
@ -56,35 +61,39 @@ void Challenge_Com_ParseMqtt(void *handler_args, esp_event_base_t base, int32_t
{"hardwareId", t_integer, .addr.integer = &hwId,},
{NULL},
};
if(json_read_object(event->data, json_attrs, NULL) != 0){
ESP_LOGE(TAG, "Parsing JSON data of CONFIG SETUP message failed. Event data was = %s", event->data);
int err = json_read_object(data, json_attrs, NULL);
if(err != 0){
ESP_LOGE(TAG, "Parsing JSON data of CONFIG SETUP message failed. Event data was = %s", data);
ESP_LOGE(TAG, "Parse error was: %s", json_error_string(err));
} else{ // successfully parsed
// check values
if(setupId >= 0 && setupId <= 10 && hwId >= 0 && hwId <= 10){
if(setupId >= 0 && setupId <= 10 && hwId >= 0 && hwId <= 50){
SplitFlap_Wrapper_SetHardwareIdentifier(setupId, hwId);
} else{
ESP_LOGE(TAG, "SetupID or HardwareID out of range. Event data was = %s", event->data);
ESP_LOGE(TAG, "SetupID or HardwareID out of range. Event data was = %s", data);
}
}
}
// CMD: INIT ALL
else if(McuUtility_strcmp((char*)event->topic, MQTT_TOPIC_SF_INITALL)==0){
else if(McuUtility_strcmp(topic, MQTT_TOPIC_SF_INITALL)==0){
handled = true;
SplitFlap_Wrapper_MoveAllToZeroPosition();
}
// CMD: DISPLAY
else if(McuUtility_strcmp((char*)event->topic, MQTT_TOPIC_SF_DISPLAY)==0){
else if(McuUtility_strcmp(topic, MQTT_TOPIC_SF_DISPLAY)==0){
handled = true;
// parse json
unsigned char message[] = "TST";
char message[10] = "TEST";
struct json_attr_t json_attrs[] = {
{"message", t_string, .addr.string = (char*)message},
{"message", t_string, .addr.string = message, .len = sizeof(message)},
{NULL},
};
if(json_read_object(event->data, json_attrs, NULL) != 0){
ESP_LOGE(TAG, "Parsing JSON data of DISPLAY message failed. Event data was = %s", event->data);
int err = json_read_object(data, json_attrs, NULL);
if(err != 0){
ESP_LOGE(TAG, "Parsing JSON data of DISPLAY message failed. Event data was = %s", data);
ESP_LOGE(TAG, "Parse error was: %s", json_error_string(err));
} else{ // successfully parsed
SplitFlap_Wrapper_Display(message);
SplitFlap_Wrapper_Display((unsigned char*)message);
}
}
}
@ -98,7 +107,7 @@ void Challenge_Com_ParseMqtt(void *handler_args, esp_event_base_t base, int32_t
if(handled == false){
ESP_LOGE(TAG, "Received data could not be handled. Topic was %s", event->topic);
ESP_LOGE(TAG, "Received data could not be handled. Topic was %s", topic);
}
return;
}

@ -10,8 +10,9 @@
#include "splitflap_wrapper.h"
#include "McuUtility.h"
#include "McuShell.h"
#include "Shell.h"
#define RS_CMD_PREFIX "rs sendcmd SplitFlap "
#define RS_CMD_PREFIX "rs sendcmd 0x01 SplitFlap "
#define BUF_SIZE 50
@ -20,8 +21,10 @@
* If all splitflaps report to be initialized before the timeout, the return value is true */
bool SplitFlap_Wrapper_MoveAllToZeroPosition(void){
unsigned char cmd[BUF_SIZE] = RS_CMD_PREFIX;
unsigned char response[128];
McuUtility_strcat(cmd, sizeof(cmd), (unsigned char*)"initAll");
McuShell_SendStr(cmd, McuShell_GetStdio()->stdOut);
SHELL_SendToESPAndGetResponse(cmd, response, sizeof(response));
McuShell_SendStr(response, McuShell_GetStdio()->stdOut);
return true;
}
@ -30,9 +33,11 @@ bool SplitFlap_Wrapper_MoveAllToZeroPosition(void){
* returns true when all movements finished */
bool SplitFlap_Wrapper_Display(unsigned char *sentence){
unsigned char cmd[BUF_SIZE] = RS_CMD_PREFIX;
unsigned char response[128];
McuUtility_strcat(cmd, sizeof(cmd), (unsigned char*)"Display ");
McuUtility_strcat(cmd, sizeof(cmd), sentence);
McuShell_SendStr(cmd, McuShell_GetStdio()->stdOut);
SHELL_SendToESPAndGetResponse(cmd, response, sizeof(response));
McuShell_SendStr(response, McuShell_GetStdio()->stdOut);
return true;
}
@ -40,6 +45,7 @@ bool SplitFlap_Wrapper_Display(unsigned char *sentence){
* returns true when successful, false when not (e.g. split flap with given id not available) */
bool SplitFlap_Wrapper_SetHardwareIdentifier(uint8_t id, uint8_t hwId){
unsigned char cmd[BUF_SIZE] = RS_CMD_PREFIX;
unsigned char response[128];
unsigned char setupId_str[4] = {0}; unsigned char hardwareId_str[4] = {0};
McuUtility_Num8uToStr(setupId_str, sizeof(setupId_str), id);
McuUtility_Num8uToStr(hardwareId_str, sizeof(hardwareId_str), hwId);
@ -47,6 +53,7 @@ bool SplitFlap_Wrapper_SetHardwareIdentifier(uint8_t id, uint8_t hwId){
McuUtility_strcat(cmd, sizeof(cmd), setupId_str);
McuUtility_strcat(cmd, sizeof(cmd), (unsigned char*)" ");
McuUtility_strcat(cmd, sizeof(cmd), hardwareId_str);
McuShell_SendStr(cmd, McuShell_GetStdio()->stdOut);
SHELL_SendToESPAndGetResponse(cmd, response, sizeof(response));
McuShell_SendStr(response, McuShell_GetStdio()->stdOut);
return true;
}

@ -155,6 +155,10 @@ uint8_t SHELL_Int32ArrayToStringForSF(int32_t* intArray, int8_t size, char *str)
return ERR_RANGE;
}
*str = (char)intArray[i];
// array ended early => return ok
if(*str == '\0'){
return ERR_OK;
}
if(!((*str <= '9' && *str >= '0') || (*str >= 'A' && *str <= 'Z') ||
*str == '!' || *str == '?' || *str == ':' || *str == ' ')){
return ERR_RANGE;

Loading…
Cancel
Save