From 4515cb3785833ab65602d45b1070fe6ef5a58d5e Mon Sep 17 00:00:00 2001 From: JoelleLee Date: Wed, 30 Oct 2024 21:02:58 -0400 Subject: [PATCH] we have a plan now --- projects/bootloader/inc/can_datagram.h | 19 ++++------- projects/bootloader/scripts/bootloader_id.py | 6 ++-- projects/bootloader/src/bootloader.c | 33 +++++++++++++++++++- projects/bootloader/src/can_datagram.c | 16 +++------- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/projects/bootloader/inc/can_datagram.h b/projects/bootloader/inc/can_datagram.h index f2293cc1..f9dc343d 100644 --- a/projects/bootloader/inc/can_datagram.h +++ b/projects/bootloader/inc/can_datagram.h @@ -17,11 +17,7 @@ typedef enum { CAN_ARBITRATION_ACK_ID, CAN_ARBITRATION_START_ID, CAN_ARBITRATION_JUMP_BOOTLOADER, - CAN_ARBITRATION_METADATA, CAN_ARBITRATION_PING, - CAN_PING_NODE_ID, - CAN_PING_PROJECT, - CAN_PING_BRANCH, } BootloaderCanID; typedef struct { @@ -46,15 +42,12 @@ typedef struct { uint16_t bootloader_error; } ack; struct { - //metadata - uint8_t metadata; - //project / Git branch - uint8_t* branchproject; - //node_id - uint8_t node_id; - //isGitorProject - uint8_t isBranch; - + // node_id + uint16_t node_ids; + // Request + uint8_t req; + // Length of data being sent + uint32_t data_len; } ping; } payload; } BootloaderDatagram_t; diff --git a/projects/bootloader/scripts/bootloader_id.py b/projects/bootloader/scripts/bootloader_id.py index b931e4f9..becc2d81 100644 --- a/projects/bootloader/scripts/bootloader_id.py +++ b/projects/bootloader/scripts/bootloader_id.py @@ -4,8 +4,6 @@ ACK = 33 START = 34 JUMP_BOOTLOADER = 35 -PING_METADATA = 37 -NODE_ID = 38 -PROJECT = 39 -BRANCH = 40 +PING_START = 36 +PING_DATA = 37 STANDARD_CRC32_POLY = 0x04C11DB7 \ No newline at end of file diff --git a/projects/bootloader/src/bootloader.c b/projects/bootloader/src/bootloader.c index 0a98f0c8..67dc9b56 100644 --- a/projects/bootloader/src/bootloader.c +++ b/projects/bootloader/src/bootloader.c @@ -235,9 +235,40 @@ static BootloaderError bootloader_fault() { return BOOTLOADER_INTERNAL_ERR; }; +volatile uint32_t bootloader_timer = 0; +#define BOOTLOADER_TIMEOUT_MS 15000 + +static void ping_run(Boot_CanMessage *msg) { + //branch out into the three ID +} + static BootloaderError bootloader_ping() { BootloaderError error = BOOTLOADER_ERROR_NONE; - // + /* Start handling each req + 1 - Git + 2 - Proj + 3 - Node_ID + */ + + Boot_CanMessage msg = { 0 }; + + while (true) { + if(boot_can_receive(&msg) == BOOTLOADER_ERROR_NONE){ + bootloader_timer = 0; + //bootloader_run(&msg); + ping_run(&msg); + } + + if (bootloader_timer > BOOTLOADER_TIMEOUT_MS) { + bootloader_timer = 0; + if (boot_verify_flash_memory() == BOOTLOADER_ERROR_NONE) { + send_ack_datagram(NACK, BOOTLOADER_TIMEOUT); + bootloader_jump_app(); + } + send_ack_datagram(NACK, BOOTLOADER_FLASH_MEMORY_VERIFY_FAILED); + } + + } } static BootloaderError bootloader_run_state() { diff --git a/projects/bootloader/src/can_datagram.c b/projects/bootloader/src/can_datagram.c index e4af1e62..1db27d5e 100644 --- a/projects/bootloader/src/can_datagram.c +++ b/projects/bootloader/src/can_datagram.c @@ -70,19 +70,11 @@ BootloaderDatagram_t unpack_datagram(Boot_CanMessage *msg, uint16_t *target_node *target_nodes = msg->data_u16[0]; break; case CAN_ARBITRATION_PING: - ret_datagram.payload.ping.metadata = msg->data_u8; - break; - case CAN_PING_NODE_ID: - ret_datagram.payload.ping.node_id = msg->data_u8; - break; - case CAN_PING_BRANCH: - ret_datagram.payload.ping.branchproject = msg->data_u8; - ret_datagram.payload.ping.isBranch = 1; - break; - case CAN_PING_PROJECT: - ret_datagram.payload.ping.branchproject = msg->data_u8; - ret_datagram.payload.ping.isBranch = 0; + + ret_datagram.payload.jump_app.node_ids = msg->data_u16[0]; + ret_datagram.payload. break; + default: break; }