#include "AdapterCommunication.h"
#include "LibCEC.h"
-#include "libPlatform/serialport.h"
+#include "platform/serialport.h"
#include "util/StdString.h"
using namespace std;
*/
#include "../../include/CECExports.h"
-#include "util/threads.h"
-
-class CSerialPort;
+#include "platform/threads.h"
namespace CEC
{
+ class CSerialPort;
class CLibCEC;
class CAdapterCommunication : CThread
*/
#include "AdapterDetection.h"
-#include "libPlatform/os-dependent.h"
+#include "platform/os-dependent.h"
#include "util/StdString.h"
#if !defined(__WINDOWS__)
#include "AdapterCommunication.h"
#include "LibCEC.h"
#include "util/StdString.h"
-#include "util/timeutils.h"
+#include "platform/timeutils.h"
using namespace CEC;
using namespace std;
#include "../../include/CECExports.h"
#include "../../include/CECTypes.h"
-#include "util/threads.h"
+#include "platform/threads.h"
#include "util/buffer.h"
class CSerialPort;
#include "AdapterDetection.h"
#include "CECProcessor.h"
#include "util/StdString.h"
-#include "util/timeutils.h"
+#include "platform/timeutils.h"
using namespace std;
using namespace CEC;
../../include/CECExports.h \
../../include/CECExportsCpp.h \
../../include/CECExportsC.h \
- util/misc.cpp \
- util/misc.h \
util/StdString.h \
- util/threads.cpp \
- util/threads.h \
- util/timeutils.h \
- libPlatform/baudrate.h \
- libPlatform/os-dependent.h \
- libPlatform/linux/os_posix.h \
- libPlatform/linux/serialport.cpp \
- libPlatform/serialport.h
+ platform/timeutils.h \
+ platform/baudrate.h \
+ platform/os-dependent.h \
+ platform/linux/os_posix.h \
+ platform/linux/serialport.cpp \
+ platform/serialport.h \
+ platform/threads.cpp \
+ platform/threads.h
libcec_la_LDFLAGS = -lrt -lpthread -ludev -version-info @VERSION@
+++ /dev/null
-#pragma once
-
-/*
- * boblight
- * Copyright (C) Bob 2009
- *
- * boblight is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * boblight is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-//every baudrate I could find is in here in an #ifdef block
-//so it should compile on everything
-
-static struct sbaudrate
-{
- int rate;
- int symbol;
-}
-baudrates[] =
-{
-#ifdef B50
- { 50, B50 },
-#endif
-#ifdef B75
- { 75, B75 },
-#endif
-#ifdef B110
- { 110, B110 },
-#endif
-#ifdef B134
- { 134, B134 },
-#endif
-#ifdef B150
- { 150, B150 },
-#endif
-#ifdef B200
- { 200, B200 },
-#endif
-#ifdef B300
- { 300, B300 },
-#endif
-#ifdef B600
- { 600, B600 },
-#endif
-#ifdef B1200
- { 1200, B1200 },
-#endif
-#ifdef B1800
- { 1800, B1800 },
-#endif
-#ifdef B2400
- { 2400, B2400 },
-#endif
-#ifdef B4800
- { 4800, B4800 },
-#endif
-#ifdef B9600
- { 9600, B9600 },
-#endif
-#ifdef B14400
- { 14400, B14400 },
-#endif
-#ifdef B19200
- { 19200, B19200 },
-#endif
-#ifdef B28800
- { 28800, B28800 },
-#endif
-#ifdef B38400
- { 38400, B38400 },
-#endif
-#ifdef B57600
- { 57600, B57600 },
-#endif
-#ifdef B76800
- { 76800, B76800 },
-#endif
-#ifdef B115200
- { 115200, B115200 },
-#endif
-#ifdef B230400
- { 230400, B230400 },
-#endif
-#ifdef B250000
- { 250000, B250000 },
-#endif
-#ifdef B460800
- { 460800, B460800 },
-#endif
-#ifdef B500000
- { 500000, B500000 },
-#endif
-#ifdef B576000
- { 576000, B576000 },
-#endif
-#ifdef B921600
- { 921600, B921600 },
-#endif
-#ifdef B1000000
- { 1000000, B1000000 },
-#endif
-#ifdef B1152000
- { 1152000, B1152000 },
-#endif
-#ifdef B1500000
- { 1500000, B1500000 },
-#endif
-#ifdef B2000000
- { 2000000, B2000000 },
-#endif
-#ifdef B2500000
- { 2500000, B2500000 },
-#endif
-#ifdef B3000000
- { 3000000, B3000000 },
-#endif
-#ifdef B3500000
- { 3500000, B3500000 },
-#endif
-#ifdef B4000000
- { 4000000, B4000000 },
-#endif
-#ifdef CBR_110
- { 110, CBR_110 },
-#endif
-#ifdef CBR_300
- { 300, CBR_300 },
-#endif
-#ifdef CBR_600
- { 600, CBR_600 },
-#endif
-#ifdef CBR_1200
- { 1200, CBR_1200 },
-#endif
-#ifdef CBR_2400
- { 2400, CBR_2400 },
-#endif
-#ifdef CBR_4800
- { 4800, CBR_4800 },
-#endif
-#ifdef CBR_9600
- { 9600, CBR_9600 },
-#endif
-#ifdef CBR_11400
- { 11400, CBR_14400 },
-#endif
-#ifdef CBR_19200
- { 19200, CBR_19200 },
-#endif
-#ifdef CBR_38400
- { 38400, CBR_38400 },
-#endif
-#ifdef CBR_56000
- { 56000, CBR_56000 },
-#endif
-#ifdef CBR_57600
- { 57600, CBR_57600 },
-#endif
-#ifdef CBR_115200
- { 115200, CBR_115200 },
-#endif
-#ifdef CBR_128000
- { 128000, CBR_128000 },
-#endif
-#ifdef CBR_256000
- { 256000, CBR_256000 },
-#endif
- { -1, -1}
-};
+++ /dev/null
-#pragma once
-
-/*
- * boblight
- * Copyright (C) Bob 2009
- *
- * boblight is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * boblight is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "os-dependent.h"
-#include <string>
-#include <vector>
-#include <stdint.h>
-
-#ifndef __WINDOWS__
-#include <termios.h>
-#else
-#include "../util/threads.h"
-#include "../util/buffer.h"
-
-class CSerialPort;
-
-typedef struct serial_cancel_options
-{
- CSerialPort *instance;
- uint64_t iWaitMs;
-} serial_cancel_options;
-
-#endif
-
-#define PAR_NONE 0
-#define PAR_EVEN 1
-#define PAR_ODD 2
-
-#include "baudrate.h"
-
-class CSerialPort
-{
- public:
- CSerialPort();
- virtual ~CSerialPort();
-
- bool Open(std::string name, int baudrate, int databits = 8, int stopbits = 1, int parity = PAR_NONE);
- void Close();
- int Write(std::vector<uint8_t> data)
- {
- return Write(&data[0], data.size());
- }
-
- int Write(uint8_t* data, int len);
- int Read(uint8_t* data, int len, int iTimeoutMs = -1);
-
- std::string GetError() { return m_name + ": " + m_error; }
- std::string GetName() { return m_name; }
-
- bool SetBaudRate(int baudrate);
-
- int IntToRate(int baudrate)
- {
- for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(sbaudrate) - 1; i++)
- {
- if (baudrates[i].rate == baudrate)
- {
- return baudrates[i].symbol;
- }
- }
- return -1;
- };
-
-#ifdef __WINDOWS__
- bool IsOpen() const { return m_bIsOpen; }
-#else
- bool IsOpen() const { return m_fd != -1; }
-#endif
-
-private:
- std::string m_error;
- std::string m_name;
-
-#ifdef __WINDOWS__
- bool SetTimeouts(bool bBlocking);
-
- HANDLE m_handle;
- bool m_bIsOpen;
- int m_iBaudrate;
- int m_iDatabits;
- int m_iStopbits;
- int m_iParity;
- int64_t m_iTimeout;
- CecBuffer<uint8_t> m_buffer;
- HANDLE m_ovHandle;
-#else
- struct termios m_options;
- int m_fd;
-#endif
-};
--- /dev/null
+#pragma once
+
+/*
+ * boblight
+ * Copyright (C) Bob 2009
+ *
+ * boblight is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * boblight is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+//every baudrate I could find is in here in an #ifdef block
+//so it should compile on everything
+
+#include <termios.h>
+
+namespace CEC
+{
+ static struct sbaudrate
+ {
+ int rate;
+ int symbol;
+ }
+ baudrates[] =
+ {
+ #ifdef B50
+ { 50, B50 },
+ #endif
+ #ifdef B75
+ { 75, B75 },
+ #endif
+ #ifdef B110
+ { 110, B110 },
+ #endif
+ #ifdef B134
+ { 134, B134 },
+ #endif
+ #ifdef B150
+ { 150, B150 },
+ #endif
+ #ifdef B200
+ { 200, B200 },
+ #endif
+ #ifdef B300
+ { 300, B300 },
+ #endif
+ #ifdef B600
+ { 600, B600 },
+ #endif
+ #ifdef B1200
+ { 1200, B1200 },
+ #endif
+ #ifdef B1800
+ { 1800, B1800 },
+ #endif
+ #ifdef B2400
+ { 2400, B2400 },
+ #endif
+ #ifdef B4800
+ { 4800, B4800 },
+ #endif
+ #ifdef B9600
+ { 9600, B9600 },
+ #endif
+ #ifdef B14400
+ { 14400, B14400 },
+ #endif
+ #ifdef B19200
+ { 19200, B19200 },
+ #endif
+ #ifdef B28800
+ { 28800, B28800 },
+ #endif
+ #ifdef B38400
+ { 38400, B38400 },
+ #endif
+ #ifdef B57600
+ { 57600, B57600 },
+ #endif
+ #ifdef B76800
+ { 76800, B76800 },
+ #endif
+ #ifdef B115200
+ { 115200, B115200 },
+ #endif
+ #ifdef B230400
+ { 230400, B230400 },
+ #endif
+ #ifdef B250000
+ { 250000, B250000 },
+ #endif
+ #ifdef B460800
+ { 460800, B460800 },
+ #endif
+ #ifdef B500000
+ { 500000, B500000 },
+ #endif
+ #ifdef B576000
+ { 576000, B576000 },
+ #endif
+ #ifdef B921600
+ { 921600, B921600 },
+ #endif
+ #ifdef B1000000
+ { 1000000, B1000000 },
+ #endif
+ #ifdef B1152000
+ { 1152000, B1152000 },
+ #endif
+ #ifdef B1500000
+ { 1500000, B1500000 },
+ #endif
+ #ifdef B2000000
+ { 2000000, B2000000 },
+ #endif
+ #ifdef B2500000
+ { 2500000, B2500000 },
+ #endif
+ #ifdef B3000000
+ { 3000000, B3000000 },
+ #endif
+ #ifdef B3500000
+ { 3500000, B3500000 },
+ #endif
+ #ifdef B4000000
+ { 4000000, B4000000 },
+ #endif
+ #ifdef CBR_110
+ { 110, CBR_110 },
+ #endif
+ #ifdef CBR_300
+ { 300, CBR_300 },
+ #endif
+ #ifdef CBR_600
+ { 600, CBR_600 },
+ #endif
+ #ifdef CBR_1200
+ { 1200, CBR_1200 },
+ #endif
+ #ifdef CBR_2400
+ { 2400, CBR_2400 },
+ #endif
+ #ifdef CBR_4800
+ { 4800, CBR_4800 },
+ #endif
+ #ifdef CBR_9600
+ { 9600, CBR_9600 },
+ #endif
+ #ifdef CBR_11400
+ { 11400, CBR_14400 },
+ #endif
+ #ifdef CBR_19200
+ { 19200, CBR_19200 },
+ #endif
+ #ifdef CBR_38400
+ { 38400, CBR_38400 },
+ #endif
+ #ifdef CBR_56000
+ { 56000, CBR_56000 },
+ #endif
+ #ifdef CBR_57600
+ { 57600, CBR_57600 },
+ #endif
+ #ifdef CBR_115200
+ { 115200, CBR_115200 },
+ #endif
+ #ifdef CBR_128000
+ { 128000, CBR_128000 },
+ #endif
+ #ifdef CBR_256000
+ { 256000, CBR_256000 },
+ #endif
+ { -1, -1}
+ };
+
+ static int IntToBaudrate(int baudrate)
+ {
+ for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(CEC::sbaudrate) - 1; i++)
+ {
+ if (baudrates[i].rate == baudrate)
+ return baudrates[i].symbol;
+ }
+
+ return -1;
+ };
+};
*/
#define _FILE_OFFSET_BITS 64
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
#include <string.h>
-#include <stdint.h>
-#include <unistd.h>
#include <errno.h>
-#include <fcntl.h>
-#include <sys/types.h>
#include <sys/time.h>
-#include <sys/timeb.h>
-#include <sys/resource.h>
-#include <sys/syscall.h>
#ifndef __APPLE__
#include <sys/prctl.h>
#endif
#define LIBTYPE
#define DECLSPEC
-
-#ifndef _STL_ALGOBASE_H
-template<class T> inline T min(T a, T b) { return a <= b ? a : b; }
-template<class T> inline T max(T a, T b) { return a >= b ? a : b; }
-template<class T> inline int sgn(T a) { return a < 0 ? -1 : a > 0 ? 1 : 0; }
-template<class T> inline void swap(T &a, T &b) { T t = a; a = b; b = t; }
-#endif
-
-/*!
- * @return the current time in seconds since unix epoch.
- */
-static inline uint64_t getcurrenttime(void)
-{
- struct timeval t;
- gettimeofday(&t, NULL);
- return ((uint64_t)t.tv_sec * 1000) + (t.tv_usec / 1000);
-}
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <iostream>//debug
-
#include <stdio.h>
-#include <unistd.h>
#include <fcntl.h>
-
#include "../serialport.h"
#include "../baudrate.h"
-#include "../../util/misc.h"
-#include "../../util/timeutils.h"
+#include "../timeutils.h"
using namespace std;
+using namespace CEC;
CSerialPort::CSerialPort()
{
- m_fd = -1;
+ m_fd = -1;
}
CSerialPort::~CSerialPort()
int returnv = select(m_fd + 1, NULL, &port, NULL, NULL);
if (returnv == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return -1;
}
returnv = write(m_fd, data + byteswritten, len - byteswritten);
if (returnv == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return -1;
}
byteswritten += returnv;
if (returnv == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return -1;
}
else if (returnv == 0)
returnv = read(m_fd, data + bytesread, len - bytesread);
if (returnv == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return -1;
}
bool CSerialPort::Open(string name, int baudrate, int databits/* = 8*/, int stopbits/* = 1*/, int parity/* = PAR_NONE*/)
{
m_name = name;
- m_error = GetErrno();
+ m_error = strerror(errno);
if (databits < 5 || databits > 8)
{
if (m_fd == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
if (tcsetattr(m_fd, TCSANOW, &m_options) != 0)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
bool CSerialPort::SetBaudRate(int baudrate)
{
- int rate = IntToRate(baudrate);
+ int rate = IntToBaudrate(baudrate);
if (rate == -1)
{
char buff[255];
//get the current port attributes
if (tcgetattr(m_fd, &m_options) != 0)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
if (cfsetispeed(&m_options, rate) != 0)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
if (cfsetospeed(&m_options, rate) != 0)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
return true;
}
+
+bool CSerialPort::IsOpen() const
+{
+ return m_fd != -1;
+}
--- /dev/null
+#pragma once
+
+/*
+ * boblight
+ * Copyright (C) Bob 2009
+ *
+ * boblight is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * boblight is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "os-dependent.h"
+#include "baudrate.h"
+#include <string>
+#include <vector>
+#include <stdint.h>
+
+#ifndef __WINDOWS__
+#include <termios.h>
+#else
+#include "../util/threads.h"
+#include "../util/buffer.h"
+#endif
+
+namespace CEC
+{
+ #define PAR_NONE 0
+ #define PAR_EVEN 1
+ #define PAR_ODD 2
+
+ class CSerialPort
+ {
+ public:
+ CSerialPort();
+ virtual ~CSerialPort();
+
+ bool Open(std::string name, int baudrate, int databits = 8, int stopbits = 1, int parity = PAR_NONE);
+ bool SetBaudRate(int baudrate);
+ bool IsOpen() const;
+ void Close();
+
+ int Write(std::vector<uint8_t> data)
+ {
+ return Write(&data[0], data.size());
+ }
+ int Write(uint8_t* data, int len);
+ int Read(uint8_t* data, int len, int iTimeoutMs = -1);
+
+ std::string GetError() { return m_error; }
+ std::string GetName() { return m_name; }
+
+ private:
+ std::string m_error;
+ std::string m_name;
+
+ #ifdef __WINDOWS__
+ bool SetTimeouts(bool bBlocking);
+
+ HANDLE m_handle;
+ bool m_bIsOpen;
+ int m_iBaudrate;
+ int m_iDatabits;
+ int m_iStopbits;
+ int m_iParity;
+ int64_t m_iTimeout;
+ CecBuffer<uint8_t> m_buffer;
+ HANDLE m_ovHandle;
+ #else
+ struct termios m_options;
+ int m_fd;
+ #endif
+ };
+};
#include "threads.h"
#include "timeutils.h"
+using namespace CEC;
+
CMutex::CMutex(void)
{
pthread_mutex_init(&m_mutex, NULL);
* http://www.pulse-eight.net/
*/
-#include "../libPlatform/os-dependent.h"
+#include "os-dependent.h"
-class CMutex;
-
-class CCondition
+namespace CEC
{
-public:
- CCondition(void);
- virtual ~CCondition(void);
+ class CMutex;
- void Signal(void);
- bool Wait(CMutex *mutex, int64_t iTimeout);
- static void Sleep(int iTimeout);
+ class CCondition
+ {
+ public:
+ CCondition(void);
+ virtual ~CCondition(void);
-private:
- pthread_cond_t m_cond;
-};
+ void Signal(void);
+ bool Wait(CMutex *mutex, int64_t iTimeout);
+ static void Sleep(int iTimeout);
-class CMutex
-{
-public:
- CMutex(void);
- virtual ~CMutex(void);
+ private:
+ pthread_cond_t m_cond;
+ };
- bool TryLock(void);
- bool Lock(void);
- void Unlock(void);
+ class CMutex
+ {
+ public:
+ CMutex(void);
+ virtual ~CMutex(void);
- pthread_mutex_t m_mutex;
-};
+ bool TryLock(void);
+ bool Lock(void);
+ void Unlock(void);
-class CLockObject
-{
-public:
- CLockObject(CMutex *mutex);
- ~CLockObject(void);
+ pthread_mutex_t m_mutex;
+ };
- bool IsLocked(void) const { return m_bLocked; }
- void Leave(void);
- void Lock(void);
+ class CLockObject
+ {
+ public:
+ CLockObject(CMutex *mutex);
+ ~CLockObject(void);
-private:
- CMutex *m_mutex;
- bool m_bLocked;
-};
+ bool IsLocked(void) const { return m_bLocked; }
+ void Leave(void);
+ void Lock(void);
-class CThread
-{
-public:
- CThread(void);
- virtual ~CThread(void);
+ private:
+ CMutex *m_mutex;
+ bool m_bLocked;
+ };
+
+ class CThread
+ {
+ public:
+ CThread(void);
+ virtual ~CThread(void);
- virtual bool IsRunning(void) const { return m_bRunning; }
- virtual bool CreateThread(void);
- virtual void StopThread(bool bWaitForExit = true);
+ virtual bool IsRunning(void) const { return m_bRunning; }
+ virtual bool CreateThread(void);
+ virtual void StopThread(bool bWaitForExit = true);
- static void *ThreadHandler(CThread *thread);
- virtual void *Process(void) = 0;
+ static void *ThreadHandler(CThread *thread);
+ virtual void *Process(void) = 0;
-protected:
- pthread_t m_thread;
- bool m_bRunning;
- bool m_bStop;
+ protected:
+ pthread_t m_thread;
+ bool m_bRunning;
+ bool m_bStop;
+ };
};
#include <stdint.h>
#include <time.h>
-inline int64_t GetTimeMs()
+namespace CEC
{
-#ifdef __WINDOWS__
- time_t rawtime;
- time(&rawtime);
-
- LARGE_INTEGER tickPerSecond;
- LARGE_INTEGER tick;
- if (QueryPerformanceFrequency(&tickPerSecond))
+ inline int64_t GetTimeMs()
{
- QueryPerformanceCounter(&tick);
- return (int64_t) (tick.QuadPart / 1000.);
- }
- return -1;
-#else
- struct timespec time;
- clock_gettime(CLOCK_MONOTONIC, &time);
+ #ifdef __WINDOWS__
+ time_t rawtime;
+ time(&rawtime);
- return ((int64_t)time.tv_sec * (int64_t)1000) + (int64_t)time.tv_nsec / (int64_t)1000;
-#endif
-}
+ LARGE_INTEGER tickPerSecond;
+ LARGE_INTEGER tick;
+ if (QueryPerformanceFrequency(&tickPerSecond))
+ {
+ QueryPerformanceCounter(&tick);
+ return (int64_t) (tick.QuadPart / 1000.);
+ }
+ return -1;
+ #else
+ struct timespec time;
+ clock_gettime(CLOCK_MONOTONIC, &time);
-template <class T>
-inline T GetTimeSec()
-{
- return (T)GetTimeMs() / (T)1000.0;
-}
+ return ((int64_t)time.tv_sec * (int64_t)1000) + (int64_t)time.tv_nsec / (int64_t)1000;
+ #endif
+ }
-void USleep(int64_t usecs, volatile bool* stop = NULL);
+ template <class T>
+ inline T GetTimeSec()
+ {
+ return (T)GetTimeMs() / (T)1000.0;
+ }
+};
#include "../serialport.h"
#include "../baudrate.h"
-#include "../../util/timeutils.h"
+#include "../timeutils.h"
using namespace std;
+using namespace CEC;
void FormatWindowsError(int iErrorCode, string &strMessage)
{
DCB dcb;
memset(&dcb,0,sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
- dcb.BaudRate = IntToRate(m_iBaudrate);
+ dcb.BaudRate = IntToBaudrate(m_iBaudrate);
dcb.fBinary = true;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
return true;
}
+
+bool CSerialPort::IsOpen() const
+{
+ return m_bIsOpen;
+}
* http://www.pulse-eight.net/
*/
-#include "threads.h"
+#include "../platform/threads.h"
#include <queue>
-template<typename _BType>
- struct CecBuffer
- {
- public:
- CecBuffer(int iMaxSize = 100)
+namespace CEC
+{
+ template<typename _BType>
+ struct CecBuffer
{
- m_maxSize = iMaxSize;
- }
- virtual ~CecBuffer(void) {}
+ public:
+ CecBuffer(int iMaxSize = 100)
+ {
+ m_maxSize = iMaxSize;
+ }
+ virtual ~CecBuffer(void) {}
- int Size(void) const { return m_buffer.size(); }
+ int Size(void) const { return m_buffer.size(); }
- bool Push(_BType entry)
- {
- CLockObject lock(&m_mutex);
- if (m_buffer.size() == m_maxSize)
- return false;
+ bool Push(_BType entry)
+ {
+ CLockObject lock(&m_mutex);
+ if (m_buffer.size() == m_maxSize)
+ return false;
- m_buffer.push(entry);
- return true;
- }
+ m_buffer.push(entry);
+ return true;
+ }
- bool Pop(_BType &entry)
- {
- bool bReturn(false);
- CLockObject lock(&m_mutex);
- if (m_buffer.size() > 0)
+ bool Pop(_BType &entry)
{
- entry = m_buffer.front();
- m_buffer.pop();
- bReturn = true;
+ bool bReturn(false);
+ CLockObject lock(&m_mutex);
+ if (m_buffer.size() > 0)
+ {
+ entry = m_buffer.front();
+ m_buffer.pop();
+ bReturn = true;
+ }
+ return bReturn;
}
- return bReturn;
- }
- private:
- int m_maxSize;
- std::queue<_BType> m_buffer;
- CMutex m_mutex;
- };
+ private:
+ int m_maxSize;
+ std::queue<_BType> m_buffer;
+ CMutex m_mutex;
+ };
+};
+++ /dev/null
-/*
- * boblight
- * Copyright (C) Bob 2009
- *
- * boblight is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * boblight is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <iostream>
-#include <locale.h>
-#include "misc.h"
-
-using namespace std;
-
-void PrintError(const std::string& error)
-{
- std::cerr << "ERROR: " << error << "\n";
-}
-
-//get the first word (separated by whitespace) from string data and place that in word
-//then remove that word from string data
-bool GetWord(string& data, string& word)
-{
- stringstream datastream(data);
- string end;
-
- datastream >> word;
- if (datastream.fail())
- {
- data.clear();
- return false;
- }
-
- size_t pos = data.find(word) + word.length();
-
- if (pos >= data.length())
- {
- data.clear();
- return true;
- }
-
- data = data.substr(pos);
-
- datastream.clear();
- datastream.str(data);
-
- datastream >> end;
- if (datastream.fail())
- data.clear();
-
- return true;
-}
-
-//convert . or , to the current locale for correct conversion of ascii float
-void ConvertFloatLocale(std::string& strfloat)
-{
- static struct lconv* locale = localeconv();
-
- size_t pos = strfloat.find_first_of(",.");
-
- while (pos != string::npos)
- {
- strfloat.replace(pos, 1, 1, *locale->decimal_point);
- pos++;
-
- if (pos >= strfloat.size())
- break;
-
- pos = strfloat.find_first_of(",.", pos);
- }
-}
+++ /dev/null
-#pragma once
-
-/*
- * boblight
- * Copyright (C) Bob 2009
- *
- * boblight is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * boblight is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <string>
-#include <sstream>
-#include <exception>
-#include <stdexcept>
-
-#include <stdint.h>
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <math.h>
-
-void PrintError(const std::string& error);
-bool GetWord(std::string& data, std::string& word);
-void ConvertFloatLocale(std::string& strfloat);
-
-template <class Value>
-inline std::string ToString(Value value)
-{
- std::string data;
- std::stringstream valuestream;
- valuestream << value;
- valuestream >> data;
- return data;
-}
-
-inline std::string GetErrno()
-{
- return strerror(errno);
-}
-
-inline std::string GetErrno(int err)
-{
- return strerror(err);
-}
-
-template <class A, class B, class C>
-inline A Clamp(A value, B min, C max)
-{
- return value < max ? (value > min ? value : min) : max;
-}
-
-template <class A, class B>
-inline A Max(A value1, B value2)
-{
- return value1 > value2 ? value1 : value2;
-}
-
-template <class A, class B, class C>
-inline A Max(A value1, B value2, C value3)
-{
- return (value1 > value2) ? (value1 > value3 ? value1 : value3) : (value2 > value3 ? value2 : value3);
-}
-
-template <class A, class B>
-inline A Min(A value1, B value2)
-{
- return value1 < value2 ? value1 : value2;
-}
-
-template <class A, class B, class C>
-inline A Min(A value1, B value2, C value3)
-{
- return (value1 < value2) ? (value1 < value3 ? value1 : value3) : (value2 < value3 ? value2 : value3);
-}
-
-template <class T>
-inline T Abs(T value)
-{
- return value > 0 ? value : -value;
-}
-
-template <class A, class B>
-inline A Round(B value)
-{
- if (value == 0.0)
- {
- return 0;
- }
- else if (value > 0.0)
- {
- return (A)(value + 0.5);
- }
- else
- {
- return (A)(value - 0.5);
- }
-}
-
-//inline int32_t Round32(float value)
-//{
-// return lroundf(value);
-//}
-//
-//inline int32_t Round32(double value)
-//{
-// return lround(value);
-//}
-//
-//inline int64_t Round64(float value)
-//{
-// return llroundf(value);
-//}
-//
-//inline int64_t Round64(double value)
-//{
-// return llround(value);
-//}
-
-inline bool StrToInt(const std::string& data, int& value)
-{
- return sscanf(data.c_str(), "%i", &value) == 1;
-}
-
-inline bool HexStrToInt(const std::string& data, int& value)
-{
- return sscanf(data.c_str(), "%x", &value) == 1;
-}
-
-inline bool StrToFloat(const std::string& data, float& value)
-{
- return sscanf(data.c_str(), "%f", &value) == 1;
-}
-
-inline bool StrToFloat(const std::string& data, double& value)
-{
- return sscanf(data.c_str(), "%lf", &value) == 1;
-}
-
-inline bool StrToBool(const std::string& data, bool& value)
-{
- std::string data2 = data;
- std::string word;
- if (!GetWord(data2, word))
- return false;
-
- if (word == "1" || word == "true" || word == "on" || word == "yes")
- {
- value = true;
- return true;
- }
- else if (word == "0" || word == "false" || word == "off" || word == "no")
- {
- value = false;
- return true;
- }
- else
- {
- int ivalue;
- if (StrToInt(word, ivalue))
- {
- value = ivalue != 0;
- return true;
- }
- }
-
- return false;
-}
*/
#include "../../include/CECExports.h"
-#include "../lib/util/threads.h"
-#include "../lib/util/misc.h"
+#include "../lib/platform/threads.h"
#include "../lib/util/StdString.h"
#include <cstdio>
#include <fcntl.h>
#include <iostream>
#include <string>
+#include <sstream>
using namespace CEC;
using namespace std;
#define CEC_TEST_CLIENT_VERSION 3
+
+inline bool HexStrToInt(const std::string& data, int& value)
+{
+ return sscanf(data.c_str(), "%x", &value) == 1;
+}
+
+
+//get the first word (separated by whitespace) from string data and place that in word
+//then remove that word from string data
+bool GetWord(string& data, string& word)
+{
+ stringstream datastream(data);
+ string end;
+
+ datastream >> word;
+ if (datastream.fail())
+ {
+ data.clear();
+ return false;
+ }
+
+ size_t pos = data.find(word) + word.length();
+
+ if (pos >= data.length())
+ {
+ data.clear();
+ return true;
+ }
+
+ data = data.substr(pos);
+
+ datastream.clear();
+ datastream.str(data);
+
+ datastream >> end;
+ if (datastream.fail())
+ data.clear();
+
+ return true;
+}
+
void flush_log(ICECAdapter *cecParser)
{
cec_log_message message;