![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
nulla
Diff: main.cpp
- Revision:
- 0:b40deb141f99
- Child:
- 1:fc463dd04a7f
diff -r 000000000000 -r b40deb141f99 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jul 27 15:52:55 2018 +0000 @@ -0,0 +1,112 @@ +#include "mbed.h" +#include "CAN3.h" +#include "mcp2515.h" +#include <string> +#include <algorithm> +using namespace std; + +RawSerial pc(USBTX,USBRX); +DigitalOut myled(LED1); +SPI spi(SPI_MOSI,SPI_MISO,SPI_SCK); +CAN3 can(spi,SPI_CS,PA_1); + +char data; +char vector[50]; + +void rxCallback(){ + data = char(pc.getc()); +} + +/*void sendID(const char* data){ + //pc.putc(data); + pc.puts(data); + pc.puts("\n"); +}*/ + +/*void sendID(const char* data1,const char* data2){ + //sprintf(temp,"%c,%c",data1,data2); + pc.puts(data1); + pc.puts(","); + pc.puts(data2); + pc.puts("-"); + //pc.puts("\n"); +}*/ + +int main() { + + bool start = false; + int i = 0; + int j = 0; + int k = 0; + int i_row = 0; + const char* FromStrToChar; + size_t n,pos; + string delimiter = ","; + string appoggio[n]; + char + can.frequency(125000); + CANMessage msg1; + bool leggi = false; + char id[1000]; + char payload[1000]; + + pc.attach(&rxCallback, RawSerial::RxIrq); + //TODO: trova un modo per uscire dal ciclo while della lettura CAN + while(true){ + + //rxCallback(); + + if(data == '+'){ + start = true; + myled = 1; + } + else if(data == '-'){ + leggi = false; + pc.puts("123?"); + //Invia tutte le frame can acquisite + /*for(k = 0; k < n; k++){ + FromStrToChar = appoggio[k].c_str(); //fa la conversione da string a char* + pc.puts(FromStrToChar); + }*/ + myled = 0; + exit(0); + } + else{ + if(start){ + if(data == '?'){ + leggi = true; + string str(vector); + n = count(str.begin(),str.end(),','); + string vett[n]; + pos = 0; + while((pos = str.find(',')) != string::npos){ + vett[i_row] = str.substr(0,pos); + appoggio[j] = vett[i_row]; + str.erase(0,pos+1); + i_row++; + j++; + } + + //begin CAN acquisition + while(leggi){ + if(can.read(&msg1)){ + if(msg1.id == vett[0] || msg1.id == vett[1]){ + //TODO: dichiara due char e poi fai conversione int-char + //pc.printf("Data read: %c from node %d\n\r",(char)msg1.data[0],msg1.id); + id = char(msg1.id); + payload = msg1.data[0]; + } + } + + } + else{ + vector[i] = data; + i++; + } + } + } + + } + + +}