24 changed files with 121 additions and 85 deletions
@ -1,40 +0,0 @@ |
|||
/*
|
|||
* Command.hpp |
|||
* |
|||
* Created on: Jul 8, 2021 |
|||
* Author: Andreas Berthoud |
|||
*/ |
|||
|
|||
#ifndef SRC_COMMAND_H_ |
|||
#define SRC_COMMAND_H_ |
|||
|
|||
#include <stdint.h> |
|||
|
|||
extern "C" void pop_and_execute_commands(); |
|||
extern "C" void handle_received_command(uint8_t command_id, uint8_t * payload_ptr, uint16_t length); |
|||
|
|||
typedef enum : uint8_t { |
|||
COMMAND_NONE = 0, |
|||
COMMAND_LOG = 0x1, |
|||
COMMAND_HEARTBEAT_REQUEST = 0x2, |
|||
COMMAND_HEARTBEAT_RESPONSE = 0x3, |
|||
COMMAND_LED_REQUEST = 0x4, |
|||
COMMAND_LED_RESPONSE = 0x5, |
|||
COMMAND_GP_REQUEST = 0x6, |
|||
COMMAND_GP_RESPONSE = 0x7, |
|||
} CommandId; |
|||
|
|||
|
|||
class Command { |
|||
public: |
|||
CommandId id; |
|||
|
|||
virtual ~Command() {}; |
|||
|
|||
virtual CommandId get_command_id() = 0; |
|||
virtual bool execute() = 0; |
|||
}; |
|||
|
|||
void push_command(Command * command); |
|||
|
|||
#endif /* SRC_COMMAND_H_ */ |
|||
@ -1,16 +0,0 @@ |
|||
/*
|
|||
* commands.hpp |
|||
* |
|||
* Created on: Jul 13, 2021 |
|||
* Author: Andreas Berthoud |
|||
*/ |
|||
|
|||
#ifndef COMMANDS_HPP_ |
|||
#define COMMANDS_HPP_ |
|||
|
|||
extern "C" void log_debug(const char * format, int nargs, ...); |
|||
extern "C" void log_info(const char * format, int nargs, ...); |
|||
extern "C" void log_warning(const char * format, int nargs, ...); |
|||
extern "C" void log_error(const char * format, int nargs, ...); |
|||
|
|||
#endif /* COMMANDS_HPP_ */ |
|||
@ -0,0 +1,32 @@ |
|||
/*
|
|||
* dispatch.cpp |
|||
* |
|||
* Created on: 18 Jul 2021 |
|||
* Author: Andreas Berthoud |
|||
*/ |
|||
|
|||
#include "dispatch.hpp" |
|||
|
|||
#include "GPCommand.hpp" |
|||
#include "HeartbeatCommand.hpp" |
|||
#include "LedCommand.hpp" |
|||
|
|||
void handle_received_command(uint8_t command_id, uint8_t * payload_ptr, uint16_t size) { |
|||
|
|||
switch (command_id) |
|||
{ |
|||
case COMMAND_HEARTBEAT_REQUEST: |
|||
push_command(new HeartbeatRequest(payload_ptr, size)); |
|||
break; |
|||
case COMMAND_LED_REQUEST: |
|||
push_command(new LedRequest(payload_ptr, size)); |
|||
break; |
|||
case COMMAND_GP_REQUEST: |
|||
push_command(new GPRequest(payload_ptr, size)); |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
/*
|
|||
* dispatch.hpp |
|||
* |
|||
* Created on: 18 Jul 2021 |
|||
* Author: Andreas Berthoud |
|||
*/ |
|||
|
|||
#ifndef DISPATCH_HPP_ |
|||
#define DISPATCH_HPP_ |
|||
|
|||
#include <stdint.h> |
|||
|
|||
extern "C" void handle_received_command(uint8_t command_id, uint8_t * payload_ptr, uint16_t length); |
|||
|
|||
#endif /* DISPATCH_HPP_ */ |
|||
@ -0,0 +1,25 @@ |
|||
/*
|
|||
* Command.hpp |
|||
* |
|||
* Created on: Jul 8, 2021 |
|||
* Author: Andreas Berthoud |
|||
*/ |
|||
|
|||
#ifndef SRC_COMMAND_H_ |
|||
#define SRC_COMMAND_H_ |
|||
|
|||
#include "commands.hpp" |
|||
|
|||
class Command { |
|||
public: |
|||
CommandId id; |
|||
|
|||
virtual ~Command() {}; |
|||
|
|||
virtual CommandId get_command_id() = 0; |
|||
virtual bool execute() = 0; |
|||
}; |
|||
|
|||
void push_command(Command * command); |
|||
|
|||
#endif /* SRC_COMMAND_H_ */ |
|||
@ -0,0 +1,24 @@ |
|||
/*
|
|||
* commands.hpp |
|||
* |
|||
* Created on: Jul 13, 2021 |
|||
* Author: Andreas Berthoud |
|||
*/ |
|||
|
|||
#ifndef COMMANDS_HPP_ |
|||
#define COMMANDS_HPP_ |
|||
|
|||
#include <stdint.h> |
|||
|
|||
typedef enum : uint8_t { |
|||
COMMAND_NONE = 0, |
|||
COMMAND_LOG = 0x1, |
|||
COMMAND_HEARTBEAT_REQUEST = 0x2, |
|||
COMMAND_HEARTBEAT_RESPONSE = 0x3, |
|||
COMMAND_LED_REQUEST = 0x4, |
|||
COMMAND_LED_RESPONSE = 0x5, |
|||
COMMAND_GP_REQUEST = 0x6, |
|||
COMMAND_GP_RESPONSE = 0x7, |
|||
} CommandId; |
|||
|
|||
#endif /* COMMANDS_HPP_ */ |
|||
@ -0,0 +1,13 @@ |
|||
/*
|
|||
* execute.hpp |
|||
* |
|||
* Created on: 18 Jul 2021 |
|||
* Author: Andreas Berthoud |
|||
*/ |
|||
|
|||
#ifndef EXECUTE_HPP_ |
|||
#define EXECUTE_HPP_ |
|||
|
|||
extern "C" void pop_and_execute_commands(); |
|||
|
|||
#endif /* EXECUTE_HPP_ */ |
|||
Loading…
Reference in new issue