{ 0x3FFF, 126, 15 } // MFX
};
-Driver::TelemetryInfo ArduControl::telemetry_info[4] =
+Driver::TelemetryInfo ArduControl::telemetry_info[6] =
{
{ "voltage", "Voltage", "V", 1 },
{ "current", "Current", "A", 2 },
+ { "cmd-rate", "Cmd rate", "/ s", 0 },
{ "cmd-queue-depth", "Cmd queue", "", 0 },
+ { "acc-queue-depth", "Acc queue", "", 0 },
{ "s88-latency", "S88 latency", "ms", 0 }
};
const Driver::TelemetryInfo *ArduControl::enumerate_telemetry(unsigned i) const
{
- if(i<4)
+ if(i<6)
return telemetry_info+i;
else
return 0;
else if(name==telemetry_info[1].name)
return monitor.get_current();
else if(name==telemetry_info[2].name)
- return command_queue.size();
+ return thread.get_command_rate();
else if(name==telemetry_info[3].name)
+ return command_queue.size();
+ else if(name==telemetry_info[4].name)
+ return accessory_queue.size();
+ else if(name==telemetry_info[5].name)
return s88.get_latency()/Time::msec;
else
throw key_error(name);
ArduControl::ControlThread::ControlThread(ArduControl &c):
control(c),
- done(false)
+ done(false),
+ cmd_rate(20),
+ cmd_count(0)
{
tasks.push_back(&control.command_queue);
tasks.push_back(&control.monitor);
void ArduControl::ControlThread::main()
{
init_baud_rate();
+ cmd_rate_start = Time::now();
while(!done)
{
control.command_queue.push(cmd);
}
}
+
+ if(cmd_count>=cmd_rate)
+ {
+ Time::TimeStamp t = Time::now();
+ cmd_rate = cmd_count/((t-cmd_rate_start)/Time::sec);
+ cmd_rate_start = t;
+ cmd_count = 0;
+ }
}
else
Time::sleep(10*Time::msec);
result = r;
}
+ ++cmd_count;
+
return result;
}
ArduControl &control;
bool done;
std::vector<Task *> tasks;
+ unsigned cmd_rate;
+ unsigned cmd_count;
+ Msp::Time::TimeStamp cmd_rate_start;
public:
ControlThread(ArduControl &);
+ unsigned get_command_rate() const { return cmd_rate; }
+
void exit();
private:
virtual void main();
ControlThread thread;
static ProtocolInfo protocol_info[2];
- static TelemetryInfo telemetry_info[4];
+ static TelemetryInfo telemetry_info[6];
public:
ArduControl(const Options &);