HiveMind
GreetHandler.h
Go to the documentation of this file.
1 #ifndef __GREETHANDLER_H_
2 #define __GREETHANDLER_H_
3 
4 #include "IGreetHandler.h"
5 #include <bsp/IBSP.h>
6 #include <pheromones/HiveMindHostDeserializer.h>
7 #include <pheromones/HiveMindHostSerializer.h>
8 
9 class GreetHandler : public IGreetHandler {
10  public:
11  GreetHandler(IHiveMindHostSerializer& serializer,
12  IHiveMindHostDeserializer& deserializer,
13  IBSP& bsp);
14 
15  ~GreetHandler() override = default;
16 
17  bool greet() override;
18 
19  private:
20  IHiveMindHostSerializer& m_serializer;
21  IHiveMindHostDeserializer& m_deserializer;
23 };
24 
25 #endif // __GREETHANDLER_H_
MessageDispatcherTask::MessageDispatcherTask
MessageDispatcherTask(const char *taskName, UBaseType_t priority, ICommInterface *stream, ICircularQueue< MessageDTO > &streamQueue)
Definition: Main.cpp:150
BittyBuzzTask::m_stringResolver
BittyBuzzStringResolver m_stringResolver
Definition: Main.cpp:67
PositionsTable
Definition: IInterloc.h:10
BBVMRet
BBVMRet
Definition: IBittyBuzzVm.h:10
MessageSenderTask::setStream
void setStream(ICommInterface *stream)
Definition: Main.cpp:207
GreetHandler::~GreetHandler
~GreetHandler() override=default
BittyBuzzVm.h
LogLevel::Error
@ Error
DeviceState::Error
@ Error
LogLevel::Debug
@ Debug
BittyBuzzContainer.h
BittyBuzzContainer
Definition: BittyBuzzContainer.h:14
ConnectionState::Error
@ Error
MessageDispatcher::deserializeAndDispatch
bool deserializeAndDispatch() override
deserialize a message and dispatches it in the appropriate queue
Definition: MessageDispatcher.cpp:27
LogRet::LowLevel
@ LowLevel
BittyBuzzSystem.h
LogRet
LogRet
The return value of the logger.
Definition: ILogger.h:23
BittyBuzzContainer::getBBZClosureRegister
BittyBuzzClosureRegister & getBBZClosureRegister()
return an instance of a bittybuzz function register
Definition: BittyBuzzContainer.cpp:16
gc_taskHighPriority
constexpr uint16_t gc_taskHighPriority
Definition: Main.cpp:28
BittyBuzzSystem::getStateString
const char * getStateString(bbzvm_state state)
Definition: BittyBuzzSystem.cpp:143
IInterloc::getPositionsTable
virtual const PositionsTable & getPositionsTable() const =0
Returns the position table for all robots in the swarm.
BittyBuzzTask
Definition: Main.cpp:36
BSPContainer.h
InterlocContainer
Definition: InterlocContainer.h:9
commInterfaceGetter
std::optional< std::reference_wrapper< ICommInterface > >(*)() commInterfaceGetter
Definition: Main.cpp:31
MessageDispatcherTask::~MessageDispatcherTask
~MessageDispatcherTask() override=default
IBSP.h
InterlocMessageHandlerTask::~InterlocMessageHandlerTask
~InterlocMessageHandlerTask() override=default
CommMonitoringTask::m_senderTask
MessageSenderTask & m_senderTask
Definition: Main.cpp:257
MessageSenderTask::m_logger
ILogger & m_logger
Definition: Main.cpp:213
LogInterlocTask::task
void task() override
Definition: Main.cpp:383
MessageDispatcherTask::m_stream
ICommInterface * m_stream
Definition: Main.cpp:164
GreetHandler::m_deserializer
IHiveMindHostDeserializer & m_deserializer
Definition: GreetHandler.h:21
LogRet::Error
@ Error
ILogger::log
virtual LogRet log(LogLevel level, const char *format,...)=0
Logs if the provided level is higher than the current log level (Thread-safe)
IInterlocMessageHandler
Definition: IInterlocMessageHandler.h:6
BittyBuzzVm::start
bool start() override
Starts the vm.
Definition: BittyBuzzVm.cpp:64
IUserInterface::printLine
virtual int printLine(const char *format,...)=0
Provides an interface to print a line to the console or serial port. Flushes the input and adds a new...
ConnectionType
ConnectionType
Definition: ICommInterface.h:6
BittyBuzzTask::resetVmButtonCallback
static void resetVmButtonCallback(void *context)
Definition: Main.cpp:76
InterlocDataHandlerTask::~InterlocDataHandlerTask
~InterlocDataHandlerTask() override=default
HardwareInterlocTask::~HardwareInterlocTask
~HardwareInterlocTask() override=default
BittyBuzzTask::task
void task() override
Definition: Main.cpp:82
BittyBuzzFactory::createBittyBuzzStringResolver
BittyBuzzStringResolver createBittyBuzzStringResolver(ILogger &logger)
Creates a BittyBuzzStringResolver with the main.bzz bytecode.
Definition: BittyBuzzFactory.cpp:16
BSPContainer::getUserInterface
IUserInterface & getUserInterface()
Returns an instance of the platform dependent UserInterface.
Definition: BSPContainer.cpp:19
IButtonCallbackRegister
Manages the callback of a single button.
Definition: IButtonCallbackRegister.h:7
LoggerContainer.h
MessageDispatcherTask::task
void task() override
Definition: Main.cpp:168
BittyBuzzContainer::getBBZMessageHandler
BittyBuzzMessageHandler & getBBZMessageHandler()
return an instance of a bittybuzz message handler
Definition: BittyBuzzContainer.cpp:8
HiveMindHostApiRequestHandler
Definition: HiveMindHostApiRequestHandler.h:10
MessageSenderTask::m_serializer
IHiveMindHostSerializer * m_serializer
Definition: Main.cpp:214
BittyBuzzFactory
Definition: BittyBuzzFactory.h:12
setHostConnectionState
void setHostConnectionState(ConnectionState state)
Definition: Main.cpp:419
GreetHandler::GreetHandler
GreetHandler(IHiveMindHostSerializer &serializer, IHiveMindHostDeserializer &deserializer, IBSP &bsp)
Definition: GreetHandler.cpp:3
LogInterlocTask
Definition: Main.cpp:370
BittyBuzzFactory::createBittyBuzzMathLib
BittyBuzzLib< std::array< BittyBuzzLibMemberRegister, 24 > > createBittyBuzzMathLib()
Creates a the math table library for the bvm.
Definition: BittyBuzzFactory.cpp:46
ICommInterface::isConnected
virtual bool isConnected() const =0
Tells if interface is connected and functionning.
IInterlocManager::startInterloc
virtual void startInterloc()=0
Dummy function to demonstrate working DW1000s.
BittyBuzzTask::m_buttonCallbackRegister
IButtonCallbackRegister & m_buttonCallbackRegister
Definition: Main.cpp:65
GreetHandler.h
BittyBuzzContainer::getBBZNeighborsManager
BittyBuzzNeighborsManager & getBBZNeighborsManager()
return an instance of a bittybuzz neighbors manager
Definition: BittyBuzzContainer.cpp:29
BittyBuzzVm::terminate
void terminate() override
Terminate the virtual machine and removes all messages that were supposed to be processed.
Definition: BittyBuzzVm.cpp:80
BittyBuzzSystem::getErrorString
const char * getErrorString(bbzvm_error error)
Definition: BittyBuzzSystem.cpp:160
ApplicationInterfaceContainer
Definition: ApplicationInterfaceContainer.h:12
InterlocMessageHandlerTask
Definition: Main.cpp:329
Logger::m_ui
IUserInterface & m_ui
Definition: Logger.h:20
LogInterlocTask::LogInterlocTask
LogInterlocTask(const char *taskName, UBaseType_t priority)
Definition: Main.cpp:372
InterlocMessageHandlerTask::InterlocMessageHandlerTask
InterlocMessageHandlerTask(const char *taskName, UBaseType_t priority)
Definition: Main.cpp:331
InterlocContainer::getInterlocMessageHandler
IInterlocMessageHandler & getInterlocMessageHandler()
Definition: InterlocContainer.cpp:19
BittyBuzzFactory::createBittyBuzzUILib
BittyBuzzLib< std::array< BittyBuzzLibMemberRegister, 2 > > createBittyBuzzUILib()
Creates a the ui table library for the bvm.
Definition: BittyBuzzFactory.cpp:76
BittyBuzzVm
Definition: BittyBuzzVm.h:17
ApplicationInterfaceContainer.h
ConnectionState::USB
@ USB
BittyBuzzUserFunctions::delay
void delay()
wait for a certain delay Signature delay(arg1) Warning this function make the whole VM sleep which ca...
Definition: BittyBuzzUserFunctions.cpp:327
CommMonitoringTask::m_dispatcherTask
MessageDispatcherTask & m_dispatcherTask
Definition: Main.cpp:256
IHandshakeUI
Manages the interface if a device was handshaked (greeted) with or not. Lights the appropriate LED to...
Definition: IHandshakeUI.h:6
InterlocContainer.h
MessageDispatcherTask::setStream
void setStream(ICommInterface *stream)
Definition: Main.cpp:161
BBVMRet::Stopped
@ Stopped
GreetHandler
Definition: GreetHandler.h:9
BittyBuzzTask::~BittyBuzzTask
~BittyBuzzTask() override=default
BittyBuzzTask::m_resetVm
std::atomic_bool m_resetVm
Definition: Main.cpp:70
Logger::logLevelToString
static char logLevelToString(LogLevel logLevel)
Definition: Logger.cpp:31
CommMonitoringTask::m_handshakeUI
IHandshakeUI & m_handshakeUI
Definition: Main.cpp:258
LogLevel
LogLevel
The log level used for the logger.
Definition: ILogger.h:9
MessageSenderTask::MessageSenderTask
MessageSenderTask(const char *taskName, UBaseType_t priority, ICommInterface *stream, INotificationQueue< MessageDTO > &streamQueue, bool keepRunning=false)
Definition: Main.cpp:194
CommMonitoringTask
Definition: Main.cpp:238
BittyBuzzVm::init
bool init(const std::reference_wrapper< IBittyBuzzLib > *bbzLibs, uint32_t bbzLibsLength) override
Init the virtual machine.
Definition: BittyBuzzVm.cpp:38
ApplicationInterfaceContainer::getButton1CallbackRegister
ButtonCallbackRegister & getButton1CallbackRegister()
get the button 1 callback register
Definition: ApplicationInterfaceContainer.cpp:17
Logger::log
LogRet log(LogLevel level, const char *format,...) override
Logs if the provided level is higher than the current log level (Thread-safe)
Definition: Logger.cpp:8
ApplicationInterfaceContainer::getHostHandshakeUI
HostHandshakeUI & getHostHandshakeUI()
get the host handshake UI
Definition: ApplicationInterfaceContainer.cpp:33
InterlocDataHandlerTask::task
void task() override
Definition: Main.cpp:363
setRemoteConnectionState
void setRemoteConnectionState(ConnectionState state)
Definition: Main.cpp:424
BittyBuzzFactory::createBittyBuzzGlobalLib
BittyBuzzLib< std::array< BittyBuzzLibMemberRegister, 15 > > createBittyBuzzGlobalLib(int16_t vmStepDelay)
Creates an array of FunctionRegister associated with the code from main.bzz.
Definition: BittyBuzzFactory.cpp:21
CommMonitoringTask::m_connectionStateSetter
connectionStateSetter m_connectionStateSetter
Definition: Main.cpp:260
CommMonitoringTask::m_logger
ILogger & m_logger
Definition: Main.cpp:261
ConnectionState::Unconnected
@ Unconnected
HiveConnectHiveMindApiMessageHandler
Definition: HiveConnectHiveMindApiMessageHandler.h:10
InterlocDataHandlerTask::m_interloc
IInterloc & m_interloc
Definition: Main.cpp:361
GreetSender.h
MessageSenderTask::setSerializer
void setSerializer(IHiveMindHostSerializer *serializer)
Definition: Main.cpp:208
BittyBuzzTask::BittyBuzzTask
BittyBuzzTask(const char *taskName, UBaseType_t priority, IDeviceStateUI &deviceStateUI, IButtonCallbackRegister &buttonCallbackRegister)
Definition: Main.cpp:38
MessageHandlerContainer::getRemoteMsgQueue
NotificationQueue< MessageDTO > & getRemoteMsgQueue()
get the remote message queue
Definition: MessageHandlerContainer.cpp:57
MessageDispatcherTask::m_streamQueue
ICircularQueue< MessageDTO > & m_streamQueue
Definition: Main.cpp:165
MessageHandlerContainer::createMessageDispatcher
MessageDispatcher createMessageDispatcher(IHiveMindHostDeserializer &deserializer, IHiveMindHostApiRequestHandler &hivemindApiReqHandler, IHiveConnectHiveMindApiMessageHandler &hiveconnectApiMessageHandler, IGreetSender &greetSender)
create a message dispatcher
Definition: MessageHandlerContainer.cpp:24
LogLevel::Warn
@ Warn
BSPContainer::getInterlocManager
IInterlocManager & getInterlocManager()
Returns an instance of the interloc manager.
Definition: BSPContainer.cpp:24
CommMonitoringTask::task
void task() override
Definition: Main.cpp:263
MessageHandlerContainer::createHiveMindHostApiRequestHandler
HiveMindHostApiRequestHandler createHiveMindHostApiRequestHandler()
create a request handler
Definition: MessageHandlerContainer.cpp:18
LogInterlocTask::m_interloc
IInterloc & m_interloc
Definition: Main.cpp:380
BittyBuzzFactory::createBittyBuzzBytecode
BittyBuzzBytecode createBittyBuzzBytecode(ILogger &logger)
Creates a BittyBuzzBytecode with the main.bzz bytecode.
Definition: BittyBuzzFactory.cpp:12
LogInterlocTask::m_logger
ILogger & m_logger
Definition: Main.cpp:381
BSPContainer
Definition: BSPContainer.h:12
IUserInterface::getPrintMutex
virtual Mutex & getPrintMutex()=0
get the mutex for printing. Note that the mutex is not used in any functions, the user needs to lock ...
ConnectionType::Ethernet
@ Ethernet
PositionsTable::m_positionsLength
uint16_t m_positionsLength
Definition: IInterloc.h:12
IBSP
Definition: IBSP.h:6
MessageSender.h
Logger.h
MessageHandlerContainer
Definition: MessageHandlerContainer.h:14
LogLevel::Info
@ Info
BittyBuzzTask::m_bytecode
BittyBuzzBytecode m_bytecode
Definition: Main.cpp:66
GreetHandler::m_bsp
IBSP & m_bsp
Definition: GreetHandler.h:22
SettingsContainer::getBBZVMStepDelayMs
uint16_t getBBZVMStepDelayMs()
Get the delay between each steps of the vm.
Definition: SettingsContainer.cpp:53
IUserInterface.h
BittyBuzzContainer::getBBZMessageService
BittyBuzzMessageService & getBBZMessageService()
return an instance of a bittybuzz message service
Definition: BittyBuzzContainer.cpp:21
IButtonCallbackRegister::setCallback
virtual void setCallback(buttonCallbackFunction_t callback, void *context)=0
sets the callback to the managed button
main
int main(int argc, char **argv)
Definition: Main.cpp:428
LogInterlocTask::~LogInterlocTask
~LogInterlocTask() override=default
BSPContainer::getRemoteCommInterface
std::optional< std::reference_wrapper< ICommInterface > > getRemoteCommInterface()
Return an instance of the connected remote comm interface.
Definition: BSPContainer.cpp:65
BittyBuzzFactory.h
gc_taskNormalPriority
constexpr uint16_t gc_taskNormalPriority
Definition: Main.cpp:27
BittyBuzzStringResolver
Definition: BittyBuzzStringResolver.h:9
LoggerContainer::getLogger
Logger & getLogger()
Return a reference to the global logger.
Definition: LoggerContainer.cpp:5
MessageSenderTask::task
void task() override
Definition: Main.cpp:217
InterlocDataHandlerTask
Definition: Main.cpp:353
MessageSenderTask
Definition: Main.cpp:192
ApplicationInterfaceContainer::getConnectionStateUI
ConnectionStateUI & getConnectionStateUI()
get the connection state UI
Definition: ApplicationInterfaceContainer.cpp:23
HardwareInterlocTask::HardwareInterlocTask
HardwareInterlocTask(const char *taskName, UBaseType_t priority)
Definition: Main.cpp:320
BittyBuzzVm::getState
bbzvm_state getState() const override
Get the state of the vm.
Definition: BittyBuzzVm.cpp:122
hostInterfaceGetter
std::optional< std::reference_wrapper< ICommInterface > > hostInterfaceGetter()
Definition: Main.cpp:398
AbstractTask
ILogger
A logger class with basic logging capabilities.
Definition: ILogger.h:35
GreetHandler::greet
bool greet() override
wait for a greet and then send the greet response. Serializes directly to the stream and not the the ...
Definition: GreetHandler.cpp:8
BSPContainer::getHostCommInterface
std::optional< std::reference_wrapper< ICommInterface > > getHostCommInterface()
Return an instance of the connected host comm interface.
Definition: BSPContainer.cpp:30
LogRet::Ok
@ Ok
connectionStateSetter
void(*)(ConnectionState state) connectionStateSetter
Definition: Main.cpp:34
IInterlocMessageHandler::processMessage
virtual bool processMessage()=0
Processes the next message in the queue.
IInterloc::process
virtual void process()=0
Spins the interloc task checking if any updates happened. Processing them and pushing update values t...
BBVMRet::OutMsgErr
@ OutMsgErr
BittyBuzzVm::step
BBVMRet step() override
Does one execution step in the virtual machine. Thus execute the buzz code in the step function.
Definition: BittyBuzzVm.cpp:90
BSPContainer::getBSP
IBSP & getBSP()
Returns an instance of the platform dependent BSP.
Definition: BSPContainer.cpp:13
ICommInterface
Definition: ICommInterface.h:8
InterlocContainer::getInterloc
IInterloc & getInterloc()
Definition: InterlocContainer.cpp:12
BittyBuzzBytecode
Definition: BittyBuzzBytecode.h:9
IBSP::initChip
virtual void initChip(void *args)=0
Initialise the chip for usage. Needs to be called early in the program.
MessageDispatcher.h
ConnectionState::Booting
@ Booting
BittyBuzzVm::stop
void stop() override
Stops the vm, can be called in another thread or in an interrupt.
Definition: BittyBuzzVm.cpp:73
GreetSender
Definition: GreetSender.h:9
MessageSender::processAndSerialize
bool processAndSerialize() override
process an item in the queue, serializes it and sends it to the deserializer
Definition: MessageSender.cpp:9
IDeviceStateUI::setDeviceState
virtual void setDeviceState(DeviceState state)=0
Sets the state of the device.
CmdLineArgs
A structure to wrap command line arguments used for certain BSPs.
Definition: IBSP.h:29
ConnectionState
ConnectionState
Definition: SystemStates.h:4
MessageDispatcherTask
Definition: Main.cpp:148
BittyBuzzTask::vmErrorToDeviceState
static DeviceState vmErrorToDeviceState(bbzvm_error err)
Definition: Main.cpp:72
SettingsContainer::getLogLevel
LogLevel getLogLevel()
Get the log level of the application.
Definition: SettingsContainer.cpp:33
MessageDispatcherTask::m_logger
ILogger & m_logger
Definition: Main.cpp:166
MessageHandlerContainer::getInterlocMsgQueue
NotificationQueue< MessageDTO > & getInterlocMsgQueue()
get the interloc message queue
Definition: MessageHandlerContainer.cpp:70
ConnectionStateUI::setConnectionState
void setConnectionState(ConnectionState state) override
Sets the state of the connection.
Definition: ConnectionStateUI.cpp:6
IInterloc
Definition: IInterloc.h:15
MessageHandlerContainer::createHiveConnectHiveMindApiMessageHandler
HiveConnectHiveMindApiMessageHandler createHiveConnectHiveMindApiMessageHandler()
create a message handler
Definition: MessageHandlerContainer.cpp:13
MessageHandlerContainer::getHostMsgQueue
NotificationQueue< MessageDTO > & getHostMsgQueue()
get the host message queue
Definition: MessageHandlerContainer.cpp:44
PositionsTable::m_positions
std::array< RelativePosition, MAX_AGENTS_IN_SWARM > m_positions
Definition: IInterloc.h:11
Logger::m_logLevel
LogLevel m_logLevel
Definition: Logger.h:21
IDeviceStateUI
Manages UI of the device state and informs the user via the board display.
Definition: IDeviceStateUI.h:7
IUserInterface::print
virtual int print(const char *format,...)=0
Provides an interface to print to the console or serial port. The arguments and return values match t...
MessageDispatcher
Definition: MessageDispatcher.h:14
InterlocMessageHandlerTask::m_interlocMessageQueue
NotificationQueue< MessageDTO > & m_interlocMessageQueue
Definition: Main.cpp:339
GreetHandler::m_serializer
IHiveMindHostSerializer & m_serializer
Definition: GreetHandler.h:20
Logger
Definition: Logger.h:9
BBVMRet::Ok
@ Ok
SettingsContainer.h
InterlocDataHandlerTask::InterlocDataHandlerTask
InterlocDataHandlerTask(const char *taskName, UBaseType_t priority)
Definition: Main.cpp:355
ConnectionState::Ethernet
@ Ethernet
BittyBuzzTask::m_logger
ILogger & m_logger
Definition: Main.cpp:63
BittyBuzzVm::logDump
void logDump(LogLevel logLevel) override
Logs the virtual machine state, stack, heap and table segments.
Definition: BittyBuzzVm.cpp:78
IUserInterface
Manages the user interface The user interface can consist of buttons, LED, serial print ports,...
Definition: IUserInterface.h:36
CommMonitoringTask::m_commInterfaceGetter
commInterfaceGetter m_commInterfaceGetter
Definition: Main.cpp:259
IGreetHandler
Definition: IGreetHandler.h:4
ConnectionType::USB
@ USB
IHandshakeUI::handshake
virtual void handshake(bool handshaked)=0
Sets the handshake status of the device.
MessageSender
Definition: MessageSender.h:10
DeviceState::Ok
@ Ok
HardwareInterlocTask
Definition: Main.cpp:318
ApplicationInterfaceContainer::getDeviceStateUI
DeviceStateUI & getDeviceStateUI()
get the device state UI
Definition: ApplicationInterfaceContainer.cpp:28
BittyBuzzTask::m_bittybuzzVm
BittyBuzzVm m_bittybuzzVm
Definition: Main.cpp:68
BittyBuzzTask::m_deviceStateUI
IDeviceStateUI & m_deviceStateUI
Definition: Main.cpp:64
Logger::Logger
Logger(LogLevel level, IUserInterface &ui)
Definition: Logger.cpp:6
MessageSenderTask::m_streamQueue
INotificationQueue< MessageDTO > & m_streamQueue
Definition: Main.cpp:212
DeviceState
DeviceState
Definition: SystemStates.h:6
MessageSenderTask::~MessageSenderTask
~MessageSenderTask() override=default
IGreetHandler.h
InterlocMessageHandlerTask::task
void task() override
Definition: Main.cpp:342
MessageSenderTask::m_keepRunning
bool m_keepRunning
Definition: Main.cpp:215
IInterloc.h
ApplicationInterfaceContainer::getUserUI
UserUI & getUserUI()
get the UI available to the user
Definition: ApplicationInterfaceContainer.cpp:43
HardwareInterlocTask::task
void task() override
Definition: Main.cpp:326
BittyBuzzVm::getError
bbzvm_error getError() const override
Get the error state of the VM.
Definition: BittyBuzzVm.cpp:124
LoggerContainer
Definition: LoggerContainer.h:6
ApplicationInterfaceContainer::getRemoteHandshakeUI
RemoteHandshakeUI & getRemoteHandshakeUI()
get the remote handshake UI
Definition: ApplicationInterfaceContainer.cpp:38
InterlocMessageHandlerTask::m_interlocMessageHandler
IInterlocMessageHandler & m_interlocMessageHandler
Definition: Main.cpp:340
MessageHandlerContainer.h
MessageSenderTask::m_stream
ICommInterface * m_stream
Definition: Main.cpp:211
BBVMRet::VmErr
@ VmErr