Go Down

Topic: Bridge.get on CPU side stops at first \0 ? (Read 1 time) previous topic - next topic

NewLine

I am using put on the MCU side and get on the CPU side.

What I put is a concatenation of fixed (max) length strings. E.g. the first character is an ID, the next 16 a command and the next 16 a value. Not all commands are 16 chars long. So it could be that what I put on the MCU side is:

AmyCommand\0\0\0\0\0\0\0myValue\0\0\0...

(ID is A, command = myCommand extended with \0 to 16 chars, value is myValue, etc..).

Now on the CPU side when I do a get I only receive AmyCommand. So it seems that although I did put 33 characters, what I get is limited to everything until the first \0.

Is this indeed the intention? It would mean I have to padd the command with somthing else than \0.
I would think the BridgeClass should know the length of each data in its store and return that, without interpreting the content of the data.


mamu

Hm, using \0 for filling char in C strings is no good idea because \0 means terminating char.

NewLine

It is exactly what strncpy does. I think it is the most obvious filler.

PCWorxLA


It is exactly what strncpy does. I think it is the most obvious filler.
Not for your case. The bridge is handling the stuff as C strings, and when handling your whole string, including the \0 as fillers, it will rightfully cut the transmission at the first \0.
Use a blank (or tab for that matter) and separate by white space on the receiving end...

Ralf

mamu

#4
Dec 11, 2013, 06:31 am Last Edit: Dec 11, 2013, 06:37 am by mamu Reason: 1

It is exactly what strncpy does. I think it is the most obvious filler.

Yep but making it end after the first \0. Check using strlen.
Maybe using string[] or char[][] would be an option?

OttoF

i use the # as seperator without any problems

001#123#123#

on php side
explode("#",$value)

on mega
strtok(value,"#")

i use this to read



NewLine

I see now, it is the MCU side that is actually cutting it after the first \0.
I am too used to work with C++ I guess....

Go Up