ichinoseki_Bteam_2019 / UART
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CSV.cpp Source File

CSV.cpp

00001 #include "mbed.h"
00002 #include "CSV.h"
00003 
00004 CSV::CSV(PinName TX, PinName RX, int bps) : myserial(TX, RX)
00005 {
00006     myserial.baud(bps);
00007     myserial.attach(this, &CSV::_serialEvent, Serial::RxIrq);
00008     dataIndex = 0;
00009 }
00010 
00011 void CSV::_serialEvent()
00012 {
00013     rcvData[dataIndex] = myserial.getc();
00014     if(rcvData[dataIndex] != '\n')
00015         dataIndex++;
00016     else
00017     {
00018         rcvData[dataIndex] = '\0';
00019         dataIndex = 0;
00020         valueData[0] = atoi(strtok(rcvData, ","));
00021         int i = 1;
00022         char *tmp;
00023         do
00024         {
00025             tmp = strtok(NULL, ",");
00026             valueData[i++] = atoi(tmp);
00027         }while(tmp != NULL);
00028     }
00029 }
00030 
00031 int CSV::getValue(int num)
00032 {
00033     return valueData[num];
00034 }