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> |
b1f50952 | 25 | #include "../platform/threads.h" |
b9187cc6 LOK |
26 | |
27 | #ifndef __WINDOWS__ | |
28 | #include <termios.h> | |
29 | #else | |
b9187cc6 LOK |
30 | #include "../util/buffer.h" |
31 | #endif | |
32 | ||
33 | namespace CEC | |
34 | { | |
35 | #define PAR_NONE 0 | |
36 | #define PAR_EVEN 1 | |
37 | #define PAR_ODD 2 | |
38 | ||
39 | class CSerialPort | |
40 | { | |
41 | public: | |
42 | CSerialPort(); | |
43 | virtual ~CSerialPort(); | |
44 | ||
8bca69de | 45 | bool Open(std::string name, uint32_t baudrate, uint8_t databits = 8, uint8_t stopbits = 1, uint8_t parity = PAR_NONE); |
b1f50952 | 46 | bool IsOpen(); |
b9187cc6 LOK |
47 | void Close(); |
48 | ||
9dee1670 | 49 | int8_t Write(const cec_adapter_message &data); |
8bca69de | 50 | int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0); |
b9187cc6 LOK |
51 | |
52 | std::string GetError() { return m_error; } | |
53 | std::string GetName() { return m_name; } | |
54 | ||
55 | private: | |
8bca69de | 56 | bool SetBaudRate(uint32_t baudrate); |
b1f50952 | 57 | |
b9187cc6 LOK |
58 | std::string m_error; |
59 | std::string m_name; | |
b1f50952 | 60 | CMutex m_mutex; |
b9187cc6 LOK |
61 | |
62 | #ifdef __WINDOWS__ | |
63 | bool SetTimeouts(bool bBlocking); | |
64 | ||
65 | HANDLE m_handle; | |
66 | bool m_bIsOpen; | |
8bca69de LOK |
67 | uint32_t m_iBaudrate; |
68 | uint8_t m_iDatabits; | |
69 | uint8_t m_iStopbits; | |
70 | uint8_t m_iParity; | |
b9187cc6 LOK |
71 | int64_t m_iTimeout; |
72 | CecBuffer<uint8_t> m_buffer; | |
73 | HANDLE m_ovHandle; | |
74 | #else | |
75 | struct termios m_options; | |
76 | int m_fd; | |
77 | #endif | |
78 | }; | |
79 | }; |