Skip to content

Commit bb5bc4c

Browse files
committed
Configurable Insteon logging
1 parent 9f2e74e commit bb5bc4c

2 files changed

Lines changed: 40 additions & 33 deletions

File tree

modInsteon.vb

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
Private serialLock As New Object
3232
Dim tmrIThermCheckTimer As System.Timers.Timer
33+
Dim tetLogInsteon As System.Diagnostics.TraceEventType = TraceEventType.Verbose
3334

3435
Function AddInsteonDeviceDb(ByVal strAddress As String, ByVal DevCat As Short, ByVal SubCat As Short, ByVal Firmware As Short) As String
3536
If CheckDbForInsteon(strAddress) = 0 Then
@@ -366,6 +367,12 @@
366367
AddHandler SerialPLM.DataReceived, AddressOf SerialPLM_DataReceived
367368

368369
CreateInsteonDb()
370+
371+
If modDatabase.GetConfig("Insteon_VerboseLogging") = "enabled" Then
372+
My.Application.Log.WriteEntry("Verbose logging of Insteon traffic is enabled")
373+
tetLogInsteon = TraceEventType.Information
374+
End If
375+
369376
Return "Insteon module loaded"
370377
Else
371378
My.Application.Log.WriteEntry("Insteon module is disabled, module not loaded")
@@ -460,7 +467,7 @@
460467
x_Start = MessageEnd
461468
' Display message
462469
PLM_Address = Hex(x(ms + 2)) & "." & Hex(x(ms + 3)) & "." & Hex(x(ms + 4))
463-
My.Application.Log.WriteEntry("PLM response to Get IM Info: PLM ID: " & PLM_Address & ", Device Category: " & Hex(x(ms + 5)) & ", Subcategory: " & Hex(x(ms + 6)) & ", Firmware: " & Hex(x(ms + 7)) & ", ACK/NAK: " & Hex(x(ms + 8)), TraceEventType.Verbose)
470+
My.Application.Log.WriteEntry("PLM response to Get IM Info: PLM ID: " & PLM_Address & ", Device Category: " & Hex(x(ms + 5)) & ", Subcategory: " & Hex(x(ms + 6)) & ", Firmware: " & Hex(x(ms + 7)) & ", ACK/NAK: " & Hex(x(ms + 8)), tetLogInsteon)
464471
' Set the PLM as the controller
465472
' --> I use this to verify the PLM is connected, disable some menu options, enable others, etc
466473
End If
@@ -492,7 +499,7 @@
492499
For i = 0 To DataAvailable
493500
strTemp = strTemp & Hex(x(ms + i)) & " "
494501
Next
495-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
502+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
496503

497504
strTemp = "PLM: Insteon Received: From: " & FromAddress & " To: " & ToAddress
498505
If ToAddress = PLM_Address Then
@@ -538,11 +545,11 @@
538545
Else
539546
strTemp = strTemp & " Command1: " & Hex(Command1) & " (" & modInsteon.InsteonCommandLookup(Command1) & ")" & " Command2: " & Hex(Command2)
540547
End If
541-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
548+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
542549

543550
If Flags = 139 AndAlso (Command1 = 1 OrElse Command1 = 2) Then
544551
' This is a 0x01 or 0x02 Product Request Data response. The 'To' field is actually the DevCat, SubCat, and Firmware Rev.
545-
My.Application.Log.WriteEntry("ADD CASE 4", TraceEventType.Verbose)
552+
My.Application.Log.WriteEntry("ADD CASE 4", tetLogInsteon)
546553
AddInsteonDeviceDb(FromAddress, x(ms + 5), x(ms + 6), x(ms + 7))
547554
End If
548555

