Skip to content

Commit

Permalink
fix: thread broadcast sender & reciever functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Otrebor671 committed Aug 29, 2024
1 parent 0662641 commit 1a3638d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 0 additions & 2 deletions firmware/components/open_thread/open_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ otError openthread_udp_send(otUdpSocket* mSocket,
messageInfo.mPeerPort = port;

message = otUdpNewMessage(instance, &messageSettings);
if (message == NULL)
printf("ERR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");

uint8_t* payload = (uint8_t*) malloc(data_size);
if (!payload) {
Expand Down
14 changes: 8 additions & 6 deletions firmware/components/thread_broadcast/thread_broadcast.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "thread_broadcast.h"
#include <stdio.h>
#include <string.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand All @@ -12,30 +13,31 @@ void (*on_msg_recieve_cb)(char*) = NULL;
void on_udp_recieve(void* aContext,
otMessage* aMessage,
const otMessageInfo* aMessageInfo) {
printf("MSG\n");
otError error = OT_ERROR_NONE;

int payload_size =
(otMessageGetLength(aMessage) - otMessageGetOffset(aMessage));
void* data = malloc(payload_size);
otMessageRead(aMessage, otMessageGetOffset(aMessage), data, payload_size);
char* str = (char*) data;
str[payload_size] = "\0";
char* str = (char*) malloc(payload_size + 1);
sprintf(str, "%s", (char*) data);
printf("MSG\n");
printf("%s\n", str);
if (on_msg_recieve_cb != NULL) {
on_msg_recieve_cb(str);
}
free(str);
free(data);
}

void sender() {
uint16_t counter = 0;
while (1) {
counter++;
char* str = (char*) malloc(15);
sprintf(str, "counter: %d", counter);
char* str = (char*) malloc(20);
sprintf(str, "Counter: %d", counter);
vTaskDelay(pdMS_TO_TICKS(500));
openthread_udp_send(&mSocket, "ff02::1", PORT, &str, sizeof(str));
openthread_udp_send(&mSocket, "ff02::1", PORT, str, strlen(str));
free(str);
}
}
Expand Down
1 change: 1 addition & 0 deletions firmware/main/modules/open_thread/open_thread_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static void thread_broadcast_input(uint8_t button_name, uint8_t button_event) {
open_thread_module_exit();
break;
case BUTTON_RIGHT:
break;
case BUTTON_UP:
printf("channel++\n");
channel = ++channel > 26 ? 11 : channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void open_thread_screens_show_new_message(char* msg) {
oled_screen_clear_line(0, 2, OLED_DISPLAY_NORMAL);
oled_screen_display_text(" New Message ", 0, 2, OLED_DISPLAY_INVERT);
char* str = (char*) malloc(18);
sprintf(str, " Counter: %s ", msg);
sprintf(str, "%s", msg);
oled_screen_clear_line(0, 4, OLED_DISPLAY_NORMAL);
oled_screen_display_text(str, 0, 4, OLED_DISPLAY_NORMAL);
free(str);
Expand Down

0 comments on commit 1a3638d

Please sign in to comment.