-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRAMS7200LibFacade.hxx
98 lines (81 loc) · 2.68 KB
/
RAMS7200LibFacade.hxx
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
/** © Copyright 2022 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: Adrien Ledeul (HSE)
*
**/
#ifndef RAMS7200LIBFACADE_HXX
#define RAMS7200LIBFACADE_HXX
#define OVERHEAD_READ_MESSAGE 13
#define OVERHEAD_READ_VARIABLE 5
#define OVERHEAD_WRITE_MESSAGE 24
#define OVERHEAD_WRITE_VARIABLE 16
#define PDU_SIZE 240
#include <string>
#include <chrono>
#include <vector>
#include <stdexcept>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <map>
#include <functional>
#include <memory>
#include <unordered_set>
#include <condition_variable>
#include <mutex>
#include <thread>
#include "RAMS7200MS.hxx"
#include "Common/Logger.hxx"
/**
* @brief The RAMS7200LibFacade class is a facade and encompasses all the consumer interaction with snap7
*/
class RAMS7200LibFacade
{
public:
/**
* @brief RAMS7200LibFacade constructor
* @param RAMS7200MS & : const reference to the MS object
* @param queueToDPCallback : a callback that will be called after each poll
* */
RAMS7200LibFacade(RAMS7200MS& , queueToDPCallback);
RAMS7200LibFacade(const RAMS7200LibFacade&) = delete;
RAMS7200LibFacade& operator=(const RAMS7200LibFacade&) = delete;
RAMS7200LibFacade(RAMS7200LibFacade&&) = delete;
RAMS7200LibFacade& operator=(RAMS7200LibFacade&&) = delete;
~RAMS7200LibFacade() = default;
void Poll();
void WriteToPLC();
void EnsureConnection(bool reduSwitch);
void Connect();
template <typename T>
void sleep_for(T duration)
{
std::unique_lock<std::mutex> lk(ms._threadMutex);
ms._threadCv.wait_for(lk, duration, [&](){
return !ms._run.load();
});
}
private:
void Reconnect();
void Disconnect();
void RAMS7200MarkDeviceConnectionError(bool);
void RAMS7200ReadWriteMaxN(std::vector<DPInfo> dpItems, std::vector<TS7DataItem> items, const uint N, const int PDU_SZ, const int VAR_OH, const int MSG_OH, const Common::S7Utils::Operation rorw);
void doSmoothing(std::vector<DPInfo>&& dpItems, std::vector<TS7DataItem>&& items);
void queueAll(std::vector<DPInfo>&& dpItems, std::vector<TS7DataItem>&& items);
uint32_t ioFailures{0};
RAMS7200MS& ms;
// S7 related
queueToDPCallback _queueToDPCB;
bool _wasConnected{false};
std::unique_ptr<TS7Client> _client{nullptr};
};
#endif //RAMS7200LIBFACADE_HXX