Commit | Line | Data |
---|---|---|
b9187cc6 LOK |
1 | #pragma once |
2 | ||
3 | /* | |
4 | * boblight | |
5 | * Copyright (C) Bob 2009 | |
6 | * | |
7 | * boblight is free software: you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * boblight is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
15 | * See the GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along | |
18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
21 | #include "os-dependent.h" | |
761dcc45 | 22 | #include <cectypes.h> |
b9187cc6 | 23 | #include <string> |
b9187cc6 | 24 | #include <stdint.h> |
220537f2 | 25 | #include "../AdapterCommunication.h" |
b1f50952 | 26 | #include "../platform/threads.h" |
b9187cc6 LOK |
27 | |
28 | #ifndef __WINDOWS__ | |
29 | #include <termios.h> | |
30 | #else | |
b9187cc6 LOK |
31 | #include "../util/buffer.h" |
32 | #endif | |
33 | ||
34 | namespace CEC | |
35 | { | |
36 | #define PAR_NONE 0 | |
37 | #define PAR_EVEN 1 | |
38 | #define PAR_ODD 2 | |
39 | ||
40 | class CSerialPort | |
41 | { | |
42 | public: | |
43 | CSerialPort(); | |
44 | virtual ~CSerialPort(); | |
45 | ||
8bca69de | 46 | bool Open(std::string name, uint32_t baudrate, uint8_t databits = 8, uint8_t stopbits = 1, uint8_t parity = PAR_NONE); |
b1f50952 | 47 | bool IsOpen(); |
b9187cc6 LOK |
48 | void Close(); |
49 | ||
28352a04 | 50 | int8_t Write(CCECAdapterMessage *data); |
8bca69de | 51 | int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0); |
b9187cc6 LOK |
52 | |
53 | std::string GetError() { return m_error; } | |
54 | std::string GetName() { return m_name; } | |
55 | ||
56 | private: | |
8bca69de | 57 | bool SetBaudRate(uint32_t baudrate); |
b1f50952 | 58 | |
b9187cc6 LOK |
59 | std::string m_error; |
60 | std::string m_name; | |
b1f50952 | 61 | CMutex m_mutex; |
b9187cc6 LOK |
62 | |
63 | #ifdef __WINDOWS__ | |
64 | bool SetTimeouts(bool bBlocking); | |
65 | ||
66 | HANDLE m_handle; | |
67 | bool m_bIsOpen; | |
8bca69de LOK |
68 | uint32_t m_iBaudrate; |
69 | uint8_t m_iDatabits; | |
70 | uint8_t m_iStopbits; | |
71 | uint8_t m_iParity; | |
b9187cc6 LOK |
72 | int64_t m_iTimeout; |
73 | CecBuffer<uint8_t> m_buffer; | |
74 | HANDLE m_ovHandle; | |
75 | #else | |
76 | struct termios m_options; | |
77 | int m_fd; | |
78 | #endif | |
79 | }; | |
80 | }; |