Stu
extern "C" {
#include <pb_encode.h>
#include <pb_decode.h>
#include <message4.pb.h>
}
void sendMessage(const void * mOutgoing){
uint8_t buffer[32];
pb_ostream_t ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
pb_encode(&ostream, block_fields, mOutgoing);
size_t num_written = ostream.bytes_written;
Serial.write(192);
for(int i=0; i < num_written; i++){
Serial.write(buffer[i]); // extra work required for the real protocol
}
Serial.write(192);
}
void setup(){
Serial.begin(9600);
}
void loop(){
static int counter = 0;
block mMessage;
mMessage.mytestint = counter++;
if (counter == 100) counter = 0;
const void * pTest = &mMessage;
// comment out the next 2 lines and it doesn't work
uint8_t sendbuffer[32];
pb_ostream_t sendostream = pb_ostream_from_buffer(sendbuffer,
sizeof(sendbuffer));
// but what have they got to do with the following call?
sendMessage(pTest);
}
Michael,
I'll happily contribute my SLIP implementation (once it works of course :-)). I've alse looked at both PPP and Varint delimited messages. Google's protocol buffer c++ api, which I'm using at the other end of the wire, doesn't make using varint delimited messages easy. I've implemented/wrapped this myself but the code was starting to bloat. Something to come back to later.
I did look at lwip but if it needs 10k + RAM and 40K ROM it's not going to fit on my Arduino UNO at 2k RAM and 32k ROM without some reworking. I also looked at an Arduino library (SerialIP) which seems to work nicely but is still large and probably overkill.
So nothing is dismissed, I just thought that SLIP would make an easy starting point! (arrggh).
Petteri,
Thank you.
Making the uint_t buffer static had no effect on my program - other than to make it better.
Making the message static broke the code as well (the function is called but it doesn't write any protocol between my 2 enclosing END markers).
I agree with your thought about overflowing stacks causing wierd issues but this seems like a tiny fragment and it breaks when I remove stuff from the stack not when I add it.
Given your sanity check, I suspect that this is something Arduino. This is my first real go with Arduino so I could well be missing something really simple.
Thanks for the links. Varints are quite useful for parsing / knowing when one has been received fully, but I was finding that they can be a bit of a pain if the sender and receiver get of of sync with each other. Your PPP suggestion is good - it would save me hand crafting PPP-like behaviour.
As it happens, my next line of development in my project was probably to migrate away from the serial port I'm using at the moment - to ethernet. If I do this on arduino, I'll probably use a hardware shield which fully implements the full tcp/ip stack. I thought this would be a gentle introduction for myself - how wrong could I be...
Stu