From 3badf6e5da27490c62a486a013ad3e1624afb4cb Mon Sep 17 00:00:00 2001 From: Justin Hammond Date: Thu, 11 Jun 2020 13:14:18 +0800 Subject: [PATCH] First Code --- .gitignore | 65 +++++++++ .vscode/settings.json | 9 ++ .vscode/tasks.json | 17 +++ CMakeLists.txt | 17 +++ agent/CMakeLists.txt | 48 +++++++ agent/include/config.h.in | 8 ++ agent/include/daemon.h | 22 ++++ agent/include/pluginbase.h | 25 ++++ agent/source/daemon.cpp | 28 ++++ agent/source/main.cpp | 34 +++++ agent/source/pluginbase.cpp | 18 +++ client/CMakeLists.txt | 52 ++++++++ client/source/main.cpp | 57 ++++++++ plugins/CMakeLists.txt | 7 + plugins/dcdc-usb-200/CMakeLists.txt | 62 +++++++++ plugins/dcdc-usb-200/include/dcdc-usb-200.h | 36 +++++ plugins/dcdc-usb-200/include/dcdc-usb.h | 92 +++++++++++++ plugins/dcdc-usb-200/source/dcdc-usb-200.cpp | 125 ++++++++++++++++++ plugins/dcdc-usb-200/source/dcdc-usb-comm.c | 119 +++++++++++++++++ plugins/dcdc-usb-200/source/dcdc-usb-parse.c | 131 +++++++++++++++++++ plugins/dcdc-usb-200/source/dcdc-usb-proto.c | 130 ++++++++++++++++++ plugins/dcdc-usb-200/source/dcdc_usb_200.rep | 25 ++++ plugins/thermal/CMakeLists.txt | 51 ++++++++ plugins/thermal/include/thermal.h | 39 ++++++ plugins/thermal/source/thermal.cpp | 101 ++++++++++++++ plugins/thermal/source/thermal.rep | 4 + 26 files changed, 1322 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt create mode 100644 agent/CMakeLists.txt create mode 100644 agent/include/config.h.in create mode 100644 agent/include/daemon.h create mode 100644 agent/include/pluginbase.h create mode 100644 agent/source/daemon.cpp create mode 100644 agent/source/main.cpp create mode 100644 agent/source/pluginbase.cpp create mode 100644 client/CMakeLists.txt create mode 100644 client/source/main.cpp create mode 100644 plugins/CMakeLists.txt create mode 100644 plugins/dcdc-usb-200/CMakeLists.txt create mode 100644 plugins/dcdc-usb-200/include/dcdc-usb-200.h create mode 100644 plugins/dcdc-usb-200/include/dcdc-usb.h create mode 100644 plugins/dcdc-usb-200/source/dcdc-usb-200.cpp create mode 100644 plugins/dcdc-usb-200/source/dcdc-usb-comm.c create mode 100644 plugins/dcdc-usb-200/source/dcdc-usb-parse.c create mode 100644 plugins/dcdc-usb-200/source/dcdc-usb-proto.c create mode 100644 plugins/dcdc-usb-200/source/dcdc_usb_200.rep create mode 100644 plugins/thermal/CMakeLists.txt create mode 100644 plugins/thermal/include/thermal.h create mode 100644 plugins/thermal/source/thermal.cpp create mode 100644 plugins/thermal/source/thermal.rep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4a6c60 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps +# C++ objects and libs +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.so.* +*.dll +*.dylib + +# Qt-es +object_script.*.Release +object_script.*.Debug +*_plugin_import.cpp +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +moc_*.h +qrc_*.cpp +ui_*.h +*.qmlc +*.jsc +Makefile* +*build-* +*.qm +*.prl + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator CMake +CMakeLists.txt.user* + +# QtCreator 4.8< compilation database +compile_commands.json + +# QtCreator local machine specific files for imported projects +*creator.user* + +*_qmlcache.qrc \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..840b58b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "files.associations": { + "qobject": "cpp", + "array": "cpp", + "string": "cpp", + "string_view": "cpp" + }, + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7d3aa8c --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,17 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Make", + "type": "shell", + "command": "make", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3802cac --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.1.0) + +project(sbcbmc) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + + + +add_subdirectory(plugins) +add_subdirectory(agent) +add_subdirectory(client) diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt new file mode 100644 index 0000000..57e0ab2 --- /dev/null +++ b/agent/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 3.1.0) + +project(sbcbmc-agent VERSION 0.0.1) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + +find_package(Qt5 COMPONENTS Core REQUIRED) +find_package(Qt5 COMPONENTS RemoteObjects REQUIRED) + +find_package(PkgConfig REQUIRED) + +pkg_check_modules(LibUSB REQUIRED libusb) + +configure_file(include/config.h.in include/config.h) + +set(HEADERS + include/daemon.h + include/pluginbase.h + ) +set(SOURCES + source/main.cpp + source/daemon.cpp + source/pluginbase.cpp + ) + +add_executable(sbcbmc-agent + ${SOURCES} + ${HEADERS} + ${REPSOURCES} +) + +target_include_directories(sbcbmc-agent PRIVATE + "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/include/" + "${CMAKE_SOURCE_DIR}/plugins/thermal/include/" + "${CMAKE_SOURCE_DIR}/plugins/thermal/" + ${LibUSB_INCLUDE_DIRS} + ) + +target_link_libraries(sbcbmc-agent ${LibUSB_LIBRARIES}) +target_link_libraries(sbcbmc-agent Qt5::Core Qt5::RemoteObjects) +target_link_libraries(sbcbmc-agent thermal dcdc-usb-200) \ No newline at end of file diff --git a/agent/include/config.h.in b/agent/include/config.h.in new file mode 100644 index 0000000..94f2d4e --- /dev/null +++ b/agent/include/config.h.in @@ -0,0 +1,8 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#define catputer_VERSION_MAJOR @carputer_VERSION_MAJOR@ +#define carputer_VERSION_MINOR @carputer_VERSION_MINOR@ +#define carputer_VERSION_PATCH @carputer_VERSION_PATCH@ + +#endif \ No newline at end of file diff --git a/agent/include/daemon.h b/agent/include/daemon.h new file mode 100644 index 0000000..cd6c9e5 --- /dev/null +++ b/agent/include/daemon.h @@ -0,0 +1,22 @@ +#ifndef DAEMON_H +#define DAEMON_H + +#include +#include +#include + +#include "pluginbase.h" + +class daemon : public QObject +{ + Q_OBJECT + public: + daemon(QObject *parent = nullptr); + ~daemon(); + private: + QHash m_Plugins; + QRemoteObjectHost *m_rohost; + QRemoteObjectRegistryHost * m_roregistryhost; +}; + +#endif \ No newline at end of file diff --git a/agent/include/pluginbase.h b/agent/include/pluginbase.h new file mode 100644 index 0000000..44d1832 --- /dev/null +++ b/agent/include/pluginbase.h @@ -0,0 +1,25 @@ +#ifndef PLUGINBASE_H +#define PLUGINBASE_H +#include +#include +#include + +class PluginBase : public QObject { + Q_OBJECT + public: + PluginBase(QObject *parent = nullptr); + ~PluginBase(); + virtual bool initilize() = 0; + virtual void startTimer(); + public Q_SLOTS: + virtual void update() = 0; + virtual bool registerSource(QRemoteObjectHostBase *host) = 0; + + + + private: + QTimer m_updateTimer; +}; + + +#endif \ No newline at end of file diff --git a/agent/source/daemon.cpp b/agent/source/daemon.cpp new file mode 100644 index 0000000..6fafd58 --- /dev/null +++ b/agent/source/daemon.cpp @@ -0,0 +1,28 @@ +#include "daemon.h" +#include "dcdc-usb-200.h" +#include "thermal.h" + +daemon::daemon(QObject *parent) : + QObject(parent) +{ + this->m_roregistryhost = new QRemoteObjectRegistryHost(QUrl("tcp://0.0.0.0:1999"), this); + this->m_rohost = new QRemoteObjectHost(QUrl("tcp://0.0.0.0:1998"), QUrl("tcp://127.0.0.1:1999"), QRemoteObjectHostBase::BuiltInSchemasOnly, this); + + + + DCDCUSB200 *dcdcusb200 = new DCDCUSB200(this); + if (dcdcusb200->initilize()) { + this->m_Plugins.insert("DCDCUSB200", dcdcusb200); + dcdcusb200->registerSource(this->m_rohost); + } + Thermal *thermal = new Thermal(this); + if (thermal->initilize()) { + this->m_Plugins.insert("Thermal", thermal); + thermal->registerSource(this->m_rohost); + } +} + +daemon::~daemon() +{ + +} \ No newline at end of file diff --git a/agent/source/main.cpp b/agent/source/main.cpp new file mode 100644 index 0000000..cbc1093 --- /dev/null +++ b/agent/source/main.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include "config.h" +#include "daemon.h" + +Q_LOGGING_CATEGORY(ozwdaemon, "ozw.daemon"); + +#define APP_VERSION #carputer_VERSION_MAJOR.#carputer_VERSION_MINOR.#carputer_VERSION_PATCH + +#define DEF2STR2(x) #x +#define DEF2STR(x) DEF2STR2(x) + +int main(int argc, char *argv[]) { + + QCoreApplication a(argc, argv); + QCoreApplication::setApplicationName("carputer"); + QCoreApplication::setApplicationVersion(DEF2STR(APP_VERSION)); + QCoreApplication::setOrganizationName("DynamX"); + QCoreApplication::setOrganizationDomain("dynam.com"); + + QCommandLineParser parser; + parser.setApplicationDescription("CarPuter Daemon"); + parser.addHelpOption(); + parser.addVersionOption(); + + parser.process(a); + + daemon carserver; + carserver; + + a.exec(); +} \ No newline at end of file diff --git a/agent/source/pluginbase.cpp b/agent/source/pluginbase.cpp new file mode 100644 index 0000000..21875ff --- /dev/null +++ b/agent/source/pluginbase.cpp @@ -0,0 +1,18 @@ +#include "pluginbase.h" + +PluginBase::PluginBase(QObject *parent) : + QObject(parent) +{ + +} +PluginBase::~PluginBase() +{ + +} + +void PluginBase::startTimer() +{ + connect(&this->m_updateTimer, &QTimer::timeout, this, &PluginBase::update); + this->m_updateTimer.setInterval(1000); + this->m_updateTimer.start(); +} \ No newline at end of file diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt new file mode 100644 index 0000000..5f78471 --- /dev/null +++ b/client/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.1.0) + +project(sbcbmc-client VERSION 0.0.1) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + +cmake_policy(SET CMP0071 NEW) + + +find_package(Qt5 COMPONENTS Core REQUIRED) +find_package(Qt5 COMPONENTS RemoteObjects REQUIRED) + +find_package(PkgConfig REQUIRED) + +#configure_file(include/config.h.in include/config.h) + +set(HEADERS + ) +set(SOURCES + source/main.cpp + ) +qt5_generate_repc(REPSOURCES + ${CMAKE_SOURCE_DIR}/plugins/dcdc-usb-200/source/dcdc_usb_200.rep + REPLICA + ) +qt5_generate_repc(REPSOURCES + ${CMAKE_SOURCE_DIR}/plugins/thermal/source/thermal.rep + REPLICA + ) + + +add_executable(sbcbmc-client + ${SOURCES} + ${HEADERS} + ${REPSOURCES} +) + +target_include_directories(sbcbmc-client PRIVATE + "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/include/" + "${PROJECT_SOURCE_DIR}/plugins/dcdc-usb-200/include/" + "${PROJECT_SOURCE_DIR}/plugins/thermal/include/" + ${LibUSB_INCLUDE_DIRS} + ) + +target_link_libraries(sbcbmc-client Qt5::Core Qt5::RemoteObjects) \ No newline at end of file diff --git a/client/source/main.cpp b/client/source/main.cpp new file mode 100644 index 0000000..95cc694 --- /dev/null +++ b/client/source/main.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include + + +Q_LOGGING_CATEGORY(ozwdaemon, "ozw.daemon"); + +#if 0 +#define APP_VERSION #carputer_VERSION_MAJOR.#carputer_VERSION_MINOR.#carputer_VERSION_PATCH + +#define DEF2STR2(x) #x +#define DEF2STR(x) DEF2STR2(x) +#endif + +int main(int argc, char *argv[]) { + + QCoreApplication a(argc, argv); + QCoreApplication::setApplicationName("carclient"); + //QCoreApplication::setApplicationVersion(DEF2STR(APP_VERSION)); + QCoreApplication::setOrganizationName("DynamX"); + QCoreApplication::setOrganizationDomain("dynam.com"); + + QCommandLineParser parser; + parser.setApplicationDescription("CarClient"); + parser.addHelpOption(); + parser.addVersionOption(); + + parser.process(a); + + QRemoteObjectNode node(QUrl("tcp://127.0.0.1:1999")); + + QObject::connect(&node, &QRemoteObjectNode::remoteObjectAdded, + [](const QRemoteObjectSourceLocation& info){ + qDebug() << "New source added : " << info; + }); + + qDebug() << "Waiting for registry "; + node.waitForRegistry(10000); + + qDebug() << "Already here sources : " << node.registry()->sourceLocations(); + + QTimer timer; + timer.start(5000); + + QObject::connect(&timer, &QTimer::timeout, + [&](){ + qDebug() << "New sources list : " << node.registry()->sourceLocations(); + }); + + QRemoteObjectDynamicReplica *plugin = node.acquireDynamic("plugins/thermal/thermal_zone1/x86_pkg_temp"); + QRemoteObjectDynamicReplica *plugin2 = node.acquireDynamic("plugins/thermal/thermal_zone0/x86_pkg_temp"); + + + a.exec(); +} \ No newline at end of file diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt new file mode 100644 index 0000000..8e1eaf1 --- /dev/null +++ b/plugins/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.1.0) + +project(carputer) + + +add_subdirectory(dcdc-usb-200) +add_subdirectory(thermal) diff --git a/plugins/dcdc-usb-200/CMakeLists.txt b/plugins/dcdc-usb-200/CMakeLists.txt new file mode 100644 index 0000000..1c4cf98 --- /dev/null +++ b/plugins/dcdc-usb-200/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.1.0) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + +cmake_policy(SET CMP0071 NEW) + + +find_package(Qt5 COMPONENTS Core REQUIRED) +find_package(Qt5 COMPONENTS RemoteObjects REQUIRED) +find_package(PkgConfig REQUIRED) + +pkg_check_modules(LibUSB REQUIRED libusb) + + +set(HEADERS + include/dcdc-usb.h + include/dcdc-usb-200.h + ) +set(SOURCES + source/dcdc-usb-comm.c + source/dcdc-usb-parse.c + source/dcdc-usb-proto.c + source/dcdc-usb-200.cpp + ) +qt5_generate_repc(REPSOURCES + source/dcdc_usb_200.rep + SOURCE + ) +#qt5_generate_repc(REPSOURCES +# source/dcdc_usb_200.rep +# REPLICA +# ) + + + +add_library(dcdc-usb-200 + STATIC + ${SOURCES} + ${HEADERS} + ${REPSOURCES} +) + +target_include_directories(dcdc-usb-200 PRIVATE + "${PROJECT_BINARY_DIR}" + "${CMAKE_SOURCE_DIR}/car/include/" + ${LibUSB_INCLUDE_DIRS} + ) + +target_include_directories(dcdc-usb-200 PUBLIC + "${PROJECT_SOURCE_DIR}/dcdc-usb-200/" + "${PROJECT_SOURCE_DIR}/dcdc-usb-200/include/" + "${CMAKE_CURRENT_BINARY_DIR}" + ) + +target_link_libraries(dcdc-usb-200 ${LibUSB_LIBRARIES}) +target_link_libraries(dcdc-usb-200 Qt5::Core Qt5::RemoteObjects) \ No newline at end of file diff --git a/plugins/dcdc-usb-200/include/dcdc-usb-200.h b/plugins/dcdc-usb-200/include/dcdc-usb-200.h new file mode 100644 index 0000000..94ad04a --- /dev/null +++ b/plugins/dcdc-usb-200/include/dcdc-usb-200.h @@ -0,0 +1,36 @@ +#ifndef DCDC_USB_200_H +#define DCDC_USB_200_H + +#include +#include + +#include "pluginbase.h" +#include "rep_dcdc_usb_200_source.h" + +class DCDCUSB200_Properties : public DCDCUSB200_PropertiesSimpleSource { + Q_OBJECT + public: + DCDCUSB200_Properties(QObject *parent = nullptr); + ~DCDCUSB200_Properties(); + bool parsePacket(quint8 *data, int size); +}; + + +class DCDCUSB200 : public PluginBase { + Q_OBJECT + public: + DCDCUSB200(QObject *parent = nullptr); + ~DCDCUSB200(); + bool initilize() override; + void update() override; + public Q_SLOTS: + void printUpdate(QVariant); + public Q_SLOTS: + bool registerSource(QRemoteObjectHostBase *host); + + private: + struct usb_dev_handle *m_usb_handle; + DCDCUSB200_Properties m_properties; +}; + +#endif \ No newline at end of file diff --git a/plugins/dcdc-usb-200/include/dcdc-usb.h b/plugins/dcdc-usb-200/include/dcdc-usb.h new file mode 100644 index 0000000..3aacb0c --- /dev/null +++ b/plugins/dcdc-usb-200/include/dcdc-usb.h @@ -0,0 +1,92 @@ +#ifndef DCDCUSB_H +#define DCDCUSB_H + +#define DCDC_VID 0x04d8 +#define DCDC_PID 0xd003 + +#define MAX_TRANSFER_SIZE 24 +/* USB communication wrappers */ +struct usb_dev_handle * dcdc_connect(); +int dcdc_send(struct usb_dev_handle *h, unsigned char *data, int size); +int dcdc_recv(struct usb_dev_handle *h, unsigned char *data, int size, int timeout); +int dcdc_setup(struct usb_dev_handle *h); + +/* DCDC USB protocol */ +int dcdc_get_status(struct usb_dev_handle *h, unsigned char *buf, int buflen); +int dcdc_set_vout(struct usb_dev_handle *h, double vout); +int dcdc_get_vout(struct usb_dev_handle *h, unsigned char *buf, int buflen); +int dcdc_parse_data(unsigned char *data, int size); + +/* DCDC USB data parsing */ +void dcdc_parse_values(unsigned char *data); +void dcdc_parse_cmd(unsigned char *data); +void dcdc_parse_internal_msg(unsigned char *data); +void dcdc_parse_mem(unsigned char *data); + +/* from windows source with small sanity edits */ + +#define STATUS_OK 0x00 +#define STATUS_ERASE 0x01 +#define STATUS_WRITE 0x02 +#define STATUS_READ 0x03 +#define STATUS_ERROR 0xff + +#define DCDCUSB_GET_ALL_VALUES 0x81 +#define DCDCUSB_RECV_ALL_VALUES 0x82 +#define DCDCUSB_CMD_OUT 0xB1 +#define DCDCUSB_CMD_IN 0xB2 +#define DCDCUSB_MEM_READ_OUT 0xA1 +#define DCDCUSB_MEM_READ_IN 0xA2 +#define DCDCUSB_MEM_WRITE_OUT 0xA3 +#define DCDCUSB_MEM_WRITE_IN 0xA4 +#define DCDCUSB_MEM_ERASE 0xA5 + +#define INTERNAL_MESG 0xFF +#define INTERNAL_MESG_DISCONNECTED 0x01 + +#define CMD_SET_AUX_WIN 0x01 +#define CMD_SET_PW_SWITCH 0x02 +#define CMD_SET_OUTPUT 0x03 +#define CMD_WRITE_VOUT 0x06 +#define CMD_READ_VOUT 0x07 +#define CMD_INC_VOUT 0x0C +#define CMD_DEC_VOUT 0x0D +#define CMD_LOAD_DEFAULTS 0x0E +#define CMD_SCRIPT_START 0x10 +#define CMD_SCRIPT_STOP 0x11 +#define CMD_SLEEP 0x12 +#define CMD_READ_REGULATOR_STEP 0x13 + +/* For reading out memory */ +#define TYPE_CODE_MEMORY 0x00 +#define TYPE_EPROM_EXTERNAL 0x01 +#define TYPE_EPROM_INTERNAL 0x02 +#define TYPE_CODE_SPLASH 0x03 + +#define FLASH_REPORT_ERASE_MEMORY 0xF2 /* AddressLo : AddressHi : AddressUp (anywhere inside the 64 byte-block to be erased) */ +#define FLASH_REPORT_READ_MEMORY 0xF3 /* AddressLo : AddressHi : AddressUp : Data Length (1...32) */ +#define FLASH_REPORT_WRITE_MEMORY 0xF4 /* AddressLo : AddressHi : AddressUp : Data Length (1...32) : Data.... */ +#define KEYBD_REPORT_ERASE_MEMORY 0xB2 /* same as F2 but in keyboard mode */ +#define KEYBD_REPORT_READ_MEMORY 0xB3 /* same as F3 but in keyboard mode */ +#define KEYBD_REPORT_WRITE_MEMORY 0xB4 /* same as F4 but in keyboard mode */ +#define KEYBD_REPORT_MEMORY 0x41 /* response to b3,b4 */ + +#define IN_REPORT_EXT_EE_DATA 0x31 +#define OUT_REPORT_EXT_EE_READ 0xA1 +#define OUT_REPORT_EXT_EE_WRITE 0xA2 + +#define IN_REPORT_INT_EE_DATA 0x32 +#define OUT_REPORT_INT_EE_READ 0xA3 +#define OUT_REPORT_INT_EE_WRITE 0xA4 + +/* MEASUREMENT CONSTANTS */ +#define CT_RW (double)75 +#define CT_R1 (double)49900 +#define CT_R2 (double)1500 +#define CT_RP (double)10000 + +#define CHECK_CHAR (unsigned char)0xAA /* used for line/write check */ + +#define MAX_MESSAGE_CNT 64 + +#endif /* DCDCUSB_H */ \ No newline at end of file diff --git a/plugins/dcdc-usb-200/source/dcdc-usb-200.cpp b/plugins/dcdc-usb-200/source/dcdc-usb-200.cpp new file mode 100644 index 0000000..e11be83 --- /dev/null +++ b/plugins/dcdc-usb-200/source/dcdc-usb-200.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "dcdc-usb-200.h" + +extern "C" { + + #include "dcdc-usb.h" + +} + +DCDCUSB200::DCDCUSB200(QObject *parent) : + PluginBase(parent) +{ + +} +DCDCUSB200::~DCDCUSB200() +{ + +} + +bool DCDCUSB200::initilize() +{ + m_usb_handle = dcdc_connect(); + if (m_usb_handle == NULL) { + qWarning() << "DCDCUSB200 - Can't Open USB Handle"; + return false; + } + if (dcdc_setup(m_usb_handle) < 0) { + qWarning() << "DCDCUSB200 - Can't Setup Device"; + return false; + } + connect(&this->m_properties, &DCDCUSB200_Properties::modeChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::timeConfigChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::voltageConfigChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::stateChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::vInChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::vIgnitionChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::vOutChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::powerSwitchChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::outputEnableChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::auxVInEnableChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::statusFlags1Changed, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::statusFlags2Changed, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::voltageFlagsChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::timerFlagsChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::flashPointerChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::timerWaitChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::timerVOutChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::timerVAuxChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::timerPwSwitchChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::timerOffDelayChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::timerHardOffDelayChanged, this, &DCDCUSB200::printUpdate); + connect(&this->m_properties, &DCDCUSB200_Properties::firmwareVersionChanged, this, &DCDCUSB200::printUpdate); + + this->startTimer(); + return true; +} + +void DCDCUSB200::update() +{ + unsigned char data[MAX_TRANSFER_SIZE]; + int ret = dcdc_get_status(m_usb_handle, data, MAX_TRANSFER_SIZE); + if (ret <= 0) { + qWarning() << "DCDCUSB200 - Failed To Get Status from Device"; + return; + } + this->m_properties.parsePacket(data, ret); + //dcdc_parse_data(data, ret); + qDebug() << ""; +} + + +void DCDCUSB200::printUpdate(QVariant data) { + QObject *sender = QObject::sender(); + int signalindex = QObject::senderSignalIndex(); + const QMetaObject *mo = sender->metaObject(); + qInfo() << "Changed Single: " << QString::fromLatin1(mo->method(signalindex).methodSignature()) << data; +} + +bool DCDCUSB200::registerSource(QRemoteObjectHostBase *host) { + return host->enableRemoting(&this->m_properties, "plugins/DCDCUSB200"); +} + + + +DCDCUSB200_Properties::DCDCUSB200_Properties(QObject *parent) : + DCDCUSB200_PropertiesSimpleSource(parent) +{ + +} +DCDCUSB200_Properties::~DCDCUSB200_Properties() +{ + +} + +bool DCDCUSB200_Properties::parsePacket(quint8 *data, int size) { + double value; + + this->setMode((data[1] & 0x03)); + this->setState(data[2]); + this->setVIn((double) data[3] * 0.1558f); + this->setVIgnition((double) data[4] * 0.1558f); + this->setVOut((float) data[5] * 0.1170f); + this->setStatusFlags1(data[6]); + this->setTimeConfig((data[1] >> 5) & 0x07); + this->setVoltageConfig((data[1] >> 2) & 0x07); + this->setPowerSwitch((data[6] & 0x04) ? true : false); + this->setOutputEnable((data[6] & 0x08) ? true : false); + this->setAuxVInEnable((data[6] & 0x10) ? true : false); + this->setStatusFlags2(data[7]); + this->setVoltageFlags(data[8]); + this->setTimerFlags(data[9]); + this->setFlashPointer(data[10]); + this->setTimerWait((data[11] << 8) | data[12]); + this->setTimerVOut((data[13] << 8) | data[14]); + this->setTimerVAux((data[15] << 8) | data[16]); + this->setTimerPwSwitch((data[17] << 8) | data[18]); + this->setTimerOffDelay((data[19] << 8) | data[20]); + this->setTimerHardOffDelay((data[21] << 8) | data[22]); + QString version("%1.%2"); + this->setFirmwareVersion(version.arg(((data[23] >> 5) & 0x07)).arg((data[23] & 0x1F))); + return true; +} diff --git a/plugins/dcdc-usb-200/source/dcdc-usb-comm.c b/plugins/dcdc-usb-200/source/dcdc-usb-comm.c new file mode 100644 index 0000000..9821324 --- /dev/null +++ b/plugins/dcdc-usb-200/source/dcdc-usb-comm.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2011 by Mini-Box.com, iTuner Networks Inc. + * Written by Nicu Pavel + * All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include + +#include + +#include "dcdc-usb.h" + +#define P(t, v...) fprintf(stderr, t "\n", ##v) + +int dcdc_send(struct usb_dev_handle *h, unsigned char *data, int size) +{ + if (data == NULL) + return -1; + + return usb_interrupt_write(h, USB_ENDPOINT_OUT + 1, (char *) data, size, 1000); +} + +int dcdc_recv(struct usb_dev_handle *h, unsigned char *data, int size, int timeout) +{ + if (data == NULL) + return -1; + + return usb_interrupt_read(h, USB_ENDPOINT_IN + 1, (char *) data, size, timeout); +} + +struct usb_dev_handle * dcdc_connect() +{ + struct usb_bus *b; + struct usb_device *d; + struct usb_dev_handle *h = NULL; + + usb_init(); + usb_set_debug(0); + usb_find_busses(); + usb_find_devices(); + + for (b = usb_get_busses(); b != NULL; b = b->next) + { + for (d = b->devices; d != NULL; d = d->next) + { + if ((d->descriptor.idVendor == DCDC_VID) && + (d->descriptor.idProduct == DCDC_PID)) + { + h = usb_open(d); + break; + } + } + } + return h; +} + +int dcdc_setup(struct usb_dev_handle *h) +{ + char buf[65535]; + + if (h == NULL) + return -1; + + if (usb_get_driver_np(h, 0, buf, sizeof(buf)) == 0) + { + if (usb_detach_kernel_driver_np(h, 0) < 0) + { + fprintf(stderr, "Cannot detach from kernel driver\n"); + return -2; + } + } + + if (usb_set_configuration(h, 1) < 0) + { + fprintf(stderr, "Cannot set configuration 1 for the device\n"); + return -3; + } + + usleep(1000); + + if (usb_claim_interface(h, 0) < 0) + { + fprintf(stderr, "Cannot claim interface 0\n"); + return -4; + } + + if (usb_set_altinterface(h, 0) < 0) + { + fprintf(stderr, "Cannot set alternate configuration\n"); + return -5; + } + + if (usb_control_msg(h, USB_TYPE_CLASS + USB_RECIP_INTERFACE, + 0x000000a, 0x0000000, 0x0000000, buf, 0x0000000, 1000) + < 0) + { + fprintf(stderr, "Cannot send control message\n"); + return -6; + } + + return 0; +} diff --git a/plugins/dcdc-usb-200/source/dcdc-usb-parse.c b/plugins/dcdc-usb-200/source/dcdc-usb-parse.c new file mode 100644 index 0000000..c83b313 --- /dev/null +++ b/plugins/dcdc-usb-200/source/dcdc-usb-parse.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2011 by Mini-Box.com, iTuner Networks Inc. + * Written by Nicu Pavel + * All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include +#include + +#include "dcdc-usb.h" + +#define P(t, v...) fprintf(stderr, t "\n", ##v) +static int bytes2int(unsigned char c1, unsigned char c2) +{ + int i = c1; + i = i << 8; + i = i | c2; + + return i; +} + +static int byte2bits(unsigned char c) +{ + int i,n = 0; + for (i = 0; i < 8; i++) + { + n = n * 10; + if ((c >> i) & 1) + n = n + 1; + } + return n; +} + +static double byte2vout(unsigned char c) +{ + double rpot = ((double) c) * CT_RP / (double)257 + CT_RW; + double voltage = (double)80 * ((double) 1 + CT_R1/(rpot + CT_R2)); + voltage = floor(voltage); + return voltage/100; +} + +void dcdc_parse_values(unsigned char *data) +{ + int mode, state, status; + float ignition_voltage, input_voltage, output_voltage; + + mode = data[1]; + state = data[2]; + input_voltage = (float) data[3] * 0.1558f; + ignition_voltage = (float) data[4] * 0.1558f; + output_voltage = (float) data[5] * 0.1170f; + status = data[6]; + switch(mode & 0x03) + { + case 0: P("mode: 0 (dumb)"); break; + case 1: P("mode: 1 (automotive)"); break; + case 2: P("mode: 2 (script)"); break; + case 3: P("mode: 3 (ups)");break; + } + P("time config: %d", (mode >> 5) & 0x07); + P("voltage config: %d", (mode >> 2) & 0x07); + P("state: %d", state); + P("input voltage: %.2f", input_voltage); + P("ignition voltage: %.2f", ignition_voltage); + P("output voltage: %2f", output_voltage); + P("power switch: %s", ((status & 0x04) ? "On":"Off")); + P("output enable: %s", ((status & 0x08) ? "On":"Off")); + P("aux vin enable %s", ((status & 0x10) ? "On":"Off")); + P("status flags 1: %d", byte2bits(data[6])); + P("status flags 2: %d", byte2bits(data[7])); + P("voltage flags: %d", byte2bits(data[8])); + P("timer flags: %d", byte2bits(data[9])); + P("flash pointer: %d", data[10]); + P("timer wait: %d", bytes2int(data[11], data[12])); + P("timer vout: %d", bytes2int(data[13], data[14])); + P("timer vaux: %d", bytes2int(data[15], data[16])); + P("timer pw switch: %d", bytes2int(data[17], data[18])); + P("timer off delay: %d", bytes2int(data[19], data[20])); + P("timer hard off: %d", bytes2int(data[21], data[22])); + P("version: %d.%d", ((data[23] >> 5) & 0x07), (data[23] & 0x1F)); + +} + +void dcdc_parse_cmd(unsigned char *data) +{ + if (data[1] == 0) + { + if (data[2] == CMD_READ_REGULATOR_STEP) + { + P("regulator step: %d", data[3]); + } + else + { + P("output voltage: %.2f", byte2vout(data[3])); + } + } + else + { + if (data[2] == CMD_READ_REGULATOR_STEP) + { + P("regulator step not defined"); + } + } +} + +void dcdc_parse_internal_msg(unsigned char *data) +{ + P("Parsing INTERNAL MESSAGE: Not implemented"); +} + +void dcdc_parse_mem(unsigned char *data) +{ + P("Parsing MEM READ IN: Not implemented"); +} \ No newline at end of file diff --git a/plugins/dcdc-usb-200/source/dcdc-usb-proto.c b/plugins/dcdc-usb-200/source/dcdc-usb-proto.c new file mode 100644 index 0000000..6b37f3f --- /dev/null +++ b/plugins/dcdc-usb-200/source/dcdc-usb-proto.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2011 by Mini-Box.com, iTuner Networks Inc. + * Written by Nicu Pavel + * All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +#include +#include +#include +#include + +#include + +#include "dcdc-usb.h" + +/* transforms user value to a value understood by device */ +static int vout2dev(double vout) +{ + double rpot = (double)0.8 * CT_R1 / (vout - (double)0.8) - CT_R2; + double result = (257 * (rpot-CT_RW) / CT_RP); + + if (result<0) result = 0; + if (result>255) result = 255; + + return (unsigned char)result; +} + +static int dcdc_send_command(struct usb_dev_handle *h, unsigned char cmd, unsigned char val) +{ + unsigned char c[3]; + c[0] = DCDCUSB_CMD_OUT; + c[1] = cmd; + c[2] = val; + + return dcdc_send(h, c, 3); +} + +int dcdc_get_status(struct usb_dev_handle *h, unsigned char *buf, int buflen) +{ + unsigned char c[2]; + int ret = 0; + + if (buflen < MAX_TRANSFER_SIZE) + return -1; + + c[0] = DCDCUSB_GET_ALL_VALUES; + c[1] = 0; + + if (dcdc_send(h, c, 2) < 0) + { + fprintf(stderr, "Cannot send command to device\n"); + return -2; + } + + if ((ret = dcdc_recv(h, buf, MAX_TRANSFER_SIZE, 1000)) < 0) + { + fprintf(stderr, "Cannot get device status\n"); + return -3; + } + + return ret; +} + +int dcdc_set_vout(struct usb_dev_handle *h, double vout) +{ + if (vout < 5) vout = 5; + if (vout > 24) vout = 24; + + return dcdc_send_command(h, CMD_WRITE_VOUT, vout2dev(vout)); +} + +/* value will be shown on dcdc_parse_data() */ +int dcdc_get_vout(struct usb_dev_handle *h, unsigned char *buf, int buflen) +{ + int ret = 0; + + if (buflen < MAX_TRANSFER_SIZE) + return -1; + + if ((ret = dcdc_send_command(h, CMD_READ_VOUT, 0)) < 0) + return ret; + + ret = dcdc_recv(h, buf, MAX_TRANSFER_SIZE, 1000); + + return ret; +} + +int dcdc_parse_data(unsigned char *data, int size) +{ + if (data == NULL) + return -1; + +#ifdef DEBUG + int i; + for (i = 0; i < size; i++) + { + if (i % 8 == 0) fprintf(stderr, "\n"); + fprintf(stderr, "[%02d] = 0x%02x ", i, data[i]); + } + fprintf(stderr, "\n"); +#endif + + switch(data[0]) + { + case DCDCUSB_RECV_ALL_VALUES: dcdc_parse_values(data);break; + case DCDCUSB_CMD_IN: dcdc_parse_cmd(data); break; + case INTERNAL_MESG: dcdc_parse_internal_msg(data); break; + case DCDCUSB_MEM_READ_IN: dcdc_parse_mem(data); break; + default: + fprintf(stderr, "Unknown message\n"); + } + + return 0; +} diff --git a/plugins/dcdc-usb-200/source/dcdc_usb_200.rep b/plugins/dcdc-usb-200/source/dcdc_usb_200.rep new file mode 100644 index 0000000..053b781 --- /dev/null +++ b/plugins/dcdc-usb-200/source/dcdc_usb_200.rep @@ -0,0 +1,25 @@ +class DCDCUSB200_Properties { + PROP(QVariant mode SOURCEONLYSETTER) + PROP(QVariant timeConfig SOURCEONLYSETTER) + PROP(QVariant voltageConfig SOURCEONLYSETTER) + PROP(QVariant state SOURCEONLYSETTER) + PROP(QVariant vIn SOURCEONLYSETTER) + PROP(QVariant vIgnition SOURCEONLYSETTER) + PROP(QVariant vOut SOURCEONLYSETTER) + PROP(QVariant powerSwitch SOURCEONLYSETTER) + PROP(QVariant outputEnable SOURCEONLYSETTER) + PROP(QVariant auxVInEnable SOURCEONLYSETTER) + PROP(QVariant statusFlags1 SOURCEONLYSETTER) + PROP(QVariant statusFlags2 SOURCEONLYSETTER) + PROP(QVariant voltageFlags SOURCEONLYSETTER) + PROP(QVariant timerFlags SOURCEONLYSETTER) + PROP(QVariant flashPointer SOURCEONLYSETTER) + PROP(QVariant timerWait SOURCEONLYSETTER) + PROP(QVariant timerVOut SOURCEONLYSETTER) + PROP(QVariant timerVAux SOURCEONLYSETTER) + PROP(QVariant timerPwSwitch SOURCEONLYSETTER) + PROP(QVariant timerOffDelay SOURCEONLYSETTER) + PROP(QVariant timerHardOffDelay SOURCEONLYSETTER) + PROP(QVariant firmwareVersion SOURCEONLYSETTER) + +} \ No newline at end of file diff --git a/plugins/thermal/CMakeLists.txt b/plugins/thermal/CMakeLists.txt new file mode 100644 index 0000000..08bb3dd --- /dev/null +++ b/plugins/thermal/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.1.0) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) +cmake_policy(SET CMP0071 NEW) + +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + +cmake_policy(SET CMP0071 NEW) + +find_package(Qt5 COMPONENTS Core REQUIRED) +find_package(Qt5 COMPONENTS RemoteObjects REQUIRED) + + + +set(HEADERS + include/thermal.h + ) +set(SOURCES + source/thermal.cpp + ) +qt5_generate_repc(REPSOURCES + source/thermal.rep + SOURCE + ) + + + +add_library(thermal + STATIC + ${SOURCES} + ${HEADERS} + ${REPSOURCES} +) + +target_include_directories(thermal PRIVATE + "${PROJECT_BINARY_DIR}" + "${CMAKE_SOURCE_DIR}/car/include/" + ) + +target_include_directories(thermal PUBLIC + "${PROJECT_SOURCE_DIR}/thermal/" + "${PROJECT_SOURCE_DIR}/thermal/include/" + "${CMAKE_CURRENT_BINARY_DIR}" + ) + + +target_link_libraries(thermal Qt5::Core Qt5::RemoteObjects) \ No newline at end of file diff --git a/plugins/thermal/include/thermal.h b/plugins/thermal/include/thermal.h new file mode 100644 index 0000000..d085cf1 --- /dev/null +++ b/plugins/thermal/include/thermal.h @@ -0,0 +1,39 @@ +#ifndef THERMAL_H +#define THERMAL_H + +#include + +#include "pluginbase.h" +#include "rep_thermal_source.h" + +class Thermal_Properties : public Thermal_PropertiesSimpleSource { + Q_OBJECT + public: + Thermal_Properties(QString name, QObject *parent = nullptr); + ~Thermal_Properties(); + Q_PROPERTY(QDir directory READ getDirectory WRITE setDirectory); + + QDir getDirectory() { return this->m_directory; } + void processPacket(QVariant); + public Q_SLOTS: + void setDirectory(QDir directory); + private: + QDir m_directory; +}; + + +class Thermal : public PluginBase { + Q_OBJECT + public: + Thermal(QObject *parent = nullptr); + ~Thermal(); + bool initilize() override; + void update() override; + public Q_SLOTS: + void printUpdate(QVariant); + bool registerSource(QRemoteObjectHostBase *host) override; + private: + QHash m_properties; +}; + +#endif \ No newline at end of file diff --git a/plugins/thermal/source/thermal.cpp b/plugins/thermal/source/thermal.cpp new file mode 100644 index 0000000..9d765b6 --- /dev/null +++ b/plugins/thermal/source/thermal.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include + +#include "thermal.h" + + +Thermal::Thermal(QObject *parent) : + PluginBase(parent) +{ + +} +Thermal::~Thermal() +{ + +} + +bool Thermal::initilize() +{ + QDir sysclass("/sys/class/thermal/"); + QStringList thermals = sysclass.entryList(QStringList() << "thermal_zone*", QDir::Dirs); + foreach(QString directory, thermals) { + /* Get the name for this Thermal class */ + QFile thermal("/sys/class/thermal/"+directory+"/type"); + if (!thermal.exists()) + { + qWarning() << "Thermal Type Entry does not Exist for " << directory; + continue; + } + if (!thermal.open(QIODevice::ReadOnly | QIODevice::Text)) + { + qWarning() << "Can Not Open Thermal Type Entry for " << directory; + continue; + } + QString name = thermal.readLine(); + Thermal_Properties *tp = new Thermal_Properties(directory+"/"+name.simplified(), this); + tp->setDirectory(QDir("/sys/class/thermal/"+directory)); + this->m_properties.insert(directory+"/"+name.simplified(), tp); + connect(tp, &Thermal_Properties::tempChanged, this, &Thermal::printUpdate); + } + this->startTimer(); + return true; +} + +void Thermal::update() +{ + foreach(Thermal_Properties *tp, this->m_properties) { + QFile temp(tp->getDirectory().absoluteFilePath("temp")); + + if (!temp.exists()) { + qWarning() << "Temp Entry for " << tp->name() << " doesn't exist"; + continue; + } + if (!temp.open(QIODevice::ReadOnly | QIODevice::Text)) + { + qWarning() << "Can't Open Temp File for " << tp->name(); + continue; + } + QString value = temp.readLine().simplified(); + tp->processPacket(value); + } +} + +void Thermal::printUpdate(QVariant data) { + QObject *sender = QObject::sender(); + int signalindex = QObject::senderSignalIndex(); + const QMetaObject *mo = sender->metaObject(); + qInfo() << "Changed Single: " << sender->objectName() << QString::fromLatin1(mo->method(signalindex).methodSignature()) << data.toString(); +} + +bool Thermal::registerSource(QRemoteObjectHostBase *host) { + bool ret = false; + foreach(Thermal_Properties *tp, this->m_properties) { + ret |= host->enableRemoting(tp, "plugins/thermal/"+tp->name().toString()); + } + return ret; +} + + + +Thermal_Properties::Thermal_Properties(QString name, QObject *parent) : + Thermal_PropertiesSimpleSource(parent) +{ + this->setObjectName(name); + this->setName(name); + qDebug() << "New Thermal Property Found: " << name; +} +Thermal_Properties::~Thermal_Properties() +{ + +} +void Thermal_Properties::setDirectory(QDir directory) +{ + this->m_directory = directory; +} + +void Thermal_Properties::processPacket(QVariant data) +{ + this->setTemp(data.toInt() * 0.001); +} diff --git a/plugins/thermal/source/thermal.rep b/plugins/thermal/source/thermal.rep new file mode 100644 index 0000000..ba1cd99 --- /dev/null +++ b/plugins/thermal/source/thermal.rep @@ -0,0 +1,4 @@ +class Thermal_Properties { + PROP(QVariant name SOURCEONLYSETTER) + PROP(QVariant temp SOURCEONLYSETTER) +} \ No newline at end of file