Skip to content

Commit

Permalink
sending working
Browse files Browse the repository at this point in the history
  • Loading branch information
jia-xie committed Apr 13, 2024
1 parent 35f2643 commit 66d1413
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app/src/debug_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ char g_debug_buffer[1024*2] = {0};
const char* top_border = "\r\n\r\n\r\n/***** System Info *****/\r\n";
const char* bottom_border = "/***** End of Info *****/\r\n";

#define DEBUG_ENABLED
// #define DEBUG_ENABLED

void Debug_Task_Loop(void)
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/src/robot.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ void Robot_Init()
Launch_Task_Init();
Remote_Init(&huart3);
CAN_Service_Init();
Referee_System_Init(&huart1);
Jetson_Orin_Init(&huart6);
// Referee_System_Init(&huart1);
Jetson_Orin_Init(&huart1);
// Initialize all tasks
Robot_Tasks_Start();
}
Expand Down
6 changes: 3 additions & 3 deletions src/devices/inc/jetson_orin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include "bsp_uart.h"

#define ORIN_DATA_RX_BUFER_SIZE (20)
#define ORIN_DATA_TX_BUFER_SIZE (33)
#define ORIN_DATA_TX_BUFER_SIZE (33+18) // 33 Normal data + 18 Remote data + 1 Remote Offline

#define ORIN_TIMEOUT_MS (3000)
#define JETSON_ORIN_PERIOD (100)
#define JETSON_ORIN_PERIOD (10)

typedef struct
{
Expand All @@ -30,7 +30,7 @@ typedef struct
union
{
float data[8];
uint8_t data_bytes[32];
uint8_t data_bytes[32+18];
} float_byte;
} sending;

Expand Down
1 change: 1 addition & 0 deletions src/devices/inc/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef struct


extern Remote_t g_remote;
extern uint8_t g_remote_shared_buffer[18];
Remote_t* Remote_Init(UART_HandleTypeDef *huart);

#endif /* __REMOTE_H */
15 changes: 11 additions & 4 deletions src/devices/src/jetson_orin.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include "imu_task.h"
#include "bsp_daemon.h"
#include "remote.h"

Jetson_Orin_Data_t g_orin_data;

UART_Instance_t *g_orin_uart_instance_ptr;
Daemon_Instance_t *g_orin_daemon_instance_ptr;

Expand Down Expand Up @@ -98,8 +98,15 @@ void Jetson_Orin_Send_Data(void)
g_orin_data.sending.float_byte.data[6] = g_orin_data.sending.velocity_x;
g_orin_data.sending.float_byte.data[7] = g_orin_data.sending.velocity_y;

g_orin_data.tx_buffer[0] = 0xAA;
memcpy(&g_orin_data.tx_buffer[1],&g_orin_data.sending.float_byte.data_bytes[0], 32*sizeof(uint8_t));
if (g_remote.online_flag == 1)
{
memcpy(&g_orin_data.sending.float_byte.data_bytes[32], &g_remote_shared_buffer, 18*sizeof(uint8_t));
} else {
memset(&g_orin_data.sending.float_byte.data_bytes[32], 0, 18*sizeof(uint8_t));
}


//UART_Transmit(g_orin_uart_instance_ptr, g_orin_data.tx_buffer, sizeof(g_orin_data.tx_buffer), UART_DMA);
g_orin_data.tx_buffer[0] = 0xAA;
memcpy(&g_orin_data.tx_buffer[1],&g_orin_data.sending.float_byte.data_bytes[0], ORIN_DATA_TX_BUFER_SIZE*sizeof(uint8_t));
UART_Transmit(g_orin_uart_instance_ptr, g_orin_data.tx_buffer, sizeof(g_orin_data.tx_buffer), UART_DMA);
}
5 changes: 4 additions & 1 deletion src/devices/src/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
Remote_t g_remote;
UART_Instance_t *g_remote_uart;
Daemon_Instance_t *g_remote_daemon;

uint8_t remote_buffer[18];
volatile uint8_t debug_buffer[18];
uint8_t g_remote_shared_buffer[18]; //protected by mutex

/*
* Remote_BufferProcess()
*
Expand All @@ -23,6 +24,8 @@ volatile uint8_t debug_buffer[18];
void Remote_Buffer_Process()
{
memcpy((void*) debug_buffer, remote_buffer, 18);
memcpy((void*) g_remote_shared_buffer, remote_buffer, 18);

// controller decode
g_remote.controller.right_stick.x = ((remote_buffer[0] | (remote_buffer[1] << 8)) & 0x07ff) - 1024;
g_remote.controller.right_stick.y = (((remote_buffer[1] >> 3) | (remote_buffer[2] << 5)) & 0x07ff) - 1024;
Expand Down

0 comments on commit 66d1413

Please sign in to comment.