Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple instances with different frame structure? #21

Open
asmwarrior opened this issue Dec 17, 2019 · 3 comments
Open

multiple instances with different frame structure? #21

asmwarrior opened this issue Dec 17, 2019 · 3 comments

Comments

@asmwarrior
Copy link

Hi, I see in the readme file, it said:

TinyFrame is re-entrant and supports creating multiple instances with the limitation that their structure (field sizes and checksum type) is the same.

In my C++ desktop application, I have use the TinyFrame library for both UART and Socket communication. In Socket, I would like CRC disabled(Because this will save a lot of computation in the target ARM based circuit board) and in UART I would like CRC enabled. Is it possible?

Any workaround about this?
For example, maybe, I can create two namespaces, and wrap those .h and .c files in different namespaces?
Or, I just have to rename all the C global functions for another frame structure?
Thanks.

@MightyPork
Copy link
Owner

Hi, unfortunately, as you already found, this isn't possible in the current implementation. Frame structure changes the typedefs and there are ifdefs to choose the checksum variant as well.

One could change it to use uint32_t for all checksums etc, and choose the checksum implementation dynamically ... at the cost of code size and performance. I don't want to merge that, but we could have two variants in the repository to choose from, that'd be fine with me. (I also wanted to add #19, that's a very good idea, but the author didn't finish it and it seems abandoned...).

For the record, I used CRC over USB before, despite USB having native checksums, and it helped me track bugs that mangled the data frames. The algorithms are fast, maybe check if the slowdown is really noticeable for you first.

I'm not too familiar with C++, see if you get it working with the namespaces. I'm afraid there's no easy trick here..

@asmwarrior
Copy link
Author

Hi, thanks for the reply, and it looks like C++ namespace is a good way to solve this issue.

I have attach the source files, and you can see I can use the two instance of different TinyFrame.
And the result is:

print from Uart: 01 80 00 00 04 00 22 d8 ce 55 41 52 54 47 7d
print from Socket: 01 80 00 00 06 00 22 53 6f 63 6b 65 74

The way I use is to paste the content of the TF_Config.h file to the TinyFrame.h. And then I make two TinyFrame.h files and two TinyFrame.cpp files, which have different C++ namespace.

The main.cpp and usage.cpp will use those different kinds of TinyFrame structures.

two-TF.zip

@asmwarrior
Copy link
Author

asmwarrior commented Apr 25, 2024

I see a fork for C++ implementation of the TinyFrame which should solve this issue.

marcelnabeck/TinyFramePlusPlus: Object-oriented implementation of TinyFrame in C++. — https://github.com/marcelnabeck/TinyFramePlusPlus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants