VitroIO SDK
Software development kit for Vitro Shard.
Loading...
Searching...
No Matches
vitroio::sdk::NodeController Class Reference

Class is a main component of the node firmware. More...

#include <node_controller.h>

Inheritance diagram for vitroio::sdk::NodeController:
Collaboration diagram for vitroio::sdk::NodeController:

Public Member Functions

 NodeController (Canbus *canbus, const FirmwareId &fwId, const Version &fwVersion, FlashSpace environmentFlashSpace, FlashSpace regionAFlashSpace, FlashSpace regionBFlashSpace, EventQueue *targetQueue, uint32_t eventQueueSize=VITROIO_NODE_CONTROLLER_DEFAULT_EVENT_QUEUE_SIZE)
 Contructor initializes the controller and chains an internal event queue to the targetQueue. More...
 
 NodeController (Canbus *canbus, const FirmwareId &fwId, const Version &fwVersion, FlashSpace environmentFlashSpace, FlashSpace regionAFlashSpace, FlashSpace regionBFlashSpace, osPriority priority=osPriorityNormal, uint32_t eventQueueSize=VITROIO_NODE_CONTROLLER_DEFAULT_EVENT_QUEUE_SIZE)
 Contructor initializes the controller and creates internal event loop using thread with priority priority. More...
 
 NodeController (Canbus *canbus, const FirmwareId &fwId, const Version &fwVersion, osPriority priority=osPriorityNormal, uint32_t eventQueueSize=VITROIO_NODE_CONTROLLER_DEFAULT_EVENT_QUEUE_SIZE)
 Contructor initializes the controller and creates internal event loop using thread with priority priority. More...
 
 NodeController (Canbus *canbus, const FirmwareId &fwId, const Version &fwVersion, EventQueue *targetQueue, uint32_t eventQueueSize=VITROIO_NODE_CONTROLLER_DEFAULT_EVENT_QUEUE_SIZE)
 Contructor initializes the controller and chains an internal event queue to the targetQueue. More...
 
 ~NodeController ()
 
bool isValid ()
 Function allows to check whether the controller is in valid state. More...
 
int initCommunication (Transport_layer *layer)
 Function initializes communication with gateway. This method blocks until the communication is not initialized and no error occurred. More...
 
int initCommunication (uint32_t sync_time, Transport_layer *layer)
 Function initializes communication with gateway. This method blocks until the communication is not initialized and no error occurred. More...
 
uint32_t nodeId ()
 Function allows to obtain node ID assigned by gateway during initialization of communication. More...
 
void setExternalFrameCallback (std::function< void(const CanbusFrame &)>)
 Function allows to attach a handler for frames with paramId matching VITROIO_PROTOCOL_EXTERNAL_FRAME. More...
 

Detailed Description

Class is a main component of the node firmware.

The class handles standard operations of vitroio system such like firmware upgrade and initialization of communication with gateway. It requires flash memory space for storing environment variables.

The class uses an event loop for handling events. The event queue can be managed by external queue specified by user or by internal queue with thread of specified priority.

Note
The controller occupies one of OnframeReceivedCallbacks of Canbus object passed to the constructor.

Constructor & Destructor Documentation

◆ NodeController() [1/4]

vitroio::sdk::NodeController::NodeController ( Canbus canbus,
const FirmwareId fwId,
const Version fwVersion,
FlashSpace  environmentFlashSpace,
FlashSpace  regionAFlashSpace,
FlashSpace  regionBFlashSpace,
EventQueue *  targetQueue,
uint32_t  eventQueueSize = VITROIO_NODE_CONTROLLER_DEFAULT_EVENT_QUEUE_SIZE 
)
explicit

Contructor initializes the controller and chains an internal event queue to the targetQueue.

Note
Thread which handles targetQueue must be run before usage of this class (construction of the object can be done earlier).

Initialization includes all of necessary components.

There is not guarantee that the object is in valid state. User should call isValid() method to determine if the object was initialized successfully. When the object is in invalid state, the behaviour is undefined.

The constructor uses mbed::EventQueue::chain method for connection to targetQueue.

Parameters
canbusPointer to Canbus object
fwIdid of firmware
fwVersionVersion of firmware
environmentFlashSpaceSpecifies flash memory space for storing environment variables
regionAFlashSpaceSpecifies region A of flash memory space intended for firmware
regionBFlashSpaceSpecifies region B of flash memory space intended for firmware
targetQueueExternal event queue to which the internal queue is to be chained
eventQueueSizeSize of internal event queue

