Browse Source

ble-dongle: Split commands into shared and non-shared

Andreas Berthoud 4 years ago
parent
commit
0fb17545c3
  1. 40
      nucleo-wb55-dongle-ble/app/Command.hpp
  2. 16
      nucleo-wb55-dongle-ble/app/commands.hpp
  3. 1
      nucleo-wb55-dongle-ble/commands/GPCommand.cpp
  4. 0
      nucleo-wb55-dongle-ble/commands/GPCommand.hpp
  5. 32
      nucleo-wb55-dongle-ble/commands/dispatch.cpp
  6. 15
      nucleo-wb55-dongle-ble/commands/dispatch.hpp
  7. 25
      nucleo-wb55-dongle-ble/shared_commands/Command.hpp
  8. 0
      nucleo-wb55-dongle-ble/shared_commands/HeartbeatCommand.cpp
  9. 0
      nucleo-wb55-dongle-ble/shared_commands/HeartbeatCommand.hpp
  10. 0
      nucleo-wb55-dongle-ble/shared_commands/LedCommand.cpp
  11. 0
      nucleo-wb55-dongle-ble/shared_commands/LedCommand.hpp
  12. 0
      nucleo-wb55-dongle-ble/shared_commands/LogCommand.cpp
  13. 1
      nucleo-wb55-dongle-ble/shared_commands/LogCommand.hpp
  14. 0
      nucleo-wb55-dongle-ble/shared_commands/Notification.cpp
  15. 0
      nucleo-wb55-dongle-ble/shared_commands/Notification.hpp
  16. 0
      nucleo-wb55-dongle-ble/shared_commands/Request.cpp
  17. 0
      nucleo-wb55-dongle-ble/shared_commands/Request.hpp
  18. 0
      nucleo-wb55-dongle-ble/shared_commands/Response.cpp
  19. 0
      nucleo-wb55-dongle-ble/shared_commands/Response.hpp
  20. 0
      nucleo-wb55-dongle-ble/shared_commands/command_interpreter.c
  21. 6
      nucleo-wb55-dongle-ble/shared_commands/commands.h
  22. 24
      nucleo-wb55-dongle-ble/shared_commands/commands.hpp
  23. 33
      nucleo-wb55-dongle-ble/shared_commands/execute.cpp
  24. 13
      nucleo-wb55-dongle-ble/shared_commands/execute.hpp

40
nucleo-wb55-dongle-ble/app/Command.hpp

@ -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_ */

16
nucleo-wb55-dongle-ble/app/commands.hpp

@ -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_ */

1
nucleo-wb55-dongle-ble/app/GPCommand.cpp → nucleo-wb55-dongle-ble/commands/GPCommand.cpp

@ -6,6 +6,7 @@
*/
#include "GPCommand.hpp"
#include "app_ble.h"
GPResponse::GPResponse(uint16_t response_identifier, bool was_successful)

0
nucleo-wb55-dongle-ble/app/GPCommand.hpp → nucleo-wb55-dongle-ble/commands/GPCommand.hpp

32
nucleo-wb55-dongle-ble/commands/dispatch.cpp

@ -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;
}
}

15
nucleo-wb55-dongle-ble/commands/dispatch.hpp

@ -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_ */

25
nucleo-wb55-dongle-ble/shared_commands/Command.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
nucleo-wb55-dongle-ble/app/HeartbeatCommand.cpp → nucleo-wb55-dongle-ble/shared_commands/HeartbeatCommand.cpp

0
nucleo-wb55-dongle-ble/app/HeartbeatCommand.hpp → nucleo-wb55-dongle-ble/shared_commands/HeartbeatCommand.hpp

0
nucleo-wb55-dongle-ble/app/LedCommand.cpp → nucleo-wb55-dongle-ble/shared_commands/LedCommand.cpp

0
nucleo-wb55-dongle-ble/app/LedCommand.hpp → nucleo-wb55-dongle-ble/shared_commands/LedCommand.hpp

