FEP interrupt, response, ring buffer
Dependents: 087_myFEP_TX 087_myFEP_RX
Diff: FEP.cpp
- Revision:
- 2:aa9a344a42a8
- Parent:
- 0:b01dc5fd59bc
- Child:
- 3:12dcc46fb9dc
diff -r a4103af46277 -r aa9a344a42a8 FEP.cpp --- a/FEP.cpp Sat Oct 09 11:54:44 2021 +0000 +++ b/FEP.cpp Sat Oct 09 13:35:40 2021 +0000 @@ -17,20 +17,20 @@ void myFEP::ReceiveBytes() { if (bufindex > 256) bufindex %= 256; - buffer[bufindex] = getc(); // データ取得 + buffer[bufindex] = getc(); // get data - if ( (bufindex > 0) && (!strcmp((char*)(buffer + bufindex - 1) , "\r\n")) ) { // <CR><LF>確認 - CheckData(); // 集計 + if ( (bufindex > 0) && (!strcmp((char*)(buffer + bufindex - 1) , "\r\n")) ) { // <CR><LF> + CheckData(); // check message } } void CheckData() { - uint8_t temp=0, length=0; // temp:配列の位置 length:配列の長さ + uint8_t temp=0, length=0; // temp:where's array length:length of array for (uint16_t i=0; i<256; i++) { temp = (256 + bufindex - i) % 256; - if ( !str((char*)(buffer + temp) , "RBN") ) { // ヘッダ確認 - length = ctoi(buffer[temp+6])*100 + ctoi(buffer[temp+7])*10 + ctoi(buffer[temp+8]); // メッセージの長さを計算 + if ( !str((char*)(buffer + temp) , "RBN") ) { // check header + length = ctoi(buffer[temp+6])*100 + ctoi(buffer[temp+7])*10 + ctoi(buffer[temp+8]); // calculate length of message for (int j = 9; j < length+9; j++) { retdata[j-9] = buffer[temp+j]; // } @@ -52,18 +52,18 @@ uint8_t SendData(uint8_t *data, uint8_t length) { if(length > 128) return 1; - uint8_t sendindex; // dataの添え字用の変数 - printf("@TBN%03d%03d", addr, length); // コマンド送信 + uint8_t sendindex; // index of 'data' + printf("@TBN%03d%03d", addr, length); // send comand for (sendindex=0; sendindex<length; sendindex++) { - putc(data[sendindex]); // データ部分送信 + putc(data[sendindex]); // send message } printf("\r\n"); // <cr><lf> - return GetResponse(); // 応答確認 + return GetResponse(); // check response } uint8_t GetResponse() { - char res[4]; // 応答格納用変数 + char res[4]; // array of storing response uint8_t resindex=0; // while (1) { res[resindex] = getc();