/
DiagnosticsApplet.lua
1083 lines (846 loc) · 25.9 KB
/
DiagnosticsApplet.lua
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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local ipairs, tostring, tonumber = ipairs, tostring, tonumber
-- NETWORK HEALTH STUFF
local type, pairs, setmetatable = type, pairs, setmetatable
-- stuff we use
local oo = require("loop.simple")
local io = require("io")
local math = require("math")
local string = require("string")
local table = require("jive.utils.table")
local Applet = require("jive.Applet")
local System = require("jive.System")
local DNS = require("jive.net.DNS")
local Networking = require("jive.net.Networking")
local Process = require("jive.net.Process")
local SocketTcp = require("jive.net.SocketTcp")
local SlimServer = require("jive.slim.SlimServer")
local Framework = require("jive.ui.Framework")
local Label = require("jive.ui.Label")
local SimpleMenu = require("jive.ui.SimpleMenu")
local Surface = require("jive.ui.Surface")
local Task = require("jive.ui.Task")
local Textarea = require("jive.ui.Textarea")
local Window = require("jive.ui.Window")
-- NETWORK HEALTH STUFF
local Popup = require("jive.ui.Popup")
local Icon = require("jive.ui.Icon")
local Tile = require("jive.ui.Tile")
local jive = jive
local jnt = jnt
local appletManager = appletManager
local JIVE_VERSION = jive.JIVE_VERSION
module(..., Framework.constants)
oo.class(_M, Applet)
function init(self)
self.generalTests = {
"FIRMWARE_VERSION",
"HARDWARE_VERSION",
"MAC_ADDRESS",
"CURRENT_PLAYER",
"PLAYER_TYPE",
"UPTIME",
"MEMORY",
}
self.wirelessTests = {
"WLAN_SSID",
"WLAN_ENCRYPTION",
"WLAN_STRENGTH",
-- (for testing): "WLAN_SNR",
"IP_ADDRESS",
"SUBNET_MASK",
"GATEWAY",
"DNS_SERVER",
}
self.ethernetTests = {
"ETH_CONNECTION",
"IP_ADDRESS",
"SUBNET_MASK",
"GATEWAY",
"DNS_SERVER",
}
self.serverTests = {
"SN_ADDRESS",
"SN_PING",
"SN_PORT_3483",
"SN_PORT_9000",
"SN_REG",
"SC_ADDRESS",
"SC_NAME",
"SC_PING",
"SC_PORT_3483",
"SC_PORT_9000",
}
self.powerTests = {
"MSP_VERSION",
"POWER_MODE",
"WALL_VOLTAGE",
"CHARGE_STATE",
"BATTERY_TEMPERATURE",
"BATTERY_VOLTAGE",
"BATTERY_VMON1",
"BATTERY_VMON2",
}
self.powerMode = {
["3"] = "POWER_ON_AC",
["7"] = "POWER_ON_AC_AND_BATT",
["5"] = "POWER_ON_BATT",
}
self.chargerState = {
["1"] = "BATT_NONE",
["2"] = "BATT_IDLE",
["3"] = "BATT_DISCHARGING",
["35"] = "BATT_DISCHARGING_WARNING",
["8"] = "BATT_CHARGING",
["24"] = "BATT_CHARGING_PAUSED",
}
self.netResultToText = {
[1] = { text="NET_INTERFACE", },
[-1] = { text="NET_INTERFACE_NOK", },
[3] = { text="NET_LINK", },
[5] = { text="NET_LINK_WIRELESS_OK", },
[-5] = { text="NET_LINK_WIRELESS_NOK", help="NET_LINK_WIRELESS_NOK_HELP"},
[6] = { text="NET_LINK_ETHERNET_OK", },
[-6] = { text="NET_LINK_ETHERNET_NOK", help="NET_LINK_ETHERNET_NOK_HELP"},
[8] = { text="NET_IP_OK", },
[-8] = { text="NET_IP_NOK", help="NET_IP_NOK_HELP"},
[10] = { text="NET_GATEWAY_OK", },
[-10] = { text="NET_GATEWAY_NOK", help="NET_GATEWAY_NOK_HELP"},
[12] = { text="NET_DNS_OK", },
[-12] = { text="NET_DNS_NOK", help="NET_DNS_NOK_HELP"},
[20] = { text="NET_ARPING", },
[21] = { text="NET_ARPING_OK", },
[-21] = { text="NET_ARPING_NOK", help="NET_ARPING_NOK_HELP"},
[-23] = { text="NET_SERVER_NOK", },
[25] = { text="NET_RESOLVE", },
[27] = { text="NET_RESOLVE_OK", },
[-27] = { text="NET_RESOLVE_NOK", help="NET_RESOLVE_NOK_HELP"},
[29] = { text="NET_PING", },
[31] = { text="NET_PING_OK", },
[-31] = { text="NET_PING_NOK", help="NET_PING_NOK_HELP"},
[33] = { text="NET_PORT", },
[35] = { text="NET_PORT_OK", },
[-35] = { text="NET_PORT_NOK", help="NET_PORT_NOK_HELP"},
[37] = { text="NET_PORT_OK", },
[-37] = { text="NET_PORT_NOK", help="NET_PORT_NOK_HELP"},
[100] = { text="NET_BRINGING_NETWORK_DOWN", },
[102] = { text="NET_BRINGING_NETWORK_UP", },
[104] = { text="NET_REPAIR_NETWORK_DONE", },
}
end
function setValue(self, key, value, customLabel)
if not value then
value = '-'
end
-- if we have customLabelArgs, we want to insert those first to the string args
if customLabel then
self.menu:setText(self.labels[key], self:string(key, tostring(customLabel), value))
else
self.menu:setText(self.labels[key], self:string(key, value))
end
end
function serverPort(self, server, port, key, customLabel)
if not server then
self:setValue(key, self.notConnected)
return
end
local portOk = tostring(self:string('PORT_OK'))
local portFail = tostring(self:string('PORT_FAIL'))
Task("ports", self, function()
local serverip = server:getIpPort()
local ip, err
if DNS:isip(serverip) then
ip = serverip
else
ip, err = DNS:toip(serverip)
end
if ip == nil then
self:setValue(key, portFail, customLabel)
return
end
local tcp = SocketTcp(jnt, ip, port, "porttest")
tcp:t_connect()
tcp:t_addWrite(function(err)
local res, err = tcp.t_sock:send(" ")
if err then
self:setValue(key, portFail, customLabel)
else
self:setValue(key, portOk, customLabel)
end
tcp:close()
end)
end):addTask()
end
function serverPing(self, server, dnsKey, pingKey, snRegKey)
local serverip = server and server:getIpPort()
local dnsFail = tostring(self:string('DNS_FAIL'))
local pingFailString = tostring(self:string('PING_FAIL'))
local pingOkString = tostring(self:string('PING_OK'))
local snRegYesString = tostring(self:string('SN_REG_YES'))
local snRegNoString = tostring(self:string('SN_REG_NO'))
if not serverip then
self:setValue(dnsKey, self.notConnected)
self:setValue(pingKey, self.notConnected)
return
end
Task("ping", self, function()
local ipaddr
-- DNS lookup
if DNS:isip(serverip) then
ipaddr = serverip
else
ipaddr = DNS:toip(serverip)
end
if not ipaddr then
self:setValue(dnsKey, dnsFail)
self:setValue(pingKey, pingFailString)
return
end
self:setValue(dnsKey, ipaddr)
-- Ping
local pingOK = false
local ping = Process(jnt, "ping -c 1 " .. ipaddr)
ping:read(function(chunk)
if chunk then
if string.match(chunk, "bytes from") then
pingOK = true
end
else
if pingOK then
self:setValue(pingKey, pingOkString)
if snRegKey then
if server:getPin() == false then
self:setValue(snRegKey, snRegYesString)
elseif server:getPin() == nil then
self:setValue(snRegKey, "")
else
self:setValue(snRegKey, snRegNoString)
end
end
else
self:setValue(pingKey, pingFailString)
end
end
end)
end):addTask()
end
function wlanStatus(self, iface)
if not iface then
return
end
Task("Netstatus", self, function()
local status = iface:t_wpaStatus()
-- (for testing): local snr, minsnr, maxsnr = iface:getSNR()
local signalStrength = iface:getSignalStrength()
if status.ssid then
local encryption = status.key_mgmt
-- white lie :)
if string.match(status.pairwise_cipher, "WEP") then
encryption = "WEP"
end
self:setValue("WLAN_SSID", status.ssid)
self:setValue("WLAN_ENCRYPTION", encryption)
self:setValue("WLAN_STRENGTH", signalStrength .. "%")
-- (for testing): self:setValue("WLAN_SNR", minsnr .. "/" .. snr .. "/" .. maxsnr)
if status.ip_address then
self:setValue("IP_ADDRESS", tostring(status.ip_address))
self:setValue("SUBNET_MASK", tostring(status.ip_subnet))
self:setValue("GATEWAY", tostring(status.ip_gateway))
self:setValue("DNS_SERVER", tostring(status.ip_dns))
end
else
self:setValue('WLAN_SSID', self.notConnected)
self:setValue("WLAN_ENCRYPTION", nil)
self:setValue("WLAN_STRENGTH", nil)
end
end):addTask()
end
function ethStatus(self, iface)
if not iface then
return
end
Task("Netstatus", self, function()
local status = iface:t_wpaStatus()
if status.link then
if status.fullduplex then
self:setValue("ETH_CONNECTION", tostring(self:string("ETH_FULL_DUPLEX", status.speed)))
else
self:setValue("ETH_CONNECTION", tostring(self:string("ETH_HALF_DUPLEX", status.speed)))
end
if status.ip_address then
self:setValue("IP_ADDRESS", tostring(status.ip_address))
self:setValue("SUBNET_MASK", tostring(status.ip_subnet))
self:setValue("GATEWAY", tostring(status.ip_gateway))
self:setValue("DNS_SERVER", tostring(status.ip_dns))
end
else
self:setValue("ETH_CONNECTION", self.notConnected)
end
end):addTask()
end
function systemStatus(self)
local uptime = ""
local memory = ""
local f = io.open("/proc/uptime")
if f then
local time = f:read("*all")
f:close()
time = string.match(time, "(%d+)")
uptime = {}
uptime.days = math.floor(time / 86400)
time = math.fmod(time, 86400)
uptime.hours = math.floor(time / 3600)
time = math.fmod(time, 3600)
uptime.minutes = math.floor(time / 60)
local ut = {}
if uptime.days > 0 then
ut[#ut + 1] = tostring(self:string("UPTIME_DAYS", uptime.days))
end
if uptime.hours > 0 then
ut[#ut + 1] = tostring(self:string("UPTIME_HOURS", uptime.hours))
end
ut[#ut + 1] = tostring(self:string("UPTIME_MINUTES", uptime.minutes))
uptime = table.concat(ut, " ")
end
local f = io.open("/proc/meminfo")
if f then
local mem = {}
while true do
local line = f:read()
if line == nil then
break
end
local key, value = string.match(line, "(.+):%s+(%d+)")
mem[key] = value
end
f:close()
memory = math.ceil(((mem.MemTotal - (mem.MemFree + mem.Buffers + mem.Cached)) / mem.MemTotal) * 100) .. "%"
end
self:setValue("UPTIME", uptime)
self:setValue("MEMORY", memory)
end
function _getSysValue(self, param)
local f = io.open("/sys/bus/i2c/devices/1-0010/" .. param)
local value = f:read("*all")
f:close()
return value
end
function _getPowerSysValue(self, param)
local f = io.open("/sys/devices/platform/i2c-adapter:i2c-1/1-0010/" .. param)
log:warn("opening: ", param)
local value = f:read("*all")
f:close()
return value
end
-- DO VALUES
function doGeneralValues(self, menu)
self.menu = menu
local machine, revision = System:getMachine();
self:setValue("FIRMWARE_VERSION", JIVE_VERSION)
if revision then
self:setValue("HARDWARE_VERSION", tostring(revision))
end
self:setValue("MAC_ADDRESS", System:getMacAddress())
self:systemStatus()
local currentPlayer = appletManager:callService("getCurrentPlayer")
if currentPlayer then
self:setValue("CURRENT_PLAYER", currentPlayer:getName())
if currentPlayer:isLocal() then
self:setValue("PLAYER_TYPE", tostring(self:string("DIAGNOSTICS_LOCAL")))
else
self:setValue("PLAYER_TYPE", tostring(self:string("DIAGNOSTICS_REMOTE")))
end
else
self:setValue("CURRENT_PLAYER", tostring(self:string("DIAGNOSTICS_NONE")))
self:setValue("PLAYER_TYPE", "")
end
end
function doWirelessValues(self, menu)
self.menu = menu
local wlanIface = Networking:wirelessInterface(jnt)
self:wlanStatus(wlanIface)
end
function doEthernetValues(self, menu)
self.menu = menu
local ethIface = Networking:wiredInterface(jnt)
if System:hasWiredNetworking() then
self:ethStatus(ethIface)
end
end
function doServerValues(self, menu)
self.menu = menu
local sn = false
for name, server in SlimServer:iterate() do
if server:isSqueezeNetwork() then
sn = server
end
end
local sc = SlimServer:getCurrentServer()
self:serverPing(sn, "SN_ADDRESS", "SN_PING", "SN_REG")
self:serverPort(sn, 3483, "SN_PORT_3483")
self:serverPort(sn, 9000, "SN_PORT_9000")
if not sc or sc:isSqueezeNetwork() then
-- connected to SN
self:setValue("SC_NAME", self.notConnected)
self:setValue("SC_ADDRESS", self.notConnected)
self:setValue("SC_PING", self.notConnected)
self:setValue("SC_PORT_3483", self.notConnected)
self:setValue("SC_PORT_9000", self.notConnected, "9000") -- guess at 9000 here
else
self:setValue("SC_NAME", sc:getName())
self:serverPing(sc, "SC_ADDRESS", "SC_PING")
self:serverPort(sc, 3483, "SC_PORT_3483")
local ip, port = sc:getIpPort()
self:serverPort(sc, port, "SC_PORT_9000", port)
end
end
function roundNumber(num, idp)
return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end
function doPowerValues(self, menu)
self.menu = menu
self:setValue("MSP_VERSION", self:_getSysValue("fw"))
local mode = self:_getPowerSysValue("power_mode"):gsub("^%s*(.-)%s*$", "%1")
self:setValue("POWER_MODE", tostring(self:string(self.powerMode[mode])))
-- Battery only
if mode == "5" then
self:setValue("WALL_VOLTAGE", "-")
-- AC (maybe Battery)
else
local wallVoltage = roundNumber(self:_getPowerSysValue("wall_voltage") / 1000.0, 1)
self:setValue("WALL_VOLTAGE", tostring(wallVoltage .. " V"))
end
local mode = self:_getPowerSysValue("charger_state"):gsub("^%s*(.-)%s*$", "%1")
self:setValue("CHARGE_STATE", tostring(self:string(self.chargerState[mode])))
-- No battery installed
if mode == "1" then
self:setValue("BATTERY_TEMPERATURE", "-")
self:setValue("BATTERY_VOLTAGE", "-")
self:setValue("BATTERY_VMON1", "-")
self:setValue("BATTERY_VMON2", "-")
-- Battery installed
else
local batteryTemperature = roundNumber(self:_getPowerSysValue("battery_temperature") / 32.0, 1)
local batteryVoltage = roundNumber(self:_getPowerSysValue("battery_voltage") / 1000.0, 1)
local batteryMonitor1 = roundNumber(self:_getPowerSysValue("battery_vmon1_voltage") / 1000.0, 1)
local batteryMonitor2 = roundNumber(self:_getPowerSysValue("battery_vmon2_voltage") / 1000.0, 1)
self:setValue("BATTERY_TEMPERATURE", tostring(batteryTemperature) .. " C")
self:setValue("BATTERY_VOLTAGE", tostring(batteryVoltage) .. " V")
self:setValue("BATTERY_VMON1", tostring(batteryMonitor1) .. " V")
self:setValue("BATTERY_VMON2", tostring(batteryMonitor2) .. " V")
end
end
-- SUB MENUS
function showGeneralDiagnosticsMenu(self)
local window = Window("text_list", self:string("MENU_GENERAL"))
window:setAllowScreensaver(false)
window:setButtonAction("rbutton", nil)
local menu = SimpleMenu("menu")
self.labels = {}
for i,name in ipairs(self.generalTests) do
self.labels[name] = {
text = self:string(name, ''),
style = 'item_info',
}
menu:addItem(self.labels[name])
end
doGeneralValues(self, menu)
menu:addTimer(5000, function()
doGeneralValues(self, menu)
end)
window:addWidget(menu)
self:tieAndShowWindow(window)
return window
end
function showWirelessDiagnosticsMenu(self)
local window = Window("text_list", self:string("MENU_WIRELESS"))
window:setAllowScreensaver(false)
window:setButtonAction("rbutton", nil)
local menu = SimpleMenu("menu")
self.labels = {}
for i,name in ipairs(self.wirelessTests) do
self.labels[name] = {
text = self:string(name, ''),
style = 'item_info',
}
menu:addItem(self.labels[name])
end
doWirelessValues(self, menu)
menu:addTimer(5000, function()
doWirelessValues(self, menu)
end)
window:addWidget(menu)
self:tieAndShowWindow(window)
return window
end
function showEthernetDiagnosticsMenu(self)
local window = Window("text_list", self:string("MENU_ETHERNET"))
window:setAllowScreensaver(false)
window:setButtonAction("rbutton", nil)
local menu = SimpleMenu("menu")
self.labels = {}
for i,name in ipairs(self.ethernetTests) do
self.labels[name] = {
text = self:string(name, ''),
style = 'item_info',
}
menu:addItem(self.labels[name])
end
doEthernetValues(self, menu)
menu:addTimer(5000, function()
doEthernetValues(self, menu)
end)
window:addWidget(menu)
self:tieAndShowWindow(window)
return window
end
function showServerDiagnosticsMenu(self)
local window = Window("text_list", self:string("MENU_SERVER"))
window:setAllowScreensaver(false)
window:setButtonAction("rbutton", nil)
local menu = SimpleMenu("menu")
self.labels = {}
for i,name in ipairs(self.serverTests) do
local label
if name == 'SC_PORT_9000' then
label = self:string(name, '9000', '-')
else
label = self:string(name, '-')
end
self.labels[name] = {
text = label,
style = 'item_info',
}
menu:addItem(self.labels[name])
end
doServerValues(self, menu)
menu:addTimer(5000, function()
doServerValues(self, menu)
end)
window:addWidget(menu)
self:tieAndShowWindow(window)
return window
end
function showPowerDiagnosticsMenu(self)
local window = Window("text_list", self:string("POWER"))
window:setAllowScreensaver(false)
window:setButtonAction("rbutton", nil)
local menu = SimpleMenu("menu")
self.labels = {}
for i,name in ipairs(self.powerTests) do
self.labels[name] = {
text = self:string(name, ''),
style = 'item_info',
}
menu:addItem(self.labels[name])
end
doPowerValues(self, menu)
menu:addTimer(5000, function()
doPowerValues(self, menu)
end)
window:addWidget(menu)
self:tieAndShowWindow(window)
return window
end
-- Error Troubleshooting menu
function networkTroubleshootingMenu(self, iface)
log:warn('networkTroubleshootingMenu: ', iface)
if not iface then
log:error('You must specify the interface object when calling this method')
return false
end
local errorCode = iface:getNetworkResult()
if type(errorCode) == 'number' and errorCode >= 0 then
log:warn('A positive number means there is no error. Do not push a diags window in this condition.')
return false
elseif type(errorCode) == 'number' then
log:warn('Error code is listed as: ', errorCode)
else
log:error('There is no network problem registered on this interface')
return
end
local titleToken = self.netResultToText[errorCode] and self.netResultToText[errorCode].text or "NETWORK_PROBLEM"
local helpTextToken = self.netResultToText[errorCode] and self.netResultToText[errorCode].help or "NETWORK_PROBLEM_HELP"
local window = Window("text_list", self:string(titleToken) )
window:setButtonAction("rbutton", nil)
local menu = SimpleMenu("menu")
menu:setHeaderWidget( Textarea( "help_text", self:string(helpTextToken) ) )
self:_addDiagnosticsMenuItem(menu)
self:_addRepairNetworkItem(menu)
window:addWidget(menu)
window:show()
return window
end
-- MAIN MENU
-- Service menu
function diagnosticsMenu(self, suppressNetworkingItem)
local window = Window("text_list", self:string("DIAGNOSTICS"))
window:setAllowScreensaver(false)
window:setButtonAction("rbutton", nil)
local menu = SimpleMenu("menu")
menu:addItem({
text = self:string("MENU_GENERAL"),
sound = "WINDOWSHOW",
style = 'item',
callback = function ()
self:showGeneralDiagnosticsMenu()
end
})
menu:addItem({
text = self:string("MENU_NETWORK_HEALTH"),
sound = "WINDOWSHOW",
style = 'item',
callback = function ()
self:showNetworkHealthDiagnosticsMenu()
end
})
menu:addItem({
text = self:string("MENU_WIRELESS"),
sound = "WINDOWSHOW",
style = 'item',
callback = function ()
self:showWirelessDiagnosticsMenu()
end
})
if System:getMachine() ~= 'jive' then
menu:addItem({
text = self:string("MENU_ETHERNET"),
sound = "WINDOWSHOW",
style = 'item',
callback = function ()
self:showEthernetDiagnosticsMenu()
end
})
end
menu:addItem({
text = self:string("MENU_SERVER"),
sound = "WINDOWSHOW",
style = 'item',
callback = function ()
self:showServerDiagnosticsMenu()
end
})
if System:getMachine() == "baby" then
menu:addItem({
text = self:string("POWER"),
sound = "WINDOWSHOW",
style = 'item',
callback = function ()
self:showPowerDiagnosticsMenu()
end
})
end
if System:isHardware() then
menu:addItem({
text = self:string("SOFTWARE_UPDATE"),
sound = "WINDOWSHOW",
style = 'item',
callback = function ()
--todo: this does setup style FW upgrade only (since this menu is avilable from setup). When we want different support for a non-setup version, make sure to leave the setup style behavior
appletManager:callService("firmwareUpgrade", nil, true)
end
})
if not suppressNetworkingItem then
menu:addItem({
text = self:string("DIAGNOSTICS_NETWORKING"),
sound = "WINDOWSHOW",
style = 'item',
callback = function ()
appletManager:callService("settingsNetworking")
end
})
end
end
self.notConnected = tostring(self:string('NOT_CONNECTED'))
self.menu = menu
window:addWidget(menu)
self:tieAndShowWindow(window)
return window
end
-- Service menu
function supportMenu(self)
local window = Window("help_list", self:string("SUPPORT"))
window:setAllowScreensaver(false)
window:setButtonAction("rbutton", nil)
local menu = SimpleMenu("menu")
self:_addDiagnosticsMenuItem(menu, true)
menu:setHeaderWidget(Textarea("help_text", self:string("SUPPORT_HELP")))
window:addWidget(menu)
self:tieAndShowWindow(window)
return window
end
-- NETWORK HEALTH STUFF
function showNetworkHealthDiagnosticsMenu(self)
local window = Window("text_list", self:string("MENU_NETWORK_HEALTH"))
window:setAllowScreensaver(false)
window:setButtonAction("rbutton", nil)
local menu = SimpleMenu("menu")
self.labels = {}
self.labels["NETWORK_STATUS"] = {
-- For some reason (I have no idea why) the second line is not show anymore in this label
-- and since the second line is the important one the quick fix is to swap the two lines
-- text = self:string("NETWORK_STATUS", tostring(self:string("NET_HEALTH_HINT"))),
text = self:string(tostring(self:string("NET_HEALTH_HINT")), ''),
style = 'item_info',
}
menu:addItem(self.labels["NETWORK_STATUS"])
menu:addItem({
text = self:string("CHECK_NETWORK"),
style = 'item',
callback = function ()
self:manualCheckNetworkHealth(true)
end
})
-- menu:addItem({
-- text = self:string("CHECK_NETWORK_PART"),
-- style = 'item',
-- callback = function ()
-- self:manualCheckNetworkHealth(false)
-- end
-- })
self:_addRepairNetworkItem(menu)
self.networkHealthMenu = menu
window:addWidget(menu)
self:tieAndShowWindow(window)
return window
end
function _addDiagnosticsMenuItem(self, menu, suppressNetworkingItem)
menu:addItem({
text = self:string("DIAGNOSTICS"),
style = 'item',
callback = function ()
self:diagnosticsMenu(suppressNetworkingItem)
end
})
end
function _addRepairNetworkItem(self, menu)
menu:addItem({
text = self:string("REPAIR_NETWORK"),
style = 'item',
callback = function ()
self:manualRepairNetwork()
end
})
end
function setResult(self, index, result, msgStr)
self:addExtraStyle(jive.ui.style)
local myItem = self.labels[index]
-- no error
if result >= 0 then
-- Replace everything's ok message with a user friendly one
msgStr = tostring(self:string("NET_SUCCESS"))
myItem.style = "item_info_green"
-- some error
else
myItem.style = "item_info_red"
end
-- For some reason (I have no idea why) the second line is not show anymore in this label
-- and since the second line is the important one the quick fix is to swap the two lines
-- self.networkHealthMenu:setText(self.labels[index], self:string(index, msgStr))
self.networkHealthMenu:setText(self.labels[index], self:string(msgStr, ''))
self.networkHealthMenu:setSelectedIndex(1)
-- TODO: needed?
-- self.networkHealthMenu:replaceIndex(myItem, 1)
end
function manualCheckNetworkHealth(self, full_check)
local popup = Popup("waiting_popup")
popup:setAllowScreensaver(false)
popup:ignoreAllInputExcept()
popup:addWidget(Icon("icon_connecting"))
if full_check then
popup:addWidget(Label("text", self:string("CHECK_NETWORK")))
else
popup:addWidget(Label("text", self:string("CHECK_NETWORK_PART")))
end
local status = Label("subtext", self:string("STATUS_MSG", "-"))
popup:addWidget(status)
-- Get current server
local server = SlimServer:getCurrentServer()
-- Get SN if SC is not available
if not server then
-- Get SN
for n, s in SlimServer:iterate() do
if s:isSqueezeNetwork() then
server = s
end
end
end
local ifObj = Networking:activeInterface()
Networking:checkNetworkHealth(
ifObj,
function(continue, result, msg_param)
local msg = self.netResultToText[result].text
local msgStr = tostring(self:string(msg, msg_param))
log:debug("checkNetworkHealth status: ", msgStr)
if continue then
-- Update spinny message
status:setValue(self:string("STATUS_MSG", msgStr))
else
log:debug("Network health error: ", result)
-- Update final message
setResult(self, "NETWORK_STATUS", result, msgStr)
popup:hide()
end
end,
full_check, -- true full check (includes arping, DNS resolution and ping)
server
)