code d'envoie de trame
Dependencies: mbed ConfigFile
Fork of app4-router by
Revision 2:bbe1253008e6, committed 2014-02-22
- Comitter:
- trixrabbit
- Date:
- Sat Feb 22 23:46:06 2014 +0000
- Parent:
- 1:568707763458
- Child:
- 3:ef0e12857e30
- Commit message:
- samedi apres-midi
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Feb 22 19:26:05 2014 +0000 +++ b/main.cpp Sat Feb 22 23:46:06 2014 +0000 @@ -1,10 +1,58 @@ #include "mbed.h" +#include <string> + + +#define ACCEL 0x01 +#define PUSHBOUTON 0x02 DigitalOut myled(LED1); DigitalOut myled2(LED2); DigitalOut reset(p8); Serial pc(USBTX, USBRX); Serial xbee(p13, p14); +string data = "allo bonjour"; + + // 7E 00 0F 10 01 00 13 A2 00 40 8B 41 98 00 00 00 00 33 62 + // 7E 00 10 10 01 00 13 A2 00 40 8B 41 98 00 00 00 00 33 33 2F + + void checksum() +{ + +} +void xbee_transmit(char type, string data) +{ + char checkSum = 0; + char size = data.length() + 0x0E; //0x0E + data type + nombre de data = 0x0F + nombre de data + xbee.putc(0x7E); // start delimeter + xbee.putc(0x00); // length + xbee.putc(size); // length + + xbee.putc(0x10); // frame type + xbee.putc(0x01); // frame ID + xbee.putc(0x00); // adress MAC debut + xbee.putc(0x13); // | + xbee.putc(0xA2); // | + xbee.putc(0x00); // | + xbee.putc(0x40); // | + xbee.putc(0x8B); // | + xbee.putc(0x41); // | + xbee.putc(0x98); // adress MAC fin + xbee.putc(0x00); // dest. adress network + xbee.putc(0x00); // dest. adress network + xbee.putc(0x00); // broadcast radius + xbee.putc(0x00); // option + checkSum = checkSum + 0x10 + 0x01 + 0x00 + 0x13+ 0xA2 + 0x00 + 0x40 + 0x8B +0x41 + 0x98 + 0x00 + 0x00 + 0x00 + 0x00; + //data type + for (int i=0;i<data.length();i++) //data + { + xbee.putc(data[i]); + checkSum += data[i]; + } + checkSum = 0xff - checkSum; + pc.printf(" check sum = %x" , checkSum); + xbee.putc(checkSum); // checksum + +} int main() { @@ -17,7 +65,11 @@ myled2 = 0; while(1) { - if(xbee.readable()) + wait(4); + xbee_transmit(ACCEL, data); + + + /* if(xbee.readable()) { pc.putc(xbee.getc()); myled2 = ! myled2; @@ -26,6 +78,7 @@ { xbee.putc(pc.getc()); myled = ! myled; - } + }*/ } } +