Help with SLIP encoding/decoding

Status
Not open for further replies.

jfhallst

Member
I keep trying to simplify this question to a point that will get me a response... so here's another try.

I need to SLIP encode a 2-4 byte message on the Teensy and send it to an esp8266, where I need to decode it so I can turn it into an OSC message. the OSC encoding/sending I've got figured out, it's the SLIP (particularly the ESC, ESC_ESC, ESC_END stuff) that confuses me.

The data will coming from various sensors on the teensy end, each of which will be given a sensor number and up to 3 data bytes (e.g. an accelerometer plus xyz) Could someone show me the Arduino code required to SLIP-encode 4 numbers (let's say 1,500,200,100) into a single packet, followed by the code required decode them on the receiving end so I'll have access to the individual numbers.

Alternatively, is there a way to encode the data into an OSC message from the get-go and transmit that to the ESP8266?

Sorry to be such a dufus... I'm a long time Max/MSP programmer who's just starting out with Arduino code and I'm struggling to learn the syntax.
 
Why do you have to use SLIP?
If you send the data as ASCII, all you need to do is send "1,500,200,100" immediately followed by the SLIP END (0xC0) character. The SLIP protocol didn't require any special character at the start of the message but it is suggested in the RFC that the message start with an END character as well. The advantage to sending ASCII is that you can guarantee that the SLIP ESC and END characters cannot occur in the message and therefore you don't have to examine the message to ensure that those two characters are escaped. Also, your receiving end only has to look for END.
If you want to send the numbers as binary, for example as four 16-bit numbers, then you must examine each character of the message and if either ESC or END happen to occur, you must add the appropriate escape character. Of course, that also requires that the receiving end be written to handle escape characters in the message.

Pete
 
I'm not a C programmer and I already have the arduino SLIP libraries (SLIPencodedSerial) . All I want is an example of how to SLIP encode a multi-byte message and an example of how to decode that same message so I have access to its original parts. Call me slow, but I'm the sort of person who needs a straightforward example in order to get a toehold on the syntax. If this is the wrong place to be asking for something like this, someone please just let me know.
 
I'm not a C programmer and I already have the arduino SLIP libraries (SLIPencodedSerial) . All I want is an example of how to SLIP encode a multi-byte message and an example of how to decode that same message so I have access to its original parts. Call me slow, but I'm the sort of person who needs a straightforward example in order to get a toehold on the syntax. If this is the wrong place to be asking for something like this, someone please just let me know.

So you need an example how to use the library ? (sry, that's a bit unclear)
 
So you need an example how to use the library ? (sry, that's a bit unclear)
Yes! I'm reading sensor values with no problem on the Teensy. I've got the ESP8266 sending OSC via udp and it's arriving at the IP destination just fine. I'm able to communicate between the ESP8266 and the Teensy. All I need to make life worth living is to figure out how to package the sensor data from the Teensy in such a way that I can send message packets (sensor number + 1-3 data bytes) from the Teensy to the ESP8266, where they will get formatted into OSC messages. The code examples I've found have either been too complicated for my little pea brain or lack any documentation. Any help would be hugely appreciated.
 
I have made a small library for creating OSC messages: https://github.com/sstaub/OSC

I'm very grateful for the help! Unfortunately, I'm already able for format the OSC message using the OSCmessage library from CNMAT. The problem I'm having is transferring multi-byte sensor value collections from Teensy to ESP8266 so I can format them into OSC on the ESP8266 and send them via UDP from there.

Since I can use numeric values to designate both the sensor and it's data, could it be so simple as to send them from the teensy to the ESP8266 as an array? And if so, how would I take it apart on the ESP8266 end? (if this is embarrassingly naive, please don't laugh!)

int myAccelVals [4]; // declare array for accelerometer

//fill array with sensor values

myAccelVals[0] = 1; //code for accelerometer
myAccelVals[1] = 100; //code for x value
myAccelVals [2] = 200; //code for y value
myAccelVals [2] = 300; //code for z value

serial.write (myAccelVals,4);
 
Lots of hammers for that problem, and several libraries that do that but the basic way is to just have a parser doing something like:

read serial bytes until key value is found (I think in your case '1' - though watch for 'ascci character 1' and 'hex 0x01')
(optional) - next byte reports length
Sit in a loop waiting for new bytes to be available, adding them to the array until it's full - have a timeout to abort if too long passes between bytes and go back to step one.
(optional) finish with a checksum or just end code - if used then work out what to do if this check indicates a problem

There are many things wrong with the above concept, hence why people use libraries that include better error checking etc but that's the basic structure of what they are doing.

Another option that may be useful is to use string conversions to turn your numbers into human readable values so your serial sends look like 'x=340' followed by an end line. Takes more work to setup and much less efficient but easier to see what is going on, and you can fire web searches at 'arduino string/float conversion' and similar to make the problem easier to search for.
 
Last edited:
Status
Not open for further replies.
Back
Top