123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /*
- * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
- /**
- * @file shellmatta_transport.h
- * @brief transport layer functions of shellmatta
- * @authors Simon Fischer <dev@s-fischer.net> Stefan Strobel <stefan.strobel@shimatta.net>
- */
- /**
- * @addtogroup shellmatta_transport
- * @{
- */
- #ifndef _SHELLMATTA_TRANSPORT_H_
- #define _SHELLMATTA_TRANSPORT_H_
- #include "shellmatta.h"
- /** @brief value of start-of-header character */
- #define SHELLMATTA_TRANSPORT_START_OF_HEADER 0x01u
- /** @brief currently supported protocol version */
- #define SHELLMATTA_TRANSPORT_PROTOCOL_VERSION 0x01u
- /** @brief broadcast address */
- #define SHELLMATTA_TRANSPORT_BROADCAST_ADDRESS 0u
- /** @brief master address */
- #define SHELLMATTA_TRANSPORT_MASTER_ADDRESS 1u
- /* header field length defines */
- /** @brief length of header */
- #define SHELLMATTA_TRANSPORT_LENGTH_HEADER ((uint8_t)(8))
- /** @brief maximum length of shellmatta internal packages (e.g. sequence counter packets) */
- #define SHELLMATTA_TRANSPORT_LENGTH_PAYLOAD_INT ((uint8_t)(32))
- /** @brief length of crc32 */
- #define SHELLMATTA_TRANSPORT_LENGTH_CRC ((uint8_t)(4))
- /** @brief length of crc32 */
- #define SHELLMATTA_TRANSPORT_LENGTH_STATIC (SHELLMATTA_TRANSPORT_LENGTH_HEADER + SHELLMATTA_TRANSPORT_LENGTH_CRC)
- /** @brief helper macro for CRC calculation */
- #define SHELLMATTA_TRANSPORT_CALC_CRC(transporLayer, data, size) NULL != (transportLayer)->customCrcFct ? \
- (transportLayer)->customCrcFct((data), (size)) : \
- crc32Calc((data), (size));
- /** @brief packet definition with reduced payload (for internal packets) */
- typedef struct __attribute__((__packed__))
- {
- shellmatta_transport_header_t header; /**< header of the packet */
- char payload[SHELLMATTA_TRANSPORT_LENGTH_PAYLOAD_INT]; /**< payload of the packet */
- uint32_t crc; /**< checksum of the packet */
- } shellmatta_transport_packet_int_t;
- /**
- * @brief definitions of shellmatta transport layer packet types
- */
- #define SHELLMATTA_TRANSPORT_PACKET_DATA 0x00u /**< packet type to send plain data */
- #define SHELLMATTA_TRANSPORT_PACKET_SEQ_CNT_REQUEST 0x01u /**< packet type to request sequence counters */
- #define SHELLMATTA_TRANSPORT_PACKET_SEQ_CNT_RESPOND 0x81u /**< packet type to respond with sequence counters */
- #define SHELLMATTA_TRANSPORT_PACKET_MAX_BUFFERSIZE_REQUEST 0x02u /**< packet type to set and request max buffersize */
- #define SHELLMATTA_TRANSPORT_PACKET_MAX_BUFFERSIZE_RESPOND 0x82u /**< packet type to respond with max buffersize */
- #define SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_REQUEST 0x03u /**< UNUSED: packet type to request search for a device by unique id */
- #define SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_RESPOND 0x83u /**< UNUSED: packet type to respond with search results */
- #define SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_REQUEST 0x04u /**< UNUSED: packet type to set and request an address */
- #define SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_RESPOND 0x84u /**< UNUSED: packet type to respond with a set address */
- shellmatta_retCode_t shellmatta_transport_init( shellmatta_transport_layer_t *transportLayer,
- shellmatta_write_t writeFct);
- shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t *transportLayer,
- char byte,
- char **data,
- uint32_t *length);
- shellmatta_retCode_t shellmatta_transport_write(shellmatta_transport_layer_t *transportLayer,
- const char* data,
- uint32_t length);
- #endif /* _SHELLMATTA_TRANSPORT_H_ */
- /** @} */
|