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.
serial.cpp
- Committer:
- kieftea
- Date:
- 2016-12-02
- Revision:
- 2:4fb5a8d15f9c
- Child:
- 3:655f4fed48d7
File content as of revision 2:4fb5a8d15f9c:
#include "mbed.h"
#include "rtos.h"
#include <string>
#include <sstream>
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Serial pc(USBTX, USBRX);
Thread *RX_THREAD_POINTER;
string test;
string* paramArray = new string[25];
int index=0;
// Rx Interupt routine
void Rx_interrupt(void){
pc.attach(NULL); // Disable Rx interrupt
(*RX_THREAD_POINTER).signal_set(0x1); // dereference of RX_THREAD_POINTER
}
// Read received chars from UART
void rx_thread(void const *argument){
while (true) {
// Signal flags that are reported as event are automatically cleared.
Thread::signal_wait(0x1);
while (pc.readable()) {
//pc.putc(pc.getc()); // read data from UART
//pc.printf("\r\nInput: \r\n");
stringstream ss;
char temp;
temp = pc.getc();
//pc.putc(temp);
while (temp != '*'){
ss << temp;
temp = pc.getc();
//pc.putc(temp);
}
ss >> test;
if(index<24){
//in_Array[i] = temp;
//pc.printf("%s\r\n", test);
//pc.printf("\r\n");
led2=!led2;
paramArray[index++] = test;
} else {
//i = 0;
pc.attach(&Rx_interrupt);
//return;
}
}
pc.attach(&Rx_interrupt); // Enable Rx interrupt
}
}
string* recieve(){
paramArray = new string[24];
index=0;
Thread t_rx(rx_thread);
RX_THREAD_POINTER = &t_rx; // Set thread pointer as globally-accessible
t_rx.set_priority(osPriorityHigh);
pc.attach(Rx_interrupt);
//pc.printf("\r\nStart\r\n");
while(test != "DONE"){
led1=!led1;
//pc.printf("%s\r\n",test);
Thread::wait(1000);
}
return paramArray;
}
void send(string input){
while(pc.writeable()){
pc.printf("%s\r\n", input);
}
}