|
30 | 30 |
|
31 | 31 | Private serialLock As New Object |
32 | 32 | Dim tmrIThermCheckTimer As System.Timers.Timer |
| 33 | + Dim tetLogInsteon As System.Diagnostics.TraceEventType = TraceEventType.Verbose |
33 | 34 |
|
34 | 35 | Function AddInsteonDeviceDb(ByVal strAddress As String, ByVal DevCat As Short, ByVal SubCat As Short, ByVal Firmware As Short) As String |
35 | 36 | If CheckDbForInsteon(strAddress) = 0 Then |
|
366 | 367 | AddHandler SerialPLM.DataReceived, AddressOf SerialPLM_DataReceived |
367 | 368 |
|
368 | 369 | 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 | + |
369 | 376 | Return "Insteon module loaded" |
370 | 377 | Else |
371 | 378 | My.Application.Log.WriteEntry("Insteon module is disabled, module not loaded") |
|
460 | 467 | x_Start = MessageEnd |
461 | 468 | ' Display message |
462 | 469 | 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) |
464 | 471 | ' Set the PLM as the controller |
465 | 472 | ' --> I use this to verify the PLM is connected, disable some menu options, enable others, etc |
466 | 473 | End If |
|
492 | 499 | For i = 0 To DataAvailable |
493 | 500 | strTemp = strTemp & Hex(x(ms + i)) & " " |
494 | 501 | Next |
495 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 502 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
496 | 503 |
|
497 | 504 | strTemp = "PLM: Insteon Received: From: " & FromAddress & " To: " & ToAddress |
498 | 505 | If ToAddress = PLM_Address Then |
|
538 | 545 | Else |
539 | 546 | strTemp = strTemp & " Command1: " & Hex(Command1) & " (" & modInsteon.InsteonCommandLookup(Command1) & ")" & " Command2: " & Hex(Command2) |
540 | 547 | End If |
541 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 548 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
542 | 549 |
|
543 | 550 | If Flags = 139 AndAlso (Command1 = 1 OrElse Command1 = 2) Then |
544 | 551 | ' 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) |
546 | 553 | AddInsteonDeviceDb(FromAddress, x(ms + 5), x(ms + 6), x(ms + 7)) |
547 | 554 | End If |
548 | 555 |
|
|
613 | 620 | Else |
614 | 621 | strTemp = strTemp & FromName & " broadcast command " & Hex(Command1) |
615 | 622 | End If |
616 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 623 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
617 | 624 | Insteon(IAddress).LastCommand = Command1 |
618 | 625 | Insteon(IAddress).LastFlags = Flags And 224 |
619 | 626 | Insteon(IAddress).LastTime = Now |
|
669 | 676 | If DeviceType = "SmokeBridge" Then |
670 | 677 | strTemp = strTemp & " Smoke Bridge: " & InsteonSmokeBridgeResponse(Group) |
671 | 678 | End If |
672 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 679 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
673 | 680 | ' Handle incoming event and play sounds |
674 | 681 | ' --> at this point I play a WAV file and run any macro associated with the device |
675 | 682 | Case 32, 96 ' 001 ACK direct message, 011 ACK group cleanup direct message |
|
682 | 689 | Case 160, 224 ' 101 NAK direct message, 111 NAK group cleanup direct message |
683 | 690 | ' Command received by another device but failed - display message in log |
684 | 691 | 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) |
686 | 693 | Insteon(IAddress).LastCommand = Command1 |
687 | 694 | Insteon(IAddress).LastFlags = Flags And 224 |
688 | 695 | Insteon(IAddress).LastTime = Now |
|
736 | 743 | strTemp = strTemp & Hex(x(ms + i)) & " " |
737 | 744 | Next |
738 | 745 | 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) |
740 | 747 | AddInsteonDeviceDb(FromAddress, x(ms + 15), x(ms + 16), x(ms + 17)) |
741 | 748 | Case 1 ' FX Username Response |
742 | 749 | strTemp = strTemp & " FX Username Response:" & " D1-D8 FX Command Username: " |
|
792 | 799 | strTemp = strTemp & Hex(x(ms + i)) & " " |
793 | 800 | Next |
794 | 801 | End If |
795 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 802 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
796 | 803 | End If |
797 | 804 | ' I’m not planning on actually doing anything with this data, just displayed |
798 | 805 | Case 82 ' 0x052 X10 Received |
|
816 | 823 | ' Now actually process the event |
817 | 824 | ' Does it have a name? |
818 | 825 | '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) |
820 | 827 | 'If LoggedIn And HasName Then frmHack.WriteWebtrix(Blue, VB6.Format(TimeOfDay) & " ") |
821 | 828 | ' Write command to event log |
822 | 829 | ' Handle incoming event |
|
833 | 840 | Case Else ' invalid data |
834 | 841 | strTemp = strTemp & "Unrecognized X10: " & Hex(x(ms + 2)) & " " & Hex(x(ms + 3)) |
835 | 842 | End Select |
836 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 843 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
837 | 844 | End If |
838 | 845 | Case 98 ' 0x062 Send Insteon standard OR extended message |
839 | 846 | ' PLM is just echoing the last command sent, discard this: 7 or 21 bytes |
|
850 | 857 | For i = 0 To 22 |
851 | 858 | strTemp = strTemp & Hex(x(ms + i)) & " " |
852 | 859 | Next |
853 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 860 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
854 | 861 | End If |
855 | 862 | Else |
856 | 863 | ' Standard message |
|
859 | 866 | For i = 0 To 8 |
860 | 867 | strTemp = strTemp & Hex(x(ms + i)) & " " |
861 | 868 | Next |
862 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 869 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
863 | 870 | End If |
864 | 871 | End If |
865 | 872 | Case 99 ' 0x063 Sent X10 |
|
893 | 900 | Case Else |
894 | 901 | strTemp = strTemp & Hex(x(ms + 4)) & " (?)" |
895 | 902 | End Select |
896 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 903 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
897 | 904 | End If |
898 | 905 | Case 83 ' 0x053 ALL-Linking complete - 8 bytes of data |
899 | 906 | MessageEnd = ms + 9 |
|
912 | 919 | FromAddress = Hex(x(ms + 4)) & "." & Hex(x(ms + 5)) & "." & Hex(x(ms + 6)) |
913 | 920 | strTemp = strTemp & " Group: " & Hex(x(ms + 3)) & " ID: " & FromAddress & " DevCat: " & Hex(x(ms + 7)) & " SubCat: " & Hex(x(ms + 8)) & " Firmware: " & Hex(x(ms + 9)) |
914 | 921 | 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) |
917 | 924 | AddInsteonDeviceDb(FromAddress, x(ms + 7), x(ms + 8), x(ms + 9)) |
918 | 925 | End If |
919 | 926 | Case 87 ' 0x057 ALL-Link record response - 8 bytes of data |
|
924 | 931 | FromAddress = Hex(x(ms + 4)) & "." & Hex(x(ms + 5)) & "." & Hex(x(ms + 6)) |
925 | 932 | ' Check if FromAddress is in device database, if not add it |
926 | 933 | If InsteonNum(FromAddress) = 0 Then |
927 | | - My.Application.Log.WriteEntry("ADD CASE 3", TraceEventType.Verbose) |
| 934 | + My.Application.Log.WriteEntry("ADD CASE 3", tetLogInsteon) |
928 | 935 | ' TODO: Make this: AddInsteonDevice(FromAddress) |
929 | 936 | ' TODO: Make this: SortInsteon() |
930 | 937 | 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) |
932 | 939 | ' --> I assume this happened because I requested the data, and want the rest of it. So now |
933 | 940 | ' Send 02 6A to get next record (e.g. continue reading link database from PLM) |
934 | 941 | data(0) = 2 ' all commands start with 2 |
|
946 | 953 | If DataAvailable >= 6 Then |
947 | 954 | x_Start = MessageEnd |
948 | 955 | 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) |
950 | 957 | End If |
951 | 958 | Case 97 ' 0x061 Sent ALL-Link (Group Broadcast) command - 4 bytes |
952 | 959 | MessageEnd = ms + 5 |
|
962 | 969 | Case Else |
963 | 970 | strTemp = strTemp & Hex(x(ms + 5)) & " (?)" |
964 | 971 | End Select |
965 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 972 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
966 | 973 | End If |
967 | 974 | Case 102 ' 0x066 Set Host Device Category - 4 bytes |
968 | 975 | MessageEnd = ms + 5 |
|
980 | 987 | Case Else |
981 | 988 | strTemp = strTemp & Hex(x(ms + 5)) & " (?)" |
982 | 989 | End Select |
983 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 990 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
984 | 991 | End If |
985 | 992 | Case 115 ' 0x073 Get IM Configuration - 4 bytes |
986 | 993 | MessageEnd = ms + 5 |
|
994 | 1001 | If x(ms + 2) And 16 Then strTemp = strTemp & " (disable deadman comm feature)" |
995 | 1002 | If x(ms + 2) And (128 + 64 + 32 + 16) Then strTemp = strTemp & " (default)" |
996 | 1003 | 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) |
998 | 1005 | End If |
999 | 1006 | Case 100 ' 0x064 Start ALL-Linking, echoed - 3 bytes |
1000 | 1007 | MessageEnd = ms + 4 |
|
1021 | 1028 | Case Else |
1022 | 1029 | strTemp = strTemp & Hex(x(ms + 4)) & " (?)" |
1023 | 1030 | End Select |
1024 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1031 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1025 | 1032 | End If |
1026 | 1033 | Case 113 ' 0x071 Set Insteon ACK message two bytes - 3 bytes |
1027 | 1034 | MessageEnd = ms + 4 |
|
1032 | 1039 | For i = 2 To 4 |
1033 | 1040 | strTemp = strTemp & Hex(x(ms + i)) & " " |
1034 | 1041 | Next |
1035 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1042 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1036 | 1043 | End If |
1037 | 1044 | Case 104, 107, 112 ' 0x068 Set Insteon ACK message byte, 0x06B Set IM Configuration, 0x070 Set Insteon NAK message byte |
1038 | 1045 | ' 2 bytes |
|
1044 | 1051 | For i = 0 To 3 |
1045 | 1052 | strTemp = strTemp & Hex(x(ms + i)) & " " |
1046 | 1053 | Next |
1047 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1054 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1048 | 1055 | End If |
1049 | 1056 | Case 88 ' 0x058 ALL-Link cleanup status report - 1 byte |
1050 | 1057 | MessageEnd = ms + 2 |
|
1060 | 1067 | Case Else |
1061 | 1068 | strTemp = strTemp & Hex(x(ms + 2)) & " (?)" |
1062 | 1069 | End Select |
1063 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1070 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1064 | 1071 | End If |
1065 | 1072 | Case 84, 103, 108, 109, 110, 114 |
1066 | 1073 | ' 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 | 1080 | For i = 0 To 2 |
1074 | 1081 | strTemp = strTemp & Hex(x(ms + i)) & " " |
1075 | 1082 | Next |
1076 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1083 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1077 | 1084 | End If |
1078 | 1085 | Case 101 ' 0x065 Cancel ALL-Linking - 1 byte |
1079 | 1086 | MessageEnd = ms + 2 |
|
1089 | 1096 | Case Else |
1090 | 1097 | strTemp = strTemp & Hex(x(ms + 2)) & " (?)" |
1091 | 1098 | End Select |
1092 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1099 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1093 | 1100 | End If |
1094 | 1101 | Case 105 ' 0x069 Get First ALL-Link record |
1095 | 1102 | MessageEnd = ms + 2 |
|
1103 | 1110 | Case 21 |
1104 | 1111 | strTemp = strTemp & " (NAK - no links in database)" |
1105 | 1112 | End Select |
1106 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1113 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1107 | 1114 | End If |
1108 | 1115 | Case 106 ' 0x06A Get Next ALL-Link record |
1109 | 1116 | MessageEnd = ms + 2 |
|
1117 | 1124 | Case 21 |
1118 | 1125 | strTemp = strTemp & " (NAK - no more links in database)" |
1119 | 1126 | End Select |
1120 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1127 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1121 | 1128 | End If |
1122 | 1129 | Case 111 ' 0x06F Manage ALL-Link record - 10 bytes |
1123 | 1130 | MessageEnd = ms + 11 |
|
1151 | 1158 | Case Else |
1152 | 1159 | strTemp = strTemp & Hex(x(ms + 11)) & " (?)" |
1153 | 1160 | End Select |
1154 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1161 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1155 | 1162 | End If |
1156 | 1163 | Case Else |
1157 | 1164 | ' in principle this shouldn't happen... unless there are undocumented PLM messages (probably!) |
|
1161 | 1168 | For i = 0 To DataAvailable |
1162 | 1169 | strTemp = strTemp & Hex(x(ms + DataAvailable)) |
1163 | 1170 | Next |
1164 | | - My.Application.Log.WriteEntry(strTemp, TraceEventType.Verbose) |
| 1171 | + My.Application.Log.WriteEntry(strTemp, tetLogInsteon) |
1165 | 1172 | Debug.WriteLine("Unrecognized command received " & Hex(x(ms)) & " " & Hex(x(ms + 1)) & " " & Hex(x(ms + 2))) |
1166 | 1173 | End Select |
1167 | 1174 |
|
|
0 commit comments