more code
This commit is contained in:
140
code/Core/Inc/photon_protocol.h
Normal file
140
code/Core/Inc/photon_protocol.h
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* photon_protocol.h
|
||||
*
|
||||
* Created on: 19 Dec 2025
|
||||
* Author: janik
|
||||
*/
|
||||
|
||||
#ifndef INC_PHOTON_PROTOCOL_H_
|
||||
#define INC_PHOTON_PROTOCOL_H_
|
||||
|
||||
#define UUID_LENGTH 12 // 12 8bit values
|
||||
#define PHOTON_NETWORK_CONTROLLER_ADDRESS 0x00
|
||||
#define PHOTON_NETWORK_BROADCAST_ADDRESS 0xFF
|
||||
#define VENDOR_SPECIFIC_OPTIONS_LENGTH 16
|
||||
|
||||
|
||||
typedef enum {
|
||||
STATUS_OK = 0x00,
|
||||
STATUS_WRONG_FEEDER_ID = 0x01,
|
||||
STATUS_COULDNT_REACH = 0x02,
|
||||
STATUS_UNINITIALIZED_FEEDER = 0x03,
|
||||
STATUS_FEEDING_IN_PROGRESS = 0x04,
|
||||
STATUS_FAIL = 0x05,
|
||||
|
||||
STATUS_TIMEOUT = 0xFE,
|
||||
STATUS_UNKNOWN_ERROR = 0xFF
|
||||
} FeederStatus;
|
||||
|
||||
typedef enum {
|
||||
// Unicast Commands
|
||||
GET_FEEDER_ID = 0x01,
|
||||
INITIALIZE_FEEDER = 0x02,
|
||||
GET_VERSION = 0x03,
|
||||
MOVE_FEED_FORWARD = 0x04,
|
||||
MOVE_FEED_BACKWARD = 0x05,
|
||||
MOVE_FEED_STATUS = 0x06,
|
||||
|
||||
VENDOR_OPTIONS = 0xbf,
|
||||
|
||||
// Broadcast Commands
|
||||
GET_FEEDER_ADDRESS = 0xc0,
|
||||
IDENTIFY_FEEDER = 0xc1,
|
||||
PROGRAM_FEEDER_FLOOR = 0xc2,
|
||||
UNINITIALIZED_FEEDERS_RESPOND = 0xc3
|
||||
// EXTENDED_COMMAND = 0xff, Unused, reserved for future use
|
||||
} FeederCommand;
|
||||
|
||||
|
||||
|
||||
/* ---------- Packet Header ---------- */
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t toAddress;
|
||||
uint8_t fromAddress;
|
||||
uint8_t packetId;
|
||||
uint8_t payloadLength;
|
||||
uint8_t crc;
|
||||
} PhotonPacketHeader;
|
||||
|
||||
/* ---------- Command Payloads ---------- */
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t distance;
|
||||
} MoveCommand;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t uuid[UUID_LENGTH];
|
||||
} GetFeederAddressCommand;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t uuid[UUID_LENGTH];
|
||||
} InitializeFeederCommand;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t options[VENDOR_SPECIFIC_OPTIONS_LENGTH];
|
||||
} VendorOptionsCommand;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t uuid[UUID_LENGTH];
|
||||
uint8_t address;
|
||||
} ProgramFeederFloorAddressCommand;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t uuid[UUID_LENGTH];
|
||||
} IdentifyFeederCommand;
|
||||
|
||||
/* ---------- Full Command Packet ---------- */
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
PhotonPacketHeader header;
|
||||
uint8_t commandId;
|
||||
union {
|
||||
MoveCommand move;
|
||||
GetFeederAddressCommand getFeederAddress;
|
||||
InitializeFeederCommand initializeFeeder;
|
||||
VendorOptionsCommand vendorOptions;
|
||||
ProgramFeederFloorAddressCommand programFeederFloorAddress;
|
||||
IdentifyFeederCommand identifyFeeder;
|
||||
} payload;
|
||||
} PhotonCommand;
|
||||
|
||||
/* ---------- Response Payloads ---------- */
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t uuid[UUID_LENGTH];
|
||||
} GetFeederIdResponse;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t uuid[UUID_LENGTH];
|
||||
} InitializeFeederResponse;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t version;
|
||||
} GetProtocolVersionResponse;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t expectedFeedTime;
|
||||
} FeedDistanceResponse;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t options[VENDOR_SPECIFIC_OPTIONS_LENGTH];
|
||||
} VendorOptionsResponse;
|
||||
|
||||
/* ---------- Full Response Packet ---------- */
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
PhotonPacketHeader header;
|
||||
uint8_t status;
|
||||
union {
|
||||
GetFeederIdResponse getFeederId;
|
||||
InitializeFeederResponse initializeFeeder;
|
||||
GetProtocolVersionResponse protocolVersion;
|
||||
FeedDistanceResponse expectedTimeToFeed;
|
||||
VendorOptionsResponse vendorOptions;
|
||||
} payload;
|
||||
} PhotonResponse;
|
||||
|
||||
|
||||
|
||||
#endif /* INC_PHOTON_PROTOCOL_H_ */
|
||||
Reference in New Issue
Block a user