-
Notifications
You must be signed in to change notification settings - Fork 1
/
hal.cpp
126 lines (100 loc) · 3.15 KB
/
hal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* SPDX-License-Identifier: GPLv3-or-later */
/* Copyright (c) 2019 Project WomoLIN */
/* Author Myron Franze <[email protected]> */
#include "hal.h"
#include "interface/helper.h"
namespace siguni
{
// Get Signals
CHalUnitInputGetSignals::CHalUnitInputGetSignals (
const std::map<std::string_view, interface::ISignal*> & attSignalMap )
: signalMap( attSignalMap )
{
}
void CHalUnitInputGetSignals::Get( std::string & attGetInput,
interface::CAdditionals & /*attAdditionals*/ )
{
if( 0 == attGetInput.compare("GET") )
{
attGetInput = std::to_string( signalMap.size() );
return;
}
// we expect the format "GET,indexvalue", indexvalue > 0
auto valueItems = helper::CSignalStrings::GetValueItems( attGetInput, ',');
if( 2 != valueItems.size() )
{
attGetInput = "invalid value";
return;
}
if( 0 != valueItems.at(0).compare("GET") )
{
attGetInput = "invalid value";
return;
}
auto index = std::atoi( valueItems.at(1).c_str());
if( index == 0)
{
attGetInput = "can't convert index";
return;
}
if( index > static_cast<int>(signalMap.size()) )
{
attGetInput = "index out of range";
return;
}
auto count = 1;
for(const auto & [key, ignored] : signalMap ){
if( count == index )
{
attGetInput = key;
break;
}
count++;
}
}
// Get Simulation Status
CHalUnitInputGetSimulationStatus::CHalUnitInputGetSimulationStatus(
const std::map<std::string_view, interface::ISignal*> & attSignalMap )
: signalMap( attSignalMap )
{
}
void CHalUnitInputGetSimulationStatus::Get( std::string & attGetInput, interface::CAdditionals & attAdditionals )
{
if( attAdditionals.SimulationMode ) {
attGetInput = "SET";
}
else {
attGetInput = "RESET";
}
}
// Set Simulation Modus
CHalUnitOutputSetResetSimulationModus::CHalUnitOutputSetResetSimulationModus( const std::map<std::string_view, interface::ISignal*> & attSignalMap )
: signalMap( attSignalMap )
{
}
void CHalUnitOutputSetResetSimulationModus::Set( std::string & attSetOutput, interface::CAdditionals & attAdditionals )
{
if ( attSetOutput.compare("SET") == 0 ) {
attAdditionals.SimulationMode = true;
}
else if ( attSetOutput.compare("RESET") == 0 ) {
attAdditionals.SimulationMode = false;
}
else {
attAdditionals.WriteErrorLog(
"CHalUnitOutputSetResetSimulationModus::Set",
"unknown attSetOutput: " + attSetOutput );
}
}
// Get Logging
CHalUnitInputGetLogging::CHalUnitInputGetLogging(
const std::map<std::string_view, interface::ISignal*> & attSignalMap )
: signalMap( attSignalMap )
{
}
void CHalUnitInputGetLogging::Get(
std::string & attGetInput, interface::CAdditionals & attAdditionals )
{
attGetInput = attAdditionals.ReadErrorLog();
}
}