added set owner details functionality
i added some code to the Qt application so that it can send the owner name and surname to set on the microcontroller
This commit is contained in:
@@ -31,8 +31,9 @@
|
|||||||
#define F_REPLY "format_reply"
|
#define F_REPLY "format_reply"
|
||||||
|
|
||||||
// Defines used by UDP callback
|
// Defines used by UDP callback
|
||||||
#define MAX_DATA_SIZE 30 // Define the maximum expected data size
|
#define MAX_DATA_SIZE 50 // Define the maximum expected data size
|
||||||
#define UDP_QUESTION1 "Where are you?v1.0" // Expected request from UDP client
|
#define UDP_QUESTION1 "Where are you?v1.0" // Expected request from UDP client
|
||||||
|
#define UDP_QUESTION2 "Change details to:" // Expected request from UDP client
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct owner_details_t
|
* @struct owner_details_t
|
||||||
|
|||||||
@@ -198,9 +198,60 @@ char* udp_broadcast_get_owner_details_surname(){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
char* udp_broadcast_get_owner_details_reply(){
|
char* udp_broadcast_get_owner_details_reply(){
|
||||||
return udp_owner.reply;
|
return udp_owner.reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn void udp_broadcast_check_function(const char[])
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void udp_broadcast_check_function(const char data[MAX_DATA_SIZE]){
|
||||||
|
char func[7];
|
||||||
|
char buffer[20];
|
||||||
|
uint8_t enders[4];
|
||||||
|
uint8_t counter = 0;
|
||||||
|
memset(func, 0, sizeof(func));
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i<6;i++){
|
||||||
|
func[i] = data[i];
|
||||||
|
}
|
||||||
|
if (strcmp(func,"func1:")==0){
|
||||||
|
for (uint8_t i = 0; i < strlen(data); i++){
|
||||||
|
if (data[i] == ',' || data[i] == ':'){
|
||||||
|
enders[counter] = i;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(enders[2] - enders[1] < 20 && strlen(data) - enders[3] < 20 && strncmp(data+enders[0],":name",5) == 0 && strncmp(data+enders[2],", surname",9) == 0 ){
|
||||||
|
counter = 0;
|
||||||
|
for (uint8_t i = enders[1]+2; i< enders[2];i++){
|
||||||
|
buffer[counter] = data[i];
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
if (strcmp(buffer,"") == 0){
|
||||||
|
strncpy(buffer,"name",sizeof(buffer));
|
||||||
|
}
|
||||||
|
LOG_INFO(TAG,"new owner name:%s",buffer);
|
||||||
|
udp_broadcast_set_owner_details_name(buffer);
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
counter = 0;
|
||||||
|
for (uint8_t i = enders[3]+2; i< strlen(data);i++){
|
||||||
|
buffer[counter] = data[i];
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
if (strcmp(buffer,"") == 0){
|
||||||
|
strncpy(buffer,"default",sizeof(buffer));
|
||||||
|
}
|
||||||
|
LOG_INFO(TAG,"new owner surname:%s",buffer);
|
||||||
|
udp_broadcast_set_owner_details_surname(buffer);
|
||||||
|
udp_broadcast_format_reply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn void udp_receive_callback(void*, struct udp_pcb*, struct pbuf*, const ip_addr_t*, u16_t)
|
* @fn void udp_receive_callback(void*, struct udp_pcb*, struct pbuf*, const ip_addr_t*, u16_t)
|
||||||
@@ -233,23 +284,33 @@ static void udp_receive_callback(void* arg, struct udp_pcb* connection, struct p
|
|||||||
if (p_data == NULL){
|
if (p_data == NULL){
|
||||||
LOG_WARN(TAG,"udp_receive_callback: unable to allocate data buffer for reply");
|
LOG_WARN(TAG,"udp_receive_callback: unable to allocate data buffer for reply");
|
||||||
}else if (len <= MAX_DATA_SIZE){
|
}else if (len <= MAX_DATA_SIZE){
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
data[i] = pc[i];
|
data[i] = pc[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO(TAG,"udp_receive_callback: received data from %s at port: %d: %s",source_ip_str,port,data);
|
LOG_INFO(TAG,"udp_receive_callback: received data from %s at port: %d: %s",source_ip_str,port,data);
|
||||||
if (strcmp(data,UDP_QUESTION1) == 0){
|
if (strcmp(data,UDP_QUESTION1) == 0){
|
||||||
p_data->payload = udp_owner.reply;
|
p_data->payload = udp_owner.reply;
|
||||||
p_data->len = strlen(udp_owner.reply);
|
p_data->len = strlen(udp_owner.reply);
|
||||||
p_data->tot_len = strlen(udp_owner.reply);
|
p_data->tot_len = strlen(udp_owner.reply);
|
||||||
udp_sendto(connection, p_data, addr, 64000); /* Was using the sending port of the pc,
|
udp_sendto(connection, p_data, addr, 64000); /* Was using the sending port of the pc,
|
||||||
* this is not the port that Qt is listening to
|
* this is not the port that Qt is listening to
|
||||||
*/
|
*/
|
||||||
LOG_INFO(TAG,"tried to reply to %s at port: %d: %s",source_ip_str,port,udp_owner.reply);
|
LOG_INFO(TAG,"tried to reply to %s at port: %d: %s",source_ip_str,port,udp_owner.reply);
|
||||||
}
|
}else{
|
||||||
|
LOG_INFO(TAG,"other function called");
|
||||||
|
udp_broadcast_check_function(data);
|
||||||
|
p_data->payload = udp_owner.reply;
|
||||||
|
p_data->len = strlen(udp_owner.reply);
|
||||||
|
p_data->tot_len = strlen(udp_owner.reply);
|
||||||
|
udp_sendto(connection, p_data, addr, 64000); /* Was using the sending port of the pc,
|
||||||
|
* this is not the port that Qt is listening to
|
||||||
|
*/
|
||||||
|
LOG_INFO(TAG,"tried to reply to %s at port: %d: %s",source_ip_str,port,udp_owner.reply);
|
||||||
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
LOG_WARN(TAG,"udp_receive_callback: input buffer was bigger than max size %d",MAX_DATA_SIZE);
|
LOG_WARN(TAG,"udp_receive_callback: input buffer was bigger than max size %d",MAX_DATA_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
Reference in New Issue
Block a user