forked from EmbeddedRPC/erpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
erpc_serial_transport.hpp
103 lines (87 loc) · 2.37 KB
/
erpc_serial_transport.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__SERIAL_TRANSPORT_H_
#define _EMBEDDED_RPC__SERIAL_TRANSPORT_H_
#include "erpc_framed_transport.hpp"
#include <string>
extern "C" {
#ifdef _WIN32
typedef long speed_t;
#else
#include <termios.h>
#endif
}
/*!
* @addtogroup serial_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Serial transport layer for host PC
*
* @ingroup serial_transport
*/
class SerialTransport : public FramedTransport
{
public:
/*!
* @brief Constructor.
*
* @param[in] portName Port name.
* @param[in] baudRate Baudrate.
*/
SerialTransport(const char *portName, speed_t baudRate);
/*!
* @brief Destructor.
*/
virtual ~SerialTransport(void);
/*!
* @brief Initialize Serial peripheral.
*
* @param[in] vtime Read timeout.
* @param[in] vmin Read timeout min.
*
* @return Status of init function.
*/
erpc_status_t init(uint8_t vtime, uint8_t vmin);
private:
using FramedTransport::underlyingReceive;
using FramedTransport::underlyingSend;
/*!
* @brief Receive data from Serial peripheral.
*
* @param[inout] data Preallocated buffer for receiving data.
* @param[in] size Size of data to read.
*
* @retval kErpcStatus_ReceiveFailed Serial failed to receive data.
* @retval kErpcStatus_Success Successfully received all data.
*/
virtual erpc_status_t underlyingReceive(uint8_t *data, uint32_t size) override;
/*!
* @brief Write data to Serial peripheral.
*
* @param[in] data Buffer to send.
* @param[in] size Size of data to send.
*
* @retval kErpcStatus_ReceiveFailed Serial failed to receive data.
* @retval kErpcStatus_Success Successfully received all data.
*/
virtual erpc_status_t underlyingSend(const uint8_t *data, uint32_t size) override;
private:
int m_serialHandle; /*!< Serial handle id. */
const char *m_portName; /*!< Port name. */
speed_t m_baudRate; /*!< Bauderate. */
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__SERIAL_TRANSPORT_H_