Advanced Distributed Systems module at HSLU
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

66 lines
1.9 KiB

/*
* challenge_com.c
*
* Created on: 05.12.2022
* Author: jonas
*/
#include "stdbool.h"
#include "challenge_app.h"
#define TAG "CHALLENGE_COM" /* tag for logging with ESP_LOG */
static void Challenge_Com_ParseMqtt(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data){
/* INFO
* TOPIC: event->topic
* TOPIC LENGTH: event->topic_len
* DATA: event->data
* DATA LENGTH: event->data_len
* CLIENT: event->client
*/
esp_mqtt_event_handle_t event = event_data;
bool handled = false;
// check if event id is MQTT_EVENT_DATA => break if not
if((esp_mqtt_event_id_t)event_id != MQTT_EVENT_DATA) {
ESP_LOGE(TAG, "Wrong data received. Can only handle MQTT_EVENT_DATA (event id %i). But received event id: %i", MQTT_EVENT_DATA, (esp_mqtt_event_id_t)event_id);
return;
}
/* check topic and call related command if allowed by robot mode */
/* stationary robot allowed commands */
if(Challenge_App_GetRobotMode() == true) {
if(McuUtility_strcmp((char*)event->topic, MQTT_TOPIC_SF_CONFIG_SETUP)==0){
handled = true;
// TODO JSON PARSER
uint8_t setupId = 0;
uint8_t hwId = 1;
SplitFlap_Wrapper_SetHardwareIdentifier(setupId, hwId);
} else if(McuUtility_strcmp((char*)event->topic, MQTT_TOPIC_SF_INITALL)==0){
handled = true;
SplitFlap_Wrapper_MoveAllToZeroPosition();
} else if(McuUtility_strcmp((char*)event->topic, MQTT_TOPIC_SF_DISPLAY)==0){
handled = true;
// TODO JSON PARSER
char message[] = "TST";
SplitFlap_Wrapper_Display(message);
}
}
/* mobile robot allowed commands */
else{
}
/* both robot modes allowed commands */
if(handled == false)
{
ESP_LOGE(TAG, "Received data could not be handled. Topic was %s", event->topic);
}
return;
}