@@ -613,7 +620,7 @@
613620
Else
614621
strTemp = strTemp & FromName & " broadcast command " & Hex(Command1)
615622
End If
616-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
623+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
617624
Insteon(IAddress).LastCommand = Command1
618625
Insteon(IAddress).LastFlags = Flags And 224
619626
Insteon(IAddress).LastTime = Now
@@ -669,7 +676,7 @@
669676
If DeviceType = "SmokeBridge" Then
670677
strTemp = strTemp & " Smoke Bridge: " & InsteonSmokeBridgeResponse(Group)
671678
End If
672-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
679+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
673680
' Handle incoming event and play sounds
674681
' --> at this point I play a WAV file and run any macro associated with the device
675682
Case 32, 96 ' 001 ACK direct message, 011 ACK group cleanup direct message
@@ -682,7 +689,7 @@
682689
Case 160, 224 ' 101 NAK direct message, 111 NAK group cleanup direct message
683690
' Command received by another device but failed - display message in log
684691
strTemp = Format(Now) & " " & FromAddress & " NAK to command " & Hex(Command1) & " (" & modInsteon.InsteonCommandLookup(Command1) & ")"
685-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
692+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
686693
Insteon(IAddress).LastCommand = Command1
687694
Insteon(IAddress).LastFlags = Flags And 224
688695
Insteon(IAddress).LastTime = Now
@@ -736,7 +743,7 @@
736743
strTemp = strTemp & Hex(x(ms + i)) & " "
737744
Next
738745
strTemp = strTemp & "--> Product Key " & Hex(x(ms + 12)) & Hex(x(ms + 13)) & Hex(x(ms + 14)) & " DevCat: " & Hex(x(ms + 15)) & " SubCat: " & Hex(x(ms + 16)) & " Firmware: " & Hex(x(ms + 17))
739-
My.Application.Log.WriteEntry("ADD CASE 1", TraceEventType.Verbose)
746+
My.Application.Log.WriteEntry("ADD CASE 1", tetLogInsteon)
740747
AddInsteonDeviceDb(FromAddress, x(ms + 15), x(ms + 16), x(ms + 17))
741748
Case 1 ' FX Username Response
742749
strTemp = strTemp & " FX Username Response:" & " D1-D8 FX Command Username: "
@@ -792,7 +799,7 @@
792799
strTemp = strTemp & Hex(x(ms + i)) & " "
793800
Next
794801
End If
795-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
802+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
796803
End If
797804
' I’m not planning on actually doing anything with this data, just displayed
798805
Case 82 ' 0x052 X10 Received
@@ -816,7 +823,7 @@
816823
' Now actually process the event
817824
' Does it have a name?
818825
'If DeviceName(X10Address) = X10Address Then HasName = False Else HasName = True
819-
My.Application.Log.WriteEntry(Format(Now) & " " & X10Address & " " & X10Code, TraceEventType.Verbose)
826+
My.Application.Log.WriteEntry(Format(Now) & " " & X10Address & " " & X10Code, tetLogInsteon)
820827
'If LoggedIn And HasName Then frmHack.WriteWebtrix(Blue, VB6.Format(TimeOfDay) & " ")
821828
' Write command to event log
822829
' Handle incoming event
@@ -833,7 +840,7 @@
833840
Case Else ' invalid data
834841
strTemp = strTemp & "Unrecognized X10: " & Hex(x(ms + 2)) & " " & Hex(x(ms + 3))
835842
End Select
836-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
843+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
837844
End If
838845
Case 98 ' 0x062 Send Insteon standard OR extended message
839846
' PLM is just echoing the last command sent, discard this: 7 or 21 bytes
@@ -850,7 +857,7 @@
850857
For i = 0 To 22
851858
strTemp = strTemp & Hex(x(ms + i)) & " "
852859
Next
853-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
860+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
854861
End If
855862
Else
856863
' Standard message
@@ -859,7 +866,7 @@
859866
For i = 0 To 8
860867
strTemp = strTemp & Hex(x(ms + i)) & " "
861868
Next
862-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
869+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
863870
End If
864871
End If
865872
Case 99 ' 0x063 Sent X10
@@ -893,7 +900,7 @@
893900
Case Else
894901
strTemp = strTemp & Hex(x(ms + 4)) & " (?)"
895902
End Select
896-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
903+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
897904
End If
898905
Case 83 ' 0x053 ALL-Linking complete - 8 bytes of data
899906
MessageEnd = ms + 9
@@ -912,8 +919,8 @@
912919
FromAddress = Hex(x(ms + 4)) & "." & Hex(x(ms + 5)) & "." & Hex(x(ms + 6))
913920
strTemp = strTemp & " Group: " & Hex(x(ms + 3)) & " ID: " & FromAddress & " DevCat: " & Hex(x(ms + 7)) & " SubCat: " & Hex(x(ms + 8)) & " Firmware: " & Hex(x(ms + 9))
914921
If x(ms + 9) = 255 Then strTemp = strTemp & " (all newer devices = FF)"
915-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
916-
My.Application.Log.WriteEntry("ADD CASE 2", TraceEventType.Verbose)
922+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
923+
My.Application.Log.WriteEntry("ADD CASE 2", tetLogInsteon)
917924
AddInsteonDeviceDb(FromAddress, x(ms + 7), x(ms + 8), x(ms + 9))
918925
End If
919926
Case 87 ' 0x057 ALL-Link record response - 8 bytes of data
@@ -924,11 +931,11 @@
924931
FromAddress = Hex(x(ms + 4)) & "." & Hex(x(ms + 5)) & "." & Hex(x(ms + 6))
925932
' Check if FromAddress is in device database, if not add it
926933
If InsteonNum(FromAddress) = 0 Then
927-
My.Application.Log.WriteEntry("ADD CASE 3", TraceEventType.Verbose)
934+
My.Application.Log.WriteEntry("ADD CASE 3", tetLogInsteon)
928935
' TODO: Make this: AddInsteonDevice(FromAddress)
929936
' TODO: Make this: SortInsteon()
930937
End If
931-
My.Application.Log.WriteEntry("PLM: ALL-Link Record response: 0x57 Flags: " & Hex(x(ms + 2)) & " Group: " & Hex(x(ms + 3)) & " Address: " & FromAddress & " Data: " & Hex(x(ms + 7)) & " " & Hex(x(ms + 8)) & " " & Hex(x(ms + 9)), TraceEventType.Verbose)
938+
My.Application.Log.WriteEntry("PLM: ALL-Link Record response: 0x57 Flags: " & Hex(x(ms + 2)) & " Group: " & Hex(x(ms + 3)) & " Address: " & FromAddress & " Data: " & Hex(x(ms + 7)) & " " & Hex(x(ms + 8)) & " " & Hex(x(ms + 9)), tetLogInsteon)
932939
' --> I assume this happened because I requested the data, and want the rest of it. So now
933940
' Send 02 6A to get next record (e.g. continue reading link database from PLM)
934941
data(0) = 2 ' all commands start with 2
@@ -946,7 +953,7 @@
946953
If DataAvailable >= 6 Then
947954
x_Start = MessageEnd
948955
ToAddress = Hex(x(ms + 4)) & "." & Hex(x(ms + 5)) & "." & Hex(x(ms + 6))
949-
My.Application.Log.WriteEntry("PLM: ALL-Link (Group Broadcast) Cleanup Failure Report 0x56 Data: " & Hex(x(ms + 2)) & " Group: " & Hex(x(ms + 3)) & " Address: " & ToAddress, TraceEventType.Verbose)
956+
My.Application.Log.WriteEntry("PLM: ALL-Link (Group Broadcast) Cleanup Failure Report 0x56 Data: " & Hex(x(ms + 2)) & " Group: " & Hex(x(ms + 3)) & " Address: " & ToAddress, tetLogInsteon)
950957
End If
951958
Case 97 ' 0x061 Sent ALL-Link (Group Broadcast) command - 4 bytes
952959
MessageEnd = ms + 5
@@ -962,7 +969,7 @@
962969
Case Else
963970
strTemp = strTemp & Hex(x(ms + 5)) & " (?)"
964971
End Select
965-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
972+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
966973
End If
967974
Case 102 ' 0x066 Set Host Device Category - 4 bytes
968975
MessageEnd = ms + 5
@@ -980,7 +987,7 @@
980987
Case Else
981988
strTemp = strTemp & Hex(x(ms + 5)) & " (?)"
982989
End Select
983-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
990+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
984991
End If
985992
Case 115 ' 0x073 Get IM Configuration - 4 bytes
986993
MessageEnd = ms + 5
@@ -994,7 +1001,7 @@
9941001
If x(ms + 2) And 16 Then strTemp = strTemp & " (disable deadman comm feature)"
9951002
If x(ms + 2) And (128 + 64 + 32 + 16) Then strTemp = strTemp & " (default)"
9961003
strTemp = strTemp & " Data: " & Hex(x(ms + 3)) & " " & Hex(x(ms + 4)) & " ACK: " & Hex(x(ms + 5))
997-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1004+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
9981005
End If
9991006
Case 100 ' 0x064 Start ALL-Linking, echoed - 3 bytes
10001007
MessageEnd = ms + 4
@@ -1021,7 +1028,7 @@
10211028
Case Else
10221029
strTemp = strTemp & Hex(x(ms + 4)) & " (?)"
10231030
End Select
1024-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1031+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
10251032
End If
10261033
Case 113 ' 0x071 Set Insteon ACK message two bytes - 3 bytes
10271034
MessageEnd = ms + 4
@@ -1032,7 +1039,7 @@
10321039
For i = 2 To 4
10331040
strTemp = strTemp & Hex(x(ms + i)) & " "
10341041
Next
1035-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1042+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
10361043
End If
10371044
Case 104, 107, 112 ' 0x068 Set Insteon ACK message byte, 0x06B Set IM Configuration, 0x070 Set Insteon NAK message byte
10381045
' 2 bytes
@@ -1044,7 +1051,7 @@
10441051
For i = 0 To 3
10451052
strTemp = strTemp & Hex(x(ms + i)) & " "
10461053
Next
1047-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1054+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
10481055
End If
10491056
Case 88 ' 0x058 ALL-Link cleanup status report - 1 byte
10501057
MessageEnd = ms + 2
@@ -1060,7 +1067,7 @@
10601067
Case Else
10611068
strTemp = strTemp & Hex(x(ms + 2)) & " (?)"
10621069
End Select
1063-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1070+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
10641071
End If
10651072
Case 84, 103, 108, 109, 110, 114
10661073
' 0x054 Button (on PLM) event, 0x067 Reset the IM, 0x06C Get ALL-Link record for sender, 0x06D LED On, 0x06E LED Off, 0x072 RF Sleep
@@ -1073,7 +1080,7 @@
10731080
For i = 0 To 2
10741081
strTemp = strTemp & Hex(x(ms + i)) & " "
10751082
Next
1076-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1083+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
10771084
End If
10781085
Case 101 ' 0x065 Cancel ALL-Linking - 1 byte
10791086
MessageEnd = ms + 2
@@ -1089,7 +1096,7 @@
10891096
Case Else
10901097
strTemp = strTemp & Hex(x(ms + 2)) & " (?)"
10911098
End Select
1092-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1099+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
10931100
End If
10941101
Case 105 ' 0x069 Get First ALL-Link record
10951102
MessageEnd = ms + 2
@@ -1103,7 +1110,7 @@
11031110
Case 21
11041111
strTemp = strTemp & " (NAK - no links in database)"
11051112
End Select
1106-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1113+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
11071114
End If
11081115
Case 106 ' 0x06A Get Next ALL-Link record
11091116
MessageEnd = ms + 2
@@ -1117,7 +1124,7 @@
11171124
Case 21
11181125
strTemp = strTemp & " (NAK - no more links in database)"
11191126
End Select
1120-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1127+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
11211128
End If
11221129
Case 111 ' 0x06F Manage ALL-Link record - 10 bytes
11231130
MessageEnd = ms + 11
@@ -1151,7 +1158,7 @@
11511158
Case Else
11521159
strTemp = strTemp & Hex(x(ms + 11)) & " (?)"
11531160
End Select
1154-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1161+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
11551162
End If
11561163
Case Else
11571164
' in principle this shouldn't happen... unless there are undocumented PLM messages (probably!)
@@ -1161,7 +1168,7 @@
11611168
For i = 0 To DataAvailable
11621169
strTemp = strTemp & Hex(x(ms + DataAvailable))
11631170
Next
1164-
My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose)
1171+
My.Application.Log.WriteEntry(strTemp, tetLogInsteon)
11651172
Debug.WriteLine("Unrecognized command received " & Hex(x(ms)) & " " & Hex(x(ms + 1)) & " " & Hex(x(ms + 2)))
11661173
End Select
11671174

modPing.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
End Function
6666

6767
Private Sub PingInternet(source As Object, e As System.Timers.ElapsedEventArgs)
68-
My.Application.Log.WriteEntry("Checking Internet connectivity")
68+
My.Application.Log.WriteEntry("Checking Internet connectivity", TraceEventType.Verbose)
6969
Dim response As String = ""
7070

7171
response = Ping(My.Settings.Ping_InternetCheckAddress)

0 commit comments

Comments
 (0)