Skip to content

marcoratto/DMFLib-Arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DMFLib (Dynamic Message Fragmentation Library for Arduino)

Introduction

When a message exceeds the maximum payload size of a single packet, it must be fragmented into multiple packets for transmission. The receiver then reassembles these packets to reconstruct the original message. Some protocols — such as LoRaWAN and MQTT-SN — require message fragmentation.

Purpose

This ANSI-C library for Arduino simplifies the process of message fragmentation and reassembly. The algorithm is illustrated in the following diagram:

Message Fragmentation

Features

Main features of the library:

  • Fully written in ANSI-C;
  • Only 1 additional byte is added to each chunk to maintain ordering;
  • Chunk size is not fixed and can change during fragmentation (useful in LoRaWAN communication with ADR);
  • The reassembler requires chunks to arrive in order;
  • No checksum added to the payload (e.g., CRC-32);
  • No padding added to chunks;
  • No dynamic memory allocation (malloc/free): the buffer must be allocated by the caller.

Test

This library has been successfully tested on the following hardware:

API Overview


Fragmenter

Initialization

fragmenter_t fragmenter;
fragmenter_init(&fragmenter, message, msg_len);

Fragment the message

while (fragmenter_has_more(&fragmenter)) {
    uint32_t chunk_size = fragmenter_next(&fragmenter, chunk, max_chunk_size);
    ...
}

Reassembler

Initialization

reassembler_t reassembler;
reassembler_ret_code = reassembler_init(&reassembler, buffer, max_buffer_size);

Reassemble the message

reassembler_ret_code = 0;
while (reassembler_ret_code != REASSEMBLER_COMPLETE) {
    reassembler_ret_code = reassembler_add_chunk(&reassembler, chunk, chunk_size);
    ...
}

About

DMFLib-Arduino (Arduino Message Fragmentation Library)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages