[101] | 1 | /*
|
---|
| 2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2015 Cores Co., Ltd. Japan
|
---|
| 5 | *
|
---|
| 6 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 7 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 8 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 9 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 10 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 11 | * スコード中に含まれていること.
|
---|
| 12 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 13 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 14 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 15 | * の無保証規定を掲載すること.
|
---|
| 16 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 17 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 18 | * と.
|
---|
| 19 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 20 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 21 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 22 | * 報告すること.
|
---|
| 23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 25 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 26 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 27 | * 免責すること.
|
---|
| 28 | *
|
---|
| 29 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 30 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 31 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 32 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 33 | * の責任を負わない.
|
---|
| 34 | *
|
---|
| 35 | * @(#) $Id: WebApiData.cs 108 2015-06-11 09:15:46Z coas-nagasima $
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | using System;
|
---|
| 39 | using System.Collections.Generic;
|
---|
| 40 | using System.Diagnostics;
|
---|
| 41 | using System.Serialization;
|
---|
| 42 | using System.Text;
|
---|
| 43 | using System.Web;
|
---|
| 44 |
|
---|
| 45 | namespace ctrlui
|
---|
| 46 | {
|
---|
| 47 | public class WebApiPropertyInfo
|
---|
| 48 | {
|
---|
| 49 | public byte epc;
|
---|
| 50 | public EPC_FLAG flag;
|
---|
| 51 |
|
---|
| 52 | public WebApiPropertyInfo(dynamic prop)
|
---|
| 53 | {
|
---|
| 54 | epc = prop.epc;
|
---|
| 55 | flag = EPC_FLAG.NONE;
|
---|
| 56 | string temp = prop.flag;
|
---|
| 57 | if (temp.Contains("RULE_ANNO"))
|
---|
| 58 | flag |= EPC_FLAG.RULE_ANNO;
|
---|
| 59 | if (temp.Contains("RULE_SET"))
|
---|
| 60 | flag |= EPC_FLAG.RULE_SET;
|
---|
| 61 | if (temp.Contains("RULE_GET"))
|
---|
| 62 | flag |= EPC_FLAG.RULE_GET;
|
---|
| 63 | if (temp.Contains("ANNOUNCE"))
|
---|
| 64 | flag |= EPC_FLAG.ANNOUNCE;
|
---|
| 65 | if (temp.Contains("VARIABLE"))
|
---|
| 66 | flag |= EPC_FLAG.VARIABLE;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public class WebApiObjectInfo
|
---|
| 71 | {
|
---|
| 72 | public bool profile;
|
---|
| 73 | public byte x1;
|
---|
| 74 | public byte x2;
|
---|
| 75 | public byte x3;
|
---|
| 76 | public int eobjid;
|
---|
| 77 | public int enodid;
|
---|
| 78 | public List<WebApiPropertyInfo> properties = new List<WebApiPropertyInfo>();
|
---|
| 79 |
|
---|
| 80 | public WebApiObjectInfo(int eobjid, dynamic obj, bool profile)
|
---|
| 81 | {
|
---|
| 82 | this.eobjid = eobjid;
|
---|
| 83 | this.profile = profile;
|
---|
| 84 | x1 = obj.x1;
|
---|
| 85 | x2 = obj.x2;
|
---|
| 86 | x3 = obj.x3;
|
---|
| 87 | enodid = obj.enodid;
|
---|
| 88 |
|
---|
| 89 | foreach (var prop in (dynamic[])obj.properties) {
|
---|
| 90 | properties.Add(new WebApiPropertyInfo(prop));
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | public class WebApiPropertyCode
|
---|
| 96 | {
|
---|
| 97 | public byte epc;
|
---|
| 98 |
|
---|
| 99 | public WebApiPropertyCode(dynamic prop, bool dummy)
|
---|
| 100 | {
|
---|
| 101 | epc = prop.epc;
|
---|
| 102 | }
|
---|
| 103 | /// <summary>
|
---|
| 104 | /// コンストラクタ
|
---|
| 105 | /// </summary>
|
---|
| 106 | /// <param name="epc">PropertyCode</param>
|
---|
| 107 | public WebApiPropertyCode(byte epc)
|
---|
| 108 | {
|
---|
| 109 | this.epc = epc;
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public class WebApiPropertyData
|
---|
| 114 | {
|
---|
| 115 | public byte epc;
|
---|
| 116 | public string edt;
|
---|
| 117 |
|
---|
| 118 | public WebApiPropertyData(dynamic prop)
|
---|
| 119 | {
|
---|
| 120 | byte[] _edt;
|
---|
| 121 |
|
---|
| 122 | epc = prop.epc;
|
---|
| 123 |
|
---|
| 124 | string text = prop.edt;
|
---|
| 125 |
|
---|
| 126 | if (text.Length > 0) {
|
---|
| 127 | _edt = new byte[text.Length / 2];
|
---|
| 128 |
|
---|
| 129 | for (int i = 0, j = 0; j < text.Length; j += 2) {
|
---|
| 130 |
|
---|
| 131 | _edt[i++] = Byte.Parse(text.Substring(j, 2), 16);
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 | else {
|
---|
| 135 | _edt = new byte[0];
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | edt = SetEdt(_edt);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | public WebApiPropertyData(byte epc, byte[] edt)
|
---|
| 142 | {
|
---|
| 143 | this.epc = epc;
|
---|
| 144 | this.edt = SetEdt(edt);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | private string SetEdt(byte[] _edt)
|
---|
| 148 | {
|
---|
| 149 | var sb = new StringBuilder();
|
---|
| 150 |
|
---|
| 151 | foreach (var b in _edt) {
|
---|
| 152 | sb.Append(b.ToString("X2"));
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | return sb.ToString();
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | internal byte[] GetEdt()
|
---|
| 159 | {
|
---|
| 160 | byte[] result = new byte[edt.Length / 2];
|
---|
| 161 |
|
---|
| 162 | for (int i = 0, j = 0; j < edt.Length; i++, j += 2) {
|
---|
| 163 | result[i] = Byte.Parse(edt.Substring(j, 2), 16);
|
---|
| 164 | }
|
---|
| 165 | return result;
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | public class WebApiEchonetMessage
|
---|
| 170 | {
|
---|
| 171 | public byte esv;
|
---|
| 172 | public ENOD_ID sender;
|
---|
| 173 | public T_ECN_EOJ seoj = new T_ECN_EOJ(new byte[3], 0);
|
---|
| 174 | public T_ECN_EOJ deoj = new T_ECN_EOJ(new byte[3], 0);
|
---|
| 175 | public List<WebApiPropertyData> properties = new List<WebApiPropertyData>();
|
---|
| 176 |
|
---|
| 177 | public WebApiEchonetMessage(dynamic esv)
|
---|
| 178 | {
|
---|
| 179 | this.esv = esv.esv;
|
---|
| 180 | sender = (ENOD_ID)esv.sender;
|
---|
| 181 | string sseoj = esv.seoj;
|
---|
| 182 | seoj.x1 = Byte.Parse(sseoj.Substring(0, 2), 16);
|
---|
| 183 | seoj.x2 = Byte.Parse(sseoj.Substring(2, 2), 16);
|
---|
| 184 | seoj.x3 = Byte.Parse(sseoj.Substring(4, 2), 16);
|
---|
| 185 |
|
---|
| 186 | foreach (var prop in (dynamic[])esv.properties) {
|
---|
| 187 | properties.Add(new WebApiPropertyData(prop));
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | public class WebApiGrsaguraMessage
|
---|
| 193 | {
|
---|
| 194 | public int pin;
|
---|
| 195 | public string value;
|
---|
| 196 | public WebApiGrsaguraMessage(dynamic esv)
|
---|
| 197 | {
|
---|
| 198 | this.pin = esv.pin;
|
---|
| 199 | if (((object)esv.value).GetType() == typeof(double)) {
|
---|
| 200 | this.value = ((double)esv.value).ToString();
|
---|
| 201 | }
|
---|
| 202 | else {
|
---|
| 203 | this.value = esv.value;
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | public class WebApiSet
|
---|
| 209 | {
|
---|
| 210 | public ENOD_ID deojid;
|
---|
| 211 | public List<WebApiPropertyData> properties = new List<WebApiPropertyData>();
|
---|
| 212 |
|
---|
| 213 | public WebApiSet()
|
---|
| 214 | {
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | public WebApiSet(dynamic esv)
|
---|
| 218 | {
|
---|
| 219 | deojid = (ENOD_ID)esv.deojid;
|
---|
| 220 |
|
---|
| 221 | foreach (var prop in (dynamic[])esv.properties) {
|
---|
| 222 | properties.Add(new WebApiPropertyData(prop));
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | public void AddEdt(byte epc, byte[] edt)
|
---|
| 227 | {
|
---|
| 228 | properties.Add(new WebApiPropertyData(epc, edt));
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | public string GetJson()
|
---|
| 232 | {
|
---|
| 233 | return "{\"esv_set\":" + Json.Stringify(this) + "}";
|
---|
| 234 | }
|
---|
| 235 | /// <summary>
|
---|
| 236 | /// "{deviceId: }"を返します。
|
---|
| 237 | /// </summary>
|
---|
| 238 | /// <returns></returns>
|
---|
| 239 | public string GetOption()
|
---|
| 240 | {
|
---|
| 241 | return "{\"deviceId\":" + ((int)deojid).ToString() + "}";
|
---|
| 242 | }
|
---|
| 243 | /// <summary>
|
---|
| 244 | /// json形式にしたオブジェクト文字をかえします
|
---|
| 245 | /// </summary>
|
---|
| 246 | /// <returns></returns>
|
---|
| 247 | public string GetArguments()
|
---|
| 248 | {
|
---|
| 249 | return Json.Stringify(this);
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | /// <summary>
|
---|
| 254 | /// WebApiから値を取得するクラス
|
---|
| 255 | /// </summary>
|
---|
| 256 | public class WebApiGet
|
---|
| 257 | {
|
---|
| 258 | /// <summary>
|
---|
| 259 | /// deojid
|
---|
| 260 | /// </summary>
|
---|
| 261 | public ENOD_ID deojid;
|
---|
| 262 | public List<WebApiPropertyCode> properties = new List<WebApiPropertyCode>();
|
---|
| 263 |
|
---|
| 264 | /// <summary>
|
---|
| 265 | /// コンストラクタ
|
---|
| 266 | /// </summary>
|
---|
| 267 | public WebApiGet()
|
---|
| 268 | {
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | public WebApiGet(dynamic esv)
|
---|
| 272 | {
|
---|
| 273 | deojid = (ENOD_ID)esv.deojid;
|
---|
| 274 |
|
---|
| 275 | foreach (var prop in (dynamic[])esv.properties) {
|
---|
| 276 | properties.Add(new WebApiPropertyCode(prop, true));
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | /// <summary>
|
---|
| 281 | /// WebApiGet.propertiesに追加
|
---|
| 282 | /// </summary>
|
---|
| 283 | /// <param name="epc"></param>
|
---|
| 284 | public void AddEpc(byte epc)
|
---|
| 285 | {
|
---|
| 286 | properties.Add(new WebApiPropertyCode(epc));
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | public string GetJson()
|
---|
| 290 | {
|
---|
| 291 | return "{\"esv_get\":" + Json.Stringify(this) + "}";
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | /// <summary>
|
---|
| 295 | /// deviceIdを返します。
|
---|
| 296 | /// </summary>
|
---|
| 297 | /// <returns></returns>
|
---|
| 298 | public string GetOption()
|
---|
| 299 | {
|
---|
| 300 | return "{\"deviceId\":" + ((int)deojid).ToString() + "}";
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | /// <summary>
|
---|
| 304 | /// Json形式の文字列を返します
|
---|
| 305 | /// </summary>
|
---|
| 306 | /// <returns></returns>
|
---|
| 307 | public string GetArguments()
|
---|
| 308 | {
|
---|
| 309 | return Json.Stringify(this);
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | public class WebApiSetGet
|
---|
| 314 | {
|
---|
| 315 | public ENOD_ID deojid;
|
---|
| 316 | public List<WebApiPropertyData> setProperties = new List<WebApiPropertyData>();
|
---|
| 317 | public List<WebApiPropertyCode> getProperties = new List<WebApiPropertyCode>();
|
---|
| 318 |
|
---|
| 319 | public WebApiSetGet()
|
---|
| 320 | {
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | public WebApiSetGet(dynamic esv)
|
---|
| 324 | {
|
---|
| 325 | deojid = (ENOD_ID)esv.deojid;
|
---|
| 326 |
|
---|
| 327 | foreach (var prop in (dynamic[])esv.properties) {
|
---|
| 328 | getProperties.Add(new WebApiPropertyCode(prop, true));
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | public void AddEdt(byte epc, byte[] edt)
|
---|
| 333 | {
|
---|
| 334 | setProperties.Add(new WebApiPropertyData(epc, edt));
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | public void AddEpc(byte epc)
|
---|
| 338 | {
|
---|
| 339 | getProperties.Add(new WebApiPropertyCode(epc));
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | public string GetJson()
|
---|
| 343 | {
|
---|
| 344 | return "{\"esv_set_get\":" + Json.Stringify(this) + "}";
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | public string GetOption()
|
---|
| 348 | {
|
---|
| 349 | return "{\"deviceId\":" + ((int)deojid).ToString() + "}";
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 | public string GetArguments()
|
---|
| 353 | {
|
---|
| 354 | return Json.Stringify(this);
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | public class WampApiKadecotDevice
|
---|
| 359 | {
|
---|
| 360 | public string description;
|
---|
| 361 | public int deviceId;
|
---|
| 362 | public string deviceType;
|
---|
| 363 | /// <summary>
|
---|
| 364 | /// ipアドレス
|
---|
| 365 | /// </summary>
|
---|
| 366 | public string ip_addr;
|
---|
| 367 | public string nickname;
|
---|
| 368 | public string protocol;
|
---|
| 369 | public bool status;
|
---|
| 370 |
|
---|
| 371 | public WampApiKadecotDevice(dynamic doc)
|
---|
| 372 | {
|
---|
| 373 | description = (string)doc.description;
|
---|
| 374 | deviceId = (int)doc.deviceId;
|
---|
| 375 | deviceType = (string)doc.deviceType;
|
---|
| 376 | ip_addr = (string)doc.ip_addr;
|
---|
| 377 | nickname = (string)doc.nickname;
|
---|
| 378 | protocol = (string)doc.protocol;
|
---|
| 379 | status = (bool)doc.status;
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | public class WampApiKadecotSet
|
---|
| 384 | {
|
---|
| 385 | public int deviceId;
|
---|
| 386 | public string propertyName;
|
---|
| 387 | public byte[] propertyValue;
|
---|
| 388 |
|
---|
| 389 | public WampApiKadecotSet(int deviceId, string propertyName, byte[] propertyValue)
|
---|
| 390 | {
|
---|
| 391 | this.deviceId = deviceId;
|
---|
| 392 | this.propertyName = propertyName;
|
---|
| 393 | this.propertyValue = propertyValue;
|
---|
| 394 | }
|
---|
| 395 |
|
---|
| 396 | internal string GetOption()
|
---|
| 397 | {
|
---|
| 398 | return "{\"deviceId\":" + ((int)deviceId).ToString() + "}";
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | internal string GetArguments()
|
---|
| 402 | {
|
---|
| 403 | return "{\"propertyName\":\"" + propertyName + "\",\"propertyValue\":" + Json.Stringify(propertyValue) + "}";
|
---|
| 404 | }
|
---|
| 405 | }
|
---|
| 406 |
|
---|
| 407 | public class WampApiKadecotGet
|
---|
| 408 | {
|
---|
| 409 | public int deviceId;
|
---|
| 410 | public string propertyName;
|
---|
| 411 |
|
---|
| 412 | public WampApiKadecotGet(int deviceId, string propertyName)
|
---|
| 413 | {
|
---|
| 414 | this.deviceId = deviceId;
|
---|
| 415 | this.propertyName = propertyName;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | internal string GetOption()
|
---|
| 419 | {
|
---|
| 420 | return "{\"deviceId\":" + ((int)deviceId).ToString() + "}";
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | internal string GetArguments()
|
---|
| 424 | {
|
---|
| 425 | return "{\"propertyName\":\"" + propertyName + "\"}";
|
---|
| 426 | }
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | public class WampApiKadecotRes
|
---|
| 430 | {
|
---|
| 431 | public string propertyName;
|
---|
| 432 | public byte[] propertyValue;
|
---|
| 433 |
|
---|
| 434 | public WampApiKadecotRes(dynamic item)
|
---|
| 435 | {
|
---|
| 436 | this.propertyName = (string)item.propertyName;
|
---|
| 437 | if (((object)item).GetType().GetProperty("propertyValue") != null) {
|
---|
| 438 | this.propertyValue = (byte[])item.propertyValue;
|
---|
| 439 | }
|
---|
| 440 | else {
|
---|
| 441 | this.propertyValue = new byte[0];
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
| 444 | }
|
---|
| 445 | }
|
---|