Rev 2271 | Rev 2280 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1765 | linlun | 1 | |
| 2275 | linlun | 2 | PID_ModuleNames = [ "PID" ]; |
| 3 | PID_SensorModuleNames = [ "DS18x20", "FOST02", "DHT11", "NTC", "TC1047A", "LM335", "TCN75A" ]; |
||
| 4 | PID_ActModuleNames = [ "hwPWM", "softPWM", "SlowPWM", "PCAPWM" ]; |
||
| 5 | |||
| 6 | PID_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
||
| 7 | //PID_Energy = function() { return [ 0, 500, 1000, 5000, 10000 ]; }; |
||
| 1765 | linlun | 8 | PID_Temperatures = function() { return [ 20, 25, 30, 35 ]; }; |
| 2271 | linlun | 9 | PID_Constants = function() { return [ 0, 0.1, 0.5, 1, 10, 100, 1000 ]; }; |
| 2275 | linlun | 10 | PID_TimeUnits = function() { return [ "s", "ms"]; }; |
| 11 | PID_Times = function() { return [ 1, 5, 10, 15, 20, 40, 60]; }; |
||
| 12 | PID_Aliases = function() { return Module_GetAliasNames(PID_ModuleNames); }; |
||
| 13 | PID_AvailableIds = function() { return Module_GetAvailableIds(PID_ModuleNames); }; |
||
| 14 | PID_SensorAliases = function() { return Module_GetAliasNames(PID_SensorModuleNames); }; |
||
| 15 | PID_ActAliases = function() { return Module_GetAliasNames(PID_ActModuleNames); }; |
||
| 1765 | linlun | 16 | |
| 17 | function PID_SetReportInterval(alias_name, interval) |
||
| 18 | { |
||
| 19 | if (arguments.length < 2) |
||
| 20 | { |
||
| 21 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 22 | return false; |
||
| 23 | } |
||
| 24 | |||
| 25 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 26 | var found = false; |
||
| 27 | |||
| 28 | for (var name in aliases_data) |
||
| 29 | { |
||
| 30 | var variables = {"Time" : interval }; |
||
| 31 | |||
| 32 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
||
| 33 | { |
||
| 34 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 35 | } |
||
| 36 | else |
||
| 37 | { |
||
| 38 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 39 | } |
||
| 40 | |||
| 41 | found = true; |
||
| 42 | } |
||
| 43 | |||
| 44 | if (!found) |
||
| 45 | { |
||
| 46 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 47 | return false; |
||
| 48 | } |
||
| 49 | |||
| 50 | return true; |
||
| 51 | } |
||
| 52 | Console_RegisterCommand(PID_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Intervals()); }); |
||
| 53 | |||
| 54 | |||
| 55 | function PID_setValue(alias_name, temperature) |
||
| 56 | { |
||
| 57 | if (arguments.length < 2) |
||
| 58 | { |
||
| 59 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 60 | return false; |
||
| 61 | } |
||
| 62 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 63 | var found = false; |
||
| 64 | |||
| 65 | Log ("Called SetValue: "+temperature+"\n"); |
||
| 66 | |||
| 67 | for (var name in aliases_data) |
||
| 68 | { |
||
| 69 | var variables = { "Value" : temperature, |
||
| 70 | "SensorId" : 0 }; |
||
| 71 | |||
| 72 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Temperature_Celsius", variables)) |
||
| 73 | { |
||
| 74 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 75 | } |
||
| 76 | else |
||
| 77 | { |
||
| 78 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 79 | } |
||
| 80 | |||
| 81 | found = true; |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!found) |
||
| 85 | { |
||
| 86 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 87 | return false; |
||
| 88 | } |
||
| 89 | |||
| 90 | return true; |
||
| 91 | } |
||
| 92 | Console_RegisterCommand(PID_setValue, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Temperatures()); }); |
||
| 93 | |||
| 2275 | linlun | 94 | function PID_setSensor(alias_name, alias_sensor) |
| 95 | { |
||
| 96 | if (arguments.length < 2) |
||
| 97 | { |
||
| 98 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 99 | return false; |
||
| 100 | } |
||
| 101 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 102 | var found = false; |
||
| 103 | |||
| 104 | var sensor_aliases_data = Module_ResolveAlias(alias_sensor, PID_SensorModuleNames); |
||
| 105 | var first = true; |
||
| 106 | for (var sensor in sensor_aliases_data) |
||
| 107 | { |
||
| 108 | if (first == false) |
||
| 109 | { |
||
| 110 | Log("\033[31mNo sensor by the name " + alias_sensor + " were applicable for this command, or alias was a group.\033[0m\n"); |
||
| 111 | return false; |
||
| 112 | } |
||
| 113 | Log ("Called Set Sensor:\n"); |
||
| 114 | Log ("sensorModuleType: " + sensor_aliases_data[sensor]["module_name"]+"\n"); |
||
| 115 | Log ("sensorModuleId: " + sensor_aliases_data[sensor]["module_id"]+"\n"); |
||
| 116 | Log ("SensorId: " + sensor_aliases_data[sensor]["specific"]["SensorId"]+"\n"); |
||
| 117 | var id = 0; |
||
| 118 | switch (sensor_aliases_data[sensor]["module_name"]) |
||
| 119 | { |
||
| 120 | case "DS18x20": id = 3; break; |
||
| 121 | case "FOST02": id = 5; break; |
||
| 122 | case "TC1047A": id = 17; break; |
||
| 123 | case "TCN75A": id = 46; break; |
||
| 124 | case "LM335": id = 51; break; |
||
| 125 | case "NTC": id = 55; break; |
||
| 126 | case "DHT11": id = 61; break; |
||
| 127 | default: |
||
| 128 | Log("\033[31mCould not resolve sensor module type.\033[0m\n"); |
||
| 129 | return; break; |
||
| 130 | } |
||
| 131 | |||
| 132 | |||
| 133 | for (var name in aliases_data) |
||
| 134 | { |
||
| 135 | var variables = { "sensorModuleType" : id, |
||
| 136 | "sensorModuleId" : sensor_aliases_data[sensor]["module_id"], |
||
| 137 | "sensorId" : sensor_aliases_data[sensor]["specific"]["SensorId"] }; |
||
| 1765 | linlun | 138 | |
| 2275 | linlun | 139 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_SENSOR", variables)) |
| 140 | { |
||
| 141 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 142 | } |
||
| 143 | else |
||
| 144 | { |
||
| 145 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 146 | } |
||
| 147 | |||
| 148 | found = true; |
||
| 149 | } |
||
| 150 | first = false; |
||
| 151 | if (!found) |
||
| 152 | { |
||
| 153 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 154 | return false; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | if (!found) |
||
| 159 | { |
||
| 160 | Log("\033[31mNo sensor aliases by the name " + alias_sensor + " were applicable for this command.\033[0m\n"); |
||
| 161 | return false; |
||
| 162 | } |
||
| 163 | |||
| 164 | return true; |
||
| 165 | } |
||
| 166 | Console_RegisterCommand(PID_setSensor, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_SensorAliases()); }); |
||
| 167 | |||
| 168 | function PID_setActuator(alias_name, alias_actuator) |
||
| 169 | { |
||
| 170 | if (arguments.length < 2) |
||
| 171 | { |
||
| 172 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 173 | return false; |
||
| 174 | } |
||
| 175 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 176 | var found = false; |
||
| 177 | |||
| 178 | var act_aliases_data = Module_ResolveAlias(alias_actuator, PID_ActModuleNames); |
||
| 179 | var first = true; |
||
| 180 | for (var act in act_aliases_data) |
||
| 181 | { |
||
| 182 | if (first == false) |
||
| 183 | { |
||
| 184 | Log("\033[31mNo actuator by the name " + alias_actuator + " were applicable for this command, or alias was a group.\033[0m\n"); |
||
| 185 | return false; |
||
| 186 | } |
||
| 187 | Log ("Called Set Actuator:\n"); |
||
| 188 | Log ("actModuleType: " + act_aliases_data[act]["module_name"]+"\n"); |
||
| 189 | Log ("actModuleId: " + act_aliases_data[act]["module_id"]+"\n"); |
||
| 190 | Log ("actId: " + act_aliases_data[act]["specific"]["Channel"]+"\n"); |
||
| 191 | var id = 0; |
||
| 192 | switch (act_aliases_data[act]["module_name"]) |
||
| 193 | { |
||
| 194 | case "hwPWM": id = 13; break; |
||
| 195 | case "softPWM": id = 21; break; |
||
| 196 | case "SlowPWM": id = 19; break; |
||
| 197 | case "PCAPWM": id = 29; break; |
||
| 198 | default: |
||
| 199 | Log("\033[31mCould not resolve actuator module type.\033[0m\n"); |
||
| 200 | return; break; |
||
| 201 | } |
||
| 202 | |||
| 203 | |||
| 204 | for (var name in aliases_data) |
||
| 205 | { |
||
| 206 | var variables = { "actuatorModuleType" : id, |
||
| 207 | "actuatorModuleId" : act_aliases_data[act]["module_id"], |
||
| 208 | "actuatorId" : act_aliases_data[act]["specific"]["Channel"] }; |
||
| 209 | |||
| 210 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_ACTUATOR", variables)) |
||
| 211 | { |
||
| 212 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 213 | } |
||
| 214 | else |
||
| 215 | { |
||
| 216 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 217 | } |
||
| 218 | |||
| 219 | found = true; |
||
| 220 | } |
||
| 221 | first = false; |
||
| 222 | if (!found) |
||
| 223 | { |
||
| 224 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 225 | return false; |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | if (!found) |
||
| 230 | { |
||
| 231 | Log("\033[31mNo actuator aliases by the name " + alias_actuator + " were applicable for this command.\033[0m\n"); |
||
| 232 | return false; |
||
| 233 | } |
||
| 234 | |||
| 235 | return true; |
||
| 236 | } |
||
| 237 | Console_RegisterCommand(PID_setActuator, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_ActAliases()); }); |
||
| 238 | |||
| 239 | |||
| 1765 | linlun | 240 | function PID_setParameters(alias_name, KP,KI,KD,Time,Unit) |
| 241 | { |
||
| 242 | if (arguments.length < 6) |
||
| 243 | { |
||
| 244 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 245 | return false; |
||
| 246 | } |
||
| 247 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 248 | var found = false; |
||
| 249 | |||
| 250 | for (var name in aliases_data) |
||
| 251 | { |
||
| 252 | var variables = { "K_P" : KP, |
||
| 253 | "K_I" : KI, |
||
| 254 | "K_D" : KD, |
||
| 255 | "RegulatorTime" : Time, |
||
| 256 | "TimeUnit" : Unit }; |
||
| 2271 | linlun | 257 | var variables_P_I = { "K_P" : KP, |
| 258 | "K_I" : KI }; |
||
| 259 | var variables_D_T = { "K_D" : KD, |
||
| 260 | "RegulatorTime" : Time, |
||
| 261 | "TimeUnit" : Unit }; |
||
| 1765 | linlun | 262 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables)) |
| 263 | { |
||
| 264 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m"); |
||
| 265 | Log("\033[32mK_P = " + KP + "K_I = " + KI + "K_D = " + KD + "RegTime = " + Time + "Unit = " + Unit + ".\033[0m\n"); |
||
| 266 | } |
||
| 267 | else |
||
| 268 | { |
||
| 269 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 270 | } |
||
| 271 | |||
| 2271 | linlun | 272 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_P_I", variables_P_I)) |
| 273 | { |
||
| 274 | Log("\033[32mK_P = " + KP + "K_I = " + KI + ".\033[0m\n"); |
||
| 275 | } |
||
| 276 | else |
||
| 277 | { |
||
| 278 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 279 | } |
||
| 280 | |||
| 281 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_D_T", variables_D_T)) |
||
| 282 | { |
||
| 283 | Log("\033[32mK_D = " + KD + "RegTime = " + Time + "Unit = " + Unit + ".\033[0m\n"); |
||
| 284 | } |
||
| 285 | else |
||
| 286 | { |
||
| 287 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 288 | } |
||
| 289 | |||
| 1765 | linlun | 290 | found = true; |
| 291 | } |
||
| 292 | |||
| 293 | if (!found) |
||
| 294 | { |
||
| 295 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 296 | return false; |
||
| 297 | } |
||
| 298 | |||
| 299 | return true; |
||
| 300 | } |
||
| 2271 | linlun | 301 | 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()); }); |
| 1765 | linlun | 302 | |
| 2275 | linlun | 303 | |
| 304 | function PID_setOutputMaxMin(alias_name, Max,Min) |
||
| 305 | { |
||
| 306 | if (arguments.length < 3) |
||
| 307 | { |
||
| 308 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 309 | return false; |
||
| 310 | } |
||
| 311 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 312 | var found = false; |
||
| 313 | |||
| 314 | for (var name in aliases_data) |
||
| 315 | { |
||
| 316 | var variables = { "Min" : Min, |
||
| 317 | "Max" : Max }; |
||
| 318 | |||
| 319 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "OutMinMax", variables)) |
||
| 320 | { |
||
| 321 | Log("\033[32mMin = " + Min + "Max = " + Max + ".\033[0m\n"); |
||
| 322 | } |
||
| 323 | else |
||
| 324 | { |
||
| 325 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 326 | } |
||
| 327 | |||
| 328 | found = true; |
||
| 329 | } |
||
| 330 | |||
| 331 | if (!found) |
||
| 332 | { |
||
| 333 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 334 | return false; |
||
| 335 | } |
||
| 336 | |||
| 337 | return true; |
||
| 338 | } |
||
| 339 | Console_RegisterCommand(PID_setOutputMaxMin, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Constants(), PID_Constants()); }); |
||
| 340 | |||
| 1765 | linlun | 341 | function PID_getConfiguration(alias_name) |
| 342 | { |
||
| 343 | if (arguments.length < 1) |
||
| 344 | { |
||
| 345 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 346 | return false; |
||
| 347 | } |
||
| 348 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 349 | var found = false; |
||
| 350 | |||
| 351 | for (var name in aliases_data) |
||
| 352 | { |
||
| 353 | var variables = {}; |
||
| 354 | |||
| 355 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_SENSOR", variables)) |
||
| 356 | { |
||
| 357 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 358 | } |
||
| 359 | else |
||
| 360 | { |
||
| 361 | Log("\033[31mFailed to send command 1 to " + name + ".\033[0m\n"); |
||
| 362 | } |
||
| 363 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_ACTUATOR", variables)) |
||
| 364 | { |
||
| 365 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 366 | } |
||
| 367 | else |
||
| 368 | { |
||
| 369 | Log("\033[31mFailed to send command 2 to " + name + ".\033[0m\n"); |
||
| 370 | } |
||
| 371 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables)) |
||
| 372 | { |
||
| 373 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 374 | } |
||
| 375 | else |
||
| 376 | { |
||
| 377 | Log("\033[31mFailed to send command 3 to " + name + ".\033[0m\n"); |
||
| 378 | } |
||
| 379 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
||
| 380 | { |
||
| 381 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 382 | } |
||
| 383 | else |
||
| 384 | { |
||
| 385 | Log("\033[31mFailed to send command 4 to " + name + ".\033[0m\n"); |
||
| 386 | } |
||
| 2271 | linlun | 387 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_P_I", variables)) |
| 388 | { |
||
| 389 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 390 | } |
||
| 391 | else |
||
| 392 | { |
||
| 393 | Log("\033[31mFailed to send command 5 to " + name + ".\033[0m\n"); |
||
| 394 | } |
||
| 395 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_D_T", variables)) |
||
| 396 | { |
||
| 397 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 398 | } |
||
| 399 | else |
||
| 400 | { |
||
| 401 | Log("\033[31mFailed to send command 6 to " + name + ".\033[0m\n"); |
||
| 402 | } |
||
| 2275 | linlun | 403 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "OutMinMax", variables)) |
| 404 | { |
||
| 405 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 406 | } |
||
| 407 | else |
||
| 408 | { |
||
| 409 | Log("\033[31mFailed to send command 6 to " + name + ".\033[0m\n"); |
||
| 410 | } |
||
| 1765 | linlun | 411 | found = true; |
| 412 | } |
||
| 413 | |||
| 414 | if (!found) |
||
| 415 | { |
||
| 416 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 417 | return false; |
||
| 418 | } |
||
| 419 | |||
| 420 | return true; |
||
| 421 | } |
||
| 422 | Console_RegisterCommand(PID_getConfiguration, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases()); }); |
||
| 423 | |||
| 424 | function PID_OnMessage(module_name, module_id, command, variables) |
||
| 425 | { |
||
| 426 | if (in_array(PID_ModuleNames, module_name)) |
||
| 427 | { |
||
| 428 | var aliases_data = Module_LookupAliases({ |
||
| 429 | "module_name" : module_name, |
||
| 430 | "module_id" : module_id, |
||
| 431 | "group" : false |
||
| 432 | }); |
||
| 433 | |||
| 434 | switch (command) |
||
| 435 | { |
||
| 436 | case "DEBUG": |
||
| 437 | for (var alias_name in aliases_data) |
||
| 438 | { |
||
| 439 | var last_value = {}; |
||
| 440 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 441 | |||
| 442 | if (last_value_string) |
||
| 443 | { |
||
| 444 | last_value = eval("(" + last_value_string + ")"); |
||
| 445 | } |
||
| 446 | |||
| 2076 | linlun | 447 | 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() }; |
| 1765 | linlun | 448 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 449 | //Log("Got message DEBUG"); |
||
| 450 | } |
||
| 451 | break; |
||
| 452 | case "CONFIG_SENSOR": |
||
| 453 | for (var alias_name in aliases_data) |
||
| 454 | { |
||
| 455 | var last_value = {}; |
||
| 456 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 457 | |||
| 458 | if (last_value_string) |
||
| 459 | { |
||
| 460 | last_value = eval("(" + last_value_string + ")"); |
||
| 461 | } |
||
| 462 | |||
| 2076 | linlun | 463 | last_value["Sensor"] = { "value" : { "sensorModuleType" : variables["sensorModuleType"],"sensorModuleId" : variables["sensorModuleId"],"sensorId" : variables["sensorId"] }, "timestamp" : get_time() }; |
| 1765 | linlun | 464 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 465 | } |
||
| 466 | break; |
||
| 467 | case "CONFIG_ACTUATOR": |
||
| 468 | for (var alias_name in aliases_data) |
||
| 469 | { |
||
| 470 | var last_value = {}; |
||
| 471 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 472 | |||
| 473 | if (last_value_string) |
||
| 474 | { |
||
| 475 | last_value = eval("(" + last_value_string + ")"); |
||
| 476 | } |
||
| 477 | |||
| 2076 | linlun | 478 | last_value["Actuator"] = { "value" : { "actuatorModuleType" : variables["actuatorModuleType"],"actuatorModuleId" : variables["actuatorModuleId"],"actuatorId" : variables["actuatorId"] }, "timestamp" : get_time() }; |
| 1765 | linlun | 479 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 480 | } |
||
| 481 | break; |
||
| 482 | case "CONFIG_PARAMETER": |
||
| 483 | for (var alias_name in aliases_data) |
||
| 484 | { |
||
| 485 | var last_value = {}; |
||
| 486 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 487 | |||
| 488 | if (last_value_string) |
||
| 489 | { |
||
| 490 | last_value = eval("(" + last_value_string + ")"); |
||
| 491 | } |
||
| 492 | |||
| 2076 | linlun | 493 | 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() }; |
| 1765 | linlun | 494 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 495 | } |
||
| 496 | break; |
||
| 497 | case "PID_STATUS": |
||
| 498 | for (var alias_name in aliases_data) |
||
| 499 | { |
||
| 500 | var last_value = {}; |
||
| 501 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 502 | |||
| 503 | if (last_value_string) |
||
| 504 | { |
||
| 505 | last_value = eval("(" + last_value_string + ")"); |
||
| 506 | } |
||
| 507 | |||
| 2076 | linlun | 508 | last_value["PID_status"] = { "value" : { "Measurment" : variables["Measurment"],"Reference" : variables["Reference"],"PWM" : variables["PWM"],"Sum" : variables["Sum"] }, "timestamp" : get_time() }; |
| 1765 | linlun | 509 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 510 | } |
||
| 511 | //log("PID status: mea:" + this.Measurment + " ref:" + this.Reference + " pwm:" + this.PWM/100 + " sum:" + this.Sum + "\n"); |
||
| 512 | //this.callEvent("newValue", canMessage.getData("Id")); |
||
| 513 | |||
| 514 | //var self = this; |
||
| 515 | // 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+""); |
||
| 516 | break; |
||
| 517 | case "Temperature_Celsius": |
||
| 518 | for (var alias_name in aliases_data) |
||
| 519 | { |
||
| 520 | var last_value = {}; |
||
| 521 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 522 | |||
| 523 | if (last_value_string) |
||
| 524 | { |
||
| 525 | last_value = eval("(" + last_value_string + ")"); |
||
| 526 | } |
||
| 527 | |||
| 2076 | linlun | 528 | last_value["Reference"] = { "value" : variables["Value"], "timestamp" : get_time() }; |
| 1765 | linlun | 529 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 530 | } |
||
| 531 | break; |
||
| 532 | case "Report_Interval": |
||
| 533 | this.myReportInterval = canMessage.getData("Time"); |
||
| 534 | break; |
||
| 535 | } |
||
| 536 | } |
||
| 537 | } |
||
| 538 | Module_RegisterToOnMessage("all", PID_OnMessage); |