UART Package with COBS

Dependents:   TWELITE_Slave_0001 TWELITE_Master_0001 TWELITE_Slave_0001 read_Pmod

UsaPack シリアル通信でパケット送受信をするライブラリ 構造体データのバイナリ化→COBS変換→送信→受信→COBS変換→構造体の解凍 までを行う

手順(送信側) [1] 送受信ピンとボードレートを設定 UsaPack master(tx_pin, rx_pin, baud); [2] 送りたいデータ群を構造体でまとめて値を詰める(intなど値型を1個だけ送ることも可能) struct pack { float f[10]; int d[3]; }; pack send_data; send_data.f[0] = 0.123f; ... [3] データ識別子をint型整数で好きな値に設定し(受信側とそろえる)構造体のアドレスを渡して送信 int address = 1234; master.Send(address, &send_data); [4] 一気にデータを流し込むとエラーを起こすのでSendした後は時間を置いてから次のSendを行うこと

手順(受信側) [1] 送受信ピンとボードレートを設定 UsaPack slave(tx_pin, rx_pin, baud); [2] 送信側と同じ構造体を用意する pack receive_data; [3] 送信側と同じデータ識別子と構造体のアドレスを設定してデータが来るのを待つ int address = 1234; slave.Subscribe(address, &receive_data); [4] 受信したら自動的にreceive_dataの内容が更新される

Revision:
7:bc00f60af715
Parent:
6:43078601fc5c
Child:
8:2c3cdcf1ae3a
--- a/UsaPack.hpp	Mon May 24 04:31:24 2021 +0000
+++ b/UsaPack.hpp	Mon May 31 16:40:55 2021 +0000
@@ -3,20 +3,21 @@
 
 #include "mbed.h"
 
+#define receive_size 256
+#define package_types 64
+#define send_size 256
+
 class UsaPack
 {
 private:
     Serial serial;
-    const int receive_size = 256;
     char receive_buffer[receive_size];
     volatile int receive_index;
-    const int package_types = 64;
     volatile int package_index;
     volatile int package_address[package_types];
     volatile int package_size[package_types];
     void* package_object[package_types];
     
-    const int send_size = 256;
     char send_buffer[send_size];
     volatile int send_index;
     volatile int send_end_index;