From 25de694682edb885093dd2469cf2151a144f306b Mon Sep 17 00:00:00 2001 From: Cameron Tacklind Date: Tue, 23 Aug 2022 15:06:50 -0700 Subject: [PATCH] Getting to work on raspi --- src_v2/engine/output/lumenarium_output_sacn.c | 20 +++++++++++++++++-- src_v2/platform/osx/lumenarium_osx_network.h | 8 ++++++++ .../platform/raspi/lumenarium_first_raspi.c | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src_v2/engine/output/lumenarium_output_sacn.c b/src_v2/engine/output/lumenarium_output_sacn.c index fd46365..67a918d 100644 --- a/src_v2/engine/output/lumenarium_output_sacn.c +++ b/src_v2/engine/output/lumenarium_output_sacn.c @@ -167,7 +167,14 @@ PackB4(u8* ptr, u32 val) ptr[2] = (u8)((val & 0xff00) >> 8); ptr[1] = (u8)((val & 0xff0000) >> 16); ptr[0] = (u8)((val & 0xff000000) >> 24); - return ptr + sizeof(val); + return ptr + sizeof(val); +} + +//Unpacks a u32 from a known big endian buffer +u32 +UpackB4(u8* ptr) +{ + return (u32)(ptr[3] | (ptr[2] << 8) | (ptr[1] << 16) | (ptr[0] << 24)); } internal void @@ -398,7 +405,14 @@ sacn_string_to_cid(String str) internal u32 sacn_universe_to_send_addr(u32 universe) { - return 0; + u8 multicast_address_buffer[4] = {}; + multicast_address_buffer[0] = 239; + multicast_address_buffer[1] = 255; + multicast_address_buffer[2] = (u8)((universe & 0xff00) >> 8); // high bit + multicast_address_buffer[3] = (u8)((universe & 0x00ff)); // low bit + + u32 v4_addr = (u32)UpackB4(multicast_address_buffer); + return v4_addr; } internal u8* @@ -421,6 +435,8 @@ output_network_sacn_init() (u8*)&ttl, sizeof(ttl) ); + printf("Registered SACN Socket\n"); + return (u8*)result; } diff --git a/src_v2/platform/osx/lumenarium_osx_network.h b/src_v2/platform/osx/lumenarium_osx_network.h index 983efda..424b3ac 100644 --- a/src_v2/platform/osx/lumenarium_osx_network.h +++ b/src_v2/platform/osx/lumenarium_osx_network.h @@ -62,6 +62,14 @@ os_socket_send_to(Socket_Handle handle, u32 addr, u32 port, Data data, s32 flags .sin_port = hton_u16(port), .sin_addr.s_addr = hton_u32(addr), }; + +#define PRINT_EVERY_SEND_ADDR 0 +#if PRINT_EVERY_SEND_ADDR + printf("Sending To:\n\tFamily: %d\n\tPort: %d\n\tAddr: %d\n", + dst.sin_family, dst.sin_port, dst.sin_addr.s_addr + ); +#endif + struct sockaddr* dst_ptr = (struct sockaddr*)&dst; s32 len_sent = sendto(sock, data.base, data.size, flags, dst_ptr, sizeof(struct sockaddr_in)); if (len_sent == -1) diff --git a/src_v2/platform/raspi/lumenarium_first_raspi.c b/src_v2/platform/raspi/lumenarium_first_raspi.c index b32edab..25684c9 100644 --- a/src_v2/platform/raspi/lumenarium_first_raspi.c +++ b/src_v2/platform/raspi/lumenarium_first_raspi.c @@ -41,7 +41,7 @@ linux_err_print_(char* proc, char* sub_proc, s32 errsv) #include "../shared/lumenarium_shared_network.h" #include "../linux/lumenarium_linux_file.h" #include "../linux/lumenarium_linux_time.h" -#include "../linux/lumenarium_linux_network.h" +#include "../osx/lumenarium_osx_network.h" int main (int arg_count, char** args)