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

Dependencies:   libuavcan mbed

main.cpp

Committer:
RuslanUrya
Date:
2018-05-10
Revision:
0:14b95d68acf6
Child:
1:16f48f8c7ad3

File content as of revision 0:14b95d68acf6:

#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){
            //обработчик ошибок
        }
        
    }
}