Rev 1925 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1925 | Rev 2305 | ||
|---|---|---|---|
| 1 | 1 | ||
| 2 | Counter_ModuleNames = [ "counter" ]; |
2 | Counter_ModuleNames = [ "counter" ]; |
| 3 | Counter_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
3 | Counter_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
| 4 | Counter_Count = function() { return [ 0, 500, 1000, 5000, 10000 ]; }; |
4 | Counter_Count = function() { return [ 0, 500, 1000, 5000, 10000 ]; }; |
| 5 | Counter_Aliases = function() { return Module_GetAliasNames(Counter_ModuleNames); }; |
5 | Counter_Aliases = function() { return Module_GetAliasNames(Counter_ModuleNames); }; |
| 6 | Counter_AvailableIds = function() { return Module_GetAvailableIds(Counter_ModuleNames); }; |
6 | Counter_AvailableIds = function() { return Module_GetAvailableIds(Counter_ModuleNames); }; |
| 7 | 7 | ||
| 8 | function Counter_SetCount(alias_name, count) |
8 | function Counter_SetCount(alias_name, count) |
| 9 | { |
9 | { |
| 10 | if (arguments.length < 2) |
10 | if (arguments.length < 2) |
| 11 | { |
11 | { |
| 12 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
12 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 13 | return false; |
13 | return false; |
| 14 | } |
14 | } |
| 15 | 15 | ||
| 16 | var aliases_data = Module_ResolveAlias(alias_name, Counter_ModuleNames); |
16 | var aliases_data = Module_ResolveAlias(alias_name, Counter_ModuleNames); |
| 17 | var found = false; |
17 | var found = false; |
| 18 | 18 | ||
| 19 | for (var name in aliases_data) |
19 | for (var name in aliases_data) |
| 20 | { |
20 | { |
| - | 21 | var variables = { |
|
| - | 22 | "PinId" : aliases_data[name]["specific"]["PinId"], |
|
| 21 |
|
23 | "Count" : count }; |
| 22 | 24 | ||
| 23 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "setCounter", variables)) |
25 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "setCounter", variables)) |
| 24 | { |
26 | { |
| 25 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
27 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 26 | } |
28 | } |
| 27 | else |
29 | else |
| 28 | { |
30 | { |
| 29 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
31 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 30 | } |
32 | } |
| 31 | 33 | ||
| 32 | found = true; |
34 | found = true; |
| 33 | } |
35 | } |
| 34 | 36 | ||
| 35 | if (!found) |
37 | if (!found) |
| 36 | { |
38 | { |
| 37 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
39 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 38 | return false; |
40 | return false; |
| 39 | } |
41 | } |
| 40 | 42 | ||
| 41 | return true; |
43 | return true; |
| 42 | } |
44 | } |
| 43 | Console_RegisterCommand(Counter_SetCount, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Counter_Aliases(), Counter_Count()); }); |
45 | Console_RegisterCommand(Counter_SetCount, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Counter_Aliases(), Counter_Count()); }); |
| 44 | 46 | ||
| 45 | function Counter_SetReportInterval(alias_name, interval) |
47 | function Counter_SetReportInterval(alias_name, interval) |
| 46 | { |
48 | { |
| 47 | if (arguments.length < 2) |
49 | if (arguments.length < 2) |
| 48 | { |
50 | { |
| 49 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
51 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 50 | return false; |
52 | return false; |
| 51 | } |
53 | } |
| 52 | 54 | ||
| 53 | var aliases_data = Module_ResolveAlias(alias_name, Counter_ModuleNames); |
55 | var aliases_data = Module_ResolveAlias(alias_name, Counter_ModuleNames); |
| 54 | var found = false; |
56 | var found = false; |
| 55 | 57 | ||
| 56 | for (var name in aliases_data) |
58 | for (var name in aliases_data) |
| 57 | { |
59 | { |
| 58 | var variables = {"Time" : interval }; |
60 | var variables = {"Time" : interval }; |
| 59 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
61 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
| 60 | { |
62 | { |
| 61 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
63 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 62 | } |
64 | } |
| 63 | else |
65 | else |
| 64 | { |
66 | { |
| 65 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
67 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 66 | } |
68 | } |
| 67 | 69 | ||
| 68 | found = true; |
70 | found = true; |
| 69 | } |
71 | } |
| 70 | 72 | ||
| 71 | if (!found) |
73 | if (!found) |
| 72 | { |
74 | { |
| 73 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
75 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 74 | return false; |
76 | return false; |
| 75 | } |
77 | } |
| 76 | 78 | ||
| 77 | return true; |
79 | return true; |
| 78 | } |
80 | } |
| 79 | Console_RegisterCommand(Counter_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Counter_Aliases(), Counter_Intervals()); }); |
81 | Console_RegisterCommand(Counter_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Counter_Aliases(), Counter_Intervals()); }); |
| 80 | 82 | ||
| 81 | function Counter_OnMessage(module_name, module_id, command, variables) |
83 | function Counter_OnMessage(module_name, module_id, command, variables) |
| 82 | { |
84 | { |
| 83 | if (in_array(Counter_ModuleNames, module_name)) |
85 | if (in_array(Counter_ModuleNames, module_name)) |
| 84 | { |
86 | { |
| 85 | var aliases_data = Module_LookupAliases({ |
87 | var aliases_data = Module_LookupAliases({ |
| 86 | "module_name" : module_name, |
88 | "module_name" : module_name, |
| 87 | "module_id" : module_id, |
89 | "module_id" : module_id, |
| 88 | "group" : false |
90 | "group" : false |
| 89 | }); |
91 | }); |
| 90 | 92 | ||
| 91 | switch (command) |
93 | switch (command) |
| 92 | { |
94 | { |
| 93 | case "Counter": |
95 | case "Counter": |
| 94 | { |
96 | { |
| 95 | for (var alias_name in aliases_data) |
97 | for (var alias_name in aliases_data) |
| 96 | { |
98 | { |
| 97 | if (aliases_data[alias_name]["specific"]["PinId"] != variables["PinId"]) |
99 | if (aliases_data[alias_name]["specific"]["PinId"] != variables["PinId"]) |
| 98 | { |
100 | { |
| 99 | continue; |
101 | continue; |
| 100 | } |
102 | } |
| 101 | 103 | ||
| 102 | var last_value = {}; |
104 | var last_value = {}; |
| 103 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
105 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 104 | 106 | ||
| 105 | if (last_value_string) |
107 | if (last_value_string) |
| 106 | { |
108 | { |
| 107 | last_value = eval("(" + last_value_string + ")"); |
109 | last_value = eval("(" + last_value_string + ")"); |
| 108 | } |
110 | } |
| 109 | 111 | ||
| 110 | last_value[command] = { "value" : variables["Count"], "timestamp" : get_time() }; |
112 | last_value[command] = { "value" : variables["Count"], "timestamp" : get_time() }; |
| 111 | 113 | ||
| 112 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
114 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 113 | } |
115 | } |
| 114 | break; |
116 | break; |
| 115 | } |
117 | } |
| 116 | } |
118 | } |
| 117 | } |
119 | } |
| 118 | } |
120 | } |
| 119 | Module_RegisterToOnMessage("all", Counter_OnMessage); |
121 | Module_RegisterToOnMessage("all", Counter_OnMessage); |
| 120 | 122 | ||