cvtdriver
Driver for SmartFarm Device Converter
cvtdevicespec.h
이 파일의 문서화 페이지로 가기
1 
12 #ifndef _CVT_DEVICESPEC_
13 #define _CVT_DEVICESPEC_
14 
15 #include <iostream>
16 #include <string>
17 
18 #include <glog/logging.h>
19 
20 #include "cvtcode.h"
21 
22 using namespace std;
23 
24 namespace stdcvt {
25 
26 typedef enum {
27  _DS_TX = 0,
28  _DS_TY = 1,
29  _DS_TZ = 2,
30  _DS_PX = 3,
31  _DS_PY = 4,
32  _DS_PZ = 5,
33 } _dsiv_t;
34 
35 #define _DS_MAX 6
36 
37 /*
38  @brief CvtDeviceSpec is a virtual class for a smartfarm device.
39 */
41 private:
42  string _manufacturer;
43  string _model;
44  devtype_t _type;
45  devsec_t _section;
46  devtarget_t _target;
47 
48  class CvtDeviceSection {
49  private:
50  int _sv[_DS_MAX];
51 
52  public:
53  CvtDeviceSection(long section) {
54  long tmp = section;
55  for (int i = 0; i < _DS_MAX; i++) {
56  _sv[i] = tmp % 100;
57  tmp = tmp / 100;
58  }
59  }
60 
61  int getvalue(_dsiv_t index) {
62  return _sv[index];
63  }
64  };
65 
66 public:
71  _type = DT_DEV_UNKNOWN;
72  _section = DL_UNKNOWN;
73  _target = DO_UNKNOWN;
74  _manufacturer = "";
75  _model = "";
76  }
77 
84  CvtDeviceSpec(devtype_t devtype, devsec_t section, devtarget_t target) {
85  _type = devtype;
86  _section = section;
87  _target = target;
88  _manufacturer = "";
89  _model = "";
90  }
91 
92  ~CvtDeviceSpec() {
93  }
94 
100  return (devgroup_t)(_type / 10000);
101  }
102 
108  return _type;
109  }
110 
116  return _section;
117  }
118 
124  return _target;
125  }
126 
132  string setmanufacturer(string manufacturer) {
133  _manufacturer = manufacturer;
134  return _manufacturer;
135  }
136 
141  string getmanufacturer() {
142  return _manufacturer;
143  }
144 
150  string setmodel(string model) {
151  _model = model;
152  return _model;
153  }
154 
159  string getmodel() {
160  return _model;
161  }
162 
167  bool copy(CvtDeviceSpec *pdevspec) {
168  _type = pdevspec->_type;
169  _section = pdevspec->_section;
170  _target = pdevspec->_target;
171  _manufacturer = pdevspec->_manufacturer;
172  _model = pdevspec->_model;
173  return true;
174  }
175 
179  string tostring() {
180  return "CvtDeviceSpec type : " + to_string(_type)
181  + ", target : " + to_string(_target) + ", section : " + to_string(_section)
182  + ", manufacturer : " + _manufacturer + ", model : " + _model;
183  }
184 
189  bool checktarget(CvtDeviceSpec *pdevspec) {
190  if ((_target == DO_UNKNOWN) ||
191  (pdevspec->_target == DO_UNKNOWN)) {
192  return false;
193  }
194  if (_target == pdevspec->_target)
195  return true;
196  // 설치 위치가 있는 장비와 설치 위치가 없는 상태의 장비에 대해
197  // 지능적 처리가 필요할 수 있지만 현재는 무시한다.
198  return false;
199  }
200 
205  bool checktype(CvtDeviceSpec *pdevspec) {
206  if ((_type == DT_DEV_UNKNOWN) || (_type == DT_SEN_UNKNOWN) ||
207  (_type == DT_MOT_UNKNOWN) || (_type == DT_SWC_UNKNOWN) ||
208  (pdevspec->_type == DT_SEN_UNKNOWN) ||
209  (pdevspec->_type == DT_MOT_UNKNOWN) ||
210  (pdevspec->_type == DT_SWC_UNKNOWN) ||
211  (pdevspec->_type == DT_DEV_UNKNOWN)) {
212  return false;
213  }
214  if (_type == pdevspec->_type)
215  return true;
216 
217  // 창이 다겹인경우 장비 타입에 대해서
218  // 지능적 처리가 필요할 수 있지만 현재는 무시한다.
219  return false;
220  }
221 
226  bool checksection(CvtDeviceSpec *pdevspec) {
227  if ((_section == DL_UNKNOWN) ||
228  (pdevspec->_section == DL_UNKNOWN)) {
229  return false;
230  }
231  if (_section == pdevspec->_section) {
232  return true;
233  }
234 
235  CvtDeviceSection in(_section);
236  CvtDeviceSection ex(pdevspec->_section);
237 
238  if (in.getvalue (_DS_TX) == ex.getvalue (_DS_TX)) {
239  if (in.getvalue (_DS_PX) != ex.getvalue (_DS_PX)) {
240  return false; // x축 방향으로 같은 개수인데 다른 위치
241  }
242  } else {
243  // x축 방향으로 다른 개수. 서로 다른 구역구분을 가지고 있는 경우.
244  // 지능적으로 처리할 수 있지만 여기서는 단순히 처리함.
245  return false;
246  }
247 
248  if (in.getvalue (_DS_TY) == ex.getvalue (_DS_TY)) {
249  if (in.getvalue (_DS_PY) != ex.getvalue (_DS_PY)) {
250  return false; // Y축 방향으로 같은 개수인데 다른 위치
251  }
252  } else {
253  // Y축 방향으로 다른 개수. 서로 다른 구역구분을 가지고 있는 경우.
254  // 지능적으로 처리할 수 있지만 여기서는 단순히 처리함.
255  return false;
256  }
257 
258  if (in.getvalue (_DS_TZ) == ex.getvalue (_DS_TZ)) {
259  if (in.getvalue (_DS_PZ) != ex.getvalue (_DS_PZ)) {
260  return false; // Z축 방향으로 같은 개수인데 다른 위치
261  }
262  } else {
263  // Z축 방향으로 다른 개수. 서로 다른 구역구분을 가지고 있는 경우.
264  // 지능적으로 처리할 수 있지만 여기서는 단순히 처리함.
265  return false;
266  }
267 
268  return true;
269  }
270 
275  bool ismatched(CvtDeviceSpec *pdevspec) {
276  if (!checksection (pdevspec))
277  return false;
278 
279  if (!checktarget (pdevspec))
280  return false;
281 
282  if (!checktype (pdevspec))
283  return false;
284 
285  return true;
286  }
287 };
288 
289 }
290 #endif
string getmanufacturer()
Definition: cvtdevicespec.h:141
devtype_t
Definition: cvtcode.h:63
devtype_t gettype()
Definition: cvtdevicespec.h:107
string getmodel()
Definition: cvtdevicespec.h:159
bool checktarget(CvtDeviceSpec *pdevspec)
Definition: cvtdevicespec.h:189
string setmodel(string model)
Definition: cvtdevicespec.h:150
bool checksection(CvtDeviceSpec *pdevspec)
Definition: cvtdevicespec.h:226
devgroup_t getgrouptype()
Definition: cvtdevicespec.h:99
알수없는 센서
Definition: cvtcode.h:79
devtarget_t gettarget()
Definition: cvtdevicespec.h:123
CvtDeviceSpec()
Definition: cvtdevicespec.h:70
devgroup_t
Definition: cvtcode.h:55
devsec_t getsection()
Definition: cvtdevicespec.h:115
알수없는 장비
Definition: cvtcode.h:64
string tostring()
Definition: cvtdevicespec.h:179
#define DL_UNKNOWN
설치구역 알수 없음
Definition: cvtcode.h:21
bool copy(CvtDeviceSpec *pdevspec)
Definition: cvtdevicespec.h:167
long devsec_t
Definition: cvtcode.h:19
대상을 알지 못함
Definition: cvtcode.h:41
devtarget_t
Definition: cvtcode.h:40
알수없는 스위치형 구동기
Definition: cvtcode.h:99
bool checktype(CvtDeviceSpec *pdevspec)
Definition: cvtdevicespec.h:205
string setmanufacturer(string manufacturer)
Definition: cvtdevicespec.h:132
Definition: cvtcode.h:17
알수없는 모터형 구동기
Definition: cvtcode.h:95
bool ismatched(CvtDeviceSpec *pdevspec)
Definition: cvtdevicespec.h:275
Definition: cvtdevicespec.h:40
CvtDeviceSpec(devtype_t devtype, devsec_t section, devtarget_t target)
Definition: cvtdevicespec.h:84