2023-07-14 15:50:45 +01:00

70 lines
1.3 KiB
C

/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) Camden Dixie O'Brien
*/
#ifndef PROTOCOL_MESSAGES_H
#define PROTOCOL_MESSAGES_H
#include "alarm_types.h"
#include <stdint.h>
#define MESSAGE_MAX_PARAMS 16
typedef enum {
MESSAGE_PARAM_TYPE_U8 = 0,
MESSAGE_PARAM_TYPE_U16 = 1,
MESSAGE_PARAM_TYPE_U32 = 2,
MESSAGE_PARAM_TYPE_U64 = 3,
MESSAGE_PARAM_TYPE_STRING = 4,
MESSAGE_PARAM_TYPE_ALARM = 5,
MESSAGE_PARAM_TYPE_COUNT,
} MessageParamType;
typedef struct {
MessageParamType type;
union {
uint8_t u8;
uint16_t u16;
uint32_t u32;
uint64_t u64;
const char *string;
Alarm alarm;
};
} MessageParam;
typedef enum {
COMMAND_INSTRUCTION_GET_VERSION = 0,
COMMAND_INSTRUCTION_SET_TIME = 1,
COMMAND_INSTRUCTION_LIST_ALARMS = 2,
COMMAND_INSTRUCTION_ADD_ALARM = 3,
COMMAND_INSTRUCTION_REMOVE_ALARM = 4,
COMMAND_INSTRUCTION_LIST_SETTINGS = 5,
COMMAND_INSTRUCTION_SET_SETTING = 6,
COMMAND_INSTRUCTION_COUNT,
} CommandInstruction;
typedef enum {
RESPONSE_STATUS_OK = 0,
RESPONSE_STATUS_BUSY = 1,
RESPONSE_STATUS_INVALID_COMMAND = 2,
RESPONSE_STATUS_INTERNAL_ERROR = 3,
RESPONSE_STATUS_OUT_OF_SPACE = 4,
RESPONSE_STATUS_COUNT,
} ResponseStatus;
typedef struct {
union {
CommandInstruction instruction;
ResponseStatus status;
};
uint8_t param_count;
MessageParam params[MESSAGE_MAX_PARAMS];
} Message;
#endif