Add re-entrancy support / multiple instances (#9)
* done with changes but now segfaulting * fixed the bug * fix some bad indents * some cleanings * updated readme
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
CFILES=../utils.c ../../TinyFrame.c
|
||||
INCLDIRS=-I. -I.. -I../..
|
||||
CFLAGS=-O0 -ggdb --std=gnu99 -Wno-main -Wall -Wextra $(CFILES) $(INCLDIRS)
|
||||
CFLAGS=-O0 -ggdb --std=gnu99 -Wno-main -Wno-unused -Wall -Wextra $(CFILES) $(INCLDIRS)
|
||||
|
||||
run: test.bin
|
||||
./test.bin
|
||||
|
||||
+36
-35
@@ -3,63 +3,64 @@
|
||||
#include "../../TinyFrame.h"
|
||||
#include "../utils.h"
|
||||
|
||||
TinyFrame *demo_tf;
|
||||
|
||||
/**
|
||||
* This function should be defined in the application code.
|
||||
* It implements the lowest layer - sending bytes to UART (or other)
|
||||
*/
|
||||
void TF_WriteImpl(const uint8_t *buff, size_t len)
|
||||
void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, size_t len)
|
||||
{
|
||||
printf("--------------------\n");
|
||||
printf("\033[32mTF_WriteImpl - sending frame:\033[0m\n");
|
||||
dumpFrame(buff, len);
|
||||
printf("--------------------\n");
|
||||
printf("\033[32mTF_WriteImpl - sending frame:\033[0m\n");
|
||||
dumpFrame(buff, len);
|
||||
|
||||
// Send it back as if we received it
|
||||
TF_Accept(buff, len);
|
||||
// Send it back as if we received it
|
||||
TF_Accept(tf, buff, len);
|
||||
}
|
||||
|
||||
/** An example listener function */
|
||||
TF_Result myListener(TF_Msg *msg)
|
||||
TF_Result myListener(TinyFrame *tf, TF_Msg *msg)
|
||||
{
|
||||
dumpFrameInfo(msg);
|
||||
return TF_STAY;
|
||||
dumpFrameInfo(msg);
|
||||
return TF_STAY;
|
||||
}
|
||||
|
||||
TF_Result testIdListener(TF_Msg *msg)
|
||||
TF_Result testIdListener(TinyFrame *tf, TF_Msg *msg)
|
||||
{
|
||||
printf("OK - ID Listener triggered for msg!\n");
|
||||
dumpFrameInfo(msg);
|
||||
return TF_CLOSE;
|
||||
printf("OK - ID Listener triggered for msg!\n");
|
||||
dumpFrameInfo(msg);
|
||||
return TF_CLOSE;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
TF_Msg msg;
|
||||
const char *longstr = "Lorem ipsum dolor sit amet.";
|
||||
TF_Msg msg;
|
||||
const char *longstr = "Lorem ipsum dolor sit amet.";
|
||||
|
||||
// Set up the TinyFrame library
|
||||
TF_Init(TF_MASTER); // 1 = master, 0 = slave
|
||||
TF_AddGenericListener(myListener);
|
||||
// Set up the TinyFrame library
|
||||
demo_tf = TF_Init(TF_MASTER); // 1 = master, 0 = slave
|
||||
TF_AddGenericListener(demo_tf, myListener);
|
||||
|
||||
printf("------ Simulate sending a message --------\n");
|
||||
printf("------ Simulate sending a message --------\n");
|
||||
|
||||
TF_ClearMsg(&msg);
|
||||
msg.type = 0x22;
|
||||
msg.data = (pu8)"Hello TinyFrame";
|
||||
msg.len = 16;
|
||||
TF_Send(&msg);
|
||||
TF_ClearMsg(&msg);
|
||||
msg.type = 0x22;
|
||||
msg.data = (pu8) "Hello TinyFrame";
|
||||
msg.len = 16;
|
||||
TF_Send(demo_tf, &msg);
|
||||
|
||||
msg.type = 0x33;
|
||||
msg.data = (pu8)longstr;
|
||||
msg.len = (TF_LEN) (strlen(longstr)+1); // add the null byte
|
||||
TF_Send(&msg);
|
||||
msg.type = 0x33;
|
||||
msg.data = (pu8) longstr;
|
||||
msg.len = (TF_LEN) (strlen(longstr) + 1); // add the null byte
|
||||
TF_Send(demo_tf, &msg);
|
||||
|
||||
msg.type = 0x44;
|
||||
msg.data = (pu8)"Hello2";
|
||||
msg.len = 7;
|
||||
TF_Send(&msg);
|
||||
msg.type = 0x44;
|
||||
msg.data = (pu8) "Hello2";
|
||||
msg.len = 7;
|
||||
TF_Send(demo_tf, &msg);
|
||||
|
||||
msg.len = 0;
|
||||
msg.type = 0x77;
|
||||
TF_Query(&msg, testIdListener, 0);
|
||||
msg.len = 0;
|
||||
msg.type = 0x77;
|
||||
TF_Query(demo_tf, &msg, testIdListener, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user