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.
Bcon.cpp@0:4e42396b06ed, 2021-10-16 (annotated)
- Committer:
- piroro4560
- Date:
- Sat Oct 16 12:39:09 2021 +0000
- Revision:
- 0:4e42396b06ed
make
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| piroro4560 | 0:4e42396b06ed | 1 | /** |
| piroro4560 | 0:4e42396b06ed | 2 | * @file Bcon.cpp |
| piroro4560 | 0:4e42396b06ed | 3 | * @brief Bcontroller送信用FEPライブラリ |
| piroro4560 | 0:4e42396b06ed | 4 | * @author 安澤瑠 |
| piroro4560 | 0:4e42396b06ed | 5 | * @date 21/10/15 |
| piroro4560 | 0:4e42396b06ed | 6 | */ |
| piroro4560 | 0:4e42396b06ed | 7 | #include "Bcon.h" |
| piroro4560 | 0:4e42396b06ed | 8 | |
| piroro4560 | 0:4e42396b06ed | 9 | Bcon::Bcon(PinName tx, PinName rx, uint8_t addr_, int baud) : |
| piroro4560 | 0:4e42396b06ed | 10 | RawSerial(tx, rx, baud) |
| piroro4560 | 0:4e42396b06ed | 11 | { |
| piroro4560 | 0:4e42396b06ed | 12 | addr = addr_; |
| piroro4560 | 0:4e42396b06ed | 13 | } |
| piroro4560 | 0:4e42396b06ed | 14 | |
| piroro4560 | 0:4e42396b06ed | 15 | int8_t Bcon::SendData(uint8_t *data) |
| piroro4560 | 0:4e42396b06ed | 16 | { |
| piroro4560 | 0:4e42396b06ed | 17 | uint8_t sendindex; // index of 'data' |
| piroro4560 | 0:4e42396b06ed | 18 | printf("@TBN%03d%03d", addr, DATANUM); // send comand |
| piroro4560 | 0:4e42396b06ed | 19 | for (sendindex=0; sendindex<DATANUM; sendindex++) { |
| piroro4560 | 0:4e42396b06ed | 20 | putc(data[sendindex]); // |
| piroro4560 | 0:4e42396b06ed | 21 | } |
| piroro4560 | 0:4e42396b06ed | 22 | printf("\r\n"); // <cr><lf> |
| piroro4560 | 0:4e42396b06ed | 23 | return GetResponse(); // check response |
| piroro4560 | 0:4e42396b06ed | 24 | } |
| piroro4560 | 0:4e42396b06ed | 25 | |
| piroro4560 | 0:4e42396b06ed | 26 | int8_t Bcon::GetResponse() |
| piroro4560 | 0:4e42396b06ed | 27 | { |
| piroro4560 | 0:4e42396b06ed | 28 | char res[256]; // array of storing response |
| piroro4560 | 0:4e42396b06ed | 29 | for (uint8_t resindex=0; resindex<256; resindex++) { |
| piroro4560 | 0:4e42396b06ed | 30 | res[resindex] = getc(); |
| piroro4560 | 0:4e42396b06ed | 31 | if (!strncmp(res+resindex-1, "\r\n", 2)) { |
| piroro4560 | 0:4e42396b06ed | 32 | if (!strncmp(res+resindex-3, "P0", 2)) return 0; |
| piroro4560 | 0:4e42396b06ed | 33 | else if (!strncmp(res+resindex-3, "N0", 2)) return 2; |
| piroro4560 | 0:4e42396b06ed | 34 | else if (!strncmp(res+resindex-3, "N1", 2)) return 3; |
| piroro4560 | 0:4e42396b06ed | 35 | else if (!strncmp(res+resindex-3, "N3", 2)) return 4; |
| piroro4560 | 0:4e42396b06ed | 36 | } |
| piroro4560 | 0:4e42396b06ed | 37 | } |
| piroro4560 | 0:4e42396b06ed | 38 | return -1; |
| piroro4560 | 0:4e42396b06ed | 39 | } |