Rev 1649 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1649 | Rev 1650 | ||
|---|---|---|---|
| Line 40... | Line 40... | ||
| 40 | } |
40 | } |
| 41 | 41 | ||
| 42 | return true; |
42 | return true; |
| 43 | } |
43 | } |
| 44 | Console_RegisterCommand(Sensor_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases(), Sensor_Intervals()); }); |
44 | Console_RegisterCommand(Sensor_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases(), Sensor_Intervals()); }); |
| 45 | - | ||
| 46 | function Sensor_GetLastValue(alias_name) |
- | |
| 47 | { |
- | |
| 48 | if (arguments.length < 1) |
- | |
| 49 | { |
- | |
| 50 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
- | |
| 51 | return false; |
- | |
| 52 | } |
- | |
| 53 | - | ||
| 54 | var aliases_data = Module_ResolveAlias(alias_name, Sensor_ModuleNames); |
- | |
| 55 | var found = false; |
- | |
| 56 | - | ||
| 57 | for (var name in aliases_data) |
- | |
| 58 | { |
- | |
| 59 | var last_value_string = Storage_GetParameter("SensorValueList", alias_name); |
- | |
| 60 | - | ||
| 61 | if (last_value_string) |
- | |
| 62 | { |
- | |
| 63 | var last_value = eval("(" + last_value_string + ")"); |
- | |
| 64 | - | ||
| 65 | for (var type_name in last_value) |
- | |
| 66 | { |
- | |
| 67 | var date = new Date(last_value[type_name]["timestamp"] * 1000); |
- | |
| 68 | - | ||
| 69 | Log("\033[96m" + type_name + ": \033[0;1m" + last_value[type_name]["value"] + "\033[0m at " + date.toString() + "\n"); |
- | |
| 70 | } |
- | |
| 71 | } |
- | |
| 72 | else |
- | |
| 73 | { |
- | |
| 74 | Log("\033[32mNo value is stored for " + name + ".\033[0m\n"); |
- | |
| 75 | } |
- | |
| 76 | - | ||
| 77 | found = true; |
- | |
| 78 | } |
- | |
| 79 | - | ||
| 80 | if (!found) |
- | |
| 81 | { |
- | |
| 82 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
- | |
| 83 | return false; |
- | |
| 84 | } |
- | |
| 85 | - | ||
| 86 | return true; |
- | |
| 87 | } |
- | |
| 88 | Console_RegisterCommand(Sensor_GetLastValue, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases()); }); |
- | |
| 89 | 45 | ||
| 90 | function Sensor_OnMessage(module_name, module_id, command, variables) |
46 | function Sensor_OnMessage(module_name, module_id, command, variables) |
| 91 | { |
47 | { |
| 92 | if (in_array(Sensor_ModuleNames, module_name)) |
48 | if (in_array(Sensor_ModuleNames, module_name)) |
| 93 | { |
49 | { |
| Line 102... | Line 58... | ||
| 102 | case "Phonenumber": |
58 | case "Phonenumber": |
| 103 | { |
59 | { |
| 104 | for (var alias_name in aliases_data) |
60 | for (var alias_name in aliases_data) |
| 105 | { |
61 | { |
| 106 | var last_value = {}; |
62 | var last_value = {}; |
| 107 | var last_value_string = Storage_GetParameter(" |
63 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 108 | 64 | ||
| 109 | if (last_value_string) |
65 | if (last_value_string) |
| 110 | { |
66 | { |
| 111 | last_value = eval("(" + last_value_string + ")"); |
67 | last_value = eval("(" + last_value_string + ")"); |
| 112 | } |
68 | } |
| 113 | 69 | ||
| 114 | last_value[command] = { "value" : variables["Number"], "timestamp" : get_time() }; |
70 | last_value[command] = { "value" : variables["Number"], "timestamp" : get_time() }; |
| 115 | 71 | ||
| 116 |
|
72 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 117 | } |
73 | } |
| 118 | 74 | ||
| 119 | break; |
75 | break; |
| 120 | } |
76 | } |
| 121 | case "Voltage": |
77 | case "Voltage": |
| Line 128... | Line 84... | ||
| 128 | { |
84 | { |
| 129 | continue; |
85 | continue; |
| 130 | } |
86 | } |
| 131 | 87 | ||
| 132 | var last_value = {}; |
88 | var last_value = {}; |
| 133 | var last_value_string = Storage_GetParameter(" |
89 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 134 | 90 | ||
| 135 | if (last_value_string) |
91 | if (last_value_string) |
| 136 | { |
92 | { |
| 137 | last_value = eval("(" + last_value_string + ")"); |
93 | last_value = eval("(" + last_value_string + ")"); |
| 138 | } |
94 | } |
| 139 | 95 | ||
| 140 | last_value[command] = { "value" : variables["Value"], "timestamp" : get_time() }; |
96 | last_value[command] = { "value" : variables["Value"], "timestamp" : get_time() }; |
| 141 | 97 | ||
| 142 | Storage_SetParameter(" |
98 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 143 | } |
99 | } |
| 144 | 100 | ||
| 145 | break; |
101 | break; |
| 146 | } |
102 | } |
| 147 | } |
103 | } |