| 29 | } |
| 30 | |
| 31 | void Decoder::decode_buffer() |
| 32 | { |
| 33 | /* |
| 34 | * This will search for frame headers and see if the length satisfys |
| 35 | * if header exits. |
| 36 | * |
| 37 | * Exit condition: |
| 38 | * 1. All data should be garbage if no frame header is found, remove it |
| 39 | * then. |
| 40 | * 2. If headers are found while no frame is retrived, indicates that |
| 41 | * all frames are not complete. |
| 42 | * |
| 43 | * It would be another story if there are CRC bytes, will be added later. |
| 44 | */ |
| 45 | bool found = false; |
| 46 | bool retrived = false; |
| 47 | do { |
| 48 | found = false; |
| 49 | retrived = false; |
| 50 | for (int i = 0; i < listProtocals.count(); i++) { |
| 51 | Protocal *protocal = listProtocals[i]; |
| 52 | int index; |
| 53 | if ((index = buffer.indexOf(protocal->getHeader())) != -1) { |
| 54 | if (buffer.length() - index >= protocal->getFrameLength()) { |
| 55 | decodeFrame(i, buffer.mid(index + protocal->getHeader().length(), protocal->getFrameLength())); |
| 56 | buffer.remove(index, protocal->getFrameLength()); |
| 57 | retrived = true; |
| 58 | } |
| 59 | found = true; |
| 60 | } |
| 61 | } |
| 62 | if (!found) |
| 63 | buffer.clear(); |
| 64 | } while (found && retrived); |
| 65 | } |
| 66 | |
| 67 | void Decoder::decodeFrame(int id, QByteArray frameRawData) |
| 68 | { |
nothing calls this directly
no test coverage detected