if(get_work(cmd))
{
bool success = true;
+ bool resync = false;
for(unsigned i=0; (success && i<cmd.repeat_count); ++i)
- success = (do_command(cmd)==COMMAND_OK);
+ {
+ unsigned result = do_command(cmd, control.command_timeout);
+ success = (result==COMMAND_OK);
+ resync = (result==0);
+ }
+
if(success && cmd.tag)
control.completed_commands.push(cmd.tag);
+
+ if(resync)
+ {
+ if(control.debug>=1)
+ IO::print("Synchronization with ArduControl lost, attempting to recover\n");
+ for(unsigned i=0; (resync && i<16); ++i)
+ {
+ control.serial.put('\xFF');
+ while(IO::poll(control.serial, IO::P_INPUT, control.command_timeout))
+ resync = (control.serial.get()!=0xFF);
+ }
+ if(resync)
+ {
+ if(control.debug>=1)
+ IO::print("Resynchronization failed, giving up\n");
+ done = true;
+ }
+ else
+ {
+ if(control.debug>=1)
+ IO::print("Resynchronization successful\n");
+ if(cmd.tag)
+ control.command_queue.push(cmd);
+ }
+ }
}
else
Time::sleep(10*Time::msec);