Help - Building a packet for W/L transmission
using cheap rf wireless modules , virtualwire library i`m trying send data 1 arduino can read in data processing sketch. figured best way decide on specific format , make packet before sending it.
i had decided on packet starting 1 command byte, followed number of data bytes, until comes terminating character.
the examples in virtualwire documentation sends strings this..
my problem building string send. lets want send sonar range result. first byte s, distance integer follows, add terminator. attempt..
but if try rfpacketout('a', 134); serial , w/l output both blank.
i don`t think know enough strings/characters/pointers etc know whats going on :-/
i had decided on packet starting 1 command byte, followed number of data bytes, until comes terminating character.
the examples in virtualwire documentation sends strings this..
code: [select]
const char *msg = "hello";
vw_send((uint8_t *)msg, strlen(msg));my problem building string send. lets want send sonar range result. first byte s, distance integer follows, add terminator. attempt..
code: [select]
void rfpacketout(char commandchar, int data)
{
char* packet;
char* buffer;
packet[0] = commandchar;
itoa(data, buffer, 10);
strcat(packet, buffer);
strcat(packet, "\n");
vw_send((uint8_t *)packet, strlen(packet));
serial.println(packet);
}but if try rfpacketout('a', 134); serial , w/l output both blank.
i don`t think know enough strings/characters/pointers etc know whats going on :-/
code: [select]
char* packet;
char* buffer;
packet[0] = commandchar"packet" doesn't point - haven't initialised it, declared it, "packet
- " (or "*packet") anywhere - 1 of main dangers of c programming.
same goes "buffer".code: [select]
typedef struct {
byte command;
char buffer [11]; //don't forget account terminator.
} packet_t;
..
..
packet_t packet;
packet.command = commandchar;
itoa(data, packet.buffer, 10);
vw_send((uint8_t *)&packet, sizeof(packet));
might 1 solution start playing with.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Help - Building a packet for W/L transmission
arduino
Comments
Post a Comment