Rev 2280 | 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" ]; |
||
| 2300 | linlun | 5 | PID_Algos = function() { return [ "ZIEGLER_NICHOLS_PI", "ZIEGLER_NICHOLS_PID", "TYREUS_LUYBEN_PI", "TYREUS_LUYBEN_PID", "CIANCONE_MARLIN_PI", "CIANCONE_MARLIN_PID", "AMIGOF_PI", "PESSEN_INTEGRAL_PID", "SOME_OVERSHOOT_PID", "NO_OVERSHOOT_PID" , "STOP" ]; }; |
| 2275 | linlun | 6 | PID_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
| 2300 | linlun | 7 | PID_Outputs = 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 ]; }; |
| 2300 | linlun | 10 | PID_LookBackTimes = function() { return [ 0, 1, 10, 100, 255 ]; }; |
| 2275 | linlun | 11 | PID_TimeUnits = function() { return [ "s", "ms"]; }; |
| 2280 | linlun | 12 | PID_ControllerDirection = function() { return [ "direct", "reverse"]; }; |
| 2275 | linlun | 13 | PID_Times = function() { return [ 1, 5, 10, 15, 20, 40, 60]; }; |
| 14 | PID_Aliases = function() { return Module_GetAliasNames(PID_ModuleNames); }; |
||
| 15 | PID_AvailableIds = function() { return Module_GetAvailableIds(PID_ModuleNames); }; |
||
| 16 | PID_SensorAliases = function() { return Module_GetAliasNames(PID_SensorModuleNames); }; |
||
| 2300 | linlun | 17 | PID_ActAliases = function() { return Module_GetAliasNames(PID_ActModuleNames); }; |
| 1765 | linlun | 18 | |
| 19 | function PID_SetReportInterval(alias_name, interval) |
||
| 20 | { |
||
| 21 | if (arguments.length < 2) |
||
| 22 | { |
||
| 23 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 24 | return false; |
||
| 25 | } |
||
| 26 | |||
| 27 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 28 | var found = false; |
||
| 29 | |||
| 30 | for (var name in aliases_data) |
||
| 31 | { |
||
| 32 | var variables = {"Time" : interval }; |
||
| 33 | |||
| 34 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
||
| 35 | { |
||
| 36 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 37 | } |
||
| 38 | else |
||
| 39 | { |
||
| 40 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 41 | } |
||
| 42 | |||
| 43 | found = true; |
||
| 44 | } |
||
| 45 | |||
| 46 | if (!found) |
||
| 47 | { |
||
| 48 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 49 | return false; |
||
| 50 | } |
||
| 51 | |||
| 52 | return true; |
||
| 53 | } |
||
| 54 | Console_RegisterCommand(PID_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Intervals()); }); |
||
| 55 | |||
| 56 | |||
| 57 | function PID_setValue(alias_name, temperature) |
||
| 58 | { |
||
| 59 | if (arguments.length < 2) |
||
| 60 | { |
||
| 61 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 62 | return false; |
||
| 63 | } |
||
| 64 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 65 | var found = false; |
||
| 66 | |||
| 67 | Log ("Called SetValue: "+temperature+"\n"); |
||
| 68 | |||
| 69 | for (var name in aliases_data) |
||
| 70 | { |
||
| 71 | var variables = { "Value" : temperature, |
||
| 72 | "SensorId" : 0 }; |
||
| 73 | |||
| 74 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Temperature_Celsius", variables)) |
||
| 75 | { |
||
| 76 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 77 | } |
||
| 78 | else |
||
| 79 | { |
||
| 80 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 81 | } |
||
| 82 | |||
| 83 | found = true; |
||
| 84 | } |
||
| 85 | |||
| 86 | if (!found) |
||
| 87 | { |
||
| 88 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 89 | return false; |
||
| 90 | } |
||
| 91 | |||
| 92 | return true; |
||
| 93 | } |
||
| 94 | Console_RegisterCommand(PID_setValue, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Temperatures()); }); |
||
| 95 | |||
| 2275 | linlun | 96 | function PID_setSensor(alias_name, alias_sensor) |
| 97 | { |
||
| 98 | if (arguments.length < 2) |
||
| 99 | { |
||
| 100 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 101 | return false; |
||
| 102 | } |
||
| 103 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 104 | var found = false; |
||
| 105 | |||
| 106 | var sensor_aliases_data = Module_ResolveAlias(alias_sensor, PID_SensorModuleNames); |
||
| 107 | var first = true; |
||
| 108 | for (var sensor in sensor_aliases_data) |
||
| 109 | { |
||
| 110 | if (first == false) |
||
| 111 | { |
||
| 112 | Log("\033[31mNo sensor by the name " + alias_sensor + " were applicable for this command, or alias was a group.\033[0m\n"); |
||
| 113 | return false; |
||
| 114 | } |
||
| 115 | Log ("Called Set Sensor:\n"); |
||
| 116 | Log ("sensorModuleType: " + sensor_aliases_data[sensor]["module_name"]+"\n"); |
||
| 117 | Log ("sensorModuleId: " + sensor_aliases_data[sensor]["module_id"]+"\n"); |
||
| 118 | Log ("SensorId: " + sensor_aliases_data[sensor]["specific"]["SensorId"]+"\n"); |
||
| 119 | var id = 0; |
||
| 120 | switch (sensor_aliases_data[sensor]["module_name"]) |
||
| 121 | { |
||
| 122 | case "DS18x20": id = 3; break; |
||
| 123 | case "FOST02": id = 5; break; |
||
| 124 | case "TC1047A": id = 17; break; |
||
| 125 | case "TCN75A": id = 46; break; |
||
| 126 | case "LM335": id = 51; break; |
||
| 127 | case "NTC": id = 55; break; |
||
| 128 | case "DHT11": id = 61; break; |
||
| 129 | default: |
||
| 130 | Log("\033[31mCould not resolve sensor module type.\033[0m\n"); |
||
| 131 | return; break; |
||
| 132 | } |
||
| 133 | |||
| 134 | |||
| 135 | for (var name in aliases_data) |
||
| 136 | { |
||
| 137 | var variables = { "sensorModuleType" : id, |
||
| 138 | "sensorModuleId" : sensor_aliases_data[sensor]["module_id"], |
||
| 139 | "sensorId" : sensor_aliases_data[sensor]["specific"]["SensorId"] }; |
||
| 1765 | linlun | 140 | |
| 2275 | linlun | 141 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_SENSOR", variables)) |
| 142 | { |
||
| 143 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 144 | } |
||
| 145 | else |
||
| 146 | { |
||
| 147 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 148 | } |
||
| 149 | |||
| 150 | found = true; |
||
| 151 | } |
||
| 152 | first = false; |
||
| 153 | if (!found) |
||
| 154 | { |
||
| 155 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 156 | return false; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | if (!found) |
||
| 161 | { |
||
| 162 | Log("\033[31mNo sensor aliases by the name " + alias_sensor + " were applicable for this command.\033[0m\n"); |
||
| 163 | return false; |
||
| 164 | } |
||
| 165 | |||
| 166 | return true; |
||
| 167 | } |
||
| 168 | Console_RegisterCommand(PID_setSensor, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_SensorAliases()); }); |
||
| 169 | |||
| 170 | function PID_setActuator(alias_name, alias_actuator) |
||
| 171 | { |
||
| 172 | if (arguments.length < 2) |
||
| 173 | { |
||
| 174 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 175 | return false; |
||
| 176 | } |
||
| 177 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 178 | var found = false; |
||
| 179 | |||
| 180 | var act_aliases_data = Module_ResolveAlias(alias_actuator, PID_ActModuleNames); |
||
| 181 | var first = true; |
||
| 182 | for (var act in act_aliases_data) |
||
| 183 | { |
||
| 184 | if (first == false) |
||
| 185 | { |
||
| 186 | Log("\033[31mNo actuator by the name " + alias_actuator + " were applicable for this command, or alias was a group.\033[0m\n"); |
||
| 187 | return false; |
||
| 188 | } |
||
| 189 | Log ("Called Set Actuator:\n"); |
||
| 190 | Log ("actModuleType: " + act_aliases_data[act]["module_name"]+"\n"); |
||
| 191 | Log ("actModuleId: " + act_aliases_data[act]["module_id"]+"\n"); |
||
| 192 | Log ("actId: " + act_aliases_data[act]["specific"]["Channel"]+"\n"); |
||
| 193 | var id = 0; |
||
| 194 | switch (act_aliases_data[act]["module_name"]) |
||
| 195 | { |
||
| 196 | case "hwPWM": id = 13; break; |
||
| 197 | case "softPWM": id = 21; break; |
||
| 198 | case "SlowPWM": id = 19; break; |
||
| 199 | case "PCAPWM": id = 29; break; |
||
| 200 | default: |
||
| 201 | Log("\033[31mCould not resolve actuator module type.\033[0m\n"); |
||
| 202 | return; break; |
||
| 203 | } |
||
| 204 | |||
| 205 | |||
| 206 | for (var name in aliases_data) |
||
| 207 | { |
||
| 208 | var variables = { "actuatorModuleType" : id, |
||
| 209 | "actuatorModuleId" : act_aliases_data[act]["module_id"], |
||
| 210 | "actuatorId" : act_aliases_data[act]["specific"]["Channel"] }; |
||
| 211 | |||
| 212 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_ACTUATOR", variables)) |
||
| 213 | { |
||
| 214 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 215 | } |
||
| 216 | else |
||
| 217 | { |
||
| 218 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 219 | } |
||
| 220 | |||
| 221 | found = true; |
||
| 222 | } |
||
| 223 | first = false; |
||
| 224 | if (!found) |
||
| 225 | { |
||
| 226 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 227 | return false; |
||
| 228 | } |
||
| 229 | } |
||
| 230 | |||
| 231 | if (!found) |
||
| 232 | { |
||
| 233 | Log("\033[31mNo actuator aliases by the name " + alias_actuator + " were applicable for this command.\033[0m\n"); |
||
| 234 | return false; |
||
| 235 | } |
||
| 236 | |||
| 237 | return true; |
||
| 238 | } |
||
| 239 | Console_RegisterCommand(PID_setActuator, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_ActAliases()); }); |
||
| 240 | |||
| 241 | |||
| 2280 | linlun | 242 | function PID_setParameters(alias_name, KP,KI,KD,Time,Unit,ControllerDirection) |
| 1765 | linlun | 243 | { |
| 244 | if (arguments.length < 6) |
||
| 245 | { |
||
| 246 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 247 | return false; |
||
| 248 | } |
||
| 249 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 250 | var found = false; |
||
| 251 | |||
| 252 | for (var name in aliases_data) |
||
| 253 | { |
||
| 2280 | linlun | 254 | var variables = { "K_P" : KP, |
| 255 | "K_I" : KI, |
||
| 256 | "K_D" : KD, |
||
| 257 | "RegulatorTime" : Time, |
||
| 258 | "TimeUnit" : Unit }; |
||
| 259 | var variables_P_I = { "K_P" : KP, |
||
| 260 | "K_I" : KI }; |
||
| 261 | var variables_D_T = { "K_D" : KD, |
||
| 262 | "ControllerDirection" : ControllerDirection, |
||
| 263 | "RegulatorTime" : Time, |
||
| 264 | "TimeUnit" : Unit }; |
||
| 1765 | linlun | 265 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables)) |
| 266 | { |
||
| 267 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m"); |
||
| 268 | Log("\033[32mK_P = " + KP + "K_I = " + KI + "K_D = " + KD + "RegTime = " + Time + "Unit = " + Unit + ".\033[0m\n"); |
||
| 269 | } |
||
| 270 | else |
||
| 271 | { |
||
| 272 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 273 | } |
||
| 274 | |||
| 2271 | linlun | 275 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_P_I", variables_P_I)) |
| 276 | { |
||
| 277 | Log("\033[32mK_P = " + KP + "K_I = " + KI + ".\033[0m\n"); |
||
| 278 | } |
||
| 279 | else |
||
| 280 | { |
||
| 281 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 282 | } |
||
| 283 | |||
| 284 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_D_T", variables_D_T)) |
||
| 285 | { |
||
| 2280 | linlun | 286 | Log("\033[32mK_D = " + KD + " RegTime = " + Time + " Unit = " + Unit + " Direction = " + ControllerDirection +".\033[0m\n"); |
| 2271 | linlun | 287 | } |
| 288 | else |
||
| 289 | { |
||
| 290 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 291 | } |
||
| 292 | |||
| 1765 | linlun | 293 | found = true; |
| 294 | } |
||
| 295 | |||
| 296 | if (!found) |
||
| 297 | { |
||
| 298 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 299 | return false; |
||
| 300 | } |
||
| 301 | |||
| 302 | return true; |
||
| 303 | } |
||
| 2280 | linlun | 304 | 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 | 305 | |
| 2275 | linlun | 306 | |
| 307 | function PID_setOutputMaxMin(alias_name, Max,Min) |
||
| 308 | { |
||
| 309 | if (arguments.length < 3) |
||
| 310 | { |
||
| 311 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 312 | return false; |
||
| 313 | } |
||
| 314 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 315 | var found = false; |
||
| 316 | |||
| 317 | for (var name in aliases_data) |
||
| 318 | { |
||
| 319 | var variables = { "Min" : Min, |
||
| 320 | "Max" : Max }; |
||
| 321 | |||
| 322 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "OutMinMax", variables)) |
||
| 323 | { |
||
| 324 | Log("\033[32mMin = " + Min + "Max = " + Max + ".\033[0m\n"); |
||
| 325 | } |
||
| 326 | else |
||
| 327 | { |
||
| 328 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 329 | } |
||
| 330 | |||
| 331 | found = true; |
||
| 332 | } |
||
| 333 | |||
| 334 | if (!found) |
||
| 335 | { |
||
| 336 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 337 | return false; |
||
| 338 | } |
||
| 339 | |||
| 340 | return true; |
||
| 341 | } |
||
| 2300 | linlun | 342 | Console_RegisterCommand(PID_setOutputMaxMin, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Outputs(), PID_Outputs()); }); |
| 2275 | linlun | 343 | |
| 1765 | linlun | 344 | function PID_getConfiguration(alias_name) |
| 345 | { |
||
| 346 | if (arguments.length < 1) |
||
| 347 | { |
||
| 348 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 349 | return false; |
||
| 350 | } |
||
| 351 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 352 | var found = false; |
||
| 353 | |||
| 354 | for (var name in aliases_data) |
||
| 355 | { |
||
| 356 | var variables = {}; |
||
| 357 | |||
| 358 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_SENSOR", variables)) |
||
| 359 | { |
||
| 360 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 361 | } |
||
| 362 | else |
||
| 363 | { |
||
| 364 | Log("\033[31mFailed to send command 1 to " + name + ".\033[0m\n"); |
||
| 365 | } |
||
| 366 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_ACTUATOR", variables)) |
||
| 367 | { |
||
| 368 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 369 | } |
||
| 370 | else |
||
| 371 | { |
||
| 372 | Log("\033[31mFailed to send command 2 to " + name + ".\033[0m\n"); |
||
| 373 | } |
||
| 374 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER", variables)) |
||
| 375 | { |
||
| 376 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 377 | } |
||
| 378 | else |
||
| 379 | { |
||
| 380 | Log("\033[31mFailed to send command 3 to " + name + ".\033[0m\n"); |
||
| 381 | } |
||
| 382 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
||
| 383 | { |
||
| 384 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 385 | } |
||
| 386 | else |
||
| 387 | { |
||
| 388 | Log("\033[31mFailed to send command 4 to " + name + ".\033[0m\n"); |
||
| 389 | } |
||
| 2271 | linlun | 390 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_P_I", variables)) |
| 391 | { |
||
| 392 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 393 | } |
||
| 394 | else |
||
| 395 | { |
||
| 396 | Log("\033[31mFailed to send command 5 to " + name + ".\033[0m\n"); |
||
| 397 | } |
||
| 398 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PARAMETER_D_T", variables)) |
||
| 399 | { |
||
| 400 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 401 | } |
||
| 402 | else |
||
| 403 | { |
||
| 404 | Log("\033[31mFailed to send command 6 to " + name + ".\033[0m\n"); |
||
| 405 | } |
||
| 2275 | linlun | 406 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "OutMinMax", variables)) |
| 407 | { |
||
| 408 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 409 | } |
||
| 410 | else |
||
| 411 | { |
||
| 2300 | linlun | 412 | Log("\033[31mFailed to send command 7 to " + name + ".\033[0m\n"); |
| 2275 | linlun | 413 | } |
| 2300 | linlun | 414 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "RUN_AUTOTUNE", variables)) |
| 415 | { |
||
| 416 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 417 | } |
||
| 418 | else |
||
| 419 | { |
||
| 420 | Log("\033[31mFailed to send command 8 to " + name + ".\033[0m\n"); |
||
| 421 | } |
||
| 422 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_AUTOTUNE_NOISE_STEP", variables)) |
||
| 423 | { |
||
| 424 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 425 | } |
||
| 426 | else |
||
| 427 | { |
||
| 428 | Log("\033[31mFailed to send command 9 to " + name + ".\033[0m\n"); |
||
| 429 | } |
||
| 430 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PID_START_VALUE", variables)) |
||
| 431 | { |
||
| 432 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 433 | } |
||
| 434 | else |
||
| 435 | { |
||
| 436 | Log("\033[31mFailed to send command 9 to " + name + ".\033[0m\n"); |
||
| 437 | } |
||
| 438 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_ONOFF_REGULATOR", variables)) |
||
| 439 | { |
||
| 440 | //Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
||
| 441 | } |
||
| 442 | else |
||
| 443 | { |
||
| 444 | Log("\033[31mFailed to send command 9 to " + name + ".\033[0m\n"); |
||
| 445 | } |
||
| 446 | |||
| 1765 | linlun | 447 | found = true; |
| 448 | } |
||
| 449 | |||
| 450 | if (!found) |
||
| 451 | { |
||
| 452 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 453 | return false; |
||
| 454 | } |
||
| 455 | |||
| 456 | return true; |
||
| 457 | } |
||
| 458 | Console_RegisterCommand(PID_getConfiguration, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases()); }); |
||
| 459 | |||
| 2300 | linlun | 460 | |
| 461 | |||
| 462 | function PID_startAutoTune(alias_name, Algo ,lookbacktime) |
||
| 463 | { |
||
| 464 | if (arguments.length < 3) |
||
| 465 | { |
||
| 466 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 467 | return false; |
||
| 468 | } |
||
| 469 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 470 | var found = false; |
||
| 471 | |||
| 472 | for (var name in aliases_data) |
||
| 473 | { |
||
| 474 | var variables= { "Method" : Algo, |
||
| 475 | "LookBackTime" : lookbacktime }; |
||
| 476 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "RUN_AUTOTUNE", variables)) |
||
| 477 | { |
||
| 478 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m"); |
||
| 479 | Log("\033[32mMethod = " + Algo + "LookBackTime = " + lookbacktime + ".\033[0m\n"); |
||
| 480 | } |
||
| 481 | else |
||
| 482 | { |
||
| 483 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 484 | } |
||
| 485 | |||
| 486 | found = true; |
||
| 487 | } |
||
| 488 | |||
| 489 | if (!found) |
||
| 490 | { |
||
| 491 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 492 | return false; |
||
| 493 | } |
||
| 494 | |||
| 495 | return true; |
||
| 496 | } |
||
| 497 | Console_RegisterCommand(PID_startAutoTune, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Algos(), PID_LookBackTimes()); }); |
||
| 498 | |||
| 499 | function PID_AutoTuneNoiceStep(alias_name, NoiseBand ,OutputStep) |
||
| 500 | { |
||
| 501 | if (arguments.length < 3) |
||
| 502 | { |
||
| 503 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 504 | return false; |
||
| 505 | } |
||
| 506 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 507 | var found = false; |
||
| 508 | |||
| 509 | for (var name in aliases_data) |
||
| 510 | { |
||
| 511 | var variables= { "NoiseBand" : NoiseBand, |
||
| 512 | "OutputStep" : OutputStep }; |
||
| 513 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_AUTOTUNE_NOISE_STEP", variables)) |
||
| 514 | { |
||
| 515 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m"); |
||
| 516 | Log("\033[32mNoiseBand = " + NoiseBand + "OutputStep = " + OutputStep + ".\033[0m\n"); |
||
| 517 | } |
||
| 518 | else |
||
| 519 | { |
||
| 520 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 521 | } |
||
| 522 | |||
| 523 | found = true; |
||
| 524 | } |
||
| 525 | |||
| 526 | if (!found) |
||
| 527 | { |
||
| 528 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 529 | return false; |
||
| 530 | } |
||
| 531 | |||
| 532 | return true; |
||
| 533 | } |
||
| 534 | Console_RegisterCommand(PID_AutoTuneNoiceStep, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Constants(), PID_Constants()); }); |
||
| 535 | |||
| 536 | |||
| 537 | function PID_ConfigStartValue(alias_name, Factor, Offset) |
||
| 538 | { |
||
| 539 | if (arguments.length < 3) |
||
| 540 | { |
||
| 541 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 542 | return false; |
||
| 543 | } |
||
| 544 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 545 | var found = false; |
||
| 546 | |||
| 547 | for (var name in aliases_data) |
||
| 548 | { |
||
| 549 | var variables= { "Factor" : Factor, |
||
| 550 | "Offset" : Offset}; |
||
| 551 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_PID_START_VALUE", variables)) |
||
| 552 | { |
||
| 553 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m"); |
||
| 554 | Log("\033[32mFactor = " + Factor+ "Offset = " + Offset+ ".\033[0m\n"); |
||
| 555 | } |
||
| 556 | else |
||
| 557 | { |
||
| 558 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 559 | } |
||
| 560 | |||
| 561 | found = true; |
||
| 562 | } |
||
| 563 | |||
| 564 | if (!found) |
||
| 565 | { |
||
| 566 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 567 | return false; |
||
| 568 | } |
||
| 569 | |||
| 570 | return true; |
||
| 571 | } |
||
| 572 | Console_RegisterCommand(PID_ConfigStartValue, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Constants(), PID_Constants()); }); |
||
| 573 | |||
| 574 | function PID_ConfigOnOff(alias_name, OnValue, OffValue, OuterRange, InnerRange) |
||
| 575 | { |
||
| 576 | if (arguments.length < 5) |
||
| 577 | { |
||
| 578 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 579 | return false; |
||
| 580 | } |
||
| 581 | var aliases_data = Module_ResolveAlias(alias_name, PID_ModuleNames); |
||
| 582 | var found = false; |
||
| 583 | |||
| 584 | for (var name in aliases_data) |
||
| 585 | { |
||
| 586 | var variables= { "OnValue" : OnValue, |
||
| 587 | "OffValue" : OffValue, |
||
| 588 | "OuterRange" : OuterRange, |
||
| 589 | "InnerRange" : InnerRange}; |
||
| 590 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "CONFIG_ONOFF_REGULATOR", variables)) |
||
| 591 | { |
||
| 592 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m"); |
||
| 593 | Log("\033[32mOnValue = " + OnValue+ "OffValue= " + OffValue+ "OuterRange= " + OuterRange+ "InnerRange= " + InnerRange+ ".\033[0m\n"); |
||
| 594 | } |
||
| 595 | else |
||
| 596 | { |
||
| 597 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
||
| 598 | } |
||
| 599 | |||
| 600 | found = true; |
||
| 601 | } |
||
| 602 | |||
| 603 | if (!found) |
||
| 604 | { |
||
| 605 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 606 | return false; |
||
| 607 | } |
||
| 608 | |||
| 609 | return true; |
||
| 610 | } |
||
| 611 | Console_RegisterCommand(PID_ConfigOnOff, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, PID_Aliases(), PID_Temperatures(), PID_Temperatures(), PID_Outputs(), PID_Outputs()); }); |
||
| 612 | |||
| 613 | |||
| 614 | |||
| 1765 | linlun | 615 | function PID_OnMessage(module_name, module_id, command, variables) |
| 616 | { |
||
| 617 | if (in_array(PID_ModuleNames, module_name)) |
||
| 618 | { |
||
| 619 | var aliases_data = Module_LookupAliases({ |
||
| 620 | "module_name" : module_name, |
||
| 621 | "module_id" : module_id, |
||
| 622 | "group" : false |
||
| 623 | }); |
||
| 624 | |||
| 625 | switch (command) |
||
| 626 | { |
||
| 627 | case "DEBUG": |
||
| 628 | for (var alias_name in aliases_data) |
||
| 629 | { |
||
| 630 | var last_value = {}; |
||
| 631 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 632 | |||
| 633 | if (last_value_string) |
||
| 634 | { |
||
| 635 | last_value = eval("(" + last_value_string + ")"); |
||
| 636 | } |
||
| 637 | |||
| 2076 | linlun | 638 | 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 | 639 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 640 | //Log("Got message DEBUG"); |
||
| 641 | } |
||
| 642 | break; |
||
| 643 | case "CONFIG_SENSOR": |
||
| 644 | for (var alias_name in aliases_data) |
||
| 645 | { |
||
| 646 | var last_value = {}; |
||
| 647 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 648 | |||
| 649 | if (last_value_string) |
||
| 650 | { |
||
| 651 | last_value = eval("(" + last_value_string + ")"); |
||
| 652 | } |
||
| 653 | |||
| 2076 | linlun | 654 | last_value["Sensor"] = { "value" : { "sensorModuleType" : variables["sensorModuleType"],"sensorModuleId" : variables["sensorModuleId"],"sensorId" : variables["sensorId"] }, "timestamp" : get_time() }; |
| 1765 | linlun | 655 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 656 | } |
||
| 657 | break; |
||
| 658 | case "CONFIG_ACTUATOR": |
||
| 659 | for (var alias_name in aliases_data) |
||
| 660 | { |
||
| 661 | var last_value = {}; |
||
| 662 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 663 | |||
| 664 | if (last_value_string) |
||
| 665 | { |
||
| 666 | last_value = eval("(" + last_value_string + ")"); |
||
| 667 | } |
||
| 668 | |||
| 2076 | linlun | 669 | last_value["Actuator"] = { "value" : { "actuatorModuleType" : variables["actuatorModuleType"],"actuatorModuleId" : variables["actuatorModuleId"],"actuatorId" : variables["actuatorId"] }, "timestamp" : get_time() }; |
| 1765 | linlun | 670 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 671 | } |
||
| 672 | break; |
||
| 673 | case "CONFIG_PARAMETER": |
||
| 674 | for (var alias_name in aliases_data) |
||
| 675 | { |
||
| 676 | var last_value = {}; |
||
| 677 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 678 | |||
| 679 | if (last_value_string) |
||
| 680 | { |
||
| 681 | last_value = eval("(" + last_value_string + ")"); |
||
| 682 | } |
||
| 683 | |||
| 2076 | linlun | 684 | 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 | 685 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 686 | } |
||
| 687 | break; |
||
| 688 | case "PID_STATUS": |
||
| 689 | for (var alias_name in aliases_data) |
||
| 690 | { |
||
| 691 | var last_value = {}; |
||
| 692 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 693 | |||
| 694 | if (last_value_string) |
||
| 695 | { |
||
| 696 | last_value = eval("(" + last_value_string + ")"); |
||
| 697 | } |
||
| 698 | |||
| 2076 | linlun | 699 | last_value["PID_status"] = { "value" : { "Measurment" : variables["Measurment"],"Reference" : variables["Reference"],"PWM" : variables["PWM"],"Sum" : variables["Sum"] }, "timestamp" : get_time() }; |
| 1765 | linlun | 700 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 701 | } |
||
| 2280 | linlun | 702 | //Log("PID status: mea:" + this.Measurment + " ref:" + this.Reference + " pwm:" + this.PWM/100 + " sum:" + this.Sum + "\n"); |
| 1765 | linlun | 703 | //this.callEvent("newValue", canMessage.getData("Id")); |
| 704 | |||
| 705 | //var self = this; |
||
| 706 | // 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+""); |
||
| 707 | break; |
||
| 708 | case "Temperature_Celsius": |
||
| 709 | for (var alias_name in aliases_data) |
||
| 710 | { |
||
| 711 | var last_value = {}; |
||
| 712 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 713 | |||
| 714 | if (last_value_string) |
||
| 715 | { |
||
| 716 | last_value = eval("(" + last_value_string + ")"); |
||
| 717 | } |
||
| 718 | |||
| 2076 | linlun | 719 | last_value["Reference"] = { "value" : variables["Value"], "timestamp" : get_time() }; |
| 1765 | linlun | 720 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 721 | } |
||
| 722 | break; |
||
| 723 | case "Report_Interval": |
||
| 724 | this.myReportInterval = canMessage.getData("Time"); |
||
| 725 | break; |
||
| 2280 | linlun | 726 | |
| 727 | case "CONFIG_PARAMETER_P_I": |
||
| 728 | for (var alias_name in aliases_data) |
||
| 729 | { |
||
| 730 | var last_value = {}; |
||
| 731 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 732 | |||
| 733 | if (last_value_string) |
||
| 734 | { |
||
| 735 | last_value = eval("(" + last_value_string + ")"); |
||
| 736 | } |
||
| 737 | |||
| 2300 | linlun | 738 | last_value["Parameters"] = { "value" : { |
| 739 | "K_P" : variables["K_P"], |
||
| 740 | "K_I" : variables["K_I"], |
||
| 741 | "K_D" : last_value["Parameters"]["value"]["K_D"], |
||
| 742 | "ControllerDirection" : last_value["Parameters"]["value"]["ControllerDirection"], |
||
| 743 | "TimeUnit" : last_value["Parameters"]["value"]["TimeUnit"], |
||
| 744 | "RegulatorTime" : last_value["Parameters"]["value"]["RegulatorTime"], |
||
| 745 | "OnValue" : last_value["Parameters"]["value"]["OnValue"], |
||
| 746 | "OffValue" : last_value["Parameters"]["value"]["OffValue"] , |
||
| 747 | "OuterRange" : last_value["Parameters"]["value"]["OuterRange"] , |
||
| 748 | "InnerRange" : last_value["Parameters"]["value"]["InnerRange"] , |
||
| 749 | "Factor" : last_value["Parameters"]["value"]["Factor"] , |
||
| 750 | "Offset" : last_value["Parameters"]["value"]["Offset"] |
||
| 751 | }, "timestamp" : get_time() }; |
||
| 2280 | linlun | 752 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 2300 | linlun | 753 | //Log("Stored PI"); |
| 2280 | linlun | 754 | } |
| 2300 | linlun | 755 | break; |
| 2280 | linlun | 756 | case "CONFIG_PARAMETER_D_T": |
| 757 | for (var alias_name in aliases_data) |
||
| 758 | { |
||
| 759 | var last_value = {}; |
||
| 760 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 761 | |||
| 762 | if (last_value_string) |
||
| 763 | { |
||
| 764 | last_value = eval("(" + last_value_string + ")"); |
||
| 765 | } |
||
| 2300 | linlun | 766 | last_value["Parameters"] = { "value" : { |
| 767 | "K_P" : last_value["Parameters"]["value"]["K_P"], |
||
| 768 | "K_I" : last_value["Parameters"]["value"]["K_I"], |
||
| 769 | "K_D" : variables["K_D"], |
||
| 770 | "ControllerDirection" : variables["ControllerDirection"], |
||
| 771 | "TimeUnit" : variables["TimeUnit"], |
||
| 772 | "RegulatorTime" : variables["RegulatorTime"], |
||
| 773 | "OnValue" : last_value["Parameters"]["value"]["OnValue"], |
||
| 774 | "OffValue" : last_value["Parameters"]["value"]["OffValue"] , |
||
| 775 | "OuterRange" : last_value["Parameters"]["value"]["OuterRange"] , |
||
| 776 | "InnerRange" : last_value["Parameters"]["value"]["InnerRange"] , |
||
| 777 | "Factor" : last_value["Parameters"]["value"]["Factor"] , |
||
| 778 | "Offset" : last_value["Parameters"]["value"]["Offset"] |
||
| 779 | }, "timestamp" : get_time() }; |
||
| 2280 | linlun | 780 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 2300 | linlun | 781 | //Log("Stored DT for "+ alias_name); |
| 2280 | linlun | 782 | } |
| 2300 | linlun | 783 | break; |
| 784 | case "CONFIG_ONOFF_REGULATOR": |
||
| 785 | for (var alias_name in aliases_data) |
||
| 786 | { |
||
| 787 | var last_value = {}; |
||
| 788 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 789 | |||
| 790 | if (last_value_string) |
||
| 791 | { |
||
| 792 | last_value = eval("(" + last_value_string + ")"); |
||
| 793 | } |
||
| 794 | last_value["Parameters"] = { "value" : { |
||
| 795 | "K_P" : last_value["Parameters"]["value"]["K_P"], |
||
| 796 | "K_I" : last_value["Parameters"]["value"]["K_I"], |
||
| 797 | "K_D" : last_value["Parameters"]["value"]["K_D"], |
||
| 798 | "ControllerDirection" : last_value["Parameters"]["value"]["ControllerDirection"], |
||
| 799 | "TimeUnit" : last_value["Parameters"]["value"]["TimeUnit"], |
||
| 800 | "RegulatorTime" : last_value["Parameters"]["value"]["RegulatorTime"], |
||
| 801 | "OnValue" : variables["OnValue"], |
||
| 802 | "OffValue" : variables["OffValue"] , |
||
| 803 | "OuterRange" : variables["OuterRange"] , |
||
| 804 | "InnerRange" : variables["InnerRange"] , |
||
| 805 | "Factor" : last_value["Parameters"]["value"]["Factor"] , |
||
| 806 | "Offset" : last_value["Parameters"]["value"]["Offset"] |
||
| 807 | }, "timestamp" : get_time() }; |
||
| 808 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
||
| 809 | //Log("Stored DT for "+ alias_name); |
||
| 810 | } |
||
| 811 | break; |
||
| 812 | case "CONFIG_PID_START_VALUE": |
||
| 813 | for (var alias_name in aliases_data) |
||
| 814 | { |
||
| 815 | var last_value = {}; |
||
| 816 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 817 | |||
| 818 | if (last_value_string) |
||
| 819 | { |
||
| 820 | last_value = eval("(" + last_value_string + ")"); |
||
| 821 | } |
||
| 822 | last_value["Parameters"] = { "value" : { |
||
| 823 | "K_P" : last_value["Parameters"]["value"]["K_P"], |
||
| 824 | "K_I" : last_value["Parameters"]["value"]["K_I"], |
||
| 825 | "K_D" : last_value["Parameters"]["value"]["K_D"], |
||
| 826 | "ControllerDirection" : last_value["Parameters"]["value"]["ControllerDirection"], |
||
| 827 | "TimeUnit" : last_value["Parameters"]["value"]["TimeUnit"], |
||
| 828 | "RegulatorTime" : last_value["Parameters"]["value"]["RegulatorTime"], |
||
| 829 | "OnValue" : last_value["Parameters"]["value"]["OnValue"], |
||
| 830 | "OffValue" : last_value["Parameters"]["value"]["OffValue"] , |
||
| 831 | "OuterRange" : last_value["Parameters"]["value"]["OuterRange"] , |
||
| 832 | "InnerRange" : last_value["Parameters"]["value"]["InnerRange"] , |
||
| 833 | "Factor" : variables["Factor"] , |
||
| 834 | "Offset" : variables["Offset"] |
||
| 835 | }, "timestamp" : get_time() }; |
||
| 836 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
||
| 837 | //Log("Stored DT for "+ alias_name); |
||
| 838 | } |
||
| 839 | break; |
||
| 2280 | linlun | 840 | case "P_I_term": |
| 841 | for (var alias_name in aliases_data) |
||
| 842 | { |
||
| 843 | var last_value = {}; |
||
| 844 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 845 | |||
| 846 | if (last_value_string) |
||
| 847 | { |
||
| 848 | last_value = eval("(" + last_value_string + ")"); |
||
| 849 | } |
||
| 850 | |||
| 851 | 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() }; |
||
| 852 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
||
| 853 | //Log("Got message DEBUG"); |
||
| 854 | } |
||
| 855 | break; |
||
| 856 | case "D_term_Out": |
||
| 857 | for (var alias_name in aliases_data) |
||
| 858 | { |
||
| 859 | var last_value = {}; |
||
| 860 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 861 | |||
| 862 | if (last_value_string) |
||
| 863 | { |
||
| 864 | last_value = eval("(" + last_value_string + ")"); |
||
| 865 | } |
||
| 866 | |||
| 2300 | linlun | 867 | //Log("Got message DEBUG"); |
| 2280 | linlun | 868 | |
| 869 | 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() }; |
||
| 870 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
||
| 871 | //Log("Got message DEBUG"); |
||
| 872 | } |
||
| 873 | break; |
||
| 874 | case "OutMinMax": |
||
| 875 | for (var alias_name in aliases_data) |
||
| 876 | { |
||
| 877 | var last_value = {}; |
||
| 878 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
||
| 879 | |||
| 880 | if (last_value_string) |
||
| 881 | { |
||
| 882 | last_value = eval("(" + last_value_string + ")"); |
||
| 883 | } |
||
| 884 | |||
| 2300 | linlun | 885 | last_value["Debug"] = { "value" : { |
| 886 | "P_term" : last_value["Debug"]["value"]["P_term"], |
||
| 887 | "I_term" : last_value["Debug"]["value"]["I_term"], |
||
| 888 | "D_term" : last_value["Debug"]["value"]["D_term"], |
||
| 889 | "Output" : last_value["Debug"]["value"]["Output"], |
||
| 890 | "Min" : variables["Min"], |
||
| 891 | "Max" : variables["Max"] |
||
| 892 | },"timestamp" : get_time() }; |
||
| 2280 | linlun | 893 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 894 | //Log("Got message DEBUG"); |
||
| 895 | } |
||
| 896 | break; |
||
| 1765 | linlun | 897 | } |
| 898 | } |
||
| 899 | } |
||
| 900 | Module_RegisterToOnMessage("all", PID_OnMessage); |
||
| 2300 | linlun | 901 | /*PID={"rrd":{"file":"/var/www/CANgraph/PID.rrd","Period_s":"10"}, "rrdNames":{"Pterm":{"Module":"PID","data":"Debug","value":"P_term"},"Iterm":{"Module":"PID","data":"Debug","value":"I_term"}."Dterm":{"Module":"PID","data":"Debug","value":"D_term"},"KP":{"Module":"PID","data":"Parameters","value":"K_P"},"KI":{"Module":"PID","data":"Parameters","value":"K_I"},"KD":{"Module":"PID","data":"Parameters","value":"K_D"},"out":{"Module":"PID","data":"Debug","value":"Output"},"ref":{"Module":"PID","data":"Reference","value":"value"},"in":{"Module":"PID","data":"PID_status","value":"Measurment"}}}*/ |