EL_dev_arduino 4.0.0
読み取り中…
検索中…
一致する文字列を見つけられません
/Users/sugimura/EL_dev_arduino/EL.h
[詳解]
1
8#ifndef __EL_H__
9#define __EL_H__
10#pragma once
11
12// auto config
13#ifndef GPP
14// arduino
15#include <Arduino.h>
16#include <WiFi.h>
17#include <WiFiUDP.h>
18#include <ELOBJ.h>
19
20#else
21// g++
22typedef unsigned char byte;
23typedef bool boolean;
24#include <iostream>
25#include "WiFiUDP.h"
26#include "ELOBJ.h"
27using std::cout;
28using std::dec;
29using std::endl;
30using std::hex;
31using std::move;
32#endif
33
34// defined
35#define EL_PORT 3610
36#define EL_EHD1 0
37#define EL_EHD2 1
38#define EL_TID 2
39#define EL_SEOJ 4
40#define EL_DEOJ 7
41#define EL_ESV 10
42#define EL_OPC 11
43#define EL_EPC 12
44#define EL_PDC 13
45#define EL_EDT 14
46#define EL_SETI_SNA 0x50
47#define EL_SETC_SNA 0x51
48#define EL_GET_SNA 0x52
49#define EL_INF_SNA 0x53
50#define EL_SETGET_SNA 0x5e
51#define EL_SETI 0x60
52#define EL_SETC 0x61
53#define EL_GET 0x62
54#define EL_INF_REQ 0x63
55#define EL_SETGET 0x6e
56#define EL_SET_RES 0x71
57#define EL_GET_RES 0x72
58#define EL_INF 0x73
59#define EL_INFC 0x74
60#define EL_INFC_RES 0x7a
61#define EL_SETGET_RES 0x7e
62#define EL_BUFFER_SIZE 1500
63#define EL_MINIMUM_FRAME 13
64
65// Device Object
66// センサ関連機器
67#define EL_GasLeakSensor 0x00, 0x01
68#define EL_CrimePreventionSensor 0x00, 0x02
69#define EL_EmergencyButton 0x00, 0x03
70#define EL_FirstAidSensor 0x00, 0x04
71#define EL_EarthquakeSensor 0x00, 0x05
72#define EL_ElectricLeakSensor 0x00, 0x06
73#define EL_HumanDetectionSensor 0x00, 0x07
74#define EL_VisitorSensor 0x00, 0x08
75#define EL_CallSensor 0x00, 0x09
76#define EL_CondensationSensor 0x00, 0x0A
77#define EL_AirPollutionSensor 0x00, 0x0B
78#define EL_OxygenSensor 0x00, 0x0C
79#define EL_IlluminanceSensor 0x00, 0x0D
80#define EL_SoundSensor 0x00, 0x0E
81#define EL_MailingSensor 0x00, 0x0F
82#define EL_WeightSensor 0x00, 0x10
83#define EL_TemperatureSensor 0x00, 0x11
84#define EL_HumiditySensor 0x00, 0x12
85#define EL_RainSensor 0x00, 0x13
86#define EL_WaterLevelSensor 0x00, 0x14
87#define EL_BathWaterLevelSensor 0x00, 0x15
88#define EL_BathHeatingStatusSensor 0x00, 0x16
89#define EL_WaterLeakSensor 0x00, 0x17
90#define EL_WaterOverflowSensor 0x00, 0x18
91#define EL_FireSensor 0x00, 0x19
92#define EL_CigaretteSmokeSensor 0x00, 0x1A
93#define EL_CO2Sensor 0x00, 0x1B
94#define EL_GasSensor 0x00, 0x1C
95#define EL_VOCSensor 0x00, 0x1D
96#define EL_DifferentialPressureSensor 0x00, 0x1E
97#define EL_AirSpeedSensor 0x00, 0x1F
98#define EL_OdorSensor 0x00, 0x20
99#define EL_FlameSensor 0x00, 0x21
100#define EL_ElectricEnergySensor 0x00, 0x22
101#define EL_CurrentValueSensor 0x00, 0x23
102#define EL_WaterFlowRateSensor 0x00, 0x25
103#define EL_MicromotionSensor 0x00, 0x26
104#define EL_PassageSensor 0x00, 0x27
105#define EL_BedPresenceSensor 0x00, 0x28
106#define EL_OpenCloseSensor 0x00, 0x29
107#define EL_ActivityAmountSensor 0x00, 0x2A
108#define EL_HumanBodyLocationSensor 0x00, 0x2B
109#define EL_SnowSensor 0x00, 0x2C
110// 空調関連機器
111#define EL_HomeAirConditioner 0x01, 0x30
112#define EL_VentilationFan 0x01, 0x32
113#define EL_AirConditionerVentilationFan 0x01, 0x34
114#define EL_AirCleaner 0x01, 0x35
115#define EL_Humidifier 0x01, 0x39
116#define EL_ElectricHeater 0x01, 0x42
117#define EL_FanHeater 0x01, 0x43
118#define EL_PackageTypeCommercialAirConditionerIndoorUnit 0x01, 0x56
119#define EL_PackageTypeCommercialAirConditionerOutdoorUnit 0x01, 0x57
120// 住宅・設備関連機器
121#define EL_ElectricallyOperatedShade 0x02, 0x60
122#define EL_ElectricShutter 0x02, 0x61
123#define EL_ElectricStormWindow 0x02, 0x63
124#define EL_Sprinkler 0x02, 0x67
125#define EL_ElectricWaterHeater 0x02, 0x6B
126#define EL_ElectricToiletSeat 0x02, 0x6E
127#define EL_ElectricLock 0x02, 0x6F
128#define EL_InstantaneousWaterHeater 0x02, 0x72
129#define EL_BathroomHeaterAndDryer 0x02, 0x73
130#define EL_HouseholdSolarPowerGeneration 0x02, 0x79
131#define EL_ColdOrHotWaterHeatSourceEquipment 0x02, 0x7A
132#define EL_FloorHeater 0x02, 0x7B
133#define EL_FuelCell 0x02, 0x7C
134#define EL_Battery 0x02, 0x7D
135#define EL_ElectricVehicle 0x02, 0x7E
136#define EL_EngineCogeneration 0x02, 0x7F
137#define EL_WattHourMeter 0x02, 0x80
138#define EL_WaterFlowmeter 0x02, 0x81
139#define EL_GasMeter 0x02, 0x82
140#define EL_LPGasMeter 0x02, 0x83
141#define EL_PowerDistributionBoardMetering 0x02, 0x87
142#define EL_SmartElectricEnergyMeter 0x02, 0x88
143#define EL_SmartGasMeter 0x02, 0x89
144#define EL_GeneralLighting 0x02, 0x90
145#define EL_Buzzer 0x02, 0xA0
146// 調理・家事関連機器
147#define EL_ElectricHotWaterPot 0x03, 0xB2
148#define EL_Refrigerator 0x03, 0xB7
149#define EL_CombinationMicrowaveOven 0x03, 0xB8
150#define EL_CookingHeater 0x03, 0xB9
151#define EL_RiceCooker 0x03, 0xBB
152#define EL_WashingMachine 0x03, 0xC5
153#define EL_ClothesDryer 0x03, 0xC6
154#define EL_WasherAndDryer 0x03, 0xD3
155// 健康関連機器
156#define EL_Weighing 0x04, 0x01
157// 管理・操作関連機器
158#define EL_Switch 0x05, 0xFD
159#define EL_Controller 0x05, 0xFF
160// AV関連機器
161#define EL_Display 0x06, 0x01
162#define EL_Television 0x06, 0x02
163// Node profile
164#define EL_NodeProfile 0x0e, 0xf0
165
166// 内部利用
167#define EL_DEVID_NODEPROFILE -1
168#define EL_DEVID_NOTHING -2
169#define EL_DEVID_MULTI -3
170
171// V.4
172// bool (*ELCallback) ( tid, seoj, deoj, esv, opc, epc, pdc, edt);
173typedef bool (*ELCallback)(byte[], byte[], byte[], byte, byte, byte, byte, byte[]);
174
179class EL
180{
181private:
182 IPAddress ip;
183 IPAddress _multi;
184 IPAddress _broad;
185 byte _mac[6];
186 byte *_eojs;
187 int deviceCount;
188 int _sendPacketSize = 0;
189 int _readPacketSize = 0;
190 byte _sBuffer[EL_BUFFER_SIZE];
191 WiFiUDP *_udp;
192 ELCallback userfunc;
193
194protected:
195 int parsePacket(void); // 受信データを読む
196 void commonConstructor(WiFiUDP &udp, byte eojs[][3], int count); // コンストラクタで共通にコールされる
197 void tidAutoIncrement(void); // データ送信時にTIDを自動的にインクリメントの再計算する(シンプルに+1するとオーバーフローするのでこれ使う)
198
199public:
203 byte _tid[2];
204
206 EL(WiFiUDP &udp, byte classGroupCode, byte classCode, byte instanceNumber); // for single dev (devid=0)
207 EL(WiFiUDP &udp, byte eojs[][3], int count); // for multi dev
208 void begin(void);
209 void begin(ELCallback cb); // V.4
210
211 // details change
212 void update(const byte epc, PDCEDT pdcedt); // for single dev (devid=0)
213 void update(const int devId, const byte epc, PDCEDT pdcedt); // for multi dev
214 void update(const byte epc, std::initializer_list<byte> edt); // for single dev (devid=0)
215 void update(const int devId, const byte epc, std::initializer_list<byte> edt); // for multi dev
216
217 // details
218 byte *at(const byte epc); // for single dev (devid=0)
219 byte *at(const int devId, const byte epc); // for multi dev
220
221 // sender
222 void send(IPAddress toip, byte sBuffer[], int size);
223 void sendOPC1(const IPAddress toip, const byte tid[], const byte seoj[], const byte deoj[], const byte esv, const byte epc, const byte pdcedt[]);
224 void sendOPC1(const IPAddress toip, const byte seoj[], const byte deoj[], const byte esv, const byte epc, const byte pdcedt[]);
225 void sendOPC1(const IPAddress toip, const byte deoj[], const byte esv, const byte epc, const byte pdcedt[]);
226 void sendOPC1ID(const IPAddress toip, const int devId, const byte deoj[], const byte esv, const byte epc, const byte pdcedt[]);
227 void sendBroad(byte sBuffer[], int size);
228 void sendMulti(byte sBuffer[], int size);
229 void sendMultiOPC1(const byte tid[], const byte seoj[], const byte deoj[], const byte esv, const byte epc, const byte pdcedt[]);
230 void sendMultiOPC1(const byte seoj[], const byte deoj[], const byte esv, const byte epc, const byte pdcedt[]);
231 void sendMultiOPC1(const byte deoj[], const byte esv, const byte epc, const byte pdcedt[]);
232 void sendMultiOPC1ID(const int devId, const byte deoj[], const byte esv, const byte epc, const byte pdcedt[]);
233 // multi opc
234 void sendDetails(const IPAddress toip, const byte tid[], const byte seoj[], const byte deoj[], const byte esv, const byte opc, const byte detail[], const byte detailSize);
235 // return
236 // void replyOPC1(const IPAddress toip, const unsigned short tid, const byte *seoj, const byte* deoj, const byte esv, const byte epc, const byte* edt);
237 void replyGetDetail(const IPAddress toip, const byte seoj[]);
238 boolean replyGetDetail_sub(const byte eoj[], const byte epc, int &devId);
239 void replySetDetail(const IPAddress toip, const byte seoj[]);
240 boolean replySetDetail_sub(const byte eoj[], const byte epc, int &devId);
241 // INFプロパティ
242 void checkInfAndSend(int devId, const byte epc);
243 void checkInfAndSend(const byte eoj[], const byte epc);
244
245 // reseiver
246 int read();
247 IPAddress remoteIP(void);
248 void returner(void);
249 void recvProcess(void); // 受信処理 V4, begin(callback)と一緒に使う
250
251 // display, debug
252 void printAll(void);
253
255 // inline function
256
257 // オブジェクトを持っているかどうか判定して、持っているならdevIdを返す
258 int getDevId(const byte obj[]);
259
260 // byte[] を安全にdeleteする
261 void delPtr(byte ptr[]);
262
263 // 受信パケットの正常生チェック
264 bool verifyPacket(const byte data[], int size);
265
266};
267
268#endif
270// EOF
#define EL_BUFFER_SIZE
BUFFER_SIZE
Definition: EL.h:62
bool(* ELCallback)(byte[], byte[], byte[], byte, byte, byte, byte, byte[])
Definition: EL.h:173
Subclasses for ECHONET Lite protocol
Main class for EL
Definition: EL.h:180
void sendMultiOPC1ID(const int devId, const byte deoj[], const byte esv, const byte epc, const byte pdcedt[])
OPC一個用のマルチキャスト送信、seojの代わりにIDで指定、TID自動
Definition: EL.cpp:533
void begin(void)
通信の開始、受信開始
Definition: EL.cpp:199
void delPtr(byte ptr[])
byte[] を安全にdeleteするinline関数
Definition: EL.cpp:1420
void replySetDetail(const IPAddress toip, const byte seoj[])
Setに対して複数OPCにも対応して返答する内部関数
Definition: EL.cpp:890
void sendMulti(byte sBuffer[], int size)
マルチキャストによる送信(default: 192.168.1.255)
Definition: EL.cpp:428
int parsePacket(void)
受信データを読む
Definition: EL.cpp:1068
void returner(void)
受信データを処理する。EL処理でupdateしたら呼ぶ
Definition: EL.cpp:1097
void sendDetails(const IPAddress toip, const byte tid[], const byte seoj[], const byte deoj[], const byte esv, const byte opc, const byte detail[], const byte detailSize)
複数のEPCで送信する場合はこれを使う
Definition: EL.cpp:696
void send(IPAddress toip, byte sBuffer[], int size)
IP指定による送信
Definition: EL.cpp:554
bool verifyPacket(const byte data[], int size)
受信パケットの正常生チェック
Definition: EL.cpp:1434
void recvProcess(void)
受信処理
Definition: EL.cpp:1184
ELOBJ profile
profile object (for specialist)
Definition: EL.h:200
byte _rBuffer[EL_BUFFER_SIZE]
receive buffer
Definition: EL.h:202
byte * at(const byte epc)
EPCの値を取得する, eojが1個の場合(複数の場合は0番に相当)
Definition: EL.cpp:372
void replyGetDetail(const IPAddress toip, const byte seoj[])
Getに対して複数OPCにも対応して返答する内部関数
Definition: EL.cpp:732
int getDevId(const byte obj[])
device idを取得する内部関数
Definition: EL.cpp:1382
void update(const byte epc, PDCEDT pdcedt)
EPCの値を変更する, eojが1個の場合(複数の場合は0番に相当)
Definition: EL.cpp:301
boolean replyGetDetail_sub(const byte eoj[], const byte epc, int &devId)
EOJとEPCを指定したとき、そのプロパティ(EDT)があるかチェックする内部関数
Definition: EL.cpp:855
ELOBJ * devices
device objects (for multi eoj)
Definition: EL.h:201
void tidAutoIncrement(void)
TIDの自動インクリメント、オーバーフロー対策
Definition: EL.cpp:179
void sendOPC1(const IPAddress toip, const byte tid[], const byte seoj[], const byte deoj[], const byte esv, const byte epc, const byte pdcedt[])
OPC1指定による送信(SEOJも指定する,ほぼ内部関数)
Definition: EL.cpp:603
void checkInfAndSend(int devId, const byte epc)
INFプロパティならマルチキャストで送信
Definition: EL.cpp:1032
void commonConstructor(WiFiUDP &udp, byte eojs[][3], int count)
コンストラクタ共通処理
Definition: EL.cpp:49
int read()
受信データを受け取る
Definition: EL.cpp:1084
boolean replySetDetail_sub(const byte eoj[], const byte epc, int &devId)
EOJとEPCを指定したとき、そのプロパティ(EDT)があるかチェックする内部関数
Definition: EL.cpp:999
byte _tid[2]
TID (semi-auto incremented)
Definition: EL.h:203
void printAll(void)
インスタンスの情報を表示
Definition: EL.cpp:1342
void sendMultiOPC1(const byte tid[], const byte seoj[], const byte deoj[], const byte esv, const byte epc, const byte pdcedt[])
OPC一個用のマルチキャスト送信、TID指定有り
Definition: EL.cpp:470
void sendBroad(byte sBuffer[], int size)
ブロードキャストによる送信(default: 192.168.1.255)
Definition: EL.cpp:399
void sendOPC1ID(const IPAddress toip, const int devId, const byte deoj[], const byte esv, const byte epc, const byte pdcedt[])
Definition: EL.cpp:679
IPAddress remoteIP(void)
受信データの送信元を取得する
Definition: EL.cpp:1076
EL Object
Definition: ELOBJ.h:75
PDC and EDT in ELOBJ
Definition: ELOBJ.h:35
byte * pdcedt
Definition: main.cpp:56