0
nucleo-wb55-dongle-ble/app/LogCommand.cpp → nucleo-wb55-dongle-ble/shared_commands/LogCommand.cpp

1
nucleo-wb55-dongle-ble/app/LogCommand.hpp → nucleo-wb55-dongle-ble/shared_commands/LogCommand.hpp

@ -9,6 +9,7 @@
#define LOGCOMMAND_H_
#include "Notification.hpp"
#include <stdarg.h>
extern "C" void log_debug(const char * logger_name, const char * format, int nargs, ...);
extern "C" void log_info(const char * logger_name, const char * format, int nargs, ...);

0
nucleo-wb55-dongle-ble/app/Notification.cpp → nucleo-wb55-dongle-ble/shared_commands/Notification.cpp

0
nucleo-wb55-dongle-ble/app/Notification.hpp → nucleo-wb55-dongle-ble/shared_commands/Notification.hpp

0
nucleo-wb55-dongle-ble/app/Request.cpp → nucleo-wb55-dongle-ble/shared_commands/Request.cpp

0
nucleo-wb55-dongle-ble/app/Request.hpp → nucleo-wb55-dongle-ble/shared_commands/Request.hpp

0
nucleo-wb55-dongle-ble/app/Response.cpp → nucleo-wb55-dongle-ble/shared_commands/Response.cpp

0
nucleo-wb55-dongle-ble/app/Response.hpp → nucleo-wb55-dongle-ble/shared_commands/Response.hpp

0
nucleo-wb55-dongle-ble/app/command_interpreter.c → nucleo-wb55-dongle-ble/shared_commands/command_interpreter.c

6
nucleo-wb55-dongle-ble/app/commands.h → nucleo-wb55-dongle-ble/shared_commands/commands.h

@ -8,12 +8,12 @@
#ifndef COMMANDS_H_
#define COMMANDS_H_
void pop_and_execute_commands();
void handle_received_command(uint8_t command_id, uint8_t * payload_ptr, uint16_t length);
void log_debug(const char * logger_name, const char * format, int nargs, ...);
void log_info(const char * logger_name, const char * format, int nargs, ...);
void log_warning(const char * logger_name, const char * format, int nargs, ...);
void log_error(const char * logger_name, const char * format, int nargs, ...);
void pop_and_execute_commands();
void handle_received_command(uint8_t command_id, uint8_t * payload_ptr, uint16_t length);
#endif /* COMMANDS_H_ */

24
nucleo-wb55-dongle-ble/shared_commands/commands.hpp

@ -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_ */

33
nucleo-wb55-dongle-ble/app/Command.cpp → nucleo-wb55-dongle-ble/shared_commands/execute.cpp

@ -1,19 +1,17 @@
/*
* Command.cpp
* execute.cpp
*
* Created on: Jul 8, 2021
* Created on: 18 Jul 2021
* Author: Andreas Berthoud
*/
#include <queue>
#include <cstring>
#include "Command.hpp"
#include "string.h"
#include "execute.hpp"
#include "stm32wbxx_hal.h"
#include "commands.hpp"
#include "HeartbeatCommand.hpp"
#include "LedCommand.hpp"
#include "GPCommand.hpp"
#include "LogCommand.hpp"
std::queue<Command*> command_queue;
@ -28,29 +26,12 @@ void pop_and_execute_commands() {
bool was_successful = command->execute();
HAL_Delay(5); // this delay is required. Otherwise, the command were not sent somehow...
if (!was_successful) {
log_error("Execution of command with ID %n was not successful!", 1, command->id);
log_error("pop_and_execute_commands", "Execution of command with ID %n was not successful!", 1, command->id);
}
delete command;
command_queue.pop();
}
}
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;
}
}

13
nucleo-wb55-dongle-ble/shared_commands/execute.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…
Cancel
Save