simulate data accoridng to #21
main.cpp
- Committer:
- gorazdko
- Date:
- 2019-05-27
- Revision:
- 43:c179810e1a75
- Parent:
- 32:0b58d21e87d6
- Child:
- 44:3b8a8dba7998
File content as of revision 43:c179810e1a75:
#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
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() {
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);
}
}
}
}