80 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			2.3 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>
 | |
| #include <unistd.h>
 | |
| #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;
 | |
| /**
 | |
|  * @brief Create a serial port object instance.
 | |
|  *
 | |
|  * @param info Serial port information
 | |
|  * @return void*
 | |
|  */
 | |
| void *CreateUartDevice(const UartInfo info);
 | |
| /**
 | |
|  * @brief Open the serial port.
 | |
|  *
 | |
|  * @param object Serial port object pointer.
 | |
|  * @return const StatusCode
 | |
|  */
 | |
| const StatusCode IUartOpen(void *object);
 | |
| /**
 | |
|  * @brief Send data using a serial port.
 | |
|  *
 | |
|  * @param object Serial port object pointer.
 | |
|  * @param buff The data to be sent.
 | |
|  * @param buffLength The length of data to be sent.
 | |
|  * @return const ssize_t
 | |
|  */
 | |
| const ssize_t IUartSend(void *object, const void *buff, const size_t buffLength);
 | |
| /**
 | |
|  * @brief Use a serial port to receive data.
 | |
|  *
 | |
|  * @param object Serial port object pointer.
 | |
|  * @param buff The cache area for receiving data.
 | |
|  * @param buffLength The size of the cache area for receiving data.
 | |
|  * @param timeoutMs The timeout time in milliseconds.
 | |
|  * @return const ssize_t
 | |
|  */
 | |
| const ssize_t IUartRecv(void *object, void *buff, const size_t buffLength, const unsigned int timeoutMs);
 | |
| /**
 | |
|  * @brief Clear the serial port cache data.
 | |
|  *
 | |
|  * @param object Serial port object pointer.
 | |
|  */
 | |
| void IUartTcflush(void *object);
 | |
| /**
 | |
|  * @brief Destroy a serial object instance.
 | |
|  *
 | |
|  * @param object Serial port object pointer.
 | |
|  */
 | |
| void IUartDeviceFree(void *object);
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| #endif | 
