-
Notifications
You must be signed in to change notification settings - Fork 0
/
RAMS7200MS.cxx
61 lines (55 loc) · 1.78 KB
/
RAMS7200MS.cxx
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
/** © Copyright 2023 CERN
*
* This software is distributed under the terms of the
* GNU Lesser General Public Licence version 3 (LGPL Version 3),
* copied verbatim in the file “LICENSE”
*
* In applying this licence, CERN does not waive the privileges
* and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*
* Author: Alexandru Savulescu (HSE)
*
**/
#include "RAMS7200MS.hxx"
#include "Common/S7Utils.hxx"
#include "Common/Logger.hxx"
#include <algorithm>
RAMS7200MSVar::RAMS7200MSVar(std::string varName, int pollTime, TS7DataItem type) : varName(varName), pollTime(pollTime), _toPlc(type), _toDP(type)
{
if(Common::Constants::getSmoothing()){
Common::S7Utils::TS7AllocateDataItemForAddress(_toDP);
}
}
void RAMS7200MS::addVar(std::string varName, int pollTime)
{
std::lock_guard lock{_rwmutex};
auto var = RAMS7200MSVar(varName, pollTime, Common::S7Utils::TS7DataItemFromAddress(varName, false));
vars.emplace(varName, std::move(var));
}
void RAMS7200MS::removeVar(std::string varName)
{
std::lock_guard lock{_rwmutex};
auto it = vars.find(varName);
if(it != vars.end()) {
if (it->second._toDP.pdata != nullptr) {
delete[] static_cast<char*>(it->second._toDP.pdata);
}
if (it->second._toPlc.pdata != nullptr) {
delete[] static_cast<char*>(it->second._toPlc.pdata);
}
vars.erase(it);
}
}
void RAMS7200MS::queuePLCItem(const std::string& varName, void* item)
{
try
{
std::lock_guard lock{_rwmutex};
vars.at(varName)._toPlc.pdata = item;
}
catch(const std::out_of_range& e)
{
Common::Logger::globalWarning(__PRETTY_FUNCTION__, "Undefined address", e.what());
}
}