Rev 2076 | Rev 2275 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2076 | Rev 2271 | ||
|---|---|---|---|
| 1 | 1 | ||
| 2 | PID_ModuleNames = [ "PID" ]; |
2 | PID_ModuleNames = [ "PID" ]; |
| 3 | PID_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
3 | PID_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
| 4 | //PID_Energy = function() { return [ 0, 500, 1000, 5000, 10000 ]; }; |
4 | //PID_Energy = function() { return [ 0, 500, 1000, 5000, 10000 ]; }; |
| 5 | PID_Temperatures = function() { return [ 20, 25, 30, 35 ]; }; |
5 | PID_Temperatures = function() { return [ 20, 25, 30, 35 ]; }; |
| - | 6 | PID_Constants = function() { return [ 0, 0.1, 0.5, 1, 10, 100, 1000 ]; }; |
|
| - | 7 | PID_TimeUnits = function() { return [ "s", "ms"]; }; |
|
| - | 8 | PID_Times = function() { return [ 1, 5, 10, 15, 20, 40, 60]; }; |
|
| 6 | PID_Aliases = function() { return Module_GetAliasNames(PID_ModuleNames); }; |
9 | PID_Aliases = function() { return Module_GetAliasNames(PID_ModuleNames); }; |
| 7 | PID_AvailableIds = function() { return Module_GetAvailableIds(PID_ModuleNames); }; |
10 | PID_AvailableIds = function() { return Module_GetAvailableIds(PID_ModuleNames); }; |
| 8 | 11 | ||
| 9 | function PID_SetReportInterval(alias_name, interval) |
12 | function PID_SetReportInterval(alias_name, interval) |
| 10 | { |
13 | { |
| 11 | if (arguments.length < 2) |
14 | if (arguments.length < 2) |
| 12 | { |
15 | { |
| 13 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
16 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 14 | return false; |
17 | return false; |
| 15 | } |
18 | } |
| 16 | 19 | ||
| 17 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
20 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
| 18 | var found = false; |
21 | var found = false; |
| 19 | 22 | ||
| 20 | for (var name in aliases_data) |
23 | for (var name in aliases_data) |
| 21 | { |
24 | { |
| 22 | var variables = {"Time" : interval }; |
25 | var variables = {"Time" : interval }; |
| 23 | 26 | ||
| 24 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
27 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
| 25 | { |
28 | { |
| 26 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
29 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 27 | } |
30 | } |
| 28 | else |
31 | else |
| 29 | { |
32 | { |
| 30 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
33 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 31 | } |
34 | } |
| 32 | 35 | ||
| 33 | found = true; |
36 | found = true; |
| 34 | } |
37 | } |
| 35 | 38 | ||
| 36 | if (!found) |
39 | if (!found) |
| 37 | { |
40 | { |
| 38 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
41 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 39 | return false; |
42 | return false; |
| 40 | } |
43 | } |
| 41 | 44 | ||
| 42 | return true; |
45 | return true; |
| 43 | } |
46 | } |
| 44 | Console_RegisterCommand(PID_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Intervals()); }); |
47 | Console_RegisterCommand(PID_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Intervals()); }); |
| 45 | 48 | ||
| 46 | 49 | ||
| 47 | function PID_setValue(alias_name, temperature) |
50 | function PID_setValue(alias_name, temperature) |
| 48 | { |
51 | { |
| 49 | if (arguments.length < 2) |
52 | if (arguments.length < 2) |
| 50 | { |
53 | { |
| 51 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
54 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 52 | return false; |
55 | return false; |
| 53 | } |
56 | } |
| 54 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
57 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
| 55 | var found = false; |
58 | var found = false; |
| 56 | 59 | ||
| 57 | Log ("Called SetValue: "+temperature+"\n"); |
60 | Log ("Called SetValue: "+temperature+"\n"); |
| 58 | 61 | ||
| 59 | for (var name in aliases_data) |
62 | for (var name in aliases_data) |
| 60 | { |
63 | { |
| 61 | var variables = { "Value" : temperature, |
64 | var variables = { "Value" : temperature, |
| 62 | "SensorId" : 0 }; |
65 | "SensorId" : 0 }; |
| 63 | 66 | ||
| 64 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Temperature_Celsius", variables)) |
67 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Temperature_Celsius", variables)) |
| 65 | { |
68 | { |
| 66 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
69 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 67 | } |
70 | } |
| 68 | else |
71 | else |
| 69 | { |
72 | { |
| 70 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
73 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 71 | } |
74 | } |
| 72 | 75 | ||
| 73 | found = true; |
76 | found = true; |
| 74 | } |
77 | } |
| 75 | 78 | ||
| 76 | if (!found) |
79 | if (!found) |
| 77 | { |
80 | { |
| 78 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
81 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 79 | return false; |
82 | return false; |
| 80 | } |
83 | } |
| 81 | 84 | ||
| 82 | return true; |
85 | return true; |
| 83 | } |
86 | } |
| 84 | Console_RegisterCommand(PID_setValue, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Temperatures()); }); |
87 | Console_RegisterCommand(PID_setValue, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Temperatures()); }); |
| 85 | 88 | ||
| 86 | 89 | ||
| 87 | function PID_setParameters(alias_name, KP,KI,KD,Time,Unit) |
90 | function PID_setParameters(alias_name, KP,KI,KD,Time,Unit) |
| 88 | { |
91 | { |
| 89 | if (arguments.length < 6) |
92 | if (arguments.length < 6) |
| 90 | { |
93 | { |
| 91 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
94 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 92 | return false; |
95 | return false; |
| 93 | } |
96 | } |
| 94 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
97 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
| 95 | var found = false; |
98 | var found = false; |
| 96 | 99 | ||
| 97 | for (var name in aliases_data) |
100 | for (var name in aliases_data) |
| 98 | { |
101 | { |
| 99 | var variables = { "K_P" : KP, |
102 | var variables = { "K_P" : KP, |
| 100 | "K_I" : KI, |
103 | "K_I" : KI, |
| 101 | "K_D" : KD, |
104 | "K_D" : KD, |
| 102 | "RegulatorTime" : Time, |
105 | "RegulatorTime" : Time, |
| 103 | "TimeUnit" : Unit }; |
106 | "TimeUnit" : Unit }; |
| - | 107 | var variables_P_I = { "K_P" : KP, |
|
| 104 | 108 | "K_I" : KI }; |
|
| - | 109 | var variables_D_T = { "K_D" : KD, |
|
| - | 110 | "RegulatorTime" : Time, |
|
| - | 111 | "TimeUnit" : Unit }; |
|
| 105 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables)) |
112 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables)) |
| 106 | { |
113 | { |
| 107 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m"); |
114 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m"); |
| 108 | Log("\033[32mK_P = " + KP + "K_I = " + KI + "K_D = " + KD + "RegTime = " + Time + "Unit = " + Unit + ".\033[0m\n"); |
115 | Log("\033[32mK_P = " + KP + "K_I = " + KI + "K_D = " + KD + "RegTime = " + Time + "Unit = " + Unit + ".\033[0m\n"); |
| - | 116 | } |
|
| - | 117 | else |
|
| - | 118 | { |
|
| - | 119 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
|
| - | 120 | } |
|
| - | 121 | ||
| - | 122 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_P_I", variables_P_I)) |
|
| - | 123 | { |
|
| - | 124 | Log("\033[32mK_P = " + KP + "K_I = " + KI + ".\033[0m\n"); |
|
| - | 125 | } |
|
| - | 126 | else |
|
| - | 127 | { |
|
| - | 128 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
|
| - | 129 | } |
|
| - | 130 | ||
| - | 131 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_D_T", variables_D_T)) |
|
| - | 132 | { |
|
| - | 133 | Log("\033[32mK_D = " + KD + "RegTime = " + Time + "Unit = " + Unit + ".\033[0m\n"); |
|
| 109 | } |
134 | } |
| 110 | else |
135 | else |
| 111 | { |
136 | { |
| 112 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
137 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 113 | } |
138 | } |
| 114 | 139 | ||
| 115 | found = true; |
140 | found = true; |
| 116 | } |
141 | } |
| 117 | 142 | ||
| 118 | if (!found) |
143 | if (!found) |
| 119 | { |
144 | { |
| 120 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
145 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 121 | return false; |
146 | return false; |
| 122 | } |
147 | } |
| 123 | 148 | ||
| 124 | return true; |
149 | return true; |
| 125 | } |
150 | } |
| - | 151 | Console_RegisterCommand(PID_setParameters, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Constants(), PID_Constants(), PID_Constants(), PID_Times(), PID_TimeUnits()); }); |
|
| 126 | 152 | ||
| 127 | function PID_getConfiguration(alias_name) |
153 | function PID_getConfiguration(alias_name) |
| 128 | { |
154 | { |
| 129 | if (arguments.length < 1) |
155 | if (arguments.length < 1) |
| 130 | { |
156 | { |
| 131 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
157 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 132 | return false; |
158 | return false; |
| 133 | } |
159 | } |
| 134 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
160 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
| 135 | var found = false; |
161 | var found = false; |
| 136 | 162 | ||
| 137 | for (var name in aliases_data) |
163 | for (var name in aliases_data) |
| 138 | { |
164 | { |
| 139 | var variables = {}; |
165 | var variables = {}; |
| 140 | 166 | ||
| 141 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_SENSOR", variables)) |
167 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_SENSOR", variables)) |
| 142 | { |
168 | { |
| 143 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
169 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 144 | } |
170 | } |
| 145 | else |
171 | else |
| 146 | { |
172 | { |
| 147 | Log("\033[31mFailed to send command 1 to " + name + ".\033[0m\n"); |
173 | Log("\033[31mFailed to send command 1 to " + name + ".\033[0m\n"); |
| 148 | } |
174 | } |
| 149 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_ACTUATOR", variables)) |
175 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_ACTUATOR", variables)) |
| 150 | { |
176 | { |
| 151 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
177 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 152 | } |
178 | } |
| 153 | else |
179 | else |
| 154 | { |
180 | { |
| 155 | Log("\033[31mFailed to send command 2 to " + name + ".\033[0m\n"); |
181 | Log("\033[31mFailed to send command 2 to " + name + ".\033[0m\n"); |
| 156 | } |
182 | } |
| 157 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables)) |
183 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables)) |
| 158 | { |
184 | { |
| 159 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
185 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 160 | } |
186 | } |
| 161 | else |
187 | else |
| 162 | { |
188 | { |
| 163 | Log("\033[31mFailed to send command 3 to " + name + ".\033[0m\n"); |
189 | Log("\033[31mFailed to send command 3 to " + name + ".\033[0m\n"); |
| 164 | } |
190 | } |
| 165 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
191 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
| - | 192 | { |
|
| - | 193 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
|
| - | 194 | } |
|
| - | 195 | else |
|
| - | 196 | { |
|
| - | 197 | Log("\033[31mFailed to send command 4 to " + name + ".\033[0m\n"); |
|
| - | 198 | } |
|
| - | 199 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_P_I", variables)) |
|
| - | 200 | { |
|
| - | 201 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
|
| - | 202 | } |
|
| - | 203 | else |
|
| - | 204 | { |
|
| - | 205 | Log("\033[31mFailed to send command 5 to " + name + ".\033[0m\n"); |
|
| - | 206 | } |
|
| - | 207 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_D_T", variables)) |
|
| 166 | { |
208 | { |
| 167 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
209 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 168 | } |
210 | } |
| 169 | else |
211 | else |
| 170 | { |
212 | { |
| 171 | Log("\033[31mFailed to send command |
213 | Log("\033[31mFailed to send command 6 to " + name + ".\033[0m\n"); |
| 172 | } |
214 | } |
| 173 | - | ||
| 174 | found = true; |
215 | found = true; |
| 175 | } |
216 | } |
| 176 | 217 | ||
| 177 | if (!found) |
218 | if (!found) |
| 178 | { |
219 | { |
| 179 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
220 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 180 | return false; |
221 | return false; |
| 181 | } |
222 | } |
| 182 | 223 | ||
| 183 | return true; |
224 | return true; |
| 184 | } |
225 | } |
| 185 | Console_RegisterCommand(PID_getConfiguration, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases()); }); |
226 | Console_RegisterCommand(PID_getConfiguration, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases()); }); |
| 186 | 227 | ||
| 187 | function PID_OnMessage(module_name, module_id, command, variables) |
228 | function PID_OnMessage(module_name, module_id, command, variables) |
| 188 | { |
229 | { |
| 189 | if (in_array(PID_ModuleNames, module_name)) |
230 | if (in_array(PID_ModuleNames, module_name)) |
| 190 | { |
231 | { |
| 191 | var aliases_data = Module_LookupAliases({ |
232 | var aliases_data = Module_LookupAliases({ |
| 192 | "module_name" : module_name, |
233 | "module_name" : module_name, |
| 193 | "module_id" : module_id, |
234 | "module_id" : module_id, |
| 194 | "group" : false |
235 | "group" : false |
| 195 | }); |
236 | }); |
| 196 | 237 | ||
| 197 | switch (command) |
238 | switch (command) |
| 198 | { |
239 | { |
| 199 | case "DEBUG": |
240 | case "DEBUG": |
| 200 | for (var alias_name in aliases_data) |
241 | for (var alias_name in aliases_data) |
| 201 | { |
242 | { |
| 202 | var last_value = {}; |
243 | var last_value = {}; |
| 203 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
244 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 204 | 245 | ||
| 205 | if (last_value_string) |
246 | if (last_value_string) |
| 206 | { |
247 | { |
| 207 | last_value = eval("(" + last_value_string + ")"); |
248 | last_value = eval("(" + last_value_string + ")"); |
| 208 | } |
249 | } |
| 209 | 250 | ||
| 210 | last_value["Debug"] = { "value" : { "P_term" : variables["P_term"],"I_term" : variables["I_term"],"D_term" : variables["D_term"],"Sum" : variables["Sum"] }, "timestamp" : get_time() }; |
251 | last_value["Debug"] = { "value" : { "P_term" : variables["P_term"],"I_term" : variables["I_term"],"D_term" : variables["D_term"],"Sum" : variables["Sum"] }, "timestamp" : get_time() }; |
| 211 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
252 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 212 | //Log("Got message DEBUG"); |
253 | //Log("Got message DEBUG"); |
| 213 | } |
254 | } |
| 214 | break; |
255 | break; |
| 215 | case "CONFIG_SENSOR": |
256 | case "CONFIG_SENSOR": |
| 216 | for (var alias_name in aliases_data) |
257 | for (var alias_name in aliases_data) |
| 217 | { |
258 | { |
| 218 | var last_value = {}; |
259 | var last_value = {}; |
| 219 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
260 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 220 | 261 | ||
| 221 | if (last_value_string) |
262 | if (last_value_string) |
| 222 | { |
263 | { |
| 223 | last_value = eval("(" + last_value_string + ")"); |
264 | last_value = eval("(" + last_value_string + ")"); |
| 224 | } |
265 | } |
| 225 | 266 | ||
| 226 | last_value["Sensor"] = { "value" : { "sensorModuleType" : variables["sensorModuleType"],"sensorModuleId" : variables["sensorModuleId"],"sensorId" : variables["sensorId"] }, "timestamp" : get_time() }; |
267 | last_value["Sensor"] = { "value" : { "sensorModuleType" : variables["sensorModuleType"],"sensorModuleId" : variables["sensorModuleId"],"sensorId" : variables["sensorId"] }, "timestamp" : get_time() }; |
| 227 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
268 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 228 | } |
269 | } |
| 229 | break; |
270 | break; |
| 230 | case "CONFIG_ACTUATOR": |
271 | case "CONFIG_ACTUATOR": |
| 231 | for (var alias_name in aliases_data) |
272 | for (var alias_name in aliases_data) |
| 232 | { |
273 | { |
| 233 | var last_value = {}; |
274 | var last_value = {}; |
| 234 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
275 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 235 | 276 | ||
| 236 | if (last_value_string) |
277 | if (last_value_string) |
| 237 | { |
278 | { |
| 238 | last_value = eval("(" + last_value_string + ")"); |
279 | last_value = eval("(" + last_value_string + ")"); |
| 239 | } |
280 | } |
| 240 | 281 | ||
| 241 | last_value["Actuator"] = { "value" : { "actuatorModuleType" : variables["actuatorModuleType"],"actuatorModuleId" : variables["actuatorModuleId"],"actuatorId" : variables["actuatorId"] }, "timestamp" : get_time() }; |
282 | last_value["Actuator"] = { "value" : { "actuatorModuleType" : variables["actuatorModuleType"],"actuatorModuleId" : variables["actuatorModuleId"],"actuatorId" : variables["actuatorId"] }, "timestamp" : get_time() }; |
| 242 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
283 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 243 | } |
284 | } |
| 244 | break; |
285 | break; |
| 245 | case "CONFIG_PARAMETER": |
286 | case "CONFIG_PARAMETER": |
| 246 | for (var alias_name in aliases_data) |
287 | for (var alias_name in aliases_data) |
| 247 | { |
288 | { |
| 248 | var last_value = {}; |
289 | var last_value = {}; |
| 249 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
290 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 250 | 291 | ||
| 251 | if (last_value_string) |
292 | if (last_value_string) |
| 252 | { |
293 | { |
| 253 | last_value = eval("(" + last_value_string + ")"); |
294 | last_value = eval("(" + last_value_string + ")"); |
| 254 | } |
295 | } |
| 255 | 296 | ||
| 256 | last_value["Parameters"] = { "value" : { "K_P" : variables["K_P"],"K_I" : variables["K_I"],"K_D" : variables["K_D"],"TimeUnit" : variables["TimeUnit"],"RegulatorTime" : variables["RegulatorTime"] }, "timestamp" : get_time() }; |
297 | last_value["Parameters"] = { "value" : { "K_P" : variables["K_P"],"K_I" : variables["K_I"],"K_D" : variables["K_D"],"TimeUnit" : variables["TimeUnit"],"RegulatorTime" : variables["RegulatorTime"] }, "timestamp" : get_time() }; |
| 257 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
298 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 258 | } |
299 | } |
| 259 | break; |
300 | break; |
| 260 | case "PID_STATUS": |
301 | case "PID_STATUS": |
| 261 | for (var alias_name in aliases_data) |
302 | for (var alias_name in aliases_data) |
| 262 | { |
303 | { |
| 263 | var last_value = {}; |
304 | var last_value = {}; |
| 264 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
305 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 265 | 306 | ||
| 266 | if (last_value_string) |
307 | if (last_value_string) |
| 267 | { |
308 | { |
| 268 | last_value = eval("(" + last_value_string + ")"); |
309 | last_value = eval("(" + last_value_string + ")"); |
| 269 | } |
310 | } |
| 270 | 311 | ||
| 271 | last_value["PID_status"] = { "value" : { "Measurment" : variables["Measurment"],"Reference" : variables["Reference"],"PWM" : variables["PWM"],"Sum" : variables["Sum"] }, "timestamp" : get_time() }; |
312 | last_value["PID_status"] = { "value" : { "Measurment" : variables["Measurment"],"Reference" : variables["Reference"],"PWM" : variables["PWM"],"Sum" : variables["Sum"] }, "timestamp" : get_time() }; |
| 272 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
313 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 273 | } |
314 | } |
| 274 | //log("PID status: mea:" + this.Measurment + " ref:" + this.Reference + " pwm:" + this.PWM/100 + " sum:" + this.Sum + "\n"); |
315 | //log("PID status: mea:" + this.Measurment + " ref:" + this.Reference + " pwm:" + this.PWM/100 + " sum:" + this.Sum + "\n"); |
| 275 | //this.callEvent("newValue", canMessage.getData("Id")); |
316 | //this.callEvent("newValue", canMessage.getData("Id")); |
| 276 | 317 | ||
| 277 | //var self = this; |
318 | //var self = this; |
| 278 | // this.myHTTP.request(function(result, header, content) { self.httpCallback(result, header, content); }, "linuxz.mine.nu/canlogg/add.php?measurment="+ this.Measurment + "&reference="+this.Reference+"&pwm="+this.PWM/100+"&sum="+this.Sum+"&p="+this.K_P+"&i="+this.K_I+"&d="+this.K_D+"&timeunit="+this.TimeUnit+"&pidtime="+this.RegulatorTime+""); |
319 | // this.myHTTP.request(function(result, header, content) { self.httpCallback(result, header, content); }, "linuxz.mine.nu/canlogg/add.php?measurment="+ this.Measurment + "&reference="+this.Reference+"&pwm="+this.PWM/100+"&sum="+this.Sum+"&p="+this.K_P+"&i="+this.K_I+"&d="+this.K_D+"&timeunit="+this.TimeUnit+"&pidtime="+this.RegulatorTime+""); |
| 279 | break; |
320 | break; |
| 280 | case "Temperature_Celsius": |
321 | case "Temperature_Celsius": |
| 281 | for (var alias_name in aliases_data) |
322 | for (var alias_name in aliases_data) |
| 282 | { |
323 | { |
| 283 | var last_value = {}; |
324 | var last_value = {}; |
| 284 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
325 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 285 | 326 | ||
| 286 | if (last_value_string) |
327 | if (last_value_string) |
| 287 | { |
328 | { |
| 288 | last_value = eval("(" + last_value_string + ")"); |
329 | last_value = eval("(" + last_value_string + ")"); |
| 289 | } |
330 | } |
| 290 | 331 | ||
| 291 | last_value["Reference"] = { "value" : variables["Value"], "timestamp" : get_time() }; |
332 | last_value["Reference"] = { "value" : variables["Value"], "timestamp" : get_time() }; |
| 292 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
333 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 293 | } |
334 | } |
| 294 | break; |
335 | break; |
| 295 | case "Report_Interval": |
336 | case "Report_Interval": |
| 296 | this.myReportInterval = canMessage.getData("Time"); |
337 | this.myReportInterval = canMessage.getData("Time"); |
| 297 | break; |
338 | break; |
| 298 | } |
339 | } |
| 299 | } |
340 | } |
| 300 | } |
341 | } |
| 301 | Module_RegisterToOnMessage("all", PID_OnMessage); |
342 | Module_RegisterToOnMessage("all", PID_OnMessage); |
| 302 | 343 | ||