/**************************************************************************** * This file is part of the project AqHome. * AqHome (c) by 2023 Martin Preuss, all rights reserved. * * The license for this file can be found in the file COPYING which you * should have received along with this file. ****************************************************************************/ #ifndef AQH_SERIAL_H #define AQH_SERIAL_H #include #include "aqhome/msg.h" #include #include #ifdef __cplusplus extern "C" { #endif typedef struct AQH_SERIAL AQH_SERIAL; typedef void (*AQH_SERIAL_PACKETRECEIVED_FN)(AQH_SERIAL *sr, AQH_MSG *msg); enum { AQH_SerialReadWriteMode_ReadOnly=1, AQH_SerialReadWriteMode_WriteOnly=2, AQH_SerialReadWriteMode_ReadWrite=3 }; AQHOME_API AQH_SERIAL *AQH_Serial_new(const char *deviceName, uint8_t addr); AQHOME_API void AQH_Serial_free(AQH_SERIAL *sr); AQHOME_API uint8_t AQH_Serial_GetAddress(const AQH_SERIAL *sr); AQHOME_API int AQH_Serial_Open(AQH_SERIAL *sr, int rwMode); AQHOME_API void AQH_Serial_Close(AQH_SERIAL *sr); AQHOME_API int AQH_Serial_Recv(AQH_SERIAL *sr, uint8_t *buf, int len); AQHOME_API int AQH_Serial_Send(AQH_SERIAL *sr, const uint8_t *ptr, uint8_t len); AQHOME_API int AQH_Serial_SendPacket(AQH_SERIAL *sr, uint8_t destAddr, const uint8_t *ptr, uint8_t len); AQHOME_API int AQH_Serial_Loop(AQH_SERIAL *sr); AQHOME_API int AQH_Serial_ReadOnlyLoop(AQH_SERIAL *sr); AQHOME_API int AQH_Serial_AddMessageToSend(AQH_SERIAL *sr, AQH_MSG *msg); AQHOME_API int AQH_Serial_StartWriting(AQH_SERIAL *sr, const uint8_t *ptr, uint8_t len); AQHOME_API void AQH_Serial_SetPacketReceivedFn(AQH_SERIAL *sr, AQH_SERIAL_PACKETRECEIVED_FN fn); #ifdef __cplusplus } #endif #endif