X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Freply.cpp;h=5a02df212897c4efd36a2261d4747d94da41617b;hb=38fb8d56efde037a71c46a58bda314655e68ab6c;hp=ede23ccb3aa939dd28665e8f0000786d7a85e5d9;hpb=449fb5de95ddb2ac9da4bd72a1c12150505d5549;p=r2c2.git diff --git a/source/libmarklin/reply.cpp b/source/libmarklin/reply.cpp index ede23cc..5a02df2 100644 --- a/source/libmarklin/reply.cpp +++ b/source/libmarklin/reply.cpp @@ -18,9 +18,9 @@ namespace { unsigned read_all(int fd, char *buf, unsigned size) { - unsigned pos=0; + unsigned pos = 0; while(pos(result.data); + char *data = reinterpret_cast(result.data); if(cmd==CMD_EVENT) { for(unsigned i=0; i<3; ++i) { - result.len+=read_all(fd, data+i, 1); + result.len += read_all(fd, data+i, 1); if(!(result.data[i]&0x80)) break; } @@ -55,54 +55,54 @@ Reply Reply::read(int fd, Cmd cmd) { for(unsigned i=0;; i+=5) { - result.len+=read_all(fd, data+i, 1); + result.len += read_all(fd, data+i, 1); if(result.data[i]&0x80) break; - result.len+=read_all(fd, data+i+1, 4); + result.len += read_all(fd, data+i+1, 4); } } else if(cmd==CMD_EVENT_TURNOUT) { - result.len+=read_all(fd, data, 1); - result.len+=read_all(fd, data+1, result.data[0]*2); + result.len += read_all(fd, data, 1); + result.len += read_all(fd, data+1, result.data[0]*2); } else if(cmd==CMD_EVENT_SENSOR) { for(unsigned i=0;; i+=3) { - result.len+=read_all(fd, data+i, 1); + result.len += read_all(fd, data+i, 1); if(result.data[i]==0) break; - result.len+=read_all(fd, data+i+1, 2); + result.len += read_all(fd, data+i+1, 2); } } else { - bool expect_errcode=(cmd!=CMD_STATUS); + bool expect_errcode = (cmd!=CMD_STATUS); - unsigned expected_bytes=0; + unsigned expected_bytes = 0; if(cmd==CMD_STATUS || cmd==CMD_FUNC_STATUS || cmd==CMD_TURNOUT_STATUS) - expected_bytes=1; + expected_bytes = 1; if(cmd==CMD_SENSOR_STATUS || cmd==CMD_TURNOUT_GROUP_STATUS) - expected_bytes=2; + expected_bytes = 2; if(cmd==CMD_LOK_STATUS) - expected_bytes=3; + expected_bytes = 3; if(cmd==CMD_LOK_CONFIG) - expected_bytes=4; + expected_bytes = 4; if(expect_errcode) { char c; read_all(fd, &c, 1); - result.err=static_cast(c); + result.err = static_cast(c); } if(result.err==ERR_NO_ERROR) - result.len+=read_all(fd, data, expected_bytes); + result.len += read_all(fd, data, expected_bytes); } return result;