Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions ElysiumCode/ccsds/sdlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ uint8_t elyRFDLLClampReg(uint8_t addr, uint8_t value) {
/* TODO learn how to deal with non-SPP packets */
void elyRFDLLBuildFrame(void) {
static ely_framebuilder_state_t state = FB_STATE_UNINIT;
static size_t idle_len = 0;
static size_t idle_len = SDLP_IDLE_PACKET_LENGTH;
static size_t idle_idx = 0;
static size_t remaining_len = 0;

size_t tf_idx = SDLP_TM_PH_LEN;
bool fhp = false;
Expand Down Expand Up @@ -207,7 +208,8 @@ void elyRFDLLBuildFrame(void) {
tf_buffer[4] &= ~0x07;
tf_buffer[5] = 0;
fhp = true;
idle_len = 0;
idle_len = SDLP_IDLE_PACKET_LENGTH;
remaining_len = 0;
idle_idx = 0;
pkt_idx = 0;
}
Expand Down Expand Up @@ -235,13 +237,7 @@ void elyRFDLLBuildFrame(void) {
}
msg_t r = chMBFetch(&rf_mbox, (msg_t *)(&active_packet), SDLP_IDLE_PACKET_TIMEOUT);
if (MSG_OK != r) {
idle_len = tf_data_len - tf_idx;
if (idle_len < 7) {
idle_len += tf_data_len;
}
idle_header[4] = (idle_len - 7) >> 8;
idle_header[5] = (idle_len - 7) & 0xFF;
idle_idx = 0;
idle_idx = idle_len;
state = FB_STATE_IDLE;
continue;
}
Expand All @@ -251,21 +247,37 @@ void elyRFDLLBuildFrame(void) {
}
tf_buffer[tf_idx++] = active_packet[pkt_idx++];
break;
case FB_STATE_IDLE:
case FB_STATE_IDLE: // we don't have any more payload data, so we need to fill the frame with idle data
if (idle_idx == idle_len){
remaining_len = tf_data_len - tf_idx; // find how much room is left in the transfer frame
if (remaining_len < idle_len){ // if the last bit of the frame can't hold a full packet's worth of idle data...
idle_len = remaining_len; // then it won't. the frame will be given a slightly smaller packet
if (remaining_len < 7){ //if another idle header can't be fit into this transfer frame...
for (idle_idx = 0;idle_idx<remaining_len;idle_idx++){
tf_buffer[tf_idx++] = 0; // the last bit of the frame is filled with 0s
}
continue;
}
}
idle_header[4] = (idle_len - 7) >> 8;
idle_header[5] = (idle_len - 7) & 0xFF;
idle_idx = 0;
}

if (idle_idx < 6) {
tf_buffer[tf_idx++] = idle_header[idle_idx++];
}
else {
tf_buffer[tf_idx++] = SPP_IDLE_DATA;
idle_idx++;
}
if (idle_idx == idle_len) {
/* if (idle_idx == idle_len && tf_idx != tf_data_len) {
chDbgAssert(tf_idx == tf_data_len, "invalid framebuilder state");
idle_len = 0;
chEvtWaitAnyTimeout(RFPktAvailable, TIME_IMMEDIATE);
state = FB_STATE_UNINIT;
continue;
}
}*/
break;
default:
chDbgAssert(false, "invalid framebuilder state");
Expand Down
2 changes: 2 additions & 0 deletions ElysiumCode/ccsds/sdlp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "core.h"
#include "sx1278.h"
#include "sx1212.h"
#include "nl.h"
#include "registers.h"
#include "errors.h"
Expand All @@ -20,6 +21,7 @@

/* TODO move this to SPP */
#define SPP_IDLE_DATA 0xAA
#define SDLP_IDLE_PACKET_LENGTH 1024

typedef enum {
DLL_STATE_HDR,
Expand Down