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