hunting/utils/UartDevice/include/UartDevice.h
2023-11-12 07:33:51 -08:00

56 lines
2.0 KiB
C

/*
* Copyright (c) 2023 Fancy Code.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef UARTD_EVICE_H
#define UARTD_EVICE_H
#include "StatusCode.h"
#include <cstddef>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct uart_info
{
const char *mDevice;
const int mSpeed;
const int mFlowCtrl;
const int mDataBits;
const int mStopBits;
const int mParity;
} UartInfo;
typedef struct uart_device UartDevice;
typedef struct uart_device
{
const StatusCode (*mOpen)(UartDevice *);
const size_t (*mSend)(UartDevice *, const char *, const size_t);
const size_t (*mRecv)(UartDevice *, char *, const size_t, const unsigned int);
void (*mTcflush)(UartDevice *);
void (*mFree)(void *);
} UartDevice;
UartDevice *CreateUartDevice(const UartInfo info);
static inline const StatusCode IUartOpen(UartDevice *object) { return object->mOpen(object); }
static inline const size_t IUartSend(UartDevice *object, const char *buff, const size_t buffLength)
{
return object->mSend(object, buff, buffLength);
}
static inline const size_t IUartRecv(UartDevice *object, char *buff, const size_t buffLength,
const unsigned int timeoutMs)
{
return object->mRecv(object, buff, buffLength, timeoutMs);
}
static inline void IUartTcflush(UartDevice *object) { return object->mTcflush(object); }
static inline void IUartDeviceFree(UartDevice *object) { object->mFree(object); }
#ifdef __cplusplus
}
#endif
#endif