-
Notifications
You must be signed in to change notification settings - Fork 3
/
blockly.js
416 lines (376 loc) · 14.7 KB
/
blockly.js
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/* eslint-disable no-undef */
'use strict';
if (typeof goog !== 'undefined') {
goog.provide('Blockly.JavaScript.Sendto');
goog.require('Blockly.JavaScript');
}
// --- general translations --------------------------------------------------
Blockly.Words['anyInstance'] = {
en: 'all instances',
pt: 'todas as instâncias',
pl: 'wszystkie przypadki',
nl: 'alle instanties',
it: 'tutte le istanze',
es: 'todas las instancias',
fr: 'toutes les instances',
de: 'Alle Instanzen',
ru: 'На все драйвера',
};
Blockly.Words['lorawanDeviceEUI'] = {
en: 'device EUI',
de: 'Device EUI',
ru: 'устройство EUI',
pt: 'dispositivo EUI',
nl: 'apparaat EUI',
fr: 'dispositif IUE',
it: 'dispositivo EUI',
es: 'dispositivo EUI',
pl: 'urządzenie EUI',
uk: 'пристрій EUI',
'zh-cn': '设备 EUI',
};
/**************************************************************************
******************************Get Device Info******************************
**************************************************************************/
// --- Get DeviceInfo translations --------------------------------------------------
Blockly.Words['lorawanGetDeviceInfo'] = {
en: 'lorawan Device Info',
de: 'lorawan Geräteinfo',
ru: 'lorawan Device Info',
pt: 'lorawan Informações do dispositivo',
nl: 'lorawan Apparaatinformatie',
fr: 'lorawan Informations sur le périphérique',
it: 'lorawan Dispositivi Info',
es: 'lorawan Device Info',
pl: 'informacje o urządzeniu Lorawan',
uk: 'інформація про пристрій lorawan',
'zh-cn': 'lorawan 设备信息',
};
Blockly.Words['lorawanGetDeviceInfotooltip'] = {
en: 'get Informations about the device with the given device EUI',
de: 'Informationen über das Gerät mit der angegebenen Geräte EUI',
ru: 'получить информацию об устройстве с данным устройством EUI',
pt: 'obter informações sobre o dispositivo com o dispositivo dado EUI',
nl: 'informatie over het apparaat met het gegeven apparaat opvragen EUI',
fr: "obtenir des informations sur l'appareil avec l'appareil donné IUE",
it: 'ottenere informazioni sul dispositivo con il dispositivo fornito EUI',
es: 'obtener Información sobre el dispositivo con el dispositivo dado EUI',
pl: 'pobierz informacje o urządzeniu z podanym urządzeniem EUI',
uk: 'отримувати інформацію про пристрій з заданим пристроєм EUI',
'zh-cn': '用指定的设备获取设备信息 EUI',
};
Blockly.Sendto.blocks['lorawanGetDeviceInfo'] =
"<block type='lorawanGetDeviceInfo'>" +
" <value name='INSTANCE'>" +
' </value>' +
" <value name='deviceEUI'>" +
" <shadow type='text'>" +
" <field name='TEXT'>text</field>" +
' </shadow>' +
' </value>' +
'</block>';
Blockly.Blocks['lorawanGetDeviceInfo'] = {
init: function () {
const options = [[Blockly.Translate('anyInstance'), '']];
if (typeof main !== 'undefined' && main.instances) {
for (let i = 0; i < main.instances.length; i++) {
let m = main.instances[i].match(/^system.adapter.lorawan.(\d+)$/);
if (m) {
let k = parseInt(m[1], 10);
options.push([`lorawan.${k}`, `.${k}`]);
}
}
if (options.length === 0) {
for (let u = 0; u <= 4; u++) {
options.push([`lorawan.${u}`, `.${u}`]);
}
}
} else {
for (let n = 0; n <= 4; n++) {
options.push([`lorawan.${n}`, `.${n}`]);
}
}
this.appendDummyInput('INSTANCE')
.appendField(Blockly.Translate('lorawanGetDeviceInfo'))
.appendField(new Blockly.FieldDropdown(options), 'INSTANCE');
this.appendValueInput('deviceEUI').appendField(Blockly.Translate('lorawanDeviceEUI'));
this.appendStatementInput('result');
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(Blockly.Sendto.HUE);
this.setTooltip(Blockly.Translate('lorawanGetDeviceInfotooltip'));
},
};
Blockly.JavaScript['lorawanGetDeviceInfo'] = function (block) {
const value_devEUI = Blockly.JavaScript.valueToCode(block, 'deviceEUI', Blockly.JavaScript.ORDER_ATOMIC);
const code_result = Blockly.JavaScript.statementToCode(block, 'result');
// build code
const objParameter = [];
objParameter.push(`deviceEUI:${value_devEUI}`);
const objEnd = [];
if (code_result) {
objEnd.push(`, async (result) => {${code_result}});`);
} else {
objEnd.push(`);`);
}
return `sendTo("lorawan${block.getFieldValue('INSTANCE')}", "getDeviceInfo", {${objParameter.join(',')}}${objEnd}`;
};
/**************************************************************************
*********************************Get uplink********************************
**************************************************************************/
// --- Get DeviceInfo translations --------------------------------------------------
Blockly.Words['lorawanGetUplink'] = {
en: 'lorawan uplinkinfo',
de: 'lorawan uplinkinfo',
ru: 'lorawan uplinkinfo',
pt: 'o que fazer',
nl: 'lorawan uplinkinfo',
fr: 'lorawan uplinkinfo',
it: 'condividi su google',
es: 'lorawan uplinkinfo',
pl: 'lorawan uplinkinfo',
uk: 'український',
'zh-cn': 'lorawan 上行链接信息',
};
Blockly.Words['lorawanGetUplinktooltip'] = {
en: 'get information about the given uplink',
de: 'Informationen zum angegebenen uplink',
ru: 'получить информацию об отказе от ссылки',
pt: 'obter informações sobre o link fornecido',
nl: 'informatie krijgen over de opgegeven uplink',
fr: 'obtenir des informations sur le lien ascendant donné',
it: 'ottenere informazioni su il link up',
es: 'obtener información sobre el enlace dado',
pl: 'uzyskać informacje o danym łączniku',
uk: 'отримувати інформацію про задану посилання',
'zh-cn': '获取上行链路的信息',
};
Blockly.Words['lorawanUplink'] = {
en: 'uplink',
de: 'Uplink',
ru: 'uplink',
pt: 'o que é',
nl: 'uplink',
fr: 'lien ascendant',
it: 'uplink',
es: 'subtítulos',
pl: 'link',
uk: 'посилання',
'zh-cn': '上行链接',
};
Blockly.Words['lorawanSubfolder'] = {
en: 'subfolder',
de: 'Unterordner',
ru: 'subfolder',
pt: 'subpastas',
nl: 'submap',
fr: 'sous-dossier',
it: 'sottocartella',
es: 'subcarpeta',
pl: 'podfolder',
uk: 'підпалювач',
'zh-cn': '子文件夹',
};
Blockly.Sendto.blocks['lorawanGetUplink'] =
"<block type='lorawanGetUplink'>" +
" <value name='INSTANCE'>" +
' </value>' +
" <value name='deviceEUI'>" +
" <shadow type='text'>" +
" <field name='TEXT'>text</field>" +
' </shadow>' +
' </value>' +
" <value name='uplink'>" +
" <shadow type='text'>" +
" <field name='TEXT'>text</field>" +
' </shadow>' +
' </value>' +
" <value name='subfolder'>" +
" <shadow type='text'>" +
" <field name='TEXT'>decoded</field>" +
' </shadow>' +
' </value>' +
'</block>';
Blockly.Blocks['lorawanGetUplink'] = {
init: function () {
const options = [[Blockly.Translate('anyInstance'), '']];
if (typeof main !== 'undefined' && main.instances) {
for (let i = 0; i < main.instances.length; i++) {
let m = main.instances[i].match(/^system.adapter.lorawan.(\d+)$/);
if (m) {
let k = parseInt(m[1], 10);
options.push([`lorawan.${k}`, `.${k}`]);
}
}
if (options.length === 0) {
for (let u = 0; u <= 4; u++) {
options.push([`lorawan.${u}`, `.${u}`]);
}
}
} else {
for (let n = 0; n <= 4; n++) {
options.push([`lorawan.${n}`, `.${n}`]);
}
}
this.appendDummyInput('INSTANCE')
.appendField(Blockly.Translate('lorawanGetUplink'))
.appendField(new Blockly.FieldDropdown(options), 'INSTANCE');
this.appendValueInput('deviceEUI').appendField(Blockly.Translate('lorawanDeviceEUI'));
this.appendValueInput('uplink').appendField(Blockly.Translate('lorawanUplink'));
this.appendValueInput('subfolder').appendField(Blockly.Translate('lorawanSubfolder'));
this.appendStatementInput('result');
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(Blockly.Sendto.HUE);
this.setTooltip(Blockly.Translate('lorawanGetUplinktooltip'));
},
};
Blockly.JavaScript['lorawanGetUplink'] = function (block) {
const value_devEUI = Blockly.JavaScript.valueToCode(block, 'deviceEUI', Blockly.JavaScript.ORDER_ATOMIC);
const value_uplink = Blockly.JavaScript.valueToCode(block, 'uplink', Blockly.JavaScript.ORDER_ATOMIC);
const value_subfolder = Blockly.JavaScript.valueToCode(block, 'subfolder', Blockly.JavaScript.ORDER_ATOMIC);
const code_result = Blockly.JavaScript.statementToCode(block, 'result');
// build code
const objParameter = [];
objParameter.push(`deviceEUI:${value_devEUI}`);
objParameter.push(`uplink:${value_uplink}`);
objParameter.push(`subfolder:${value_subfolder}`);
const objEnd = [];
if (code_result) {
objEnd.push(`, async (result) => {${code_result}});`);
} else {
objEnd.push(`);`);
}
return `sendTo("lorawan${block.getFieldValue('INSTANCE')}", "getUplink", {${objParameter.join(',')}}${objEnd}`;
};
/**************************************************************************
*******************************Set downlink********************************
**************************************************************************/
// --- Get DeviceInfo translations --------------------------------------------------
Blockly.Words['lorawanSetDownlink'] = {
en: 'lorawan downlink',
de: 'lorawan downlink',
ru: 'lorawan downlink',
pt: 'para baixo',
nl: 'lorawan downlink',
fr: 'lorawan lien descendant',
it: 'lorawan downlink',
es: 'lorawan downlink',
pl: 'lorawan downlink',
uk: 'логін',
'zh-cn': '龙卷风下行链路',
};
Blockly.Words['lorawanSetDownlinktooltip'] = {
en: 'set downlink',
de: 'Downlink zur lorawan instanz absetzen',
ru: 'set downlink',
pt: 'definir link',
nl: 'downlink instellen',
fr: 'définir la liaison descendante',
it: 'impostare il collegamento',
es: 'desplazamiento',
pl: 'set downlink',
uk: 'увійти',
'zh-cn': '设置下行链路',
};
Blockly.Words['lorawanDownlink'] = {
en: 'downlink',
de: 'Downlink',
ru: 'downlink',
pt: 'o que é',
nl: 'downlink',
fr: 'lien ascendant',
it: 'downlink',
es: 'subtítulos',
pl: 'link',
uk: 'посилання',
'zh-cn': '上行链接',
};
Blockly.Words['lorawanValue'] = {
en: 'value',
de: 'Wert',
ru: 'стоимость',
pt: 'valor',
nl: 'waarde',
fr: 'valeur',
it: 'valore',
es: 'valor',
pl: 'wartość',
uk: 'значення',
'zh-cn': '价值',
};
Blockly.Sendto.blocks['lorawanSetDownlink'] =
"<block type='lorawanSetDownlink'>" +
" <value name='INSTANCE'>" +
' </value>' +
" <value name='deviceEUI'>" +
" <shadow type='text'>" +
" <field name='TEXT'>text</field>" +
' </shadow>' +
' </value>' +
" <value name='downlink'>" +
" <shadow type='text'>" +
" <field name='TEXT'>text</field>" +
' </shadow>' +
' </value>' +
" <value name='value'>" +
" <shadow type='text'>" +
" <field name='text'></field>" +
' </shadow>' +
' </value>' +
'</block>';
Blockly.Blocks['lorawanSetDownlink'] = {
init: function () {
const options = [[Blockly.Translate('anyInstance'), '']];
if (typeof main !== 'undefined' && main.instances) {
for (let i = 0; i < main.instances.length; i++) {
let m = main.instances[i].match(/^system.adapter.lorawan.(\d+)$/);
if (m) {
let k = parseInt(m[1], 10);
options.push([`lorawan.${k}`, `.${k}`]);
}
}
if (options.length === 0) {
for (let u = 0; u <= 4; u++) {
options.push([`lorawan.${u}`, `.${u}`]);
}
}
} else {
for (let n = 0; n <= 4; n++) {
options.push([`lorawan.${n}`, `.${n}`]);
}
}
this.appendDummyInput('INSTANCE')
.appendField(Blockly.Translate('lorawanSetDownlink'))
.appendField(new Blockly.FieldDropdown(options), 'INSTANCE');
this.appendValueInput('deviceEUI').appendField(Blockly.Translate('lorawanDeviceEUI'));
this.appendValueInput('downlink').appendField(Blockly.Translate('lorawanDownlink'));
this.appendValueInput('value').appendField(Blockly.Translate('lorawanValue'));
this.appendStatementInput('result');
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(Blockly.Sendto.HUE);
this.setTooltip(Blockly.Translate('lorawanSetDownlinktooltip'));
},
};
Blockly.JavaScript['lorawanSetDownlink'] = function (block) {
const value_devEUI = Blockly.JavaScript.valueToCode(block, 'deviceEUI', Blockly.JavaScript.ORDER_ATOMIC);
const value_downlink = Blockly.JavaScript.valueToCode(block, 'downlink', Blockly.JavaScript.ORDER_ATOMIC);
const value_value = Blockly.JavaScript.valueToCode(block, 'value', Blockly.JavaScript.ORDER_ATOMIC);
const code_result = Blockly.JavaScript.statementToCode(block, 'result');
// build code
const objParameter = [];
objParameter.push(`deviceEUI:${value_devEUI}`);
objParameter.push(`downlink:${value_downlink}`);
objParameter.push(`value:${value_value}`);
const objEnd = [];
if (code_result) {
objEnd.push(`, async (result) => {${code_result}});`);
} else {
objEnd.push(`);`);
}
return `sendTo("lorawan${block.getFieldValue('INSTANCE')}", "setDownlink", {${objParameter.join(',')}}${objEnd}`;
};