1 /*----------------------------------------------------------------------------+ 2 | | 3 | Enhanced HEYU Functionality for Uploaded Timers and Macros | 4 | Copyright 2002,2003,2004,2005,2006 Charles W. Sullivan | 5 | | 6 | | 7 | As used herein, HEYU is a trademark of Daniel B. Suthers. | 8 | X10, CM11A, and ActiveHome are trademarks of X-10 (USA) Inc. | 9 | The author is not affiliated with either entity. | 10 | | 11 | Charles W. Sullivan | 12 | Co-author and Maintainer | 13 | Greensboro, North Carolina | 14 | Email ID: cwsulliv01 | 15 | Email domain: -at- heyu -dot- org | 16 | | 17 +----------------------------------------------------------------------------*/ 18 19 /* 20 * This program is free software: you can redistribute it and/or modify 21 * it under the terms of the GNU General Public License as published by 22 * the Free Software Foundation, either version 3 of the License, or 23 * (at your option) any later version. 24 * 25 * This program is distributed in the hope that it will be useful, 26 * but WITHOUT ANY WARRANTY; without even the implied warranty of 27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 * GNU General Public License for more details. 29 * 30 * You should have received a copy of the GNU General Public License 31 * along with this program. If not, see <http://www.gnu.org/licenses/>. 32 * 33 */ 34 35 #include <sys/types.h> 36 #include <sys/stat.h> 37 #include <time.h> 38 39 /* Some array length limits */ 40 #define NAME_LEN 32 /* Alias label length */ 41 #define MACRO_LEN 32 /* Macro label length */ 42 #define SCENE_LEN 32 /* Scene label length */ 43 #define PATH_LEN 127 /* File paths */ 44 #define LINE_LEN 4096 /* Line length in input files */ 45 46 #ifndef NUM_FLAG_BANKS 47 #define NUM_FLAG_BANKS 1 /* 32 flags per bank, maximum 32 banks (1024 flags) */ 48 #endif 49 #ifndef NUM_COUNTER_BANKS 50 #define NUM_COUNTER_BANKS 1 /* 32 counters per bank, maximum 32 banks (1024 counters) */ 51 #endif 52 #ifndef NUM_TIMER_BANKS 53 #define NUM_TIMER_BANKS 1 /* 32 user timers per bank, maximum 32 banks (1024 timers) */ 54 #endif 55 56 #define NUM_USER_TIMERS (32 * NUM_TIMER_BANKS) 57 58 59 /* Maximum number of unsigned long data storage locations */ 60 /* in x10global state tables. */ 61 #define MAXDATASTORAGE 128 62 63 /* Values for x10config variables DAWN_OPTION and DUSK_OPTION */ 64 #define FIRST 1 65 #define EARLIEST 2 66 #define LATEST 3 67 #define AVERAGE 4 68 #define MEDIAN 5 69 70 /* Values for LAUNCH_SCRIPTS */ 71 #define FIRST_MATCH 0 72 #define ALL_MATCH 1 73 74 /* Values for Launcher flow mode */ 75 #define FM_CONTINUE 1 76 #define FM_BREAK 2 77 78 /* Bitmaps for x10config variables LAUNCH_SOURCE */ 79 #define SNDC 1 80 #define SNDM 2 81 #define SNDP 4 82 #define SNDS 8 83 #define SNDT 16 84 #define RCVI 32 85 #define RCVT 64 86 #define SNDA 128 87 #define RCVA 256 88 #define XMTF 512 89 #define LSNONE 1024 90 #define LSALL (SNDC | SNDM | SNDT | RCVI | RCVT | SNDA | RCVA | XMTF) 91 92 enum {SndC, SndM, SndP, SndS, SndT, RcvI, RcvT, SndA, RcvA, Xmtf}; 93 94 /* Bitmaps for script options */ 95 #define SCRIPT_HEYU 0 /* Generate heyu environment for scripts */ 96 #define SCRIPT_XTEND 1 /* Generate xtend environment for scripts */ 97 #define SCRIPT_RAWLEVEL 2 /* Heyu environ variables use raw levels */ 98 #define SCRIPT_NOENV 4 /* Create no new environment variables */ 99 #define SCRIPT_QUIET 8 /* Suppress display of command line in log file */ 100 #define SCRIPT_QQUIET 16 /* Suppress display of launcher in log file */ 101 102 /* Values for script_mode */ 103 #define HEYU_SCRIPT 0 /* Use general heyu scripting */ 104 #define HEYU_HELPER 1 /* Use heyuhelper */ 105 106 /* Function Modes */ 107 #define FUNC_ACTUAL 0 108 #define FUNC_GENERIC 1 109 110 /* Flags for alias options (Preset modules only) */ 111 #define ALFLAG_RESUME 1 /* 'resume level' has been set */ 112 #define ALFLAG_FIXED 2 /* 'fixed on level' has been set */ 113 114 /* Values for x10config variabe RESOLVE_OVERLAP */ 115 #define RES_OVLAP_SEPARATE 0 116 #define RES_OVLAP_COMBINED 1 117 118 /* Yes/No */ 119 #define NO 0 120 #define YES 1 121 #define VERBOSE 3 122 #define IGNORE 4 123 #define NO_ANSWER 0xff 124 125 /* Check lockup */ 126 #define CHECK_PORT 1 127 #define CHECK_CM11 2 128 129 #define DISABLE 0 130 #define ENABLE 1 131 132 #define NATIVE 0 133 #define SCALED 1 134 135 #define SC_SINGLE 0 136 #define SC_BITMAP 1 137 138 #define PCTMODE 0 139 #define RAWMODE 1 140 141 /* Module Option flags (alias[].optflags) */ 142 #define MOPT_RESUME 0x00000001 143 #define MOPT_ONFULL 0x00000002 144 #define MOPT_SENSOR 0x00000004 145 #define MOPT_SECURITY 0x00000008 146 #define MOPT_ENTERTAIN 0x00000010 147 #define MOPT_NOPLC 0x00000020 148 #define MOPT_RFIGNORE 0x00000040 149 #define MOPT_TRANSCEIVE 0x00000080 150 #define MOPT_RFFORWARD 0x00000100 151 #define MOPT_REVERSE 0x00000200 152 #define MOPT_MAIN 0x00000400 153 #define MOPT_AUX 0x00000800 154 #define MOPT_RFXSENSOR 0x00001000 155 #define MOPT_RFXT2 0x00002000 156 #define MOPT_RFXVS 0x00004000 157 #define MOPT_RFXVAD 0x00008000 158 #define MOPT_RFXRH 0x00010000 159 #define MOPT_RFXBP 0x00020000 160 #define MOPT_RFXPOT 0x00040000 161 #define MOPT_RFXPULSE 0x00080000 162 #define MOPT_RFXPOWER 0x00100000 163 #define MOPT_RFXWATER 0x00200000 164 #define MOPT_RFXGAS 0x00400000 165 #define MOPT_RFXCOUNT 0x00800000 166 #define MOPT_HEARTBEAT 0x01000000 167 #define MOPT_PLCSENSOR 0x02000000 168 #define MOPT_LOBAT 0x04000000 169 #define MOPT_LOBATUNKN 0x08000000 170 #define MOPT_KAKU 0x10000000 171 172 #define MOPT_RFXMETER (MOPT_RFXPULSE | MOPT_RFXPOWER | MOPT_RFXWATER | MOPT_RFXGAS | MOPT_RFXCOUNT) 173 174 /* More Module Option flags (alias[].optflags2) */ 175 #define MOPT2_TMIN 0x00000001 176 #define MOPT2_TMAX 0x00000002 177 #define MOPT2_RHMIN 0x00000004 178 #define MOPT2_RHMAX 0x00000008 179 #define MOPT2_BPMIN 0x00000010 180 #define MOPT2_BPMAX 0x00000020 181 #define MOPT2_DUMMY 0x00000040 182 #define MOPT2_SWMAX 0x00000080 183 #define MOPT2_SWHOME 0x00000100 184 #define MOPT2_IATO 0x00000200 /* Inactive timeout */ 185 #define MOPT2_AUF 0x00000400 /* ACT AllUnitsOff option */ 186 #define MOPT2_ALO 0x00000800 /* ACT AllLightsOn option */ 187 #define MOPT2_ALF 0x00001000 /* ACT AllLightsOff option */ 188 #define MOPT2_DEFER 0x00002000 /* Defer update until StatusOn/Off */ 189 190 /* Maximum number of security and RFXMeter sensors */ 191 /* (door/window, motion sensor) */ 192 #define MAX_SEC_SENSORS 256 193 #define MAX_RFX_SENSORS 256 194 195 /* Old/New */ 196 #define OLD 0 197 #define NEW 1 198 199 /* High/Low */ 200 #define HIGH_STATE 1 201 #define LOW_STATE 0 202 203 /* Config option */ 204 #define CONFIG_INIT 0 205 #define CONFIG_RESTART 1 206 207 /* Start/Restart */ 208 #define E_START 0 209 #define E_RESTART 1 210 211 /* Manual or Automatic */ 212 #define MANUAL 0 213 #define AUTOMATIC 1 214 215 /* For MIN/MAX DAWN/DUSK */ 216 #define OFF -1 217 218 /* Bitmaps for mode variables */ 219 #define UNSPECIFIED 0 220 #define COMPATIBLE 1 221 #define HEYU_MODE 2 222 #define HAS_TIMERS 16 223 224 /* Values for variable CM11A_DAY_ZERO */ 225 #define ZERO 0 226 #define TODAY 1 227 #define MIXED 2 228 229 /* Values involving the X10 Record File */ 230 #define VALID_RECORD_FILE 0 231 #define SCHEDULE_EXPIRED -1 232 #define NO_EXPIRATION -2 233 #define NO_RECORD_FILE -3 234 #define BAD_RECORD_FILE -4 235 236 /* Prefixes for combined and delay-modified macro names */ 237 #define COMB_MAC_PREFIX "_co" 238 #define DELAY_MAC_PREFIX "_de" 239 #define SECUR_MAC_PREFIX "_se" 240 241 /* Prefix for subdirectories under xxxBASEDIR */ 242 /* (For optional use with command line parameters */ 243 /* -0 ... -9 when there is a CM11A interface on */ 244 /* more than one serial port.) */ 245 #define HEYUSUB_PREFIX "" 246 247 /* Files which must have a fixed name and be */ 248 /* in a fixed location. */ 249 250 #define CONFIG_FILE "x10config" 251 #define CONFIG_FILE_ETC "x10.conf" 252 #define RECORD_FILE "x10record" 253 #define MACROXREF_FILE "x10macroxref" 254 #define IMAGE_FILE "x10image" 255 #define STATE_FILE "x10state" 256 #define RESTART_RELAY_FILE "__restart_relay" 257 #define RESTART_AUX_FILE "__restart_aux" 258 259 /* Device types */ 260 #define DEV_CM11A 0 261 #define DEV_CM10A 1 262 #define DEV_CM17A 2 263 #define DEV_W800RF32 4 264 #define DEV_MR26A 8 265 #define DEV_RFXCOM32 16 266 #define DEV_RFXCOMVL 32 267 #define DEV_DUMMY 256 268 269 /* TTY */ 270 #define TTY_CLOSED -1 271 #define TTY_DUMMY -2 272 273 /* Date Formats */ 274 #define YMD_ORDER 1 275 #define DMY_ORDER 2 276 #define MDY_ORDER 4 277 278 /* Aux daemon transceive/transcode defaults */ 279 #define TR_NONE 0 280 #define TR_ALL 0xffff 281 282 /* X10 RF code types */ 283 #define RF_STD 0 /* Standard X10 RF */ 284 #define RF_ENT 1 /* Entertainment X10 RF */ 285 #define RF_SEC 2 /* Security X10 RF */ 286 #define RF_XSENSOR 3 /* RFXSensor data */ 287 #define RF_XMETER 4 /* RFXMeter data */ 288 #define RF_DUSK 5 /* Security Dusk RF */ 289 #define RF_VISONIC 6 /* Visonic sensors and remotes */ 290 #define RF_XJAM 7 /* RFXCOMVL jamming signal */ 291 #define RF_XJAM32 8 /* RFXCOM32 jamming signal */ 292 #define RF_SEC16 9 /* Security X10 RF 16-bit ID */ 293 #define RF_DIGIMAX 10 /* Digimax */ 294 #define RF_OREGON 11 /* Oregon sensors */ 295 #define RF_ELECSAVE 12 /* Electrisave sensor */ 296 #define RF_SECX 13 /* DM10 Alert */ 297 #define RF_KAKU 14 /* KAKU/HomeEasy */ 298 #define RF_OWL 15 /* OWL CM119 */ 299 #define RF_VDATAM 16 /* VDATA for memory byte */ 300 301 #define RF_XSENSORHDR 0x77 /* RFXSensor Initialization */ 302 #define RF_RAWW800 0x78 /* Raw data from W800RF32A */ 303 #define RF_RAWMR26 0x79 /* Raw data from MR26A */ 304 #define RF_RAWVL 0x7a /* Raw variable length */ 305 #define RF_FLOOD 0x7b /* Unceasing RF signals */ 306 #define RF_TEST 0x7c 307 #define RF_NOISEW800 0x7d /* Noise from W800RF32A */ 308 #define RF_NOISEMR26 0x7e /* Noise from MR26A */ 309 #define RF_NOISEVL 0x7f /* Variable length noise */ 310 311 /* RF Raw display modes */ 312 #define DISPMODE_RF_NONE 0 313 #define DISPMODE_RF_NORMAL 1 314 #define DISPMODE_RF_NOISE 2 315 316 /* Treatment of RF codes */ 317 #define RF_IGNORE 0 318 #define RF_FORWARD 1 319 #define RF_TRANSCEIVE 2 320 321 /* RFXSensor ID offsets */ 322 #define RFX_T 0 /* Temperature */ 323 #define RFX_H 1 /* Humidity or Pressure A/D */ 324 #define RFX_S 2 /* Supply Voltage A/D */ 325 326 /* RFXSensor output bitmap */ 327 #define RFXO_T 0x0001 /* Temperature */ 328 #define RFXO_H 0x0002 /* Humidity */ 329 #define RFXO_S 0x0004 /* Supply Voltage */ 330 #define RFXO_V 0x0008 /* A/D Voltage */ 331 #define RFXO_B 0x0010 /* Barometric Pressure */ 332 #define RFXO_P 0x0020 /* Potentiometer */ 333 #define RFXO_T2 0x0040 /* Second Temperature */ 334 #define RFXO_LO 0x0080 /* Low battery */ 335 #define RFXO_VI 0x0100 /* Internal A/D Voltage */ 336 #define RFXO_ALL 0xffff 337 338 #define RAISE_DTR 1 339 #define RAISE_RTS 2 340 341 #define ADDR_STD 0x40 /* Includes a HU address */ 342 #define ADDR_EXT 0x80 /* Virtual extended housecode Q-Z */ 343 344 /* Wind Direction bitmap */ 345 #define COMPASS_POINTS 1 346 #define COMPASS_ANGLE 2 347 348 /* Wind speed bitmap */ 349 #define WINDSPEED 1 350 #define BEAUFORT 2 351 352 /* RFXCOM Receiver types and positions */ 353 #define RFXX10 0 354 #define VISONIC 1 355 #define RFXMASTER 0 356 #define RFXSLAVE 1 357 358 /* The state engine lockfile */ 359 #define STATE_LOCKFILE "heyu.engine" 360 361 /* These files are written for 'heyu upload' or */ 362 /* 'heyu upload check' if the WRITE_CHECK_FILES */ 363 /* directive in the x10config file is YES. */ 364 #define RECORD_FILE_CHECK "x10record.check" 365 #define MACROXREF_FILE_CHECK "x10macroxref.check" 366 #define IMAGE_BIN_FILE "x10image.bin" 367 #define IMAGE_FILE_CHECK "x10image.check" 368 #define IMAGE_HEX_FILE "x10image.hex" 369 370 /* Other files */ 371 #define REPORT_FILE "report.txt" 372 #define CRON_REPORT_FILE "cronreport.txt" 373 #define SUN_TABLE_FILE "sun_%d.txt" 374 375 enum {RiseSet, CivilTwi, NautTwi, AstroTwi, AngleOffset, }; 376 enum {ArmLogicStrict, ArmLogicMedium, ArmLogicLoose}; 377 378 #define RFXCOM_ARCTECH 0x00000001 379 #define RFXCOM_OREGON 0x00000002 380 #define RFXCOM_ATIWONDER 0x00000004 381 #define RFXCOM_X10 0x00000008 382 #define RFXCOM_VISONIC 0x00000010 383 #define RFXCOM_KOPPLA 0x00000020 384 #define RFXCOM_HE_UK 0x00000040 385 #define RFXCOM_HE_EU 0x00000080 386 387 /* Default values for X10 configuration file */ 388 389 #define DEF_MODE COMPATIBLE 390 #define DEF_SCHEDFILE "x10.sched" 391 #define DEF_PROGRAM_DAYS 366 392 #define DEF_COMBINE_EVENTS YES 393 #define DEF_COMPRESS_MACROS NO 394 #define DEF_FEB_KLUGE YES 395 #define DEF_HOUSECODE 'A' 396 #define DEF_DAWN_OPTION FIRST 397 #define DEF_DUSK_OPTION FIRST 398 #define DEF_DAWN_SUBSTITUTE (6*60) 399 #define DEF_DUSK_SUBSTITUTE (18*60) 400 #define DEF_MIN_DAWN OFF 401 #define DEF_MAX_DAWN OFF 402 #define DEF_MIN_DUSK OFF 403 #define DEF_MAX_DUSK OFF 404 #define DEF_CHECK_FILES NO 405 #define DEF_TTY "/dev/ttyS0" 406 #define DEF_REPL_DELAYED_MACROS YES 407 #define DEF_FORCE_ADDR NO 408 #define DEF_ACK_HAILS NO 409 #define DEF_TRIGGER_TAG YES 410 #define DEF_XREF_APPEND NO 411 #define DEF_RCS_TEMPERATURE NO 412 #define DEF_MACTERM YES 413 #define DEF_MAX_PPARMS 8 414 #define DEF_STATUS_TIMEOUT 2 415 #define DEF_SPF_TIMEOUT 3 416 #define DEF_DISPLAY_OFFSET YES 417 #define DEF_RESERVED_TIMERS 0 418 #define DEF_DISPLAY_EXP_MACROS YES 419 #define DEF_AUTO_CHAIN NO 420 #define DEF_MODULE_TYPES YES 421 #define DEF_LAUNCH_MODE TMODE_SIGNAL 422 #define DEF_LAUNCH_SOURCE RCVI 423 #define DEF_RES_OVERLAP RES_OVLAP_SEPARATE 424 #define DEF_DEFAULT_MODULE "LM" 425 #define DEF_SCRIPT_OPTION SCRIPT_HEYU 426 #define DEF_SCRIPT_MODE HEYU_SCRIPT 427 #define DEF_FUNCTION_MODE FUNC_ACTUAL 428 #define DEF_LOGFILE "/dev/null" 429 #define DEF_ISDARK_OFFSET 30 430 #define DEF_ENV_ALIAS_PREFIX "x10" 431 #define DEF_DEVICE_TYPE DEV_CM11A 432 #define DEF_SUNMODE RiseSet 433 #define DEF_FIX_5A YES 434 #define DEF_AUTOFETCH YES 435 #define DEF_PFAIL_UPDATE YES 436 #define DEF_CM17A_BIT_DELAY 500 437 #define DEF_RF_BURST_SPACING 110 438 #define DEF_RF_TIMER_TWEAK 20 439 #define DEF_RF_POST_DELAY 850 440 #define DEF_RF_FARB_DELAY 850 441 #define DEF_RF_FARW_DELAY 850 442 #define DEF_DISP_RF_XMIT YES 443 #define DEF_RF_BURSTS 5 444 #define DEF_RESTRICT_DIMS YES 445 #define DEF_STATE_FORMAT NEW 446 #define DEF_CM11_POST_DELAY 80 /* 4 cycles @ 50 Hz */ 447 #define DEF_START_ENGINE MANUAL 448 #define DEF_RF_NOSWITCH NO 449 #define DEF_RESPOOL_PERMS 01777 450 #define DEF_SPOOLFILE_MAX 1000000 451 #define DEF_CHECK_RI_LINE YES 452 #define DEF_RING_CTRL ENABLE 453 #define DEF_SEND_RETRIES 3 454 #define DEF_SCRIPT_CTRL ENABLE 455 #define DEF_TRANSCEIVE TR_ALL 456 #define DEF_RFFORWARD TR_NONE 457 #define DEF_TRANS_DIMLEVEL 2 458 #define DEF_STATE_CTRL SC_SINGLE 459 #define DEF_RF_FUNCMASK 0x7f 460 #define DEF_DISP_RF_NOISE NO 461 #define DEF_AUX_MINCOUNT_W800 1 462 #define DEF_AUX_MINCOUNT_MR26 2 463 #define DEF_AUX_MINCOUNT_RFXCOM 1 464 #define DEF_AUX_MINCOUNT_RFX 1 /* RFXSensor data */ 465 #define DEF_AUX_REPCOUNT 8 466 #define DEF_AUX_MAXCOUNT 200 467 #define DEF_AUX_FLOODREP 0 468 #define DEF_HIDE_UNCHANGED NO 469 #define DEF_HIDE_UNCHANGED_INACTIVE NO 470 #define DEF_SHOW_CHANGE NO 471 #define DEF_ARM_MAX_DELAY 0 472 #define DEF_DISP_RAW_RF DISPMODE_RF_NONE 473 #define DEF_ARM_LOGIC ArmLogicMedium 474 #define DEF_INACTIVE_TIMEOUT 14400 /* 4 hours */ 475 #define DEF_HEYU_UMASK 0000 476 #define DEF_LOG_UMASK -1 477 #define DEF_AUTO_WAIT 0 478 #define DEF_FULL_BRIGHT 22 479 #define DEF_ENGINE_POLL 10000 /* microsends */ 480 #define DEF_RFX_TSCALE 'C' 481 #define DEF_RFX_TOFFSET 0.0 482 #define DEF_RFX_VADSCALE 1.0 483 #define DEF_RFX_VADOFFSET 0.0 484 #define DEF_RFX_VADUNITS "Volts" 485 #define DEF_RFX_BPSCALE 1.0 486 #define DEF_RFX_BPOFFSET 0.0 487 #define DEF_RFX_BPUNITS "hPa" 488 #define DEF_RFXCOM_DTR_RTS (RAISE_DTR | RAISE_RTS) 489 #define DEF_DEV_RFXCOM DEV_RFXCOMVL 490 #define DEF_RFXCOM_HIBAUD NO 491 #define DEF_RFX_POWERSCALE 0.001 492 #define DEF_RFX_POWERUNITS "kWh" 493 #define DEF_RFX_WATERSCALE 1.0 494 #define DEF_RFX_WATERUNITS "" 495 #define DEF_RFX_GASSCALE 1.0 496 #define DEF_RFX_GASUNITS "" 497 #define DEF_RFX_PULSESCALE 1.0 498 #define DEF_RFX_PULSEUNITS "" 499 #define DEF_RFXCOM_ENABLE 0 500 #define DEF_RFXCOM_DISABLE 0 501 #define DEF_LOCKUP_CHECK 0 502 #define DEF_TAILPATH "" 503 #define DEF_SUPPRESS_RFXJAM NO 504 #define DEF_DISPLAY_DMXTEMP YES 505 #define DEF_SECURID_16 YES 506 #define DEF_SECURID_MASK 0xffffu 507 #define DEF_SECURID_PARITY YES 508 #define DEF_LOGDATE_YEAR NO 509 #define DEF_DMX_TSCALE 'C' 510 #define DEF_DMX_TOFFSET 0.0 511 #define DEF_ORE_TSCALE 'C' 512 #define DEF_ORE_TOFFSET 0.0 513 #define DEF_ORE_BPSCALE 1.0 514 #define DEF_ORE_BPOFFSET 0.0 515 #define DEF_ORE_BPUNITS "hPa" 516 #define DEF_ORE_WGTSCALE 1.0 517 #define DEF_ORE_WGTUNITS "kg" 518 #define DEF_ORE_LOWBATTERY 20 519 #define DEF_DISPLAY_ORE_ALL NO 520 #define DEF_ORE_CHGBITS_T 1 521 #define DEF_ORE_CHGBITS_RH 1 522 #define DEF_ORE_CHGBITS_BP 1 523 #define DEF_ORE_CHGBITS_WGT 1 524 #define DEF_ORE_CHGBITS_WSP 1 525 #define DEF_ORE_CHGBITS_WAVSP 1 526 #define DEF_ORE_CHGBITS_WDIR 1 527 #define DEF_ORE_CHGBITS_RRATE 1 528 #define DEF_ORE_CHGBITS_RTOT 1 529 #define DEF_ORE_CHGBITS_UV 1 530 #define DEF_ORE_DATA_ENTRY NATIVE 531 #define DEF_ORE_DISPLAY_CHAN YES 532 #define DEF_ORE_DISPLAY_BATLVL YES 533 #define DEF_OREID_16 NO 534 #define DEF_OREID_MASK 0xffffu 535 #define DEF_LOGDATE_UNIX NO 536 #define DEF_INACTIVE_TIMEOUT_ORE 14400 /* 4 hours */ 537 #define DEF_DISPLAY_SENSOR_INTV NO 538 #define DEF_DATE_FORMAT YMD_ORDER 539 #define DEF_DATE_SEPARATOR '/' 540 #define DEF_LOCK_TIMEOUT 10 541 #define DEF_ORE_DISPLAY_FCAST NO 542 #define DEF_CM11A_QUERY_DELAY 0 543 #define DEF_ELS_NUMBER 1 544 #define DEF_ELS_VOLTAGE 0.0 545 #define DEF_ELS_CHGBITS_CURR 1 546 #define DEF_ORE_WINDSCALE 1.0 547 #define DEF_ORE_WINDUNITS "m/s" 548 #define DEF_ORE_WINDSENSORDIR 0 549 #define DEF_ORE_RAINRATESCALE 1.0 550 #define DEF_ORE_RAINRATEUNITS "" 551 #define DEF_ORE_RAINTOTSCALE 1.0 552 #define DEF_ORE_RAINTOTUNITS "" 553 #define DEF_ORE_WINDDIR_MODE (COMPASS_POINTS | COMPASS_ANGLE) 554 #define DEF_ORE_DISPLAY_COUNT NO 555 #define DEF_ORE_DISPLAY_BFT NO 556 #define DEF_SCANMODE FM_BREAK; 557 #define DEF_RFX_INLINE NO 558 #define DEF_OWL_CHGBITS_POWER 1 559 #define DEF_OWL_CHGBITS_ENERGY 1 560 #define DEF_OWL_CALIB_POWER 1.0 561 #define DEF_OWL_CALIB_ENERGY 1.0 562 #define DEF_OWL_VOLTAGE 230.0 563 #define DEF_OWL_DISPLAY_COUNT NO 564 #define DEF_ARM_REMOTE AUTOMATIC 565 #define DEF_ACTIVE_CHANGE NO 566 #define DEF_INACTIVE_HANDLING NEW 567 #define DEF_PROCESS_XMIT NO 568 #define DEF_SHOW_FLAGS_MODE NEW 569 #define DEF_RFX_MASTER RFXX10 570 #define DEF_RFX_SLAVE RFXX10 571 #define DEF_LAUNCHPATH_APPEND "" 572 #define DEF_LAUNCHPATH_PREFIX "" 573 #define DEF_FIX_STOPSTART_ERROR NO 574 #define DEF_CHKSUM_TIMEOUT 10 575 576 #define DTR_INIT LOW_STATE 577 #define RTS_INIT LOW_STATE 578 579 #define SPOOLFILE_ABSMIN 20 580 #define SPOOLFILE_ABSMAX 0x100000 581 582 /* Max errors to display before quitting when */ 583 /* parsing configuration or schedule files. */ 584 585 #define MAX_ERRORS 15 586 587 /* Bitmap flags for timers and tevents */ 588 #define NO_EVENT 0 589 #define CLOCK_EVENT 1 590 #define DAWN_EVENT 2 591 #define DUSK_EVENT 4 592 #define SEC_EVENT 8 593 594 #define PRT_EVENT 16 595 #define COMB_EVENT 32 596 #define SUBST_EVENT 64 597 #define LOST_EVENT 128 598 599 #define TMP_EVENT 256 600 #define ACTIVE_EVENT 512 601 #define NOW_EVENT 1024 602 #define CHAIN_EVENT 2048 603 #define CANCEL_EVENT 4096 604 #define INVALID_EVENT 0xFFFF 605 #define TIME_EVENTS (CLOCK_EVENT | DAWN_EVENT | DUSK_EVENT) 606 #define NOCOPY_EVENTS (PRT_EVENT | LOST_EVENT) 607 608 /* Event cancellation flags */ 609 #define MIN_DAWN_CANCEL 1 610 #define MAX_DAWN_CANCEL 2 611 #define MIN_DUSK_CANCEL 4 612 #define MAX_DUSK_CANCEL 8 613 614 /* Dawn/Dusk limit option flags */ 615 #define DAWNGT 1 616 #define DAWNLT 2 617 #define DUSKGT 4 618 #define DUSKLT 8 619 620 /* Bitmap for shifted events */ 621 #define SAME_DAY 0 622 #define PREV_DAY 1 623 #define NEXT_DAY 2 624 625 /* Bitmap used by function macro_index() */ 626 #define MACRO_PARSER 1 627 #define TIMER_PARSER 2 628 #define TRIGGER_PARSER 4 629 #define CHAIN_PARSER 8 630 #define MACRO_DUPLICATE 16 631 #define DERIVED_MACRO 32 632 633 /* Macro modification bitmap */ 634 #define UNMODIFIED 0 635 #define COMBINED 1 636 #define COMPRESSED 2 637 #define DELAY_MOD 4 638 #define SECURITY_MOD 8 639 #define TERMINATE 16 640 #define CHAINED 32 641 642 #define NULL_MACRO_INDEX 0 643 #define NULL_MACRO_OFFSET 0 644 #define NULL_TIME (120 * 0x0f + 0x7f) /* ( = 1927 minutes ) */ 645 646 /* Flag values for valid Lat/Long. */ 647 #define LATITUDE 1 648 #define LONGITUDE 2 649 650 /* Controls accepted by function get_freespace() */ 651 #define ALL_TIMERS 1 652 #define CLK_TIMERS 2 653 654 /* Arguments for process_data() */ 655 #define PROC_CHECK 1 656 #define PROC_UPLOAD 2 657 658 /* Arguments for direct_cmd() */ 659 #define CMD_VERIFY 0 660 #define CMD_RUN 1 661 #define CMD_INT 2 662 663 /* Counter functions */ 664 #define CNT_SET 0 665 #define CNT_INC 1 666 #define CNT_DEC 2 667 #define CNT_DSKPZ 3 668 #define CNT_DSKPNZ 4 669 #define CNT_DSKPNZIZ 5 670 671 /* Identifies macros which are used over the programmed interval */ 672 #define NOTUSED 0 673 #define USED 1 674 675 #define ACTIVE_START 1 676 #define ACTIVE_STOP 2 677 678 /* Values for Trigger Off/On mode in schedule */ 679 #define TRIGGER_OFF 0 680 #define TRIGGER_ON 1 681 682 /* Value for Trigger Tag */ 683 #define TRIGGER_TAG 0x40 684 #define TIMER_EXEC 0 685 #define TRIGGER_EXEC 1 686 687 /* Values for CM11a security mode bits and offset adjustment */ 688 #define SECURITY_OFF 0x00 689 #define SECURITY_ON 0x02 690 #define SECURITY_OFFSET_ADJUST 30 691 692 /* Bitmap flags for "as-of" dates and times */ 693 #define ASIF_NONE 0 694 #define ASIF_DATE 1 695 #define ASIF_TIME 2 696 697 /* Controls for time_adjust() */ 698 #define LGL2STD 0 699 #define STD2LGL 1 700 701 /* Bitmap flags for SCENE/USERSYN */ 702 #define F_SCENE 1 703 #define F_USYN 2 704 705 /* How to interpret undefined legal times, e.g., in the */ 706 /* USA, times between 02:00 and 02:59 on the day when */ 707 /* Daylight Time goes into effect. */ 708 #define STD_TIME 0 709 #define DST_TIME 1 710 #define UNDEF_TIME STD_TIME 711 712 /* An env variable name for use by the relay */ 713 #define CLOCKSTAMP "HEYUCLOCKSTAMP" 714 715 /* Delay after setclock, reset, purge, or clear */ 716 #define SETCLOCK_DELAY 2000 /* milliseconds */ 717 718 /* Flags for parse_addr() function */ 719 #define A_VALID 1 720 #define A_HCODE 2 721 #define A_BMAP 4 722 #define A_PLUS 8 723 #define A_MINUS 16 724 #define A_ALIAS 32 725 #define A_DUMMY 64 726 #define A_MULT 128 727 #define A_STAR 256 728 729 /* CM17A RF Timing modes */ 730 #define RF_SLOW 0 731 #define RF_FAST 1 732 733 /* Origin of call to parse_config_tail() */ 734 #define SRC_CONFIG 1 735 #define SRC_SCHED 2 736 #define SRC_ENVIRON 4 737 #define SRC_STOP 8 738 #define SRC_HELP 16 739 #define SRC_SYSCHECK 32 740 #define SRC_MULT 64 741 742 /* Phase synch modes */ 743 #define NO_SYNC 0 744 #define RISE_SYNC 1 745 #define FALL_SYNC 2 746 747 /* RFXmitter frequency */ 748 #define MHZ310 1 749 #define MHZ433 2 750 751 /* State engine command functions */ 752 /* 3 bytes: header, function, data */ 753 #define ST_COMMAND 0x7b /* header */ 754 #define ST_INIT_ALL 0 755 #define ST_INIT 1 756 #define ST_WRITE 2 757 #define ST_LAUNCH 3 758 #define ST_LAUNCH_GLOBAL 4 759 #define ST_CHKSUM 5 760 #define ST_APPEND 6 761 #define ST_EXIT 7 762 #define ST_MSG 8 763 #define ST_XMITRF 9 764 #define ST_RESETRF 10 765 #define ST_REWIND 11 766 #define ST_INIT_OTHERS 12 767 #define ST_BUSYWAIT 13 768 #define ST_SOURCE 14 769 #define ST_FLAGS 15 770 #define ST_PFAIL 16 771 #define ST_SHOWBYTE 17 772 #define ST_CLRSTATUS 18 773 #define ST_VDATA 19 774 #define ST_RESTART 20 775 #define ST_SECFLAGS 21 776 #define ST_LONGVDATA 22 777 #define ST_RFFLOOD 23 778 #define ST_AUX_ADDR 24 779 #define ST_AUX_FUNC 25 780 #define ST_SETTIMER 26 781 #define ST_CLRTIMERS 27 782 #define ST_CLRTAMPER 28 783 #define ST_RFXTYPE 29 784 #define ST_RFXSERIAL 30 785 #define ST_RFXNOISEVL 31 786 #define ST_RFXRAWVL 32 787 #define ST_VARIABLE_LEN 33 788 #define ST_LOCKUP 34 789 #define ST_COUNTER 35 790 #define ST_GENLONG 36 791 #define ST_ORE_EMU 37 792 #define ST_SCRIPT 38 793 #define ST_SECURITY 39 794 #define ST_FLAGS32 40 795 #define ST_TESTPOINT 41 796 #define ST_SHOWBUFFER 42 797 798 /* Launch trigger modes */ 799 #define TMODE_SIGNAL 0 800 #define TMODE_MODULE 1 801 802 /* Launcher types */ 803 #define L_NORMAL 0x0001 804 #define L_POWERFAIL 0x0002 805 #define L_ADDRESS 0x0004 806 #define L_RFFLOOD 0x0008 807 #define L_TIMEOUT 0x0010 808 #define L_SENSORFAIL 0x0020 809 #define L_LOCKUP 0x0040 810 #define L_RFXJAM 0x0080 811 #define L_EXEC 0x0100 812 #define L_HOURLY 0x0200 813 #define L_ANY (L_NORMAL|L_POWERFAIL|L_ADDRESS|L_RFFLOOD|L_TIMEOUT|L_SENSORFAIL|L_LOCKUP|L_RFXJAM|L_EXEC|L_HOURLY) 814 815 /* Flags for powerfail time relative to relay startup */ 816 #define R_ATSTART 1 817 #define R_NOTATSTART 2 818 /* Time in seconds defining R_ATSTART versus R_NOTATSTART */ 819 #define ATSTART_DELAY 10 820 821 /* Daemon which launches script */ 822 #define D_CMDLINE 0 823 #define D_ENGINE 1 824 #define D_RELAY 2 825 #define D_AUXDEV 3 826 #define D_AUXRCV 4 827 828 /* Flag modification modes */ 829 #define CLRFLAG 0 830 #define SETFLAG 1 831 832 /* Sensor activity modes */ 833 #define S_ACTIVE 0 834 #define S_INACTIVE 1 835 836 /* Bitmap definitions for Heyu script environment variables */ 837 #define HEYUMAP_LEVEL 0x000000ff /* Lowest byte is level 0-100 */ 838 #define HEYUMAP_APPL 0x00000100 /* Appliance (non-dimmable) module */ 839 #define HEYUMAP_SPEND 0x00000200 /* Status pending state */ 840 #define HEYUMAP_OFF 0x00000400 /* Off state */ 841 #define HEYUMAP_ADDR 0x00000800 /* Addressed state */ 842 #define HEYUMAP_CHG 0x00001000 /* Changed state */ 843 #define HEYUMAP_DIM 0x00002000 /* Dimmed state */ 844 #define HEYUMAP_SIGNAL 0x00004000 /* Signal state */ 845 #define HEYUMAP_CLEAR 0x00008000 /* Clear state */ 846 #define HEYUMAP_ALERT 0x00010000 /* Alert state */ 847 #define HEYUMAP_AUXCLEAR 0x00020000 /* AuxClear state */ 848 #define HEYUMAP_AUXALERT 0x00040000 /* AuxAlert state */ 849 #define HEYUMAP_ACTIVE 0x00080000 /* Active */ 850 #define HEYUMAP_INACTIVE 0x00100000 /* Inactive */ 851 #define HEYUMAP_MODCHG 0x00200000 /* Module Change */ 852 #define HEYUMAP_ON 0x00400000 /* On state */ 853 854 #define FLAGMAP_LOBAT 0x00000001 /* Low battery */ 855 #define FLAGMAP_ROLLOVER 0x00000002 /* Rollover flag */ 856 #define FLAGMAP_SWMIN 0x00000004 /* Min switch */ 857 #define FLAGMAP_SWMAX 0x00000008 /* Max switch */ 858 #define FLAGMAP_MAIN 0x00000010 /* Main channel */ 859 #define FLAGMAP_AUX 0x00000020 /* Aux channel */ 860 #define FLAGMAP_TAMPER 0x00000040 /* Tamper flag */ 861 #define FLAGMAP_TMIN 0x00000080 /* Tmin flag */ 862 #define FLAGMAP_TMAX 0x00000100 /* Tmax flag */ 863 #define FLAGMAP_RHMIN 0x00000200 /* RHmin flag */ 864 #define FLAGMAP_RHMAX 0x00000400 /* RHmax flag */ 865 #define FLAGMAP_BPMIN 0x00000800 /* BPmin flag */ 866 #define FLAGMAP_BPMAX 0x00001000 /* BPmin flag */ 867 #define FLAGMAP_DMXSET 0x00002000 /* DMX Set flag */ 868 #define FLAGMAP_DMXHEAT 0x00004000 /* DMX Heat flag */ 869 #define FLAGMAP_DMXINIT 0x00008000 /* DMX Init flag */ 870 #define FLAGMAP_DMXTEMP 0x00010000 /* DMX Temp flag */ 871 872 /* Bitmap definitions for Xtend script environment variables */ 873 #define XTMAP_APPL 32 /* Appliance module */ 874 #define XTMAP_ADDR 64 /* Addressed state */ 875 #define XTMAP_ON 128 /* On state */ 876 877 /* Night and Dark flags share space with 16 common flags */ 878 #define NIGHT_FLAG (0x01 << 16) 879 #define DARK_FLAG (0x02 << 16) 880 881 /* Global security flags share space with 16 common flags plus */ 882 /* night and dark flags so need to be shifted by 18 bits. */ 883 #define GLOBSEC_SHIFT 18 884 #define GLOBSEC_ARMED (0x01 << GLOBSEC_SHIFT) 885 #define GLOBSEC_HOME (0x02 << GLOBSEC_SHIFT) 886 #define GLOBSEC_PENDING (0x04 << GLOBSEC_SHIFT) 887 #define GLOBSEC_TAMPER (0x08 << GLOBSEC_SHIFT) 888 #define GLOBSEC_SLIGHTS (0x10 << GLOBSEC_SHIFT) 889 #define GLOBSEC_FLOOD (0x20 << GLOBSEC_SHIFT) 890 #define GLOBSEC_RFXJAM (0x40 << GLOBSEC_SHIFT) 891 892 /* Unit Security and RFXMeter vflags */ 893 #define SEC_LOBAT 0x00000001 894 #define SEC_HOME 0x00000002 895 #define SEC_AWAY 0x00000004 896 #define SEC_MIN 0x00000008 897 #define SEC_MAX 0x00000010 898 #define SEC_FLOOD 0x00000020 899 #define SEC_TAMPER 0x00000040 900 #define SEC_MAIN 0x00000080 901 #define SEC_AUX 0x00000100 902 #define RFX_ROLLOVER 0x00000200 903 #define RFX_JAM 0x00000400 904 #define DMX_HEAT 0x00000800 905 #define DMX_SET 0x00001000 906 #define DMX_INIT 0x00002000 907 #define ORE_TMIN 0x00004000 908 #define ORE_TMAX 0x00008000 909 #define ORE_RHMIN 0x00010000 910 #define ORE_RHMAX 0x00020000 911 #define ORE_BPMIN 0x00040000 912 #define ORE_BPMAX 0x00080000 913 #define SEC_FAULT 0x00100000 914 #define DMX_TEMP 0x00200000 915 916 /* Used for DS90 sensor model ID determination */ 917 #define COMPUTE_AUX 1 918 #define COMPUTE_MAIN -1 919 920 /* Virtual data packet lengths */ 921 #define LEN_VDATA 6 922 #define LEN_LONGVDATA 8 923 924 /* Types of data written to the spoolfile by heyu */ 925 enum {SENT_WRMI, SENT_ADDR, SENT_FUNC, SENT_EXTFUNC, SENT_STCMD, SENT_OTHER, 926 SENT_MESSAGE, SENT_RF, SENT_FLAGS, SENT_PFAIL, SENT_CLRSTATUS, 927 SENT_VDATA, SENT_LONGVDATA, SENT_RFFLOOD, SENT_LOCKUP, SENT_SETTIMER, SENT_RFXTYPE, 928 SENT_RFXSERIAL, SENT_RFVARIABLE, SENT_COUNTER, SENT_GENLONG, SENT_ORE_EMU, SENT_SCRIPT, 929 SENT_KAKU, SENT_FLAGS32, SENT_INITSTATE, SENT_VISONIC, SENT_SHOWBUFFER}; 930 931 /* X10 generic signal types */ 932 enum { 933 AllOffSignal, LightsOnSignal, OnSignal, OffSignal, 934 DimSignal, BriSignal, LightsOffSignal, Ext3Signal, Ext3DimSignal, 935 AllOnSignal, PresetSignal, StatusSignal, StatusOnSignal, StatusOffSignal 936 }; 937 938 /* Module masks */ 939 enum { 940 AllOffMask, LightsOnMask, OnMask, OffMask, DimMask, BriMask, 941 BriDimMask, LightsOffMask, StdMask, Ext3Mask, Ext3DimMask, AllOnMask, 942 PresetMask, StatusMask, StatusOnMask, StatusOffMask, 943 LightsOnFullMask, OnFullMask, OnFullOffMask, ResumeMask, 944 TargMask, Exc16Mask, Exc8Mask, Exc4Mask, Ext0Mask, VdataMask, 945 ResumeDimMask, LightsOnUnaddrMask, LightsOffUnaddrMask, Ext3GrpExecMask, 946 Ext3GrpRelMask, Ext3GrpOffMask, Ext3GrpOffExecMask, Ext3GrpBriDimFullMask, 947 Ext3GrpBriDimMask, Ext3GrpRelT1Mask, Ext3GrpRelT2Mask, Ext3GrpRelT3Mask, 948 Ext3GrpRelT4Mask, Ext3StatusMask, Ext3GrpRemMask, PlcSensorMask, AddrMask, 949 PhysMask, DeferMask, OnOffUnaddrMask, NumModMasks 950 }; 951 952 /* Virtual Module masks */ 953 enum {VstdMask, VentMask, VsecMask, VrfxsMask, VrfxmMask, VdmxMask, VoreMask, 954 VtstampMask, VkakuMask, NumVmodMasks 955 }; 956 957 /* KaKu Module masks */ 958 enum {KoffMask, KonMask, KGoffMask, KGonMask, KpreMask, KGpreMask, KresumeMask, 959 KPhysMask, NumKmodMasks 960 }; 961 962 /* State bitmap indexes */ 963 enum {OnState, DimState, ModChgState, ChgState, LightsOnState, AlertState, ClearState, 964 AuxAlertState, AuxClearState, ActiveState, InactiveState, LoBatState, 965 ValidState, NullState, ActiveChgState, SpendState, TamperState, 966 AddrState, /* SwMinState, SwMaxState,*/ NumStates}; 967 968 /* Launch trigger types */ 969 enum { 970 AllOffTrig, LightsOnTrig, OnTrig, OffTrig, DimTrig, BriTrig, 971 LightsOffTrig, ExtendedTrig, HailReqTrig, HailAckTrig, 972 PresetTrig, PresetTrig2, DataXferTrig, StatusOnTrig, StatusOffTrig, 973 StatusReqTrig, AllOnTrig, ExtPowerUpTrig, VdataTrig, VdataMTrig, NumTriggers 974 }; 975 976 /* Enum security trigger types */ 977 enum { 978 PanicTrig, ArmTrig, DisarmTrig, AlertTrig, ClearTrig, TestTrig, 979 SecLightsOnTrig, SecLightsOffTrig, TamperTrig, DuskTrig, DawnTrig, 980 AkeyOnTrig, AkeyOffTrig, BkeyOnTrig, BkeyOffTrig, InactiveTrig, NumSecTriggers 981 }; 982 983 /* Launch RFXSensor, RFXMeter, Digimax, Oregon trigger types */ 984 enum { 985 RFXTempTrig, RFXTemp2Trig, RFXHumidTrig, RFXPressTrig, RFXVadTrig, 986 RFXPotTrig, RFXVsTrig, RFXLoBatTrig, RFXOtherTrig, RFXPulseTrig, 987 RFXPowerTrig, RFXWaterTrig, RFXGasTrig, RFXCountTrig, 988 DmxTempTrig, DmxOnTrig, DmxOffTrig, DmxSetPtTrig, NumRFXTriggers 989 }; 990 991 /* Launch Oregon trigger types */ 992 enum { 993 OreTempTrig, OreHumidTrig, OreBaroTrig, OreWeightTrig, 994 OreWindSpTrig, OreWindAvSpTrig, OreWindDirTrig, 995 OreRainRateTrig, OreRainTotTrig, ElsCurrTrig, OreUVTrig, 996 OwlPowerTrig, OwlEnergyTrig, NumOreTriggers 997 }; 998 999 /* KaKu trigger types */ 1000 enum { 1001 KakuOffTrig, KakuOnTrig, KakuGrpOffTrig, KakuGrpOnTrig, KakuUnkTrig, 1002 KakuPreTrig, KakuGrpPreTrig, KakuUnkPreTrig, NumKakuTriggers 1003 }; 1004 1005 /* X10 functions (must align with funclabel[] in cmd.c) */ 1006 enum { 1007 AllOffFunc, LightsOnFunc, OnFunc, OffFunc, DimFunc, 1008 BrightFunc, LightsOffFunc, ExtendedFunc, HailFunc, 1009 HailAckFunc, Preset1Func, Preset2Func, DataXferFunc, 1010 StatusOnFunc, StatusOffFunc, StatusReqFunc, AllOnFunc, 1011 ExtPowerUpFunc, VdataFunc, VdataMFunc, PanicFunc, ArmFunc, DisarmFunc, 1012 AlertFunc, ClearFunc, TestFunc, SecLightsOnFunc, SecLightsOffFunc, 1013 TamperFunc, DuskFunc, DawnFunc, AkeyOnFunc, AkeyOffFunc, 1014 BkeyOnFunc, BkeyOffFunc, 1015 RFXTempFunc, RFXTemp2Func, RFXHumidFunc, RFXPressFunc, 1016 RFXVadFunc, RFXPotFunc, RFXVsFunc, RFXLoBatFunc, RFXOtherFunc, 1017 RFXPulseFunc, RFXPowerFunc, RFXWaterFunc, RFXGasFunc, RFXCountFunc, 1018 DmxTempFunc, DmxOnFunc, DmxOffFunc, DmxSetPtFunc, 1019 OreTempFunc, OreHumidFunc, OreBaroFunc, OreWeightFunc, 1020 OreWindSpFunc, OreWindAvSpFunc, OreWindDirFunc, 1021 OreRainRateFunc, OreRainTotFunc, ElsCurrFunc, OreUVFunc, 1022 KakuOffFunc, KakuOnFunc, KakuGrpOffFunc, KakuGrpOnFunc, KakuUnkFunc, 1023 KakuPreFunc, KakuGrpPreFunc, KakuUnkPreFunc, 1024 OwlPowerFunc, OwlEnergyFunc, InactiveFunc, InvalidFunc 1025 }; 1026 1027 #if 0 1028 /* X10 functions (must align with funclabel[] in cmd.c) */ 1029 enum { 1030 AllOffFunc, LightsOnFunc, OnFunc, OffFunc, DimFunc, 1031 BrightFunc, LightsOffFunc, ExtendedFunc, HailFunc, 1032 HailAckFunc, Preset1Func, Preset2Func, DataXferFunc, 1033 StatusOnFunc, StatusOffFunc, StatusReqFunc, AllOnFunc, 1034 ExtPowerUpFunc, VdataFunc, PanicFunc, ArmFunc, DisarmFunc, 1035 AlertFunc, ClearFunc, SecLightsOnFunc, SecLightsOffFunc, 1036 TamperFunc, RFXSensorFunc, InvalidFunc 1037 }; 1038 1039 /* RFXSensor functions (must align with rfxfunclabel[] in cmd.c) */ 1040 enum { 1041 RFXTempFunc, RFXTemp2Func, RFXHumidFunc, RFXPressFunc, RFXVadFunc, 1042 RFXVsFunc, RFXLoBatFunc, RFXOtherFunc, RFXPulseFunc, RFXPowerFunc, 1043 RFXWaterFunc, RFXGasFunc 1044 }; 1045 #endif 1046 1047 /* RFXCOM disable modes */ 1048 struct rfx_disable_st { 1049 unsigned long bitmap; 1050 unsigned short code; 1051 char *label; 1052 int minlabel; 1053 }; 1054 1055 1056 /* Place to store an alias from user's x10config file */ 1057 #define NIDENT 16 /* Max number of ident per alias */ 1058 #define NOFFSET 2 /* Max number of offset values per alias */ 1059 #define NFUNCLIST 8 /* Max number of functions per alias */ 1060 typedef struct { 1061 int line_no; 1062 char label[NAME_LEN + 1]; 1063 char housecode; 1064 unsigned char hcode; 1065 unsigned int unitbmap; 1066 unsigned int ext0links; 1067 int modtype; 1068 unsigned long vflags; 1069 unsigned long flags; 1070 unsigned long xflags; 1071 unsigned long kflags; 1072 unsigned long optflags; 1073 unsigned long optflags2; 1074 int tmin; 1075 int tmax; 1076 int rhmin; 1077 int rhmax; 1078 int bpmin; 1079 int bpmax; 1080 double offset[NOFFSET]; 1081 int onlevel; 1082 int maxlevel; 1083 unsigned char vtype; 1084 unsigned char subtype; 1085 unsigned char nident; 1086 unsigned long ident[NIDENT]; 1087 int nvar; 1088 int storage_index; 1089 int storage_units; 1090 unsigned char funclist[NFUNCLIST]; 1091 unsigned char statusoffset[NFUNCLIST]; 1092 int (*xlate_func)(); 1093 // long timeout; 1094 long hb_timeout; 1095 int hb_index; 1096 unsigned int kaku_keymap[NIDENT]; 1097 unsigned int kaku_grpmap[NIDENT]; 1098 } ALIAS; 1099 1100 /* Place to store scene definition from config file */ 1101 typedef struct { 1102 int line_no; 1103 int nparms; 1104 unsigned int type; 1105 char label[SCENE_LEN + 1]; 1106 char *body; 1107 } SCENE; 1108 1109 /* Place to store script info from config file */ 1110 typedef struct { 1111 int line_no; 1112 char label[NAME_LEN + 1]; 1113 unsigned char script_option; 1114 unsigned char done; 1115 int num_launchers; 1116 char *cmdline; 1117 } SCRIPT; 1118 1119 typedef struct { 1120 int stindex; 1121 unsigned char hcode; 1122 unsigned int bmap; 1123 } STATEFLAG; 1124 1125 typedef struct { 1126 int vfindex; 1127 unsigned char hcode; 1128 unsigned int ucode; 1129 } VIRTFLAG; 1130 1131 typedef struct { 1132 int line_no; 1133 char label[NAME_LEN + 1]; 1134 int scriptnum; 1135 int launchernum; 1136 unsigned int type; 1137 unsigned char matched; 1138 unsigned char scanmode; 1139 unsigned char oksofar; 1140 unsigned int source; 1141 unsigned int nosource; 1142 unsigned char hcode; 1143 unsigned long afuncmap; 1144 unsigned long gfuncmap; 1145 unsigned long xfuncmap; 1146 unsigned long sfuncmap; 1147 unsigned long ofuncmap; 1148 unsigned long kfuncmap; 1149 unsigned int signal; 1150 unsigned int module; 1151 unsigned int bmaptrig; 1152 unsigned int bmaptrigemu; 1153 unsigned int chgtrig; 1154 unsigned long flags[NUM_FLAG_BANKS]; 1155 unsigned long notflags[NUM_FLAG_BANKS]; 1156 unsigned long sflags; 1157 unsigned long notsflags; 1158 unsigned long vflags; 1159 unsigned long notvflags; 1160 unsigned long czflags[NUM_COUNTER_BANKS]; 1161 unsigned long notczflags[NUM_COUNTER_BANKS]; 1162 unsigned long tzflags[NUM_TIMER_BANKS]; 1163 unsigned long nottzflags[NUM_TIMER_BANKS]; 1164 unsigned char bootflag; 1165 unsigned char trigemuflag; 1166 unsigned char unitstar; 1167 unsigned char timer; 1168 int sensor; 1169 1170 unsigned char genfunc; 1171 unsigned char actfunc; 1172 unsigned char xfunc; 1173 unsigned char level; 1174 unsigned char rawdim; 1175 unsigned int bmaplaunch; 1176 unsigned int actsource; 1177 int num_stflags; 1178 int num_virtflags; 1179 STATEFLAG stlist[32]; 1180 VIRTFLAG virtlist[32]; 1181 } LAUNCHER; 1182 1183 /* Place to store info from the user's x10config file */ 1184 /* and timezone from the system clock/calendar. */ 1185 1186 typedef struct { 1187 unsigned char read_flag; /* Indicates config file has been processed */ 1188 unsigned char mode; /* HEYU or COMPATIBLE (with ActiveHome (tm)) */ 1189 char schedfile[PATH_LEN + 1]; /* Pathname of x10 schedule file */ 1190 long int asif_date; /* Assumed program date (yyyymmdd) instead of today */ 1191 int asif_time; /* Assumed minutes after 00:00 Legal time */ 1192 int program_days_in; /* Number of days to program, beginning today */ 1193 int program_days; /* Number of days to program, beginning today */ 1194 int lat_d; /* Latitude degrees */ 1195 int lat_m; /* Latitude minutes */ 1196 int lon_d; /* Longitude degrees */ 1197 int lon_m; /* Longitude minutes */ 1198 double latitude; /* Latitude degrees as double */ 1199 double longitude; /* Longitude degrees as double */ 1200 unsigned char loc_flag; /* Indicates valid Lat and Lon */ 1201 unsigned char feb_kluge; /* Use FEB_KLUGE config option */ 1202 unsigned char dawn_option; /* Use First, Average, Median, etc.*/ 1203 unsigned char dusk_option; /* Use First, Average, Median, etc.*/ 1204 int sunmode; /* Definition of Dawn/Dusk */ 1205 int sunmode_offset; /* Custom Dawn/Dusk angle offset */ 1206 int dawn_substitute; /* For days when there's no dawn */ 1207 int dusk_substitute; /* For days when there's no dusk */ 1208 int min_dawn; /* Lower bound on dawn */ 1209 int max_dawn; /* Upper bound on dawn */ 1210 int min_dusk; /* Lower bound on dusk */ 1211 int max_dusk; /* Upper bound on dusk */ 1212 unsigned char combine_events; /* Similar timed events should be combined */ 1213 unsigned char compress_macros; /* Merge unit codes in uploaded macro commands */ 1214 unsigned char repl_delay; /* Flag: Replace delayed macros */ 1215 unsigned char display_offset; /* Display offsets in report file */ 1216 char tty[PATH_LEN + 1]; /* Serial port to use */ 1217 char suffix[PATH_LEN + 1]; /* Suffix for file locks */ 1218 char ttyaux[PATH_LEN + 1]; /* Auxiliary input serial port */ 1219 char auxhost[NAME_LEN + 1]; /* Auxiliary input network host address or name */ 1220 char auxport[NAME_LEN + 1]; /* Auxiliary input network port number or name */ 1221 char suffixaux[PATH_LEN + 1]; /* Suffix for aux file lock */ 1222 char ttyrfxmit[PATH_LEN + 1]; /* RFXmitter serial port */ 1223 unsigned char rfxmit_freq; /* RFXmitter frequency */ 1224 char housecode; /* Base housecode */ 1225 char force_addr; /* Send an address byte for all commands */ 1226 unsigned int device_type; /* Identify non-CM11A interfaces */ 1227 unsigned int auxdev; /* Auxilliary device type */ 1228 unsigned char newformat; /* NEWFORMAT flag */ 1229 unsigned char checkfiles; /* Write .check, .bin, and .hex files? */ 1230 long int tzone; /* Timezone */ 1231 unsigned char isdst; /* Indicates Daylight Time is in effect */ 1232 /* at some time during the year. (Don't */ 1233 /* confuse with CALEND.isdst) */ 1234 int dstminutes; /* Minutes to add to standard time to get DST */ 1235 int alias_size; /* Size of array of ALIAS structures */ 1236 ALIAS *aliasp; /* Pointer to array of ALIAS structures */ 1237 SCENE *scenep; /* Pointer to array of SCENE structures */ 1238 SCRIPT *scriptp; /* Pointer to array of SCRIPT structures */ 1239 LAUNCHER *launcherp; /* Pointer to array of LAUNCHER structures */ 1240 int max_pparms; /* Maximum number of positional parameters */ 1241 int trigger_tag; /* Tag trigger events. */ 1242 unsigned int rcs_temperature; /* Housecode bitmap for translation via RCS table */ 1243 int xref_append; /* Append helper events to x10macroxref entries */ 1244 int ack_hails; /* Send hail_ack when a hail is received */ 1245 int macterm; /* Terminate each macro */ 1246 int status_timeout; /* Loop count for status timeout */ 1247 int spf_timeout; /* Loop count for special func timeout */ 1248 int reserved_timers; /* Number of timers to hold in reserve */ 1249 int disp_exp_mac; /* Display commands in macro in monitor */ 1250 int auto_chain; /* Use chained macros for events *WIP* */ 1251 int module_types; /* Customize behavior per module type */ 1252 int launch_mode; /* Launch on signal or module characteristic */ 1253 int function_mode; /* Launch on actual or generic function types */ 1254 unsigned int launch_source; /* Signal sources allowed to launch a script */ 1255 unsigned char res_overlap; /* Resolve overlaps separately or combined */ 1256 int default_module; /* Default module type */ 1257 char script_shell[PATH_LEN + 1]; /* Default shell for scripts */ 1258 char logfile[PATH_LEN + 1]; /* Log file for state engine output */ 1259 unsigned char logcommon; /* Use common log file */ 1260 unsigned char disp_subdir; /* Display subdir 0-9 in log file and monitor */ 1261 unsigned char script_mode; /* Use heyuhelper vs general scripts */ 1262 int isdark_offset; /* Minutes after Dusk and before Dawn */ 1263 char env_alias_prefix[8]; /* Prefix for alias env variables */ 1264 unsigned char fix_5a; /* Modify 5A checksum if possible */ 1265 unsigned char autofetch; /* Rewrite state file at every state cmd */ 1266 unsigned char pfail_update; /* Set clock after power restored */ 1267 int cm11_post_delay; /* Delay between direct commands */ 1268 int cm17a_bit_delay; /* Intra-bit delay for CM17A commands (us) */ 1269 int rf_burst_spacing; /* Time between successive CM17A RF bursts */ 1270 int rf_timer_tweak; /* Correct for millisleep low resolution */ 1271 int rf_post_delay; /* Post-delay for normal CM17A commands (ms) */ 1272 int rf_farb_delay; /* Post delay for farb CM17A command (ms) */ 1273 int rf_farw_delay; /* Post delay for farw CM17A command (ms) */ 1274 unsigned char disp_rf_xmit; /* Display CM17A transmissions in monitor */ 1275 unsigned char def_rf_bursts; /* Nominal CM17A RF bursts */ 1276 unsigned char rf_bursts[12]; /* CM17A RF bursts for each CM11A function */ 1277 unsigned long timer_loopcount; /* 1 second countdown base for timing loops */ 1278 unsigned char restrict_dims; /* Restrict dims/brights to range 1-22 */ 1279 unsigned char state_format; /* New or old (heyuhelper-style) state format */ 1280 char *pfail_script; /* Script command line run by relay after power fail */ 1281 unsigned char start_engine; /* Start engine automatically or manually */ 1282 unsigned char rf_noswitch; /* Suppress switch in TM751 and RR501 Xceivers */ 1283 unsigned int respool_perms; /* Permissions for re-creating SPOOLDIR */ 1284 unsigned long spool_max; /* Spool file size when rewind is attempted. */ 1285 unsigned char check_RI_line; /* Check RI serial line before sending command. */ 1286 unsigned char ring_ctrl; /* Run with Ring Indicator line disabled */ 1287 int send_retries; /* Number of times to try sending a command */ 1288 unsigned char script_ctrl; /* Enable/Disable launching of scripts */ 1289 unsigned int transceive; /* Aux transceive options */ 1290 unsigned int rfforward; /* Aux RF forward options */ 1291 unsigned char trans_dim; /* Transceived dim level */ 1292 unsigned char state_ctrl; /* Single or Bitmap for state commands */ 1293 int heyu_umask; /* umask for creating all Heyu files */ 1294 int log_umask; /* umask for creating the Heyu log file */ 1295 unsigned char rf_funcmask; /* Mask for RF functions to be transceived */ 1296 int aux_repcounts[4]; /* Aux mincount, repcount, maxcount, floodrep */ 1297 int aux_mincount_rfx; /* Mincount for RFXSensor with RFXCOM receiver. */ 1298 unsigned char hide_unchanged; /* Hide periodic sensor check-in reports */ 1299 unsigned char hide_unchanged_inactive; /* Override above "Hide" for Inactive reports */ 1300 unsigned char show_change; /* (Debug) append CHG|NOCHG to monitor display */ 1301 unsigned char disp_rf_noise; /* Display Aux RF Noise reception */ 1302 long arm_max_delay; /* Delay time for Armed Max */ 1303 unsigned char disp_raw_rf; /* Display raw RF characters received by Aux */ 1304 int arm_logic; /* Logic function (1-3) to use for arming */ 1305 long inactive_timeout; /* Time when sensors are considered inactive */ 1306 int auto_wait; /* busywait() timeout before each sent command. */ 1307 unsigned char full_bright; /* Level to achieve full brightness */ 1308 long engine_poll; /* Engine/Monitor poll delay (microseconds) */ 1309 char dmx_tscale; /* Digimax sensor temperature scale (F, C, K, or R) */ 1310 double dmx_toffset; /* Digimax sensor temperature offset */ 1311 unsigned char ore_lobat; /* Low battery percent */ 1312 char ore_tscale; /* Oregon sensor temperature scale (F, C, K, or R) */ 1313 double ore_toffset; /* Oregon sensor temperature offset */ 1314 double ore_bpscale; /* Oregon sensor barometric pressure unit scale factor */ 1315 double ore_bpoffset; /* Oregon sensor barometric pressure offset */ 1316 char ore_bpunits[NAME_LEN]; /* Oregon sensor barometric pressure unit name */ 1317 double ore_wgtscale; /* Oregon sensor weight unit scale factor */ 1318 char ore_wgtunits[NAME_LEN]; /* Oregon sensor weight unit name */ 1319 double ore_windscale; /* Oregon sensor wind speed unit scale factor */ 1320 char ore_windunits[NAME_LEN]; /* Oregon sensor wind speed unit name */ 1321 int ore_windsensordir; /* Oregon wind direction offset angle in decidegrees*/ 1322 double ore_rainratescale; /* Oregon rain rate scale factor */ 1323 char ore_rainrateunits[NAME_LEN]; /* Oregon rain rate units */ 1324 double ore_raintotscale; /* Oregon total rain scale factor */ 1325 char ore_raintotunits[NAME_LEN]; /* Oregon total rain units */ 1326 unsigned char ore_winddir_mode; /* Display Points, Angle, or Both */ 1327 char rfx_tscale; /* RFXSensor temperature scale (F, C, K, or R) */ 1328 double rfx_toffset; /* RFX_Sensor temperature offset */ 1329 double rfx_vadscale; /* RFXSensor A/D voltage scale factor */ 1330 double rfx_vadoffset; /* RFXSEnsor A/D voltage offset */ 1331 char rfx_vadunits[NAME_LEN]; /* RFXSensor A/D voltage unit name */ 1332 double rfx_bpscale; /* RFXSensor barometric pressure unit scale factor */ 1333 double rfx_bpoffset; /* RFXSensor barometric pressure offset */ 1334 char rfx_bpunits[NAME_LEN]; /* RFXSensor barometric pressure unit name */ 1335 unsigned char rfxcom_dtr_rts; /* DTR and RTS line state for RFXCOM receiver */ 1336 unsigned char rfxcom_hibaud; /* Use high baud rate */ 1337 unsigned long rfxcom_enable; /* Enable bitmap for certain RF protocols */ 1338 unsigned long rfxcom_disable; /* Disable bitmap for certain RF protocols */ 1339 double rfx_powerscale; /* RFXMeter Power meter scale factor */ 1340 char rfx_powerunits[NAME_LEN]; /* RFXMeter Power (energy) units */ 1341 double rfx_waterscale; /* RFXMeter Water meter scale factor */ 1342 char rfx_waterunits[NAME_LEN]; /* RFXMeter Water meter units */ 1343 double rfx_gasscale; /* RFXMeter Gas meter scale factor */ 1344 char rfx_gasunits[NAME_LEN]; /* RFXMeter Gas meter units */ 1345 double rfx_pulsescale; /* RFXMeter Pulse meter scale factor */ 1346 char rfx_pulseunits[NAME_LEN]; /* RFXMeter Pulse meter units */ 1347 unsigned char lockup_check; /* Relay checks for port and/or CM11A lockup */ 1348 char tailpath[PATH_LEN + 1]; /* Pathspec of 'tail' command */ 1349 unsigned char suppress_rfxjam; /* Suppress jamming signals from older RFXCOM */ 1350 unsigned char display_dmxtemp; /* Display Digimax Temperature signals */ 1351 unsigned char securid_16 ; /* Use 16 bit Security ID */ 1352 unsigned long securid_mask; /* Mask for Security ID */ 1353 unsigned char securid_parity; /* Check parity for 16 bit security RF */ 1354 unsigned char logdate_year; /* Include year in log/monitor dates */ 1355 unsigned char disp_ore_all; /* Display both supported and unsupported Oregon types */ 1356 unsigned char ore_chgbits_t; /* Change in least bits for temperature changed state */ 1357 unsigned char ore_chgbits_rh; /* Change in least bits for humidity changed state */ 1358 unsigned char ore_chgbits_bp; /* Change in least bits for baro pressure changed state */ 1359 unsigned char ore_chgbits_wgt; /* Change in least bits for weight changed state */ 1360 unsigned int ore_chgbits_wsp; /* Change in least bits for wind speed changed state */ 1361 unsigned int ore_chgbits_wavsp; /* Change in least bits for wind avg speed changed state */ 1362 unsigned int ore_chgbits_wdir; /* Change in least bits for wind direction changed state */ 1363 unsigned int ore_chgbits_rrate; /* Change in least bits for rain rate changed state */ 1364 unsigned int ore_chgbits_rtot; /* Change in least bits for total rain changed state */ 1365 unsigned int ore_chgbits_uv; /* Change in least bit for UV factor changed state */ 1366 unsigned char ore_data_entry; /* Enter data in Native or Scaled units */ 1367 unsigned char ore_display_chan; /* Display Oregon channel number */ 1368 unsigned char ore_display_batlvl; /* Display Oregon battery level (0-100%) */ 1369 unsigned char ore_display_count; /* Display raw count from wind and rain sensors */ 1370 unsigned char ore_display_bft; /* Display Beaufort wind scale */ 1371 unsigned char oreid_16; /* Use 16 bit Oregon ID */ 1372 unsigned short oreid_mask; /* Mask for Oregon ID */ 1373 unsigned char logdate_unix; /* Display log dates as seconds from 1/1/1970 epoch */ 1374 long inactive_timeout_ore; /* Time when Oregon sensors are considered inactive */ 1375 unsigned char display_sensor_intv; /* Display elapsed time since previous transmission */ 1376 unsigned char date_format; /* Date format for entry and display */ 1377 char date_separator; /* Separator character for date, e.g., '/', '-', or '.' */ 1378 int lock_timeout; /* Timeout for acquiring lock file */ 1379 unsigned char ore_display_fcast; /* Display forecast from Oregon THB sensors */ 1380 int cm11a_query_delay; /* Delay between receiving 0x5A and sending 0xC3 */ 1381 unsigned char els_number; /* Number of ElectriSave current probes (1-3) */ 1382 double els_voltage; /* Nominal voltage for ElectriSave power calculation */ 1383 unsigned int els_chgbits_curr; /* Change in least bits for current changed state */ 1384 unsigned char scanmode; /* Launcher continue or break */ 1385 unsigned char rfx_inline; /* Display rfxmeter setup in normal monitor */ 1386 double owl_voltage; /* Voltage to use with OWL CM119 */ 1387 double owl_calib_power; /* Owl power calibration */ 1388 double owl_calib_energy; /* Owl energy calibration */ 1389 unsigned long owl_chgbits_power; /* Change in least bits for power changed state */ 1390 unsigned long owl_chgbits_energy; /* Change in least bits for energu changed state */ 1391 unsigned char owl_display_count; /* Display raw OWL Power and Energy counts */ 1392 unsigned char arm_remote; /* Auto or Manual arming from remote signal */ 1393 unsigned char active_change; /* Active <==> Inactive sets "changed" flag for sensor */ 1394 unsigned char inactive_handling; /* New or old method */ 1395 unsigned char process_xmit; /* Process xmit signal as if actual */ 1396 unsigned char show_flags_mode; /* Display flags in old (16 flags) or new format */ 1397 unsigned char rfx_master; /* RFXCOM Master receiver type */ 1398 unsigned char rfx_slave; /* RFXCOM Slave receiver type */ 1399 char launchpath_append[PATH_LEN + 1]; /* Append this to normal search PATH */ 1400 char launchpath_prefix[PATH_LEN + 1]; /* Prefix this to normal search PATH */ 1401 unsigned char fix_stopstart_error; /* Workaround for Stop time = Start time internal error */ 1402 int chksum_timeout; /* Wait for checksum timeout */ 1403 1404 } CONFIG; 1405 1406 1407 /* Place to store timed events from timers */ 1408 typedef struct { 1409 int line_no; /* Line number in input file */ 1410 unsigned char pos; /* Start (1) or stop (2) position in input timer. */ 1411 int link; /* Index to next tevent in linked list */ 1412 int plink; /* Backlink for printing */ 1413 int chain_len; /* Length of chain of macros */ 1414 int timer; /* Index of input timer */ 1415 int trig; /* Index to trigger, if any */ 1416 unsigned char generation; /* Parent or Child */ 1417 unsigned char done; /* Has been processed. */ 1418 unsigned char combined; /* Number of combined tevents */ 1419 unsigned char cancel; /* Min/Max Dawn/Dusk cancel flags */ 1420 int print; /* Number of headers to be printed */ 1421 unsigned char dow_bmap; /* Days of Week bitmap */ 1422 int sched_beg; /* Begin date as integer mmdd */ 1423 int sched_end; /* End date as integer mmdd */ 1424 unsigned char spflag; /* (Reserved) */ 1425 int spindex; /* (Reserved) */ 1426 int *spdata; /* (Reserved) */ 1427 int notify; /* Notify days before expire */ 1428 int resolv_beg; /* Resolved day of year to begin */ 1429 int resolv_end; /* Resolved day of year to end */ 1430 unsigned int flag; /* Clock, Dawn, or Dusk, plus other flags */ 1431 unsigned int flag2; /* Auxilliary flag */ 1432 int offset; /* Minutes from Midnight or Dawn/Dusk */ 1433 unsigned char delay; /* Macro delay, 0-240 min */ 1434 int security; /* Security event offset */ 1435 unsigned char ddoptions; /* Dawn/Dusk option flags */ 1436 int dawnlt; /* DAWNLT time */ 1437 int dawngt; /* DAWNGT time */ 1438 int dusklt; /* DUSKLT time */ 1439 int duskgt; /* DUSKGT time */ 1440 int lostday; /* Day shifted out of program period */ 1441 int macro; /* Index into MACRO array */ 1442 int *ptr; /* Pointer used in resolve_times() */ 1443 int intv; /* Index into array of subintervals */ 1444 int nintv; /* Number of subintervals */ 1445 } TEVENT; 1446 1447 /* Place to store info about a timer command */ 1448 typedef struct { 1449 int line_no; /* Line number in input file */ 1450 int line1; /* Start event original timer */ 1451 int line2; /* Stop event original timer */ 1452 unsigned char pos1; /* Start event original timer start or stop */ 1453 unsigned char pos2; /* Stop event original timer start or stop */ 1454 int link; /* Index of next timer in linked list */ 1455 int tevent_start; /* Index of ancestor tevent for start */ 1456 int tevent_stop; /* Index of ancestor tevent for stop */ 1457 unsigned char generation; /* Parent or Child */ 1458 unsigned char dow_bmap; /* Days of Week bitmap */ 1459 int sched_beg; /* Begin date as integer mmdd */ 1460 int sched_end; /* End date as integer mmdd */ 1461 unsigned char spflag; /* (Reserved) */ 1462 int spindex; /* (Reserved) */ 1463 int *spdata; /* (Reserved) */ 1464 int notify; /* Notify days before expire. */ 1465 int resolv_beg; /* Resolved day of year to begin */ 1466 int resolv_end; /* Resolved day of year to end */ 1467 unsigned int flag_start; /* Start based on Clock, Dawn, or Dusk */ 1468 unsigned int flag_stop; /* Stop based on Clock, Dawn, or Dusk */ 1469 unsigned int flag_combined; /* Above flags or'd together */ 1470 int dawnlt; /* DAWNLT option - minutes from midnight */ 1471 int dawngt; /* DAWNGT option - minutes from midnight */ 1472 int dusklt; /* DUSKLT option - minutes from midnight */ 1473 int duskgt; /* DUSKGT option - minutes from midnight */ 1474 unsigned char ddoptions; /* Flags for above options */ 1475 unsigned char cancel; /* Min/Max Dawn/Dusk cancel flags */ 1476 int offset_start; /* Minutes from Midnight or Dawn/Dusk */ 1477 int offset_stop; /* Minutes from Midnight or Dawn/Dusk */ 1478 unsigned char delay_start; /* Macro delay, 0-240 min */ 1479 unsigned char delay_stop; /* Macro delay, 0-240 min */ 1480 int security_start; /* Security mode flag for start time */ 1481 int security_stop; /* Security mode flag for stop time */ 1482 int macro_start; /* Index into MACRO array */ 1483 int macro_stop; /* Index into MACRO array */ 1484 int error_start; /* Max Dawn/Dusk error in start time */ 1485 int error_stop; /* Max Dawn/Dusk error in stop time */ 1486 int *ptr_start; /* Pointer used in resolve_sun_times() */ 1487 int *ptr_stop; /* Pointer used in resolve_sun_times() */ 1488 int num_ptr; /* Number of above pointers actually used */ 1489 int intv; /* Index into array of subintervals */ 1490 int nintv; /* Number of subintervals */ 1491 int memloc; /* Offset of timer in Cm11a memory image */ 1492 } TIMER; 1493 1494 /* Place to store info about a trigger command */ 1495 typedef struct { 1496 int line_no; /* Line number in input file */ 1497 unsigned char housecode; /* x10 code for housecode */ 1498 unsigned char unitcode; /* x10 code for unit code */ 1499 unsigned char command; /* Command: ON = 1, OFF = 0 */ 1500 int macro; /* Index into MACRO array */ 1501 unsigned char tag; /* Sequence number 1-7 for triggers to above macro */ 1502 int memloc; /* Offset of trigger in Cm11a memory image */ 1503 } TRIGGER; 1504 1505 /* Place to store info about a macro */ 1506 typedef struct { 1507 int line_no; /* Line number in input file */ 1508 int link; /* Index of next macro in linked list */ 1509 int rlink; /* Index of previous macro in linked list */ 1510 char label[MACRO_LEN + 1]; /* Name of macro */ 1511 unsigned char refer; /* Indicates parsers which reference the macro */ 1512 int trig; /* Trigger index, if any */ 1513 unsigned char use; /* Use macro in current program */ 1514 unsigned char flag; /* Macro flags */ 1515 unsigned char modflag; /* Macro modification flags */ 1516 unsigned char delay; /* Delay time in seconds 0-240 */ 1517 int offset; /* Offset of macro in CM11a memory image */ 1518 int element; /* Index into list of macro elements. */ 1519 int nelem; /* Number of elements. */ 1520 int total; /* Total size of element code (bytes) */ 1521 unsigned char isnull; /* Indicates if this is the null macro */ 1522 } MACRO; 1523 1524 /* Place to store calendar information */ 1525 typedef struct { 1526 int year; /* year */ 1527 int month; /* month (1-12) */ 1528 int mday; /* day of month (1-31) */ 1529 int yday; /* day of year (0-365) */ 1530 int create_day; /* day of year (0-365) */ 1531 int minutes; /* minutes from 0:00 hours Legal time */ 1532 int day_zero; /* day of year corresponding to CM11a day 0 */ 1533 long jan1day; /* Day number on 1 Jan counted from 1 Jan 1970 */ 1534 long today; /* Day number today counted from 1 Jan 1970 */ 1535 unsigned char isdst; /* Indicates daylight time is in effect this day */ 1536 /* (Don't confuse with CONFIG.isdst) */ 1537 unsigned char valid; /* Indicates the above info has been filled in */ 1538 unsigned char asif_flag; /* 0 indicates today's date; 1 indicates noon on */ 1539 /* ASIF_DATE in configuration file. */ 1540 } CALEND; 1541 1542 /* Structure used by heyu_getopt() */ 1543 struct opt_st { 1544 char *configp; 1545 char *schedp; 1546 char *subp; 1547 char dispsub[NAME_LEN]; 1548 int verbose; 1549 int linesync; 1550 }; 1551 1552 /* Structure used as argument to pass data by xlate_func() */ 1553 struct xlate_vdata_st { 1554 unsigned char vdata; 1555 unsigned char hcode; 1556 unsigned char ucode; 1557 unsigned long optflags; 1558 unsigned long optflags2; 1559 unsigned long ident; 1560 int nident; 1561 unsigned long *identp; 1562 unsigned char func; 1563 unsigned char xfunc; 1564 unsigned long vflags; 1565 unsigned char hibyte; 1566 unsigned char lobyte; 1567 int trig; 1568 }; 1569 1570 /* Contains info written to or read from the x10record file */ 1571 struct record_info { 1572 unsigned char isready; 1573 long int dayset; 1574 int yday; 1575 int day_zero; 1576 long int tzone; 1577 unsigned int flags; 1578 int dstminutes; 1579 int program_days; 1580 }; 1581 1582 1583 /* Used by function write_macroxref() */ 1584 struct macindx { 1585 int index; 1586 int offset; 1587 }; 1588 1589 /* Used by function display_events() */ 1590 struct ev_s { 1591 int tevent; 1592 int timer; 1593 int line; 1594 int pos; 1595 int tpos; 1596 int beg; 1597 int flag; 1598 }; 1599 1600 #ifndef min 1601 #define min( a, b ) ((a) < (b) ? (a) : (b)) 1602 #endif 1603 1604 #ifndef max 1605 #define max( a, b ) ((a) > (b) ? (a) : (b)) 1606 #endif 1607 1608 #ifndef abs 1609 #define abs( a ) ((a) < 0 ? -(a) : (a)) 1610 #endif 1611 1612 int code2unit ( unsigned char ); 1613 int bmap2wday ( unsigned char ); 1614 int isleapyear ( int ); 1615 int get_dst_info ( int ); 1616 int isdst_test ( int, int ); 1617 int parse_latitude ( char * ); 1618 int parse_longitude ( char * ); 1619 int parse_config ( FILE *, unsigned char ); 1620 int get_alias ( ALIAS *, char *, char *, unsigned int * ); 1621 int alias_lookup ( char *, char *, unsigned int * ); 1622 int alias_lookup_index ( char, unsigned int, unsigned char ); 1623 int add_alias ( ALIAS **, char *, int, char, char *, int ); 1624 int parse_time_token ( char *, int * ); 1625 int spawn_child_tevent ( TEVENT **, int ); 1626 int spawn_child_timer ( TIMER **, int ); 1627 int timer_index ( TIMER ** ); 1628 int tevent_index ( TEVENT ** ); 1629 int update_current_timer_generation ( void ); 1630 int update_current_tevent_generation ( void ); 1631 int update_current_timer_generation_anyway ( void ); 1632 int trigger_index ( TRIGGER ** ); 1633 int macro_element_index ( unsigned char **, int ); 1634 int macro_index ( MACRO **, char *, unsigned char ); 1635 int intv_index ( int **, unsigned int * ); 1636 int parse_sched ( FILE *, TIMER **, TRIGGER **, MACRO **, unsigned char ** ); 1637 int parse_timer ( TIMER **, MACRO **, char * ); 1638 int parse_trigger ( TRIGGER **, MACRO **, char * ); 1639 int parse_macro ( MACRO **, unsigned char **, char * ); 1640 int is_compatible ( TEVENT *, TEVENT * ); 1641 int reconstruct_timers ( TEVENT *, TIMER ** ); 1642 int iter_mgr ( int, long *, long, int * ); 1643 int set_suntime ( int *, int, int, unsigned char, int * ); 1644 int resolve_sun_times ( TIMER **, CALEND *, int, int *, int * ); 1645 int get_freespace ( int, TIMER *, TRIGGER *, MACRO * ); 1646 int write_image_bin ( char *, unsigned char * ); 1647 int write_image_hex ( char *, unsigned char * ); 1648 int write_record_file ( char *, CALEND * ); 1649 int read_record_file ( void ); 1650 int get_upload_expire ( void ); 1651 int compmac ( struct macindx *, struct macindx * ); 1652 int write_macroxref ( char *, MACRO *, unsigned char *, int ); 1653 int process_data ( int ); 1654 int crontest ( void ); 1655 int write_sun_table ( int, int, int, int, int ); 1656 int comp_events ( struct ev_s *, struct ev_s * ); 1657 int display_events ( FILE *, TIMER *, TEVENT *, MACRO *, CALEND * ); 1658 int display_timers ( FILE *, TIMER *, TEVENT *, MACRO * ); 1659 int display_macros ( FILE *, unsigned char, MACRO *, unsigned char * ); 1660 int final_report ( char *, CALEND *, TIMER *, TEVENT *, 1661 TRIGGER *, MACRO *, unsigned char *, int ); 1662 int c_upload ( int, char ** ); 1663 int c_utility ( int argc, char ** ); 1664 int is_tevent_similar ( int, int, TEVENT * ); 1665 int compress_elements ( unsigned char *, int *, int * ); 1666 int verify_tevent_links ( TEVENT * ); 1667 int verify_timer_links ( TIMER * ); 1668 int macro_element_length ( unsigned char ); 1669 1670 void tp ( int ); 1671 void bcx ( char *, int, int ); 1672 void dump_tevents_raw ( FILE *, TEVENT * ); 1673 void dump_tevents ( FILE *, TEVENT * ); 1674 void dump_timer_generation ( FILE *, TIMER *, int ); 1675 void display_sys_calendar ( void ); 1676 void calendar_today ( CALEND * ); 1677 void advance_calendar ( CALEND *, int ); 1678 void save_timer_config ( TIMER * ); 1679 void save_tevent_config ( TEVENT * ); 1680 void save_state ( TIMER *, TEVENT * ); 1681 void restore_timer_config ( TIMER * ); 1682 void restore_tevent_config ( TEVENT * ); 1683 void restore_state ( TIMER *, TEVENT * ); 1684 void increment_tevent_generation ( TEVENT *, int ); 1685 void increment_timer_generation ( TIMER *, int ); 1686 void resolve_dates ( TEVENT **, CALEND *, int ); 1687 void security_adjust_legal_old ( TEVENT * ); 1688 void security_adjust_legal ( TEVENT **, MACRO **, unsigned char ** ); 1689 void split_timers ( TIMER *, TEVENT ** ); 1690 void associate_tevent_triggers ( TEVENT *, MACRO * ); 1691 void identify_macros_in_use ( MACRO *, TEVENT * ); 1692 void resolve_tevent_overlap ( TEVENT ** ); 1693 void create_memory_image_high ( unsigned char *, TIMER *, TRIGGER *, MACRO *, unsigned char * ); 1694 void create_memory_image_low ( unsigned char *, TIMER *, TRIGGER *, MACRO *, unsigned char * ); 1695 void store_record_info ( CALEND * ); 1696 void remove_record_file ( void ); 1697 void display_cm11a_status ( int ); 1698 void display_status_message ( int ); 1699 int get_configuration ( unsigned char ); 1700 void yday2date ( long, int, int *, int *, int *, int * ); 1701 void find_heyu_path ( void ); 1702 void combine_similar_tevents ( TEVENT **, MACRO **, unsigned char ** ); 1703 void compress_macros ( MACRO *, unsigned char * ); 1704 void fix_february ( int, int, int, int *, int * ); 1705 void display_syn( void ); 1706 long day_count ( int, int, int, int ); 1707 long int daycount2JD ( long int ); 1708 char *strtrim ( char * ); 1709 char *strlower ( char * ); 1710 char *strupper ( char * ); 1711 char *strncpy2 ( char *, char *, int ); 1712 char *get_token ( char *, char **, char *, int ); 1713 char code2hc ( unsigned char ); 1714 char *bmap2dow ( unsigned char ); 1715 char *bmap2ascdow ( unsigned char ); 1716 char *bmap2units ( unsigned int ); 1717 char *bmap2asc ( unsigned int, char *); 1718 char *bmap2asc2 ( unsigned int, unsigned int, char *); 1719 char *bmap2rasc ( unsigned int, char *); 1720 char *legal_time_string ( void ); 1721 char *pathspec ( char * ); 1722 char *unique_macro_name ( int *, int, MACRO *, char * ) ; 1723 char flag_def ( unsigned int ); 1724 unsigned char unit2code ( int ); 1725 unsigned char dow2bmap ( char * ); 1726 unsigned char rev_low_nybble ( unsigned char ); 1727 unsigned char rev_byte_bits ( unsigned char ); 1728 unsigned char lrotbmap ( unsigned char ); 1729 unsigned char rrotbmap ( unsigned char ); 1730 unsigned char single_bmap_unit( unsigned int ); 1731 unsigned char checksum( unsigned char *, int ); 1732 unsigned int units2bmap ( char * ); 1733 unsigned int flags2bmap ( char * ); 1734 unsigned long flags2longmap ( char * ); 1735 int lookup_scene ( SCENE *, char * ); 1736 void free_scenes ( SCENE ** ); 1737 void free_scripts ( SCRIPT ** ); 1738 void free_launchers ( LAUNCHER ** ); 1739 void free_aliases ( ALIAS ** ); 1740 int tokenize2 ( char *, char *, int *, char ** ); 1741 int tokenize ( char *, char *, int *, char *** ); 1742 int is_admin_cmd ( char * ); 1743 int is_direct_cmd ( char * ); 1744 int is_heyu_cmd ( char * ); 1745 int verify_scene ( char * ); 1746 int macro_command( int, char **, int *, int *, unsigned char * ); 1747 void clear_error_message( void ); 1748 void store_error_message ( char * ); 1749 void add_error_prefix ( char * ); 1750 void add_error_suffix ( char * ); 1751 char *error_message ( void ); 1752 unsigned char hc2code ( char ); 1753 int max_parms ( int, char ** ); 1754 int lookup_macro ( int, char *, int * ); 1755 int lookup_alias_mult ( char, unsigned int, int * ); 1756 char *lookup_label_mult ( char, unsigned int, int * ); 1757 char *lookup_label ( char, unsigned int ); 1758 char *alias_rev_lookup_mult ( char, unsigned int, int * ); 1759 char *alias_rev_lookup ( char, unsigned int ); 1760 int parse_units ( char *, unsigned int * ); 1761 void replace_dummy_parms ( int, char ***, char ** ); 1762 int image_chksum ( unsigned char * ); 1763 int macro_dupe ( MACRO **, int, unsigned char **, char * ); 1764 unsigned int parse_addr ( char *, char *, unsigned int * ); 1765 int add_scene ( SCENE **, char *, int, char *, unsigned int ); 1766 void get_std_timezone ( void ); 1767 int parse_config_tail ( char *, unsigned char ); 1768 void display_config_overrides ( FILE * ); 1769 int finalize_config ( unsigned char ); 1770 int environment_config( void ); 1771 void millisleep ( long ); 1772 void microsleep ( long ); 1773 void write_x10state_file ( void ); 1774 void x10state_update_sticky_addr ( unsigned char ); 1775 void x10state_update_addr ( unsigned char, int * ); 1776 void x10state_update_func ( unsigned char *, int * ); 1777 void x10state_update_ext3func ( unsigned char *, int * ); 1778 void x10state_update_ext0func ( unsigned char *, int * ); 1779 void x10state_update_extotherfunc ( unsigned char *, int * ); 1780 int x10state_update_virtual ( unsigned char *, int, int * ); 1781 void x10state_init_all ( void ); 1782 void x10state_init_others ( void ); 1783 void update_flags ( unsigned char * ); 1784 void update_flags_32 ( unsigned char * ); 1785 int send_clear_statusflags ( unsigned char, unsigned int ); 1786 void clear_statusflags ( unsigned char, unsigned int ); 1787 void x10state_init_old ( unsigned char ); 1788 void x10state_init ( unsigned char, unsigned int ); 1789 void x10state_show ( unsigned char ); 1790 void x10state_update_bitmap ( unsigned char, unsigned int ); 1791 int load_image ( int * ); 1792 int loadcheck_image ( int ); 1793 void display_trigger( char *, unsigned int, unsigned char ); 1794 int expand_macro( char *, unsigned int, int ); 1795 char *translate_sent ( unsigned char *, int, int * ); 1796 char *translate_virtual ( unsigned char *, int, unsigned char *, int * ); 1797 char *translate_long_virtual ( unsigned char *, unsigned char *, int * ); 1798 void x10state_reset_all_triggers ( void ); 1799 void x10state_reset_all_modmasks ( void ); 1800 int parse_launch ( char * ); 1801 int launch_scripts ( int *); 1802 void send_sptty_x10state_command ( int, unsigned char, unsigned char ); 1803 void send_x10state_command ( unsigned char, unsigned char ); 1804 void set_module_masks ( ALIAS * ); 1805 int lookup_module_type ( char * ); 1806 void finalize_launch ( void ); 1807 char *lookup_module_name ( int ); 1808 int absdims( int ); 1809 unsigned char level2dims( unsigned char, char **, char ** ); 1810 void show_hc_dimlevel ( unsigned char ); 1811 void show_all_dimlevels ( void ); 1812 int add_script( SCRIPT **, LAUNCHER **, int, char * ); 1813 int add_launchers ( LAUNCHER **, int, char * ); 1814 int send_address ( unsigned char, unsigned int, int ); 1815 int send_command ( unsigned char *, int, unsigned int, int ); 1816 int heyu_getopt( int, char **, struct opt_st * ); 1817 int alias_count ( void ); 1818 int launch_heyuhelper ( unsigned char, unsigned int, unsigned char ); 1819 void module_attributes ( int, unsigned long *, unsigned long *, unsigned long *, unsigned long *, int * ); 1820 int add_module_options ( ALIAS *, int, char **, int ); 1821 char *display_module_options ( int ); 1822 long int systime_now ( void ); 1823 int dawndusk_today ( long *, long * ); 1824 int unlock_state_engine( void ); 1825 void free_all_arrays ( CONFIG * ); 1826 int display_x10state_message( char * ); 1827 int c_cm10a_init( int, char ** ); 1828 int invalidate_for_cm10a ( void ); 1829 void wait_next_tick ( void ); 1830 void send_virtual_data ( unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char ); 1831 int send_virtual_aux_data ( unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char ); 1832 int send_virtual_cmd_data ( unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char ); 1833 int reread_config ( void ); 1834 int check_for_engine ( void ); 1835 int check_for_aux ( void ); 1836 int alias_rev_index ( char, unsigned int, unsigned char, unsigned long ); 1837 void read_minimal_config ( unsigned char, unsigned int ); 1838 void set_user_timer_countdown ( int, long ); 1839 void display_settimer_setting ( int, long ); 1840 void create_lock_suffix ( char *, char * ); 1841 long parse_hhmmss ( char *, int ); 1842 int busywait ( int ); 1843 char *translate_settimer_message( unsigned char * ); 1844 void reset_user_timers( void ); 1845 int set_global_dawndusk ( time_t ); 1846 int update_global_nightdark_flags ( time_t ); 1847 int engine_local_setup ( int ); 1848 void midnight_tick ( time_t ); 1849 void hour_tick ( time_t ); 1850 void minute_tick ( time_t ); 1851 void second_tick ( time_t, long ); 1852 void set_global_tomorrow ( time_t ); 1853 int is_tomorrow ( time_t ); 1854 unsigned long list2linmap ( char *, int, int ); 1855 char *linmap2list( unsigned long ); 1856 int decode_rfxsensor_data ( ALIAS *, int, unsigned int *, unsigned int *, double *, double *, double *, double *); 1857 int rfxsensor_count ( void ); 1858 void set_macro_timestamp ( time_t ); 1859 time_t get_macro_timestamp ( void ); 1860 void create_rfxpower_panels( void ); 1861 int check_dir_rw ( char *, char * ); 1862 void gendate ( char *, time_t, unsigned char, unsigned char ); 1863 int warn_zone_faults ( FILE *, char * ); 1864 double hilo2dbl ( unsigned long, unsigned long ); 1865 int is_unmatched_flags ( LAUNCHER * ); 1866 void setup_countdown_timers ( void ); 1867 int update_activity_states ( unsigned char, unsigned int, unsigned char ); 1868 1869