AP_UAVCAN: handle restart_node

This commit is contained in:
Peter Barker 2019-02-06 16:13:30 +11:00 committed by Andrew Tridgell
parent 31a9ac7dbd
commit d0ac09899b
2 changed files with 35 additions and 0 deletions

View File

@ -83,6 +83,29 @@ protected:
}
};
class AP_UAVCAN_RestartRequestHandler : public uavcan::IRestartRequestHandler {
public:
bool handleRestartRequest(uavcan::NodeID request_source) override {
// swiped from reboot handling in GCS_Common.cpp
AP_Notify *notify = AP_Notify::instance();
if (notify) {
AP_Notify::flags.firmware_update = 1;
notify->update();
}
// force safety on
hal.rcout->force_safety_on();
hal.rcout->force_safety_no_wait();
// flush pending parameter writes
AP_Param::flush();
hal.scheduler->delay(200);
hal.scheduler->reboot(false);
return true;
}
};
class AP_UAVCAN_FileStorageBackend : public uavcan::dynamic_node_id_server::IStorageBackend
{
/**
@ -271,6 +294,14 @@ bool AP_UAVCAN_Servers::init(uavcan::Node<0> &node)
}
}
if (_restart_request_handler == nullptr) {
_restart_request_handler = new AP_UAVCAN_RestartRequestHandler();
if (_restart_request_handler == nullptr) {
goto failed;
}
}
node.setRestartRequestHandler(_restart_request_handler);
//Start Dynamic Node Server
ret = _server_instance->init(node.getHardwareVersion().unique_id);
if (ret < 0) {
@ -281,6 +312,7 @@ bool AP_UAVCAN_Servers::init(uavcan::Node<0> &node)
return true;
failed:
delete _restart_request_handler;
delete _storage_backend;
delete _tracer;
delete _server_instance;

View File

@ -11,6 +11,7 @@
class AP_UAVCAN_FileEventTracer;
class AP_UAVCAN_FileStorageBackend;
class AP_UAVCAN_CentralizedServer;
class AP_UAVCAN_RestartRequestHandler;
class AP_UAVCAN_Servers
{
@ -23,6 +24,8 @@ private:
AP_UAVCAN_CentralizedServer *_server_instance;
AP_UAVCAN_FileEventTracer *_tracer;
AP_UAVCAN_FileStorageBackend *_storage_backend;
AP_UAVCAN_RestartRequestHandler *_restart_request_handler; // one for all nodes....
};
#endif