EL_dev_arduino 2.2.1
読み取り中…
検索中…
一致する文字列を見つけられません
/Users/sugimura/EL_dev_arduino/ELOBJ.cpp
[詳解]
1
8#include "ELOBJ.h"
9
10
12// PDCEDT
15{
16 m_pdcedt = nullptr;
17 length = 0;
18}
19PDCEDT::PDCEDT(const PDCEDT& val) // copy constractor
20{
21 length = val[0] + 1;
22 m_pdcedt = new byte[length];
23 memcpy(m_pdcedt, val, length);
24}
25
26PDCEDT::PDCEDT(const byte* val)
27{
28 length = val[0] + 1;
29 m_pdcedt = new byte[length];
30 memcpy(m_pdcedt, val, length);
31}
32
34{
35 if (nullptr != m_pdcedt)
36 {
37 delete[] m_pdcedt;
38 m_pdcedt = nullptr;
39 length = 0;
40 }
41}
42
44{
45 // cout << "ope = PDCEDT" << endl;
46 if (nullptr != m_pdcedt)
47 {
48 // cout << "delete" << endl;
49 delete[] m_pdcedt;
50 m_pdcedt = nullptr;
51 }
52 // cout << "new" << endl;
53
54 length = val[0] + 1;
55 // cout << size << endl;
56 m_pdcedt = new byte[length];
57 memcpy(m_pdcedt, val, length);
58 return *this;
59}
60
61const byte* PDCEDT::operator=(const byte* val)
62{
63 // cout << "ope = byte" << endl;
64 if (nullptr != m_pdcedt)
65 {
66 // cout << "delete" << endl;
67 delete[] m_pdcedt;
68 m_pdcedt = nullptr;
69 }
70 // cout << "new" << endl;
71
72 length = val[0] + 1;
73 // cout << size << endl;
74 m_pdcedt = new byte[length];
75 memcpy(m_pdcedt, val, length);
76
77 return m_pdcedt;
78}
79
80PDCEDT::operator byte* () const
81{
82 return m_pdcedt;
83}
84
85void PDCEDT::print(void) const
86{
87
88#ifdef Arduino_h
89 if(length == 0) {
90 Serial.println("error: PDCEDT len 0");
91 return;
92 }
93 Serial.print("[");
94 Serial.print(length);
95 Serial.print("]: ");
96 Serial.print((int)m_pdcedt[0]);
97 for (byte i = 1; i < length; i += 1)
98 {
99 Serial.print(", ");
100 Serial.print((int)m_pdcedt[i]);
101 }
102 Serial.print("\n");
103#else
104 if(length == 0) {
105 cout << "error: PDCEDT len 0" << endl;
106 return;
107 }
108 cout << "[" << dec << (int)length << "]: ";
109 cout << dec << (int)m_pdcedt[0];
110 for (byte i = 1; i < length; i += 1)
111 {
112 cout << ", " << hex << (int)m_pdcedt[i];
113 }
114 cout << endl;
115#endif
116}
117
119// EOOBJ
122{
123}
124
126
128// キー文字列からデータ取得
129const PDCEDT ELOBJ::GetPDCEDT(const byte epc) const
130{
131 int key = epc - 0x80;
132 return m_pdcedt[key];
133}
134
135// データセット, 更新
136const PDCEDT ELOBJ::SetPDCEDT(const byte epc, const PDCEDT pdcedt)
137{
138 // cout << "Set PDCEDT" << endl;
139 int key = epc - 0x80;
140 m_pdcedt[key] = pdcedt;
141 return (m_pdcedt[key]);
142}
143
144const PDCEDT ELOBJ::SetPDCEDT(const byte epc, const byte*&& pdcedt)
145{
146 // cout << "Set byte*" << endl;
147 int key = epc - 0x80;
148 m_pdcedt[key] = pdcedt;
149 return (m_pdcedt[key]);
150}
151
152// 配列らしいインターフェイス,const this
153const PDCEDT ELOBJ::operator[](const byte epc) const
154{
155 int key = epc - 0x80;
156 return ((const PDCEDT)m_pdcedt[key]);
157}
158
159// 配列らしいインターフェイス,not const this
160PDCEDT &ELOBJ::operator[](const byte epc)
161{
162 int key = epc - 0x80;
163 return ((PDCEDT &)m_pdcedt[key]);
164}
165
166// 状態表示系
167
168// null以外全部出力
169void ELOBJ::printAll() const
170{
171 for (int i = 0; i < PDC_MAX; i += 1)
172 {
173 if (nullptr != m_pdcedt[i])
174 {
175#ifdef Arduino_h
176 Serial.print( (int)(i + 0x80) );
177 Serial.print(": ");
178#else
179 cout << hex << i + 0x80 << ": ";
180#endif
181 m_pdcedt[i].print();
182 }
183 }
184}
185
187// EOF
Subclasses for ECHONET Lite protocol
const PDCEDT SetPDCEDT(const byte epc, const PDCEDT pdcedt)
Definition: ELOBJ.cpp:136
void printAll() const
Definition: ELOBJ.cpp:169
virtual ~ELOBJ()
Definition: ELOBJ.cpp:125
ELOBJ()
Definition: ELOBJ.cpp:121
PDCEDT m_pdcedt[PDC_MAX]
Definition: ELOBJ.h:58
const PDCEDT operator[](const byte epc) const
Definition: ELOBJ.cpp:153
static const byte PDC_MAX
Definition: ELOBJ.h:55
const PDCEDT GetPDCEDT(const byte epc) const
Definition: ELOBJ.cpp:129
PDC and EDT
Definition: ELOBJ.h:31
virtual ~PDCEDT()
Definition: ELOBJ.cpp:33
void print(void) const
Definition: ELOBJ.cpp:85
const PDCEDT operator=(const PDCEDT val)
Definition: ELOBJ.cpp:43
byte * m_pdcedt
Definition: ELOBJ.h:33
PDCEDT()
Definition: ELOBJ.cpp:14
byte length
Definition: ELOBJ.h:34
byte * pdcedt
Definition: main.cpp:56