-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.h
112 lines (81 loc) · 2.85 KB
/
config.h
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
#ifndef PLC_EMULATOR__CONFIG_H_
#define PLC_EMULATOR__CONFIG_H_
#include <memory>
#include <string>
#include <thread>
#include <unordered_map>
#include "config.pb.h"
#include "datatype_registry.h"
#include "logger.h"
#include "mem_unit.h"
#include "resource_registry.h"
#include "resource_manager.h"
namespace plc_emulator {
class Config {
private:
std::unique_ptr<DataTypeRegistry> registered_data_types_;
ResourceRegistry *registered_resource_{};
int mem_size_{};
MemUnit memory_;
std::string path_;
std::string name_;
config::Specification spec_;
std::unique_ptr<Variable> global_pou_var_;
std::unique_ptr<Variable> access_pou_var_;
std::unordered_map<int, std::string> default_initial_values_;
std::unordered_map<std::string, std::unique_ptr<Variable>> accessed_fields_;
virtual void RegisterAllElementaryDataTypes() = 0;
virtual void RegisterAllComplexDataTypes() = 0;
virtual void RegisterAllResources() = 0;
public:
std::unique_ptr<Logger> logger;
Config() = default;
~Config() = default;
std::string GetName() {
return name_;
}
virtual DataType *LookupDataType(std::string name) = 0;
virtual Variable *GetExternalVariable(std::string nested_field_name) = 0;
virtual Variable *GetPou(std::string name) = 0;
virtual Variable *GetVariablePointerToMem(int byte_offset,
int bit_offset,
std::string var_data_type_name) = 0;
virtual void Cleanup() = 0;
};
class ConfigImpl : public Config {
private:
int num_resources_;
std::unordered_map<std::string, std::unique_ptr<ResourceManager>>
resource_managers_;
std::vector<std::thread> launched_resources_;
bool stop_;
bool enable_kronos_;
float rel_cpu_speed_;
int64_t per_round_inc_ns;
void RegisterAllResources();
void RegisterAllElementaryDataTypes();
void RegisterAllComplexDataTypes();
void InitializeAllPouVariables();
public:
Variable *GetExternalVariable(std::string nested_field_name);
Variable *GetPOU(std::string name);
Variable *GetAccessPathVariable(std::string access_path);
DataType *LookupDataType(std::string name);
ConfigImpl(std::string config_path,
bool enable_kronos,
long per_round_inc_ns = 1000000);
Variable *GetVariablePointerToMem(int byte_offset, int bit_offset,
std::string var_data_type_name);
Variable *GetVariablePointerToResourceMem(std::string resource_name,
int MemType,
int byte_offset,
int bit_offset,
std::string var_data_type_name);
void RunPlc();
void LaunchPlc();
void WaitForCompletion();
void StopAllResources();
void Cleanup();
};
}
#endif //PLC_EMULATOR__CONFIG_H_