changes to udp code

now working as intended
This commit is contained in:
joran2738
2023-11-13 13:43:15 +01:00
parent 123653cc03
commit 984c573ae6
3 changed files with 6 additions and 5 deletions

View File

@@ -16,6 +16,7 @@
#include "lwip.h"
#define LOGGER_LEVEL_ALL
#include "log.h"
#include "udp.h"
// Defines used by owner details error handler
#define SOD_NAME "set_owner_details_name"

View File

@@ -282,7 +282,7 @@ static void udp_receive_callback(void *arg, struct udp_pcb *connection, struct p
len = p->tot_len;
p_data = pbuf_alloc(PBUF_TRANSPORT, sizeof(reply_str), PBUF_RAM);
if (p_data == NULL){
LOG_WARN(TAG,"udp_receive_callback: unable to allocated data buffer for reply");
LOG_WARN(TAG,"udp_receive_callback: unable to allocate data buffer for reply");
}
else if(len <= MAX_DATA_SIZE){
for(i = 0; i < len; i++) {
@@ -291,10 +291,11 @@ static void udp_receive_callback(void *arg, struct udp_pcb *connection, struct p
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){
*((uint32_t*)p_data->payload) = reply_str;
p_data->payload = reply_str;
p_data->len = sizeof(reply_str);
p_data->tot_len = sizeof(reply_str);
udp_sendto(connection, p_data, addr, port);
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,reply_str);
}

View File

@@ -25,7 +25,6 @@
#define LOGGER_LEVEL_ALL
#include "log.h"
#include "UDP_broadcast.h"
#include "udp.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@@ -114,7 +113,7 @@ int main(void)
owner_details_t owner;
init_UDP_server();
if(!set_owner_details(&owner, "joran", "vn")){
if(!set_owner_details(&owner, "Joran", "Van Nieuwenhoven")){
LOG_DEBUG(TAG,"error");;
}
LOG_DEBUG(TAG,"%s",get_owner_details_reply(&owner));