simulate data accoridng to #21
Diff: main.cpp
- Revision:
- 43:c179810e1a75
- Parent:
- 32:0b58d21e87d6
- Child:
- 44:3b8a8dba7998
--- a/main.cpp Thu Jun 22 09:00:02 2017 +0100
+++ b/main.cpp Mon May 27 07:14:08 2019 +0000
@@ -1,12 +1,79 @@
#include "mbed.h"
+
+
+#define TYPE_MEASEUREMENT 0xA
+
+
+#define ST_TX D1
+#define ST_RX D0
+#define RTS D15
+
+
+
DigitalOut led1(LED1);
+Serial pc(USBTX, USBRX, NULL, 115200); // tx, rx
+DigitalIn pin_rts(RTS);
+DigitalIn button(USER_BUTTON);
+Serial st_uart(ST_TX, ST_RX, NULL, 115200); // tx, rx
-// main() runs in its own thread in the OS
+
+
+uint8_t test_vector[10000];
+
+
+void uart_busy_check(void)
+{
+ while (pin_rts == 0)
+ {
+ // do nothing
+ led1=0;
+ }
+}
+
+
+void write_sample(uint16_t sample)
+{
+ led1=1;
+
+ uint8_t byte_little = ((uint8_t *)&sample)[0];
+ uint8_t byte_big = ((uint8_t *)&sample)[1];
+
+ st_uart.putc(byte_little);
+ st_uart.putc(byte_big);
+
+ uart_busy_check();
+}
+
int main() {
- while (true) {
- led1 = !led1;
- wait(0.5);
+
+ led1=1;
+ pc.printf("About to simulate data over the second uart D1 (Tx), D0 (Rx) - **Press button**... \n\r");
+
+ while (!button)
+ {
+
+ }
+
+ pc.printf("Button pressed! Starting...");
+
+ while(1)
+ {
+
+ /* simulate data */
+ for (uint16_t i=9; i>=0; i--)
+ {
+ st_uart.putc(TYPE_MEASEUREMENT);
+ st_uart.putc(0x00); /* CRC */
+ st_uart.putc(i); /* INDEX (decrementing) */
+ st_uart.putc(5000); /* SIZE OF SAMPLES 5000 == 10000 bytes */
+
+ for (int i=0; i<5000; i++)
+ {
+ write_sample(i);
+ }
+
+ }
+
}
}
-