◆ NodeController() [2/4]

vitroio::sdk::NodeController::NodeController ( Canbus canbus,
const FirmwareId fwId,
const Version fwVersion,
FlashSpace  environmentFlashSpace,
FlashSpace  regionAFlashSpace,
FlashSpace  regionBFlashSpace,
osPriority  priority = osPriorityNormal,
uint32_t  eventQueueSize = VITROIO_NODE_CONTROLLER_DEFAULT_EVENT_QUEUE_SIZE 
)
explicit

Contructor initializes the controller and creates internal event loop using thread with priority priority.

Initialization includes all of necessary components.

There is not guarantee that the object is in valid state. User should call isValid() method to determine if the object was initialized successfully. When the object is in invalid state, the behaviour is undefined.

Parameters
canbusPointer to Canbus object
fwIdid of firmware
fwVersionVersion of firmware
environmentFlashSpaceSpecifies flash memory space for storing environment variables
regionAFlashSpaceSpecifies region A of flash memory space intended for firmware
regionBFlashSpaceSpecifies region B of flash memory space intended for firmware
priorityPriority of thread for handling internal events
eventQueueSizeSize of internal event queue

◆ NodeController() [3/4]

vitroio::sdk::NodeController::NodeController ( Canbus canbus,
const FirmwareId fwId,
const Version fwVersion,
osPriority  priority = osPriorityNormal,
uint32_t  eventQueueSize = VITROIO_NODE_CONTROLLER_DEFAULT_EVENT_QUEUE_SIZE 
)

Contructor initializes the controller and creates internal event loop using thread with priority priority.

Initialization includes all of necessary components.

There is not guarantee that the object is in valid state. User should call isValid() method to determine if the object was initialized successfully. When the object is in invalid state, the behaviour is undefined.

Parameters
canbusPointer to Canbus object
fwIdid of firmware
fwVersionVersion of firmware
priorityPriority of thread for handling internal events
eventQueueSizeSize of internal event queue

◆ NodeController() [4/4]

vitroio::sdk::NodeController::NodeController ( Canbus canbus,
const FirmwareId fwId,
const Version fwVersion,
EventQueue *  targetQueue,
uint32_t  eventQueueSize = VITROIO_NODE_CONTROLLER_DEFAULT_EVENT_QUEUE_SIZE 
)

Contructor initializes the controller and chains an internal event queue to the targetQueue.

Note
Thread which handles targetQueue must be run before usage of this class (construction of the object can be done earlier).

Initialization includes all of necessary components.

There is not guarantee that the object is in valid state. User should call isValid() method to determine if the object was initialized successfully. When the object is in invalid state, the behaviour is undefined.

The constructor uses mbed::EventQueue::chain method for connection to targetQueue.

Parameters
canbusPointer to Canbus object
fwIdid of firmware
fwVersionVersion of firmware
targetQueueExternal event queue to which the internal queue is to be chained
eventQueueSizeSize of internal event queue

◆ ~NodeController()

vitroio::sdk::NodeController::~NodeController ( )

Member Function Documentation

◆ initCommunication() [1/2]

int vitroio::sdk::NodeController::initCommunication ( Transport_layer layer)

Function initializes communication with gateway. This method blocks until the communication is not initialized and no error occurred.

Returns
Function returns VITROIO_ERR_SUCCESS when the communication was initialized successfully or appropriate error code otherwise.

◆ initCommunication() [2/2]

int vitroio::sdk::NodeController::initCommunication ( uint32_t  sync_time,
Transport_layer layer 
)

Function initializes communication with gateway. This method blocks until the communication is not initialized and no error occurred.

Returns
Function returns VITROIO_ERR_SUCCESS when the communication was initialized successfully or appropriate error code otherwise.

◆ isValid()

bool vitroio::sdk::NodeController::isValid ( )

Function allows to check whether the controller is in valid state.

Note
This method should be called always after creation of the object.

◆ nodeId()

uint32_t vitroio::sdk::NodeController::nodeId ( )

Function allows to obtain node ID assigned by gateway during initialization of communication.

Note
To obtain node ID, the communication with gateway must be initialized successfully.
Returns
Function returns node ID or 0 when the ID is not assigned.

◆ setExternalFrameCallback()

void vitroio::sdk::NodeController::setExternalFrameCallback ( std::function< void(const CanbusFrame &)>  )

Function allows to attach a handler for frames with paramId matching VITROIO_PROTOCOL_EXTERNAL_FRAME.