From 1c2678007c21c11af76a55e46fc3a8c62a0003a8 Mon Sep 17 00:00:00 2001 From: Myron Franze <58065110+Norym@users.noreply.github.com> Date: Thu, 18 Jun 2020 20:16:52 +0200 Subject: [PATCH] expanded basemanager with signal GetSignals --- CMakeLists.txt | 1 + hal.cpp | 25 +++++++++++++++++++++++++ hal.h | 25 +++++++++++++++++++++++++ interface/isignal.h | 8 ++++++++ managerbase.cpp | 5 +++++ managerbase.h | 13 +++++++++++-- signal.cpp | 7 +++++++ signal.h | 11 +++++++++++ unit.cpp | 9 +++++---- unit.h | 5 ++++- 10 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 hal.cpp create mode 100644 hal.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b58e612..86fa8b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ add_library(${PRJ_NAME} unit signal + hal protocol managerbase diff --git a/hal.cpp b/hal.cpp new file mode 100644 index 0000000..cf50c03 --- /dev/null +++ b/hal.cpp @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPLv3-or-later */ +/* Copyright (c) 2019 Project WomoLIN */ +/* Author Myron Franze */ + +#include "hal.h" + +namespace siguni +{ + + CHalUnitInputGetSignals::CHalUnitInputGetSignals( const std::map & attSignalMap ) + : signalMap( attSignalMap ) + { + + } + + void CHalUnitInputGetSignals::Get( std::string & attGetInput ) + { + attGetInput.clear(); + for(const auto & [key, ignored] : signalMap ){ + attGetInput.append( key ); + attGetInput.append( "," ); + } + } + +} diff --git a/hal.h b/hal.h new file mode 100644 index 0000000..03479cf --- /dev/null +++ b/hal.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPLv3-or-later */ +/* Copyright (c) 2019 Project WomoLIN */ +/* Author Myron Franze */ + +#pragma once + +#include "interface/isignal.h" +#include "interface/iunit.h" + +namespace siguni +{ + + class CHalUnitInputGetSignals : public interface::IUnitInput + { + public: + CHalUnitInputGetSignals( const std::map & attSignalMap ); + ~CHalUnitInputGetSignals() = default; + + void Get( std::string & attGetInput ) override final; + + private: + const std::map & signalMap; + }; + +} diff --git a/interface/isignal.h b/interface/isignal.h index 2aa6414..6047fd2 100644 --- a/interface/isignal.h +++ b/interface/isignal.h @@ -40,6 +40,14 @@ namespace siguni::interface virtual void UpdateUnitSignalGetVersion( std::string & attKey, std::string & attVersion ) = 0; }; + class ISignalGetSignals + { + public: + virtual ~ISignalGetSignals() = default; + virtual void UpdateUnitSignalGetSignals( std::string & attKey, std::string & attVersion ) = 0; + }; + + } diff --git a/managerbase.cpp b/managerbase.cpp index 6b11352..2507371 100644 --- a/managerbase.cpp +++ b/managerbase.cpp @@ -12,7 +12,12 @@ namespace siguni CManagerBase::CManagerBase( interface::IControlbus & attControlbus ) : controlbus( attControlbus ) , protocol( controlbus ) + , halUnitInputGetSignals( signalVector ) { + + signalVector["GetSignals"] = &GetSignals; + GetSignals.AddUnit( &unitInputGetSignals ); + } void CManagerBase::DoWork() diff --git a/managerbase.h b/managerbase.h index 9d03db7..ddc4695 100644 --- a/managerbase.h +++ b/managerbase.h @@ -4,7 +4,9 @@ #pragma once -#include "interface/isignal.h" +#include "unit.h" +#include "hal.h" +#include "signal.h" #include "protocol.h" #include @@ -23,10 +25,17 @@ namespace siguni protected: std::string message; std::map signalVector; - + private: interface::IControlbus & controlbus; CProtocol protocol; + // units + CHalUnitInputGetSignals halUnitInputGetSignals; + CUnitInput unitInputGetSignals{ halUnitInputGetSignals } ; + + // signals + CSignalGetSignals GetSignals { CSignalGetSignals() }; + }; } diff --git a/signal.cpp b/signal.cpp index 64afec6..d14707f 100644 --- a/signal.cpp +++ b/signal.cpp @@ -30,6 +30,13 @@ namespace siguni } } + void CSignalGetSignals::UpdateUnit( std::string & attKey, std::string & attValue ) + { + for( const auto & unit : units ){ + unit->UpdateUnitSignalGetSignals( attKey, attValue ); + } + } + } diff --git a/signal.h b/signal.h index 688c897..02c5253 100644 --- a/signal.h +++ b/signal.h @@ -63,4 +63,15 @@ namespace siguni }; + class CSignalGetSignals final + : public CSignalAddUnit + , public interface::ISignal + { + public: + CSignalGetSignals() = default; + ~CSignalGetSignals() = default; + void UpdateUnit( std::string & attKey, std::string & attValue ) override final; + }; + + } diff --git a/unit.cpp b/unit.cpp index 6f8f03a..708eeea 100644 --- a/unit.cpp +++ b/unit.cpp @@ -9,6 +9,11 @@ namespace siguni CUnitOutput::CUnitOutput( interface::IUnitOutput & attUnitOutput ) : unitOutput( attUnitOutput ) {} + void CUnitInput::UpdateUnitSignalGetSignals( std::string & /*attKey*/, std::string & attValue ) + { + unitInput.Get( attValue ); + } + void CUnitOutput::UpdateUnitSignalSetReset( std::string & /*attKey*/, std::string & attValue ) { unitOutput.Set( attValue ); @@ -30,8 +35,4 @@ namespace siguni { unitInput.Get( attValue ); } - - - - } diff --git a/unit.h b/unit.h index 2dcfa17..ff790f7 100644 --- a/unit.h +++ b/unit.h @@ -24,7 +24,8 @@ namespace siguni }; class CUnitInput - : public interface::ISignalSetReset + : public interface::ISignalGetSignals + , public interface::ISignalSetReset , public interface::ISignalGetVersion , public interface::ISignalGetVoltage { @@ -32,6 +33,8 @@ namespace siguni CUnitInput( interface::IUnitInput & attUnitInput) ; ~CUnitInput() = default; + void UpdateUnitSignalGetSignals( std::string & attKey, std::string & attValue ) override final; + void UpdateUnitSignalSetReset( std::string & attKey, std::string & attValue ) override final; void UpdateUnitSignalGetVersion( std::string & attKey, std::string & attValue ) override final; void UpdateUnitSignalGetVoltage( std::string & attKey, std::string & attValue ) override final;