Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Fragmentation #100

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2dbfe61
log: force stdout flush for log_print_data
pnunes30 Oct 17, 2019
fa905c4
d7a: fix packet length when CRC is supported by hardware
pnunes30 Dec 23, 2019
68f2e45
fix Cortus build due to missing symbol regarding the d7ap_fs buffers
pnunes30 Feb 7, 2020
0891b83
d7asp: fix regression introduced by the commit f95d894
pnunes30 Jul 25, 2019
db343d2
fs: fix build when using default values like the PERMANENT_STORAGE_SIZE
pnunes30 Oct 6, 2020
5718b51
d7ap: fix warnings
pnunes30 Oct 6, 2020
b60c459
blockdevice: fix trace
pnunes30 Oct 14, 2020
9fecf05
fs: fix warnings
pnunes30 Oct 14, 2020
4c4cd95
alp_layer: fix uninitialised variable
pnunes30 Oct 14, 2020
c7d6670
alp_layer: free resp_command in case of unregistered interface
pnunes30 Oct 14, 2020
e909441
sensor apps: add FS initialisation
pnunes30 Oct 14, 2020
36826c8
d7asp: fix FIFO buffer size
pnunes30 Feb 12, 2021
0b0b94f
d7asp: fix bitmap search size
pnunes30 Feb 12, 2021
59cd704
d7asp: fix d7atp_ctrl flag in the response packet
pnunes30 Feb 12, 2021
10b8729
d7atp: fix start and Tl flag in D7ATP ctrl header
pnunes30 Feb 12, 2021
13ebdb7
d7asp: fix BITMAP byte count
pnunes30 Feb 12, 2021
1602ad6
d7atp: fix current_tl_received
pnunes30 Feb 26, 2021
fb4ea08
d7a: registration is only possible when the stack is completly initia…
pnunes30 Apr 24, 2020
d71e3ad
d7ap: introduce Te in d7ap_session_config_t structure
pnunes30 Oct 14, 2020
ab832d3
d7asp: remove alp payload terminology
pnunes30 Feb 12, 2021
01518f0
d7asp: introduce a retry counter per request
pnunes30 Feb 12, 2021
77e0b5f
d7asp: set TX duration for each request (used by TL computation)
pnunes30 Feb 12, 2021
552bbfb
[New feature] introduce the fragmentation feature
pnunes30 Feb 12, 2021
f52226d
sensor_without_alp: fragmentation test
pnunes30 Feb 12, 2021
b6d53e4
crc: extend crc computation to larger payloads
pnunes30 Mar 3, 2021
892b897
modem_interface: extend length byte to handle larger payloads
pnunes30 Mar 3, 2021
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
2 changes: 1 addition & 1 deletion stack/apps/gateway/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
IF(${MODULE_LORAWAN})
SET(libs alp d7ap d7ap_fs lorawan framework)
ELSE()
SET(libs alp d7ap d7ap_fs framework)
SET(libs alp d7ap framework d7ap_fs)
ENDIF()

APP_BUILD(NAME ${APP_NAME} SOURCES app.c LIBS ${libs})
2 changes: 1 addition & 1 deletion stack/apps/modem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
IF(${MODULE_LORAWAN})
SET(libs alp d7ap d7ap_fs lorawan framework)
ELSE()
SET(libs alp d7ap d7ap_fs framework)
SET(libs alp d7ap framework d7ap_fs)
ENDIF()

APP_BUILD(NAME ${APP_NAME} SOURCES modem.c LIBS ${libs})
1 change: 1 addition & 0 deletions stack/apps/sensor_action/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void bootstrap()
{
log_print_string("Device booted\n");

d7ap_fs_init();
d7ap_init();

alp_layer_init(NULL, false);
Expand Down
2 changes: 1 addition & 1 deletion stack/apps/sensor_without_alp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
IF(${MODULE_LORAWAN})
SET(libs d7ap d7ap_fs lorawan framework)
ELSE()
SET(libs d7ap d7ap_fs framework)
SET(libs d7ap framework d7ap_fs)
ENDIF()

APP_BUILD(NAME ${APP_NAME} SOURCES sensor_without_alp.c LIBS ${libs})
21 changes: 11 additions & 10 deletions stack/apps/sensor_without_alp/sensor_without_alp.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static d7ap_session_config_t d7ap_session_config = (d7ap_session_config_t){

void on_receive(uint16_t trans_id, uint8_t* payload, uint8_t len, d7ap_session_result_t result);
void on_transmitted(uint16_t trans_id, error_t error);
bool on_unsolicited_response(uint8_t* payload, uint8_t len, d7ap_session_result_t result);
bool on_unsolicited_response(uint8_t* payload, uint16_t len, d7ap_session_result_t result);

d7ap_resource_desc_t callbacks = {
.receive_cb = &on_receive,
Expand All @@ -83,17 +83,17 @@ uint8_t d7_client_id;

void execute_sensor_measurement()
{
// first get the sensor reading ...
int16_t temperature = 0; // in decicelsius. When there is no sensor, we just transmit 0 degrees
int8_t metadata[1024];

#if defined USE_HTS221
HTS221_Get_Temperature(hts221_handle, &temperature);
#endif

temperature = __builtin_bswap16(temperature); // convert to big endian before transmission
for (int i = 0, j = 0x30; i < 1024; i++)
{
metadata[i] = j++;
if (j == 0x3A)
j = 0x30;
}

uint16_t trans_id;
d7ap_send(d7_client_id, &d7ap_session_config, (uint8_t*)&temperature, sizeof(temperature), 0, &trans_id);
d7ap_send(d7_client_id, &d7ap_session_config, metadata, sizeof(metadata), 0, &trans_id);
}

void on_receive(uint16_t trans_id, uint8_t* payload, uint8_t len, d7ap_session_result_t result)
Expand All @@ -107,7 +107,7 @@ void on_transmitted(uint16_t trans_id, error_t error)
timer_post_task_delay(&execute_sensor_measurement, SENSOR_INTERVAL_SEC);
}

bool on_unsolicited_response(uint8_t* payload, uint8_t len, d7ap_session_result_t result)
bool on_unsolicited_response(uint8_t* payload, uint16_t len, d7ap_session_result_t result)
{
log_print_string("Unsolicited response received\n");
return false;
Expand All @@ -117,6 +117,7 @@ void bootstrap()
{
log_print_string("Device booted\n");

d7ap_fs_init();
d7ap_init();
d7_client_id = d7ap_register(&callbacks);

Expand Down
2 changes: 1 addition & 1 deletion stack/framework/components/crc/crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void update_crc(uint8_t x)
crc = crc_new;
}

uint16_t crc_calculate(uint8_t* data, uint8_t length)
uint16_t crc_calculate(uint8_t* data, uint16_t length)
{
crc = 0xffff;
uint8_t i = 0;
Expand Down
20 changes: 13 additions & 7 deletions stack/framework/components/fs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@

#if defined(FRAMEWORK_LOG_ENABLED) && defined(FRAMEWORK_FS_LOG_ENABLED)
#define DPRINT(...) log_print_string( __VA_ARGS__)
#define DPRINT_DATA(...) log_print_data(__VA_ARGS__)
#else
#define DPRINT(...)
#define DPRINT_DATA(...)
#endif

static fs_file_t files[FRAMEWORK_FS_FILE_COUNT] = { 0 }; // TODO do not keep all file metadata in RAM but use smaller MRU cache to save RAM
Expand Down Expand Up @@ -87,7 +89,7 @@ error_t fs_register_block_device(blockdevice_t* block_device, uint8_t bd_index)

uint32_t fs_get_address(uint8_t file_id) { return files[file_id].addr; }

void fs_init()
void fs_init(void)
{
if (is_fs_init_completed)
return /*0*/;
Expand All @@ -106,7 +108,7 @@ void fs_init()
DPRINT("fs_init OK");
}

int _fs_init()
int _fs_init(void)
{
uint8_t expected_magic_number[FS_MAGIC_NUMBER_SIZE] = FS_MAGIC_NUMBER;
uint32_t number_of_files;
Expand All @@ -126,6 +128,7 @@ int _fs_init()
#endif

assert(number_of_files < FRAMEWORK_FS_FILE_COUNT);
DPRINT("number_of_files: %ld", number_of_files);
for(int file_id = 0; file_id < FRAMEWORK_FS_FILE_COUNT; file_id++)
{
blockdevice_read(bd[FS_BLOCKDEVICE_TYPE_METADATA], (uint8_t*)&files[file_id],
Expand All @@ -146,12 +149,12 @@ int _fs_init()
bd_data_offset[files[file_id].blockdevice_index] += files[file_id].length;
}
}

return 0;
}

//TODO: CRC MAGIC
static int _fs_create_magic()
static int _fs_create_magic(void)
{
assert(!is_fs_init_completed);
uint8_t magic[] = FS_MAGIC_NUMBER;
Expand All @@ -169,6 +172,9 @@ static int _fs_verify_magic(uint8_t* expected_magic_number)
uint8_t magic_number[FS_MAGIC_NUMBER_SIZE];
memset(magic_number,0,FS_MAGIC_NUMBER_SIZE);
blockdevice_read(bd[FS_BLOCKDEVICE_TYPE_METADATA], magic_number, 0, FS_MAGIC_NUMBER_SIZE);

DPRINT("READ MAGIC NUMBER:");
DPRINT_DATA(magic_number, FS_MAGIC_NUMBER_SIZE);
if(memcmp(expected_magic_number, magic_number, FS_MAGIC_NUMBER_SIZE) != 0) // if not the FS on EEPROM is not compatible with the current code
return -EINVAL;

Expand All @@ -191,7 +197,7 @@ int _fs_create_file(uint8_t file_id, fs_blockdevice_types_t bd_type, const uint8
if (bd_type == FS_BLOCKDEVICE_TYPE_VOLATILE)
{
files[file_id].addr = bd_data_offset[bd_type];
bd_data_offset[bd_type] += length;
bd_data_offset[bd_type] += length;
}
else
{
Expand Down Expand Up @@ -221,7 +227,7 @@ int _fs_create_file(uint8_t file_id, fs_blockdevice_types_t bd_type, const uint8

blockdevice_program(bd[bd_type], current_data, current_address, remaining_length);
remaining_length = 0;
/* else if this is the starting block, only write untill the end of the first write_block */
/* else if this is the starting block, only write until the end of the first write_block */
} else if(current_address == files[file_id].addr) {
remaining_length -= bd[bd_type]->driver->write_block_size - (current_address & (bd[bd_type]->driver->write_block_size - 1));

Expand Down Expand Up @@ -303,7 +309,7 @@ int fs_write_file(uint8_t file_id, uint32_t offset, const uint8_t* buffer, uint3

} while (remaining_length > 0);

DPRINT("fs write_file (file_id %d, offset %d, addr %lu, length %d)\n",
DPRINT("fs write_file (file_id %d, offset %lu, addr %lu, length %lu)",
file_id, offset, files[file_id].addr, length);

return 0;
Expand Down
4 changes: 1 addition & 3 deletions stack/framework/components/log/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ __LINK_C void log_print_data(uint8_t* message, uint32_t length)
for( uint32_t i=0 ; i<length ; i++ )
{
printf(" %02X", message[i]);
//printf will enter an infinite loop when we enter to many characters without a newline character
if(((i % 100) == 0) && i)
printf("\n\r");
fflush(stdout);
}
}

Expand Down
29 changes: 16 additions & 13 deletions stack/framework/components/modem_interface/modem_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include "log.h"


#define RX_BUFFER_SIZE 256
#define RX_BUFFER_SIZE 512

#define TX_FIFO_FLUSH_CHUNK_SIZE 10 // at a baudrate of 115200 this ensures completion within 1 ms
#define TX_FIFO_FLUSH_CHUNK_SIZE 20 // at a baudrate of 115200 this ensures completion within 1 ms
// TODO baudrate dependent

static uart_handle_t* uart;
Expand All @@ -44,20 +44,21 @@ static fifo_t rx_fifo;

#define SERIAL_FRAME_SYNC_BYTE 0xC0
#define SERIAL_FRAME_VERSION 0x00
#define SERIAL_FRAME_HEADER_SIZE 7
#define SERIAL_FRAME_SIZE 4
#define SERIAL_FRAME_HEADER_SIZE 8
#define SERIAL_FRAME_SIZE_MSB 4
#define SERIAL_FRAME_SIZE_LSB 5
#define SERIAL_FRAME_COUNTER 2
#define SERIAL_FRAME_TYPE 3
#define SERIAL_FRAME_CRC1 5
#define SERIAL_FRAME_CRC2 6
#define SERIAL_FRAME_CRC1 6
#define SERIAL_FRAME_CRC2 7

#define MODEM_INTERFACE_TX_FIFO_SIZE 255
#define MODEM_INTERFACE_TX_FIFO_SIZE 512
static uint8_t modem_interface_tx_buffer[MODEM_INTERFACE_TX_FIFO_SIZE];
static fifo_t modem_interface_tx_fifo;
static bool request_pending = false;

uint8_t header[SERIAL_FRAME_HEADER_SIZE];
static uint8_t payload_len = 0;
static uint16_t payload_len = 0;
static uint8_t packet_up_counter = 0;
static uint8_t packet_down_counter = 0;
static pin_id_t uart_state_pin;
Expand Down Expand Up @@ -269,8 +270,9 @@ static void execute_state_machine()
*/
static bool verify_payload(fifo_t* bytes, uint8_t* header)
{
uint16_t payload_length = ((header[SERIAL_FRAME_SIZE_MSB] << 8) | header[SERIAL_FRAME_SIZE_LSB]);
static uint8_t payload[RX_BUFFER_SIZE - SERIAL_FRAME_HEADER_SIZE]; // statically allocated so this does not end up on stack
fifo_peek(bytes, (uint8_t*) &payload, 0, header[SERIAL_FRAME_SIZE]);
fifo_peek(bytes, (uint8_t*) &payload, 0, payload_length);

//check for missing packages
packet_down_counter++;
Expand All @@ -286,7 +288,7 @@ static bool verify_payload(fifo_t* bytes, uint8_t* header)
DPRINT("RX PAYLOAD: ");
DPRINT_DATA(payload, header[SERIAL_FRAME_SIZE]);

uint16_t calculated_crc = crc_calculate(payload, header[SERIAL_FRAME_SIZE]);
uint16_t calculated_crc = crc_calculate(payload, payload_length);

if(header[SERIAL_FRAME_CRC1]!=((calculated_crc >> 8) & 0x00FF) || header[SERIAL_FRAME_CRC2]!=(calculated_crc & 0x00FF))
{
Expand Down Expand Up @@ -352,7 +354,7 @@ static void process_rx_fifo(void *arg)
}
parsed_header = true;
fifo_skip(&rx_fifo, SERIAL_FRAME_HEADER_SIZE);
payload_len = header[SERIAL_FRAME_SIZE];
payload_len = ((header[SERIAL_FRAME_SIZE_MSB] << 8) | header[SERIAL_FRAME_SIZE_LSB]);
DPRINT("UART RX, payload size = %i", payload_len);
sched_post_task(&process_rx_fifo);
}
Expand Down Expand Up @@ -485,7 +487,7 @@ void modem_interface_init(uint8_t idx, uint32_t baudrate, pin_id_t uart_state_pi
modem_interface_transfer_bytes(&reboot_reason, 1, SERIAL_MESSAGE_TYPE_REBOOTED);
}

void modem_interface_transfer_bytes(uint8_t* bytes, uint8_t length, serial_message_type_t type)
void modem_interface_transfer_bytes(uint8_t* bytes, uint16_t length, serial_message_type_t type)
{
uint8_t header[SERIAL_FRAME_HEADER_SIZE];
uint16_t crc=crc_calculate(bytes,length);
Expand All @@ -496,7 +498,8 @@ void modem_interface_transfer_bytes(uint8_t* bytes, uint8_t length, serial_messa

header[SERIAL_FRAME_COUNTER] = packet_up_counter;
header[SERIAL_FRAME_TYPE] = type;
header[SERIAL_FRAME_SIZE] = length;
header[SERIAL_FRAME_SIZE_MSB] = ((length & 0xFF00) >> 8);
header[SERIAL_FRAME_SIZE_LSB] = (length & 0x00FF);
header[SERIAL_FRAME_CRC1] = (crc >> 8) & 0x00FF;
header[SERIAL_FRAME_CRC2] = crc & 0x00FF;

Expand Down
3 changes: 2 additions & 1 deletion stack/framework/hal/common/blockdevice_ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ blockdevice_driver_t blockdevice_driver_ram = {

static void init(blockdevice_t* bd) {
blockdevice_ram_t* bd_ram = (blockdevice_ram_t*)bd;
DPRINT("init RAM block device of size %i\n", bd_ram->size);
(void)bd_ram;
DPRINT("init RAM block device of size %i\n", bd_ram->base.size);
}

static error_t read(blockdevice_t* bd, uint8_t* data, uint32_t addr, uint32_t size) {
Expand Down
2 changes: 1 addition & 1 deletion stack/framework/inc/alp.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ typedef struct {
alp_itf_id_t itf_id;
uint8_t itf_cfg_len;
uint8_t itf_status_len;
error_t (*send_command)(uint8_t* payload, uint8_t payload_length, uint8_t expected_response_length, uint16_t* trans_id, alp_interface_config_t* itf_cfg);
error_t (*send_command)(uint8_t* payload, uint16_t payload_length, uint8_t expected_response_length, uint16_t* trans_id, alp_interface_config_t* itf_cfg);
interface_init init;
interface_deinit deinit;
bool unique; // TODO
Expand Down
2 changes: 1 addition & 1 deletion stack/framework/inc/crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include <stdint.h>

uint16_t crc_calculate(uint8_t* data, uint8_t length);
uint16_t crc_calculate(uint8_t* data, uint16_t length);

#endif /* CRC_H_ */

Expand Down
11 changes: 6 additions & 5 deletions stack/framework/inc/d7ap.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

#define ID_TYPE_IS_BROADCAST(id_type) (id_type == ID_TYPE_NBID || id_type == ID_TYPE_NOID)

#define D7A_PAYLOAD_MAX_SIZE 255 // TODO confirm this value when FEC and security are disabled
#define D7A_PAYLOAD_MAX_SIZE 233 // TODO confirm this value when FEC and security are disabled


typedef enum {
Expand Down Expand Up @@ -148,6 +148,7 @@ typedef struct {
typedef struct __attribute__((__packed__)) {
d7ap_session_qos_t qos;
uint8_t dormant_timeout;
uint8_t te;
d7ap_addressee_t addressee;
} d7ap_session_config_t;

Expand All @@ -157,7 +158,7 @@ typedef void (*d7ap_receive_callback)(uint16_t trans_id, uint8_t* payload, uint8
* @returns true when the unsolicited request will result in a response payload from the upper layer. If no response is expected
* the upper layer should return false, so the stack can respond with an ack immediately (if requested by origin).
*/
typedef bool (*d7ap_receive_unsolicited_callback)(uint8_t* payload, uint8_t len, d7ap_session_result_t result);
typedef bool (*d7ap_receive_unsolicited_callback)(uint8_t* payload, uint16_t len, d7ap_session_result_t result);
typedef void (*d7ap_transmitted_callback)(uint16_t trans_id, error_t error);

typedef struct{
Expand Down Expand Up @@ -192,9 +193,9 @@ void d7ap_stop(void);
*
* @param[in] desc pointer to the client resource
*
* @return the client Id
* @return the client Id (-1 when trying to register whereas the D7A stack is not initialised)
*/
uint8_t d7ap_register(d7ap_resource_desc_t* desc);
int8_t d7ap_register(d7ap_resource_desc_t* desc);


/**
Expand Down Expand Up @@ -232,7 +233,7 @@ uint8_t d7ap_get_payload_max_size(nls_method_t nls_method);
* @return an error (errno.h) in case of failure
*/
error_t d7ap_send(uint8_t clientId, d7ap_session_config_t* config, uint8_t* payload,
uint8_t len, uint8_t expected_response_len, uint16_t* trans_id);
uint16_t len, uint8_t expected_response_len, uint16_t* trans_id);


/**
Expand Down
2 changes: 1 addition & 1 deletion stack/framework/inc/d7ap_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool d7ap_fs_unregister_file_modified_callback(uint8_t file_id);
bool d7ap_fs_register_file_modifying_callback(uint8_t file_id, d7ap_fs_modifying_file_callback_t callback);
bool d7ap_fs_unregister_file_modifying_callback(uint8_t file_id);

void d7ap_fs_init();
void d7ap_fs_init(void);
int d7ap_fs_init_file(uint8_t file_id, const d7ap_fs_file_header_t* file_header, const uint8_t* initial_data);
int d7ap_fs_init_file_on_blockdevice(uint8_t file_id, uint8_t blockdevice_index, const d7ap_fs_file_header_t* file_header, const uint8_t* initial_data);

Expand Down
4 changes: 2 additions & 2 deletions stack/framework/inc/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#endif

#ifndef FRAMEWORK_FS_PERMANENT_STORAGE_SIZE
#define FRAMEWORK_FS_PERMANENT_STORAGE_SIZE 1900
#define FRAMEWORK_FS_PERMANENT_STORAGE_SIZE 2200
#endif

#ifndef FRAMEWORK_FS_VOLATILE_STORAGE_SIZE
Expand Down Expand Up @@ -87,7 +87,7 @@ typedef struct __attribute__((__packed__))
uint32_t addr;
} fs_file_t;

void fs_init();
void fs_init(void);
int fs_init_file(uint8_t file_id, fs_blockdevice_types_t bd_type, const uint8_t* initial_data, uint32_t initial_data_length, uint32_t length);
int fs_read_file(uint8_t file_id, uint32_t offset, uint8_t* buffer, uint32_t length);
int fs_write_file(uint8_t file_id, uint32_t offset, const uint8_t* buffer, uint32_t length);
Expand Down
Loading