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

Dependencies:   mbed-STM32F103C8T6 mbed libuavcan

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "chip.h" //build configuration
00003 #include "libuavcan/libuavcan/include/uavcan/build_config.hpp" //All default configuration options
00004 #include "libuavcan/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp" //OS detection; Any General-Purpose timer
00005 #include "libuavcan/libuavcan/include/uavcan/node/publisher.hpp" //Publisher class
00006 #include "stm32f103c8t6.h"
00007 
00008 #include <uavcan/equipment/actuator/Command.hpp> //message type
00009 
00010 extern uavcan::ICanDriver& getCanDriver();
00011 extern uavcan::ISystemClock& getSystemClock();
00012 
00013 const unsigned NodeMemoryPoolSize = 16384; // Need calulate (tutorial 2).
00014 typedef uavcan::Node<NodeMemoryPoolSize> Node;
00015 
00016 static Node& getNode() {
00017     static Node node(getCanDriver(), getSystemClock());
00018     return node;
00019 }
00020 
00021 
00022 int main() {
00023     confSysClock();
00024     auto& node = getNode();
00025     node.setNodeID(1);
00026     node.setName("Publisher");
00027     if (node.start() > 0){ //<>?
00028         //обработка ошибок запуска
00029     }
00030     uavcan::Publisher <uavcan::equipment::actuator::Command> pub(node); //define node to publisher
00031     if (pub.init() > 0) { //инициализация паблишера
00032         //обработка ошибок
00033     }
00034     
00035     node.setMoreOptional();
00036     
00037     while(1) {
00038         if (node.spin(uavcan::MonotonicDuration::fromMSec(1000)) < 1){
00039             //обработка ошибок
00040         }
00041         uavcan::equipment::actuator::Command msg;  
00042         msg.actuator_id = 2;
00043         msg.command_type = COMMAND_TYPE_POSITION //meter or radian
00044         msg.command_value = pi;
00045         
00046         if (pub.broadcast(msg) > 0){ // отправка сообщения
00047             // обработка ошибок
00048         }
00049         
00050         
00051     }
00052 }