Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:318ad4f36a90
- Parent:
- 0:25f9d14d01bd
- Child:
- 2:c6d623a30254
- Child:
- 3:5010d20e681f
--- a/main.cpp Thu Feb 09 03:27:58 2017 +0000
+++ b/main.cpp Mon Feb 13 17:42:31 2017 +0000
@@ -1,6 +1,8 @@
#include "mbed.h"
#define FRAMEDELIMITER 0x7E
+#include "rtos.h"
+// 4269
DigitalOut resetswitch(p8);
Serial xbee(p13, p14);
Serial pc(USBTX, USBRX);
@@ -68,23 +70,25 @@
//assert
char len_msb = xbee.getc();
char len_lsb = xbee.getc();
+
int len = ((int) len_msb << 4) + (int) len_lsb;
char frame_data[len];
int i = 0;
pc.printf("%d : ", len);
while (i < len)
{
- wait(0.2);
if (xbee.readable())
- {
+ {
frame_data[i] = xbee.getc();
printhexa(frame_data[i]);
+ i++;
}
- i++;
}
char checksum = xbee.getc();
// Verify checksum
+ pc.printf(" checksum = ");
+ printhexa(checksum);
pc.printf("\r\n");
}
@@ -101,7 +105,7 @@
cmdtosend[3] = 0x08;
cmdtosend[4] = 0x52;
cmdtosend[5] = 'S'; // 0x53
- cmdtosend[6] = 'H'; // 0x48
+ cmdtosend[6] = 'L'; // 0x48
cmdtosend[7] = 0xFF - (cmdtosend[3]+cmdtosend[4]+cmdtosend[5]+cmdtosend[6]);
while (i < 8)
@@ -110,15 +114,15 @@
i++;
}
- GetATResponse();
- pc.printf("Sending second\r\n");
+ wait(0.5);
+ i = 0;
cmdtosend[0] = FRAMEDELIMITER;
cmdtosend[1] = 0x00;
cmdtosend[2] = 0x04;
cmdtosend[3] = 0x08;
cmdtosend[4] = 0x52;
cmdtosend[5] = 'S'; // 0x53
- cmdtosend[6] = 'H'; // 0x4C
+ cmdtosend[6] = 'H'; // 0x48
cmdtosend[7] = 0xFF - (cmdtosend[3]+cmdtosend[4]+cmdtosend[5]+cmdtosend[6]);
while (i < 8)
@@ -126,28 +130,39 @@
xbee.putc(cmdtosend[i]);
i++;
}
- pc.printf("Sent\r\n");
- GetATResponse();
}
+void xbee_reader()
+{
+ while(1)
+ {
+ if (xbee.readable())
+ {
+ GetATResponse();
+ }
+ wait(0.001);
+ }
+}
+
+void tick()
+{
+ myled = !myled;
+}
+
int main() {
+ Thread thread(xbee_reader);
+ Ticker ticker;
+ ticker.attach(&tick, 1);
pc.printf("\r\n");
- myled = 0;
resetswitch = 0;
wait(0.4);
resetswitch = 1;
- //StartAPIMode();
- wait(1);
- GetATResponse();
- GetATResponse();
+ wait(3);
+
ReadSerial();
- myled = 1;
while(1) {
- // Attend une réception de signal
- GetATResponse();
- myled = !myled;
}
}
\ No newline at end of file