-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiot_sensor.js
696 lines (649 loc) · 24.1 KB
/
iot_sensor.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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
var iot_unit = ["℃", "%RH","μg/m³","cm","m","m/s","km/h","kg","g","mv/g","bar","KPa","MPa"];
var devIndex = parseInt(getQueryString("devIndex"));
var MAX_SENSOR_NUM = 24;
var m_cur_chn_index = 0;
var DEV_LORA_SENSOR = "0";
var DEV_LORA_NODE = "1";
var PORT_NONE = "0";
var PORT_RS485 = "1";
var PORT_GPIO = "2";
var PORT_AI = "3";
var g_cur_edit_index = -1;
var m_device_lora_type_list = iot_sensor_json.iotdevicetype;
var m_device_lora_type = m_device_lora_type_list.split(",");
var m_device_sensortype_list = new Array(iot_sensor_json["iotdevsensortype.0"],iot_sensor_json["iotdevsensortype.1"],iot_sensor_json["iotdevsensortype.2"],iot_sensor_json["iotdevsensortype.3"],iot_sensor_json["iotdevsensortype.4"],
iot_sensor_json["iotdevsensortype.5"],iot_sensor_json["iotdevsensortype.6"],iot_sensor_json["iotdevsensortype.7"]);
var m_device_sensorname_list = new Array(iot_sensor_json["iotdevsensorname.0"],iot_sensor_json["iotdevsensorname.1"],iot_sensor_json["iotdevsensorname.2"],iot_sensor_json["iotdevsensorname.3"],iot_sensor_json["iotdevsensorname.4"],
iot_sensor_json["iotdevsensorname.5"],iot_sensor_json["iotdevsensorname.6"],iot_sensor_json["iotdevsensorname.7"]);
var m_device_decimal_list = new Array(iot_sensor_json["iotdevdecimal.0"],iot_sensor_json["iotdevdecimal.1"],iot_sensor_json["iotdevdecimal.2"],iot_sensor_json["iotdevdecimal.3"],iot_sensor_json["iotdevdecimal.4"],
iot_sensor_json["iotdevdecimal.5"],iot_sensor_json["iotdevdecimal.6"],iot_sensor_json["iotdevdecimal.7"]);
var m_device_unit_list = new Array(iot_sensor_json["iotdevunit.0"],iot_sensor_json["iotdevunit.1"],iot_sensor_json["iotdevunit.2"],iot_sensor_json["iotdevunit.3"],iot_sensor_json["iotdevunit.4"],
iot_sensor_json["iotdevunit.5"],iot_sensor_json["iotdevunit.6"],iot_sensor_json["iotdevunit.7"]);
var m_device_showosd_list = new Array(iot_sensor_json["iotdevshowosd.0"],iot_sensor_json["iotdevshowosd.1"],iot_sensor_json["iotdevshowosd.2"],iot_sensor_json["iotdevshowosd.3"],iot_sensor_json["iotdevshowosd.4"],
iot_sensor_json["iotdevshowosd.5"],iot_sensor_json["iotdevshowosd.6"],iot_sensor_json["iotdevshowosd.7"]);
var m_device_sign_list = new Array(iot_sensor_json["iotdevsign.0"],iot_sensor_json["iotdevsign.1"],iot_sensor_json["iotdevsign.2"],iot_sensor_json["iotdevsign.3"],iot_sensor_json["iotdevsign.4"],
iot_sensor_json["iotdevsign.5"],iot_sensor_json["iotdevsign.6"],iot_sensor_json["iotdevsign.7"]);
var m_device_port_type_list = new Array(iot_sensor_json["iotdevporttype.0"],iot_sensor_json["iotdevporttype.1"],iot_sensor_json["iotdevporttype.2"],iot_sensor_json["iotdevporttype.3"],iot_sensor_json["iotdevporttype.4"],
iot_sensor_json["iotdevporttype.5"],iot_sensor_json["iotdevporttype.6"],iot_sensor_json["iotdevporttype.7"]);
var m_device_osh_list = new Array(iot_sensor_json["iotdevosh.0"],iot_sensor_json["iotdevosh.1"],iot_sensor_json["iotdevosh.2"],iot_sensor_json["iotdevosh.3"],iot_sensor_json["iotdevosh.4"],
iot_sensor_json["iotdevosh.5"],iot_sensor_json["iotdevosh.6"],iot_sensor_json["iotdevosh.7"]);
var m_device_osl_list = new Array(iot_sensor_json["iotdevosl.0"],iot_sensor_json["iotdevosl.1"],iot_sensor_json["iotdevosl.2"],iot_sensor_json["iotdevosl.3"],iot_sensor_json["iotdevosl.4"],
iot_sensor_json["iotdevosl.5"],iot_sensor_json["iotdevosl.6"],iot_sensor_json["iotdevosl.7"]);
var m_device_chn_list = new Array(iot_sensor_json["iotdevchn.0"],iot_sensor_json["iotdevchn.1"],iot_sensor_json["iotdevchn.2"],iot_sensor_json["iotdevchn.3"],iot_sensor_json["iotdevchn.4"],
iot_sensor_json["iotdevchn.5"],iot_sensor_json["iotdevchn.6"],iot_sensor_json["iotdevchn.7"]);
var m_sensor_type_array = m_device_sensortype_list[devIndex].split(";");
var m_sensor_name_array = m_device_sensorname_list[devIndex].split("/,;");
var m_decimal_array = m_device_decimal_list[devIndex].split(";");
var m_sign_array = m_device_sign_list[devIndex].split(";");
var m_unit_array = m_device_unit_list[devIndex].split("/,;");
var m_show_osd_array = m_device_showosd_list[devIndex].split(";");
var m_sign_array = m_device_sign_list[devIndex].split(";");
var m_port_type_array = m_device_port_type_list[devIndex].split(";");
var m_osh_array = m_device_osh_list[devIndex].split(";");
var m_osl_array = m_device_osl_list[devIndex].split(";");
var m_chn_array = m_device_chn_list[devIndex].split(";");
window.onload = function()
{
ASTGUI.cookies.fe_check_cookie();
ForbidUserViewer();
My_Load();
};
function init_ui(lora_type)
{
if(lora_type == DEV_LORA_SENSOR)
{
$("#tr_sensor_id").show();
$("#tr_port_type").hide();
$("#tr_rs485_id").hide();
$("#tr_gpio_id").hide();
$("#tr_ai_id").hide();
$("#tr_sensor_type").show();
$("#tr_sign").show();
$("#tr_decimal_place").show();
$("#tr_osh").hide();
$("#tr_osl").hide();
$("#tr_unit").show();
$("#tr_show_osd").show();
changeSensorId();
}
else
{
$("#tr_sensor_id").hide();
changePortType();
init_sensor_list();
getUnuseChannel();
}
}
function changeSensorId()
{
var index = parseInt(document.getElementById("sel_sensor_id").value);
document.getElementById("sel_sensor_type").value = m_sensor_type_array[index];
document.getElementById("input_sensor_type").value = m_sensor_name_array[index];
changeSensorType();
init_show_unit(m_unit_array[index]);
document.getElementById("check_sign").checked = m_sign_array[index]=="1"?true:false;
document.getElementById("input_decimal_place").value = m_decimal_array[index];
document.getElementById("check_showosd").checked = m_show_osd_array[index]=="1"?true:false;
setMsTableStyle();
}
function changePortType(setRecommendChannel)
{
var value = document.getElementById("sel_port_type").value;
$("#tr_port_type").show();
$("#tr_sensor_type").show();
$("#tr_show_osd").show();
if(value == PORT_RS485) //RS485
{
$("#tr_sign").show();
$("#tr_decimal_place").show();
$("#tr_osh").hide();
$("#tr_osl").hide();
$("#tr_unit").show();
$("#tr_rs485_id").show();
$("#tr_gpio_id").hide();
$("#tr_ai_id").hide();
changeUnit();
}
else if(value == PORT_GPIO)
{
$("#tr_sign").hide();
$("#tr_decimal_place").hide();
$("#tr_osh").hide();
$("#tr_osl").hide();
$("#tr_unit").hide();
$("#tr_unit_other").hide();
$("#tr_rs485_id").hide();
$("#tr_gpio_id").show();
$("#tr_ai_id").hide();
}
else if(value == PORT_AI)
{
$("#tr_sign").hide();
$("#tr_decimal_place").hide();
$("#tr_osh").show();
$("#tr_osl").show();
$("#tr_unit").show();
$("#tr_rs485_id").hide();
$("#tr_gpio_id").hide();
$("#tr_ai_id").show();
changeUnit();
}
changeSensorType();
if(setRecommendChannel == "1")
getUnuseChannel();
setMsTableStyle();
}
function My_Load()
{
init_ui(m_device_lora_type[devIndex]);
}
function changeSensorType()
{
var value = document.getElementById("sel_sensor_type").value;
if(value == "-1")
{
$("#tr_sensor_type_other").show();
}
else
{
$("#tr_sensor_type_other").hide();
}
setMsTableStyle();
}
function changeUnit()
{
var value = document.getElementById("sel_unit").value;
if(value == "-1")
{
$("#tr_unit_other").show();
}
else
{
$("#tr_unit_other").hide();
}
setMsTableStyle();
}
function modify_sensorList(num,port_type, sensor_name,row_index)
{
var port_name = "";
if(port_type == PORT_RS485)
{
port_name = "RS485";
channel_id = num;
}
else if(port_type == PORT_GPIO)
{
port_name = "GPIO";
channel_id = "GPIO " + num;
}
else
{
port_name = "AI";
channel_id = "AI " + num;
}
$("#table_sensor_list").find('tr').eq(row_index).find('td').eq(1).html(port_name);
$("#table_sensor_list").find('tr').eq(row_index).find('td').eq(2).html(channel_id);
$("#table_sensor_list").find('tr').eq(row_index).find('td').eq(3).html(sensor_name);
}
function get_unuse_sensorList_index()
{
var index_array = new Array(MAX_SENSOR_NUM);
for(var i = 0;i < MAX_SENSOR_NUM;i++)
index_array[i] = 0;
var row_num = $("#table_sensor_list").find("tr").length;
for(var i = 1;i < row_num;i++) //not include thead
{
var cur_no = $("#table_sensor_list").find('tr').eq(i).find('td').eq(0).html();
index_array[parseInt(cur_no)-1] = 1;
}
for(var i = 0;i < MAX_SENSOR_NUM;i++)
{
if(index_array[i] != 1)
return i + 1;
}
}
function insert_sensorList(TBL,index,channel_id,port_type, sensor_name)
{
var newRow = TBL.insertRow(-1);
newRow.vAlign = "middle";
var addCell = ASTGUI.domActions.tr_addCell;
newRow.className = ((TBL.rows.length)%2==1)?'odd':'even';
addCell( newRow , { html: index,align:"center" } );
if(port_type == PORT_RS485)
{
addCell( newRow , { html: "RS485",align:"center" } );
channel_id = channel_id;
}
else if(port_type == PORT_GPIO)
{
addCell( newRow , { html: "GPIO",align:"center" } );
channel_id = "GPIO " + channel_id;
}
else
{
addCell( newRow , { html: "AI",align:"center" } );
channel_id = "AI " + channel_id;
}
addCell( newRow , { html: channel_id,align:"center" } );
addCell( newRow , { html: sensor_name,align:"center" } );
var sEdit = "<a class='guiButtonModify' href='javascript:onEdit(" + index + ");' id='sensorListEdit_"+index+"'><img style=' border:0px;' src='/image/hammer_screwdriver.png' alt='"+Edit+"' /></a>";
addCell(newRow, {html: sEdit,align: "center"});
var sRemove = "<a class='guiButtonDelete' href='javascript:onDel(" + index + ");' id='sensorListDel_"+index+"'><img style=' border:0px;' src='/image/cross.png' alt='"+Delete+"' /></a>";
addCell(newRow, {html: sRemove,align: "center"});
}
function ChannelIsUse(channel,skip_index,type)
{
var row_num = $("#table_sensor_list").find("tr").length;
var using_channel = "";
if(type == PORT_RS485)
using_channel = channel + "";
else if(type == PORT_GPIO)
using_channel = "GPIO " + channel;
else if(type == PORT_AI)
using_channel = "AI " + channel;
for(var i = 1;i < row_num;i++) //not include thead
{
var cur_no = $("#table_sensor_list").find('tr').eq(i).find('td').eq(0).html();
if(cur_no == skip_index)
continue;
var cur_chn = $("#table_sensor_list").find('tr').eq(i).find('td').eq(2).html();
if(cur_chn == using_channel)
{
return 1;
}
}
return 0;
}
function onSave()
{
if(m_device_lora_type[devIndex] == DEV_LORA_SENSOR)
{
if(document.getElementById("input_decimal_place").value.trim().length != 0)
{
if(!ASTGUI.checkRequiredFields(['input_decimal_place']))
return;
if(!ASTGUI.validateFields(['input_decimal_place']))
return;
}
var index = parseInt(document.getElementById("sel_sensor_id").value);
var url = "/vb.htm?page=iotsensor";
m_sensor_type_array[index] = document.getElementById("sel_sensor_type").value;
m_sensor_name_array[index] = (document.getElementById("sel_sensor_type").value != "-1")?"":document.getElementById("input_sensor_type").value;
m_sign_array[index] = document.getElementById("check_sign").checked==true?"1":"0";
m_decimal_array[index] = document.getElementById("input_decimal_place").value.trim();
if(document.getElementById("sel_unit").value != "-1")
m_unit_array[index] = document.getElementById("sel_unit").value;
else
m_unit_array[index] = document.getElementById("input_unit").value.trim();
m_show_osd_array[index] = document.getElementById("check_showosd").checked==true?"1":"0";
url += "&index=" + index;
url += "&sensortype=" + m_sensor_type_array[index];
url += "&sensorname=" + encodeURIComponent(m_sensor_name_array[index]);
url += "&sign=" + m_sign_array[index];
url += "&decimal=" + (m_decimal_array[index] == ""?"0":m_decimal_array[index]);
url += "&unit=" + encodeURIComponent(m_unit_array[index]);
url += "&showosd=" + m_show_osd_array[index];
url += "&deviceindex=" + devIndex;
url += "&porttype=" + m_port_type_array[index];
url += "&channelid=" + index;
SendHttp(url, false,function(g_SubmitHttp){
if (g_SubmitHttp.readyState == 4)
{
if (g_SubmitHttp.status == 200)
{
ShowMessageView_by_IFrame(general_savetips);
}
}
});
}
else
{
var port_type = document.getElementById("sel_port_type").value;
var sensor_name = get_sensor_name(parseInt(document.getElementById("sel_sensor_type").value));
if(sensor_name == "")
sensor_name = document.getElementById("input_sensor_type").value.trim();
var channel_id = "";
var index = 0;
if(g_cur_edit_index == -1) //add
{
index = get_unuse_sensorList_index() - 1;
var TBL = _$('table_sensor_list');
var nIndex = TBL.rows.length-1;
if(nIndex+1 > MAX_SENSOR_NUM)
{
ShowAlert(nas_mount_tip);
return;
}
}
else //edit
index = g_cur_edit_index - 1;
var url = "/vb.htm?page=iotsensor";
if(port_type == PORT_RS485)
{
if(document.getElementById("input_decimal_place").value.trim().length != 0)
{
if(!ASTGUI.checkRequiredFields(['input_decimal_place']))
return;
if(!ASTGUI.validateFields(['input_decimal_place']))
return;
}
channel_id = parseInt(document.getElementById("sel_rs485_id").value) + 1;
if(ChannelIsUse(channel_id + "",g_cur_edit_index,port_type))
{
ASTGUI.highlightField(_$("sel_rs485_id"), channel_repeat);
return;
}
m_sensor_type_array[index] = document.getElementById("sel_sensor_type").value;
m_sensor_name_array[index] = (document.getElementById("sel_sensor_type").value != "-1")?"":document.getElementById("input_sensor_type").value;
m_sign_array[index] = document.getElementById("check_sign").checked==true?"1":"0";
m_decimal_array[index] = document.getElementById("input_decimal_place").value.trim();
if(document.getElementById("sel_unit").value != "-1")
m_unit_array[index] = document.getElementById("sel_unit").value;
else
m_unit_array[index] = document.getElementById("input_unit").value.trim();
m_show_osd_array[index] = document.getElementById("check_showosd").checked==true?"1":"0";
m_chn_array[index] = document.getElementById("sel_rs485_id").value;
url += "&index=" + index;
url += "&sensortype=" + m_sensor_type_array[index];
url += "&sensorname=" + encodeURIComponent(m_sensor_name_array[index]);
url += "&sign=" + m_sign_array[index];
url += "&decimal=" + (m_decimal_array[index] == ""?"0":m_decimal_array[index]);
url += "&unit=" + encodeURIComponent(m_unit_array[index]);
url += "&showosd=" + m_show_osd_array[index];
url += "&channelid=" + m_chn_array[index];
}
else if(port_type == PORT_GPIO)
{
channel_id = parseInt(document.getElementById("sel_gpio_id").value) + 1;
if(ChannelIsUse(channel_id + "",g_cur_edit_index,port_type))
{
ASTGUI.highlightField(_$("sel_gpio_id"), channel_repeat);
return;
}
m_sensor_type_array[index] = document.getElementById("sel_sensor_type").value;
m_sensor_name_array[index] = (document.getElementById("sel_sensor_type").value != "-1")?"":document.getElementById("input_sensor_type").value;
m_show_osd_array[index] = document.getElementById("check_showosd").checked==true?"1":"0";
m_chn_array[index] = document.getElementById("sel_gpio_id").value;
url += "&index=" + index;
url += "&sensortype=" + m_sensor_type_array[index];
url += "&sensorname=" + m_sensor_name_array[index];
url += "&showosd=" + m_show_osd_array[index];
url += "&channelid=" + m_chn_array[index];
}
else if(port_type == PORT_AI)
{
if(!ASTGUI.checkRequiredFields(['input_osh','input_osl']))
return;
if(!ASTGUI.validateFields(['input_osh','input_osl']))
return;
channel_id = parseInt(document.getElementById("sel_ai_id").value) + 1;
if(ChannelIsUse(channel_id + "",g_cur_edit_index,port_type))
{
ASTGUI.highlightField(_$("sel_ai_id"), channel_repeat);
return;
}
var osh = document.getElementById("input_osh").value;
var osl = document.getElementById("input_osl").value;
if(parseInt(osh) < parseInt(osl))
{
ASTGUI.highlightField(_$("input_osl"), osl_tips);
return;
}
m_sensor_type_array[index] = document.getElementById("sel_sensor_type").value;
m_sensor_name_array[index] = (document.getElementById("sel_sensor_type").value != "-1")?"":document.getElementById("input_sensor_type").value;
m_osh_array[index] = document.getElementById("input_osh").value;
m_osl_array[index] = document.getElementById("input_osl").value;
if(document.getElementById("sel_unit").value != "-1")
m_unit_array[index] = document.getElementById("sel_unit").value;
else
m_unit_array[index] = document.getElementById("input_unit").value.trim();
m_show_osd_array[index] = document.getElementById("check_showosd").checked==true?"1":"0";
m_chn_array[index] = document.getElementById("sel_ai_id").value;
url += "&index=" + index;
url += "&sensortype=" + m_sensor_type_array[index];
url += "&sensorname=" + encodeURIComponent(m_sensor_name_array[index]);
url += "&osh=" + m_osh_array[index];
url += "&osl=" + m_osl_array[index];
url += "&unit=" + encodeURIComponent(m_unit_array[index]);
url += "&showosd=" + m_show_osd_array[index];
url += "&channelid=" + m_chn_array[index];
}
m_port_type_array[index] = document.getElementById("sel_port_type").value;
var TBL = _$('table_sensor_list');
if(g_cur_edit_index == -1) //Add
{
var tr_index = get_unuse_sensorList_index();
insert_sensorList(TBL,tr_index,channel_id,port_type,sensor_name);
$("#table_sensor_list").show();
}
else //Edit
{
var row_index = 0;
var row_num = $("#table_sensor_list").find("tr").length;
for(var i = 1;i < row_num;i++)
{
var cur_index = $("#table_sensor_list").find('tr').eq(i).find('td').eq(0).html();
cur_index = parseInt(cur_index);
if(cur_index == g_cur_edit_index)
{
row_index = i;
}
}
modify_sensorList(channel_id,port_type,sensor_name,row_index);
}
url += "&porttype=" + m_port_type_array[index];
url += "&deviceindex=" + devIndex;
SendHttp(url, false,function(g_SubmitHttp){
if (g_SubmitHttp.readyState == 4)
{
if (g_SubmitHttp.status == 200)
{
ShowMessageView_by_IFrame(general_savetips);
}
}
});
reinit_ui();
getUnuseChannel();
}
}
function reinit_ui()
{
document.getElementById("sel_sensor_type").value = "0";
document.getElementById("input_sensor_type").value = "";
document.getElementById("check_sign").checked = false;
document.getElementById("input_decimal_place").value = "";
document.getElementById("sel_unit").value = "℃";
document.getElementById("input_unit").value = "";
document.getElementById("check_showosd").checked = false;
document.getElementById("input_osh").value = "20";
document.getElementById("input_osl").value = "4";
changeUnit();
changeSensorType();
g_cur_edit_index = -1;
}
function onCancel()
{
windowObj.layer.closeAll();
}
function init_sensor_list()
{
var TBL = _$('table_sensor_list');
var newRow = TBL.insertRow(-1);
var addCell = ASTGUI.domActions.tr_addCell;
newRow.className = "frow";
addCell( newRow , { html:"No",align:"center"} );
addCell( newRow , { html:lang_port_type,align:"center"} );
addCell( newRow , { html:lang_channel_id,align:"center"} );
addCell( newRow, { html:sensor_type,align:"center"});
addCell( newRow , { html:Edit,align:"center"});
addCell( newRow , { html:Delete,align:"center"});
$("#table_sensor_list").hide();
for(var i = 0;i < MAX_SENSOR_NUM;i++)
{
if(m_port_type_array[i] != "0")
{
$("#table_sensor_list").show();
var sensor_name = get_sensor_name(parseInt(m_sensor_type_array[i]));
if(sensor_name == "")
sensor_name = m_sensor_name_array[i];
insert_sensorList(TBL,i+1,parseInt(m_chn_array[i])+1,m_port_type_array[i],sensor_name);
}
}
}
function init_show_unit(unit)
{
var i = 0;
for(i = 0;i < iot_unit.length;i++)
{
if(unit == iot_unit[i])
{
document.getElementById("sel_unit").value = unit;
document.getElementById("input_unit").value = "";
break;
}
}
if(i == iot_unit.length)
{
document.getElementById("sel_unit").value = "-1";
document.getElementById("input_unit").value = unit;
}
changeUnit();
}
function onEdit(num){
var index = num - 1;
var port_type = m_port_type_array[index];
if(port_type == PORT_RS485)
{
document.getElementById("sel_sensor_type").value = m_sensor_type_array[index];
document.getElementById("input_sensor_type").value = m_sensor_name_array[index];
document.getElementById("check_sign").checked = m_sign_array[index]=="1"?true:false;
document.getElementById("input_decimal_place").value = m_decimal_array[index];
init_show_unit(m_unit_array[index]);
document.getElementById("check_showosd").checked = m_show_osd_array[index]=="1"?true:false;
document.getElementById("sel_rs485_id").value = m_chn_array[index];
}
else if(port_type == PORT_GPIO)
{
document.getElementById("sel_sensor_type").value = m_sensor_type_array[index];
document.getElementById("input_sensor_type").value = m_sensor_name_array[index];
document.getElementById("check_showosd").checked = m_show_osd_array[index]=="1"?true:false;
document.getElementById("sel_gpio_id").value = m_chn_array[index];
}
else
{
document.getElementById("sel_sensor_type").value = m_sensor_type_array[index];
document.getElementById("input_sensor_type").value = m_sensor_name_array[index];
document.getElementById("input_osh").value = m_osh_array[index];
document.getElementById("input_osl").value = m_osl_array[index];
init_show_unit(m_unit_array[index]);
document.getElementById("check_showosd").checked = m_show_osd_array[index]=="1"?true:false;
document.getElementById("sel_ai_id").value = m_chn_array[index];
}
document.getElementById("sel_port_type").value = port_type;
changePortType();
g_cur_edit_index = num;
}
function get_row_index(num)
{
var row_num = $("#table_sensor_list").find("tr").length;
for(var i = 1;i < row_num;i++) //not include thead
{
var cur_num = $("#table_sensor_list").find('tr').eq(i).find('td').eq(0).html();
cur_num = parseInt(cur_num);
if(cur_num == num)
{
return i;
}
}
return -1;
}
function onDel(num)
{
ShowConfirm(del_device_tips, function()
{
var row_index = get_row_index(num);
var id = $("#table_sensor_list").find('tr').eq(row_index).find('td').eq(0).html();
if(parseInt(id) == g_cur_edit_index) //editing
g_cur_edit_index = -1;
id = parseInt(id) - 1;
$("#table_sensor_list").find('tr').eq(row_index).remove();
var row_num = $("#table_sensor_list").find("tr").length;
if(row_num <= 1)
$("#table_sensor_list").hide();
var url = "/vb.htm?deliotsensor=" + devIndex + ";" + id + ";";
SendHttp(url, false,function(g_SubmitHttp){
if (g_SubmitHttp.readyState == 4)
{
if (g_SubmitHttp.status == 200)
{
ShowMessageView_by_IFrame(general_savetips);
}
}
});
m_port_type_array[id] = PORT_NONE;
});
}
function getUnuseChannel()
{
var type = document.getElementById("sel_port_type").value;
var used_channels = new Array(0,0,0,0,0,0,0,0);
var i = 0;
for(i = 0;i < MAX_SENSOR_NUM;i++)
{
if(m_port_type_array[i] == type)
{
var chn = parseInt(m_chn_array[i]);
used_channels[chn] = 1;
}
}
for(i = 0;i < MAX_SENSOR_NUM/3;i++)
{
if(used_channels[i] != 1)
{
break;
}
}
if(i == MAX_SENSOR_NUM/3)
i = 0;
if(type == "1")
{
document.getElementById("sel_rs485_id").value = String(parseInt(i));
}
else if(type == "2")
{
document.getElementById("sel_gpio_id").value = String(parseInt(i));
}
else
{
document.getElementById("sel_ai_id").value = String(parseInt(i));
}
}
function changeChannelId(index)
{
var id = 0;
var name = "";
var type = "";
if(index == 0)
{
id = parseInt(document.getElementById("sel_rs485_id").value);
name = "sel_rs485_id";
type = PORT_RS485;
}
else if(index == 1)
{
id = parseInt(document.getElementById("sel_gpio_id").value);
name = "sel_gpio_id";
type = PORT_GPIO;
}
else
{
id = parseInt(document.getElementById("sel_ai_id").value);
name = "sel_ai_id";
type = PORT_AI;
}
if(ChannelIsUse((id+1) + "",g_cur_edit_index,type))
{
ASTGUI.highlightField(_$(name), channel_repeat);
return;
}
}