- string result;
- if(cmd==CMD_EVENT)
- {
- result+=ERR_NO_ERROR;
- for(unsigned i=0; i<3; ++i)
- {
- char c;
- read(serial_fd, &c, 1);
- result+=c;
- if(!(c&0x80)) break;
- }
- }
- else if(cmd==CMD_EVENT_LOK)
- {
- result+=ERR_NO_ERROR;
- char c[5];
- read(serial_fd, c+4, 1);
- result+=c[4];
- while(c[4]&0x80)
- {
- read_all(serial_fd, c, 5);
- result.append(c, 5);
- }
- }
- else if(cmd==CMD_EVENT_TURNOUT)
- {
- result+=ERR_NO_ERROR;
- char c[511];
- read(serial_fd, c, 1);
- read_all(serial_fd, c+1, c[0]*2);
- result.append(c, c[0]*2+1);
- }
- else if(cmd==CMD_EVENT_SENSOR)
- {
- result+=ERR_NO_ERROR;
- char c[3];
- read(serial_fd, c+2, 1);
- result+=c[2];
- while(c[2])
- {
- read_all(serial_fd, c, 3);
- result.append(c, 3);
- }
- }
- else
- {
- unsigned expected_bytes=1;
- if(cmd==CMD_FUNC_STATUS || cmd==CMD_TURNOUT_STATUS)
- expected_bytes=2;
- if(cmd==CMD_SENSOR_STATUS || cmd==CMD_TURNOUT_GROUP_STATUS)
- expected_bytes=3;
- if(cmd==CMD_LOK_STATUS)
- expected_bytes=4;
- if(cmd==CMD_LOK_CONFIG)
- expected_bytes=5;
- char c[5];
- read_all(serial_fd, c, 1);
- result+=c[0];
- if(!c[0])
- {
- read_all(serial_fd, c+1, expected_bytes-1);
- result.append(c+1, expected_bytes-1);
- }
- }
-
- return result;
-}
-
-void Control::event_query_done(Error, const string &resp)
-{
- if(resp[0]&0x20)
- command(string(1, CMD_EVENT_TURNOUT)).signal_done.connect(sigc::mem_fun(this, &Control::turnout_event_done));
- if(resp[0]&0x04)
- command(string(1, CMD_EVENT_SENSOR)).signal_done.connect(sigc::mem_fun(this, &Control::sensor_event_done));
+ const unsigned char *data = reply.get_data();
+ if(data[0]&0x01)
+ command(CMD_EVENT_LOK);
+ if(data[0]&0x20)
+ command(CMD_EVENT_TURNOUT).signal_done.connect(sigc::mem_fun(this, &Control::turnout_event_done));
+ if(data[0]&0x04)
+ command(CMD_EVENT_SENSOR).signal_done.connect(sigc::mem_fun(this, &Control::sensor_event_done));
+ if((data[0]&0x80) && (data[1]&0x40))
+ command(CMD_STATUS).signal_done.connect(sigc::mem_fun(this, &Control::status_done));