Руслан Урядинский / Mbed 2 deprecated UAVCAN_Subscriber

Dependencies:   libuavcan mbed

Revision:
0:14b95d68acf6
Child:
1:16f48f8c7ad3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 10 15:08:30 2018 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "chip.h"
+#include "libuavcan/libuavcan/include/uavcan/build_config.hpp" //All default configuration options
+#include "libuavcan/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp" //OS detection; Any General-Purpose timer
+#include "libuavcan/libuavcan/include/uavcan/node/subscriber.hpp" //Subscriber class
+
+#include <uavcan/equipment/actuator/Command.hpp> //message type
+
+extern uavcan::ICanDriver& getCanDriver();
+extern uavcan::ISystemClock& getSystemClock();
+
+const unsigned NodeMemoryPoolSize = 16384; // Need calulate (tutorial 2).
+typedef uavcan::Node<NodeMemoryPoolSize> Node;
+
+static Node& getNode() {
+    static Node node(getCanDriver(), getSystemClock());
+    return node;
+}
+
+int main() {
+    auto& node = getNode();
+    node.setNodeID(2);
+    node.setName("Actuator");
+    if (node.start() > 0){ //<>?
+        //обработка ошибок запуска
+    }
+    uavcan::Subscriber <uavcan::equipment::actuator::Command> sub(node); //define node to publisher
+    if (sub.start() > 0) { //инициализация паблишера
+        //обработка ошибок
+    }
+    
+    node.setMoreOptional();
+    while(1) {
+        if (node.spin(uavcan::MonotonicDuration::getInfinite()) < 0){
+            //обработчик ошибок
+        }
+        
+    }
+}