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.
Fork of daplink-validation by
Revision 1:db2a55107c7e, committed 2015-09-11
- Comitter:
- c1728p9
- Date:
- Fri Sep 11 14:50:00 2015 +0000
- Parent:
- 0:c4a3bb148a79
- Child:
- 2:204ef796ee06
- Commit message:
- Create test program for daplink
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Sep 10 16:03:46 2015 +0000
+++ b/main.cpp Fri Sep 11 14:50:00 2015 +0000
@@ -1,34 +1,57 @@
#include "mbed.h"
+#include <stdio.h>
-DigitalOut myled1(LED1);
-DigitalOut myled2(LED2);
-DigitalOut myled3(LED3);
-//Serial pc(P0_6, P0_1);
Serial pc(USBTX, USBRX);
-float blink_time = 0.5;
+int main()
+{
+ uint32_t baud;
+ uint32_t count;
+ uint32_t index;
+ uint32_t val;
+ uint8_t str[64];
-int main() {
+ count = 0;
+ index = 0;
+
pc.baud(115200);
- myled1 = 1;
- myled3 = 1;
- myled2 = 1;
+ pc.printf("{init}");
while(1) {
- myled1 = 0;
- wait(blink_time);
- myled1 = 1;
- wait(blink_time);
-
- myled2 = 0;
- wait(blink_time);
- myled2 = 1;
- wait(blink_time);
-
- myled3 = 0;
- wait(blink_time);
- myled3 = 1;
- wait(blink_time);
- pc.printf("Some data\r\n");
-
+ while (1) {
+ val = pc.getc();
+
+ // Check for overflow. Leave space for
+ // a null terminating character
+ if (index >= sizeof(str) - 1) {
+ index = 0;
+ }
+
+ // Check for start of frame
+ if ('{' == val) {
+ index = 0;
+ }
+
+ // Check for end of frame
+ str[index] = val;
+ index++;
+
+ // Check for end of frame
+ if ('}' == val && index > 0) {
+ str[index] = 0;
+ count = sscanf((char*)str, "{baud:%i}", &baud);
+ }
+
+ // Echo back character
+ pc.putc(val);
+
+ // Set baud if there is a valid command
+ if (count == 1) {
+ wait(0.01f);
+ pc.baud(baud);
+ wait(0.01f);
+ pc.printf("{change}");
+ count = 0;
+ }
+ }
}
}
