diff --git a/src/connectionconfig.h b/include/connectionconfig.h index 48bda8a..48bda8a 100644 --- a/src/connectionconfig.h +++ b/include/connectionconfig.h diff --git a/include/imodbus.h b/include/imodbus.h index e69de29..2b870d7 100644 --- a/include/imodbus.h +++ b/include/imodbus.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Peter M. Groen + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#pragma once + +#include "request.h" +#include "connectionconfig.h" +#include + +namespace osdev { +namespace components { +namespace modbus { + +class IModBus +{ +public: + virtual ~IModBus() {} + + virtual bool Open(const ConnectionConfig &connection_config) = 0; + virtual bool Close() = 0; + virtual std::vector Read(const Request &request) = 0; + virtual std::vector Write(const Request &request) = 0; +}; + +} /* End namespace modbus */ +} /* End namespace components */ +} /* End namespace osdev */ diff --git a/include/request.h b/include/request.h index 355648a..525f8fe 100644 --- a/include/request.h +++ b/include/request.h @@ -111,25 +111,25 @@ public: /// @note never change the length of this vector. std::vector getDataBuffer() const {return m_dataBuffer;} - /// @return Callbacks registered to call when new data is available. - /// @note Functionn pointer returns False if the device state is OFFLINE. True, otherwise. - std::vector> callbacks; - private: /// Function code of this request. - FunctionCode m_functionCode; + FunctionCode m_functionCode = FunctionCode::FC_UNKNOWN; /// SlaveID of this request. - uint8_t m_slaveId; + uint8_t m_slaveId = 0; /// Start address of the register for this request - uint8_t m_startAddress; + uint8_t m_startAddress = 0x00; /// Amount of registers to read/write in this request - uint8_t m_numberOfRegisters; + uint8_t m_numberOfRegisters = 0x00; /// Data to send to the device; must be the same size as \ref m_numberOfItems. - std::vector m_dataBuffer; + std::vector m_dataBuffer = {}; + + /// @return Callbacks registered to call when new data is available. + /// @note Functionn pointer returns False if the device state is OFFLINE. True, otherwise. + std::vector> callbacks = {}; }; } /* End namespace modbus */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e893c9c..42c4ec8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,6 @@ set(SRC_LIST ${CMAKE_CURRENT_SOURCE_DIR}/modbustcp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modbusrtu.h ${CMAKE_CURRENT_SOURCE_DIR}/modbusrtu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/connectionconfig.h ${CMAKE_CURRENT_SOURCE_DIR}/connectionconfig.cpp ) diff --git a/src/modbus.cpp b/src/modbus.cpp index 115d75c..e38cd72 100644 --- a/src/modbus.cpp +++ b/src/modbus.cpp @@ -1,6 +1,34 @@ #include "modbus.h" +using namespace osdev::components::modbus; + ModBus::ModBus() { } + +bool ModBus::Open(const ConnectionConfig &connection_config) +{ + (void)connection_config; + + return true; +} + +bool ModBus::Close() +{ + return true; +} + +std::vector ModBus::Read(const Request &request) +{ + (void)request; + + return std::vector(); +} + +std::vector ModBus::Write(const Request &request) +{ + (void)request; + + return std::vector(); +} diff --git a/src/modbus.h b/src/modbus.h index b9072d5..aae2635 100644 --- a/src/modbus.h +++ b/src/modbus.h @@ -1,11 +1,30 @@ -#ifndef MODBUS_H -#define MODBUS_H +/* + * Copyright (c) 2023 Peter M. Groen + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#pragma once +#include "imodbus.h" -class ModBus +namespace osdev { +namespace components { +namespace modbus { + +class ModBus : public IModBus { public: ModBus(); + + virtual ~ModBus() {} + + virtual bool Open(const ConnectionConfig &connection_config) override; + virtual bool Close() override; + virtual std::vector Read(const Request &request) override; + virtual std::vector Write(const Request &request) override; }; -#endif // MODBUS_H +} /* End namespace modbus */ +} /* End namespace components */ +} /* End namespace osdev */