/* ************************************************************************ ** ** Copyright (c) 2007..2014 by ** Core|Vision B.V. ** Cereslaan 10b ** 5384 VT Heesch ** The Netherlands ** ** All Rights Reserved ** ************************************************************************ */ /* ************************************************************************ ** ** Project name: Dual Inventive: Zelfsignalerende Kortsluit Lans ** Module 1 ** Filename: zkl-common.h ** Author: Jack Weeland ** Date: April 26, 2007 ** File version: $Revision: 1.123 $ ** $Date: 2015/05/13 13:53:37 $ ** ************************************************************************ */ /* ************************************************************************ ** ** Common definitions for the microcontroller and wireless CPU ** ************************************************************************ */ #ifndef _ZKL_COMMON_H #define _ZKL_COMMON_H /* ** I2C bus addresses */ // general call address #define I2CAD_GC 0x00 // main bus of the ZKL 3000 #define I2CAD_MCU 0xB0 // chip address of the MCU #define I2CAD_AFT2 0xB2 // AFT version 2 MCU #define I2CAD_TD3000 0xB4 // Train Detection 3000 address #define I2CAD_UALFAT 0xA4 // address fixed by the µALFAT chip #define I2CAD_LM75 0x9E // LM75 temperature sensor #define I2CAD_LM75_AFT2 0x9A // LM75 temperature sensor on AFT2 board // software I²C bus to the Power Management 3000 add-on board #define I2CAD_MCP3424_BATT 0xD0 // MCP3424 18-bit ADC on Power Management 3000 board #define I2CAD_MCP23008_GPIO 0x40 // MCP23008 I/O expander on Power Management 3000 board #define I2CAD_PCM3000 0x96 // Power cycle module // Addresses interpreted by the MCU // Bus protocol for writes (Wavecom is the master, MCU is the slave): // [S]10110000[A]address[A]databyte[A]...[A][P] // (slave ACKs each data byte) // Bus protocol for reads (Wavecom is the master, MCU is the slave): // [S]10110001[A]address[A][Sr]10110001[A]databyte...[N][P] // (master ACKs each data byte, except the last) #define MCUAD_STATUS 0x00 // (read) short circuit and battery status (upto 20 bytes) // [0,1] 2 bytes MCU state (MCUSYS_xxx and MCUERR_xxx) // [2,3] 2 bytes MCU local state (MCULOC_xxx) // [4,5] 2 bytes start-up counter // [6,7] 2 bytes battery selection (0, 1 or -1) // [8,9] 2 bytes battery #1 level // [10,11] 2 bytes battery #2 level // [12] 1 byte on-board temperature (signed char) // [13] 1 byte external temperature (signed char) // [14,15] 2 bytes flags (bits 0..15) // [16,17] 2 bytes b/a threshold (after auto-calibration) // [18,19] 2 bytes PWM period (after auto-calibration) // [20,21] 2 bytes reprogramming counter (determines name of the log file) // [22,23] 2 bytes b/a last measurement (0 if no measurement) // [24,25] 2 bytes RMS last measurement (0 if no measurement) // [26,27] 2 bytes calibrated amplitude // [28,29] 2 bytes ZKL 3000 RC state (MCURC_xxx) // [30,31] 2 bytes Switch3000 state (MCUSW_xxx) // [32] 1 byte Switch3000 temperature // [33] not used // [34,35] 2 bytes on-board temperature with fraction // [36,37] 2 bytes external temperature with fraction // [38,39] 2 bytes Switch3000 temperature with fraction // [40,41] 2 bytes detection counter // [42,43] 2 bytes detection direction (0 if not defined or undetermined) // [44,45] place holder: write-only reset register // [46,47] 2 bytes extended flags (bits 16..31) // (write) offset as above (byte), mask (16-bit int), value (16-bit int) #define MCUAD_INT 0x01 // (read+write) interrupt source (2 bytes) #define MCUAD_GPS 0x02 // (read+write) GPS location (3 floats = 12 bytes, hdop (2 bytes), speed and heading (2 * 2 bytes) #define MCUAD_RTC 0x03 // (write) RTC data (6 bytes: yymmddhhmmss) #define MCUAD_SERIAL 0x04 // (write) product id (12 bytes) for logging and flash memory #define MCUAD_VERSION (MCUAD_SERIAL) // (read) MCU and board version, MCU firmware date (2+1+8 bytes) #define MCUAD_IDCODE 0x05 // (write) id code (mas 32 bytes, for logging only) #define MCUAD_GSM_REGISTERED 0x06 // (write) SIM registered and connected to GSM or TCP-server // (1 byte: 0 = connected and logged on, 0xFF = disconnected, rssi+ber otherwise) #define MCUAD_DEBUG 0x07 // (write) 1 byte; log level in bits 3..0 #define MCUAD_RELAYDRV 0x08 // (write) relay driver on or off (1 byte, '0' = off) // (read) relay driver is on ('1') or off ('0') #define MCUAD_LED 0x09 // (write) led dimmed ('0') or bright ('1') // (read) current setting #define MCUAD_LANTERN 0x0A // (Write) lantern function on ('1') or off ('0') // (read) current setting #define MCUAD_EXT_CONTACT 0x0B // (Write) extern contact driver on ('1') or off ('0') // (read) current setting #define MCUAD_GPSPOWER 0x0C // (write) GPS and 5V circuit on ('1') or off ('0') // (read) current status #define MCUAD_uALFAT_VERSION 0x0D // (read) µALFAT firmware version #define MCUAD_LOGREPLAY 0x0E // (write) request to replay a log (2+2+4 or 2 bytes) // 2 bytes reprogramming count, / all once reads from current pos // 2 bytes start-up count // 4 bytes file position // (read) access to the log-data #define MCUAD_NOTIFY 0x0F // (write) log an error (2 byte, see MCUNOT_xxx) // debug read-back of one measurement #define MCUAD_MEAS_READBACK 0x10 // (write) start ('1') read-back, or completed ('0') // (read) non-zero when lock succesfull (retry the write otherwise) #define MCUAD_MEAS_INFO 0x11 // (read) number of samples, b/a, rms of v_ref and v_meas (4x2 bytes) #define MCUAD_MEAS_SAMPLES 0x12 // (read) samples (number of samples x 2 bytes, raw v_ref and v_meas and filtered) // get the directory listing of the SD-card #define MCUAD_DIR 0x13 // (write) start ('1') or next ('0') // software watchdog reset when connected to GPRS (not used) #define MCUAD_GPRS_XMT 0x14 // (Write) restart the watchdog timer (1 byte of data) // switch 3000 #define MCUAD_SW3000 0x15 // (write) 1 byte, Switch 3000 command (SWCMD_xxx) // (read) 3 bytes // [0] status present // [1] section enabled ('1') or not (four sections) // [2] battery status: ok ('1') or not ('0') (four sections + emergency in MSB) #define MCUAD_GSM_SIGNAL 0x16 // (write) 1 byte RSSI (bits 7..3) and BERR (2..0), cf GSM 05.08 // geofencing #define MCUAD_GEOFENCE 0x17 // (write) 1 byte command // n bytes depending on command // configurable parameters #define MCUAD_NTC_PARAM 0x18 // (read+write) 3 floats (NTC B, T_0, R_0), 12 bytes #define MCUAD_TIMING_PARAM 0x19 // (read+write) // [0,1] power save period in s // extended status #define MCUAD_EXT_STATUS 0x80 // (read) (byte count returned in the first byte) // [0] '0' if not supported, '5' otherwize // [1] reserved, '10' (bytes for this item) // [2,3] MCUAD_ES_FLAGS size (items,bytes) // [4,5] MCUAD_ES_MEASUREMENT size (items,bytes) // [6,7] MCUAD_ES_BATT size (items,bytes) // [8,9] MCUAD_ES_TEMP size (items,bytes) // (others are reserved) #define MCUAD_ES_FLAGS 0x81 // (read) 12 bytes state // [0,1] start-up counter // [2,3] reprogramming counter // [4,5] global state // [6,7] local state // [8,9] flags // [10,11] rc state // [12,13] switch state (see MCUAD_SW3000) #define MCUAD_ES_MEASUREMENT 0x82 // (read) 25 bytes // [0,1] 2 bytes number of samples // [2,3] 2 bytes b/a last measurement // [4,5] 2 bytes RMS V_ref last measurement (actually w/o "root") // [6,7] 2 bytes RMS V_meas last measurement ( " ) // [8,9] 2 bytes latency (ms) // [10-13] 4 bytes ADC timing (ADCON3 register) // [14,15] 2 bytes calibrated b/a // [16,17] 2 bytes calibrated PWM period // [18,19] 2 bytes calibrated PWM amplitude // [20] 1 byte detection: // 0x01 short circuit detected // 0x02 Switch 3000 turned off or error (i.e. '0' means that the // short circuit is preset, for compatibility with the ZKL3000) // [21,22] 2 bytes PWM period // [23,24] 2 bytes PWM amplitude // [25,26] 2 bytes detection counter // [27,28] 2 bytes detection direction (0 if not defined or undetermined) #define MCUAD_ES_BATT 0x83 // (read) (max) 20 bytes (historically n/1024 x 26.45V) // [0,3] 4 bytes battery status as MCUSTAT_BATTERY_xx // bits 0.. 1: battery #1 // bits 2.. 3: battery #2 // bits 16..17: switch section #1 // bits 18..19: switch section #2 // bits 20..21: switch section #3 // bits 22..23: switch section #4 // bits 30..31: switch emergency // [4,5] selection // [6,7] battery #1 // [8,9] battery #2 // [10,11] Vbatt for the ZKL board // [12,13] 3.5V supply // [14,15] 5V supply *) // [16,17] 2.8V supply *) // [18,19] 1.8V supply *) // *) usually not available #define MCUAD_ES_TEMP 0x84 // (read) 3 + 6 bytes temperature // [0] on-board LM75 sensor // [1] external temperature via NTC *) // [2] Switch 3000 temperature // [4,5] on-board LM75 sensor (8.8 signed fixed point) // [6,7] external temperature via NTC (8.8 signed fixed point) // [8,9] Switch 3000 temperature (8.8 signed fixed point) #define MCUAD_ES_LOG 0x85 // (read) 8 bytes log internal state // [0,1] log state (LFS_xxx constants in "zkl-mcu/src/log.c") // [2,3] current async command // [4,5] count // [6,7] state (0x01: stalled, 0x02: buffer filled) #define MCUAD_ES_PCM3000 0x86 // (read) registers of the power cycle module // [0,1] time-out // [2,3] normal reset counter // [4,5] abnormal reset counter // [6,7] power cycle counter // (write) // [0,1] time-out #define MCUAD_ES_MCU 0x8F // MCU internal state for debugging // place holder #define MCUAD_ILLEGAL 0xFF // Lengths, message contents see above #define MCURDLEN_STATUS 48 #define MCURDLEN_STATUS_MCU (2 + 2) // MCU state and local state only #define MCUWRLEN_STATUS (1 + 2 + 2) // write interface: offset, mask (2 bytes), data (2 bytes) #define MCURDLEN_INT 2 #define MCURDLEN_VERSION (3 + 8 + 1 + 1 + 4 + (2 * (1 + 1 + 2))) #define MCURDLEN_uALFAT_VERSION 24 #define MCURDLEN_MEAS_READBACK 1 #define MCURDLEN_MEAS_INFO (5*2 + 4 + 2*2) #define MCUWRLEN_INT 2 #define MCUWRLEN_GPS (3*4 + 2 + 2 + 2) #define MCURDLEN_GPS (MCUWRLEN_GPS) #define MCUWRLEN_RTC 6 #define MCURDLEN_RTC 6 #define MCUWRLEN_SERIAL 12 #define MCUWRLEN_IDCODE 32 #define MCUWRLEN_LOGREPLAY (2+2+4) #define MCUWRLEN_MEAS_READBACK 1 #define MCUWRLEN_DEBUG 1 #define MCUWRLEN_SW3000 1 #define MCURDLEN_SW3000 4 #define MCURDLEN_NTC_PARAM (3*4) #define MCUWRLEN_NTC_PARAM (MCURDLEN_NTC_PARAM) #define MCURDLEN_TIMING_PARAM (2) #define MCUWRLEN_TIMING_PARAM (MCURDLEN_TIMING_PARAM) // Maximum lengths for the extended status (reading address MCUAD_EXT_STATUS returns the actual length) #define MCURDLEN_EXT_STATUS 16 #define MCURDLEN_ES_FLAGS 14 #define MCURDLEN_ES_MEASUREMENT 29 #define MCURDLEN_ES_BATT 20 #define MCURDLEN_ES_TEMP_INT 3 #define MCURDLEN_ES_TEMP (3 + 1 /* filler */ + 3*2) #define MCURDLEN_ES_LOG 10 #define MCURDLEN_ES_MCU 36 #define MCURDLEN_ES_PCM3000 10 #define MCUWRLEN_ES_PCM3000 (MCUWRLEN_STATUS) // identical interface // Components of those messages, abstracted from the string or byte array 's' #define BYTE2UINT(s,b) ((unsigned int)((unsigned char)(s)[b])) #define BYTE2INT(s,b) ((signed int)((signed char)(s)[b])) #define WORD2UINT(s,lsb) ((BYTE2UINT(s,(lsb)) << 0) | (BYTE2UINT(s,(lsb) + 1) << 8)) #define WORD2INT(s,lsb) ((signed int)((BYTE2UINT(s,(lsb)) << 0) | (BYTE2UINT(s,(lsb) + 1) << 8) | ((s[(lsb)+1]) & 0x80 ? 0xFFFF0000 : 0))) #define WORD2ULONG(s,lsb) ((((unsigned long)WORD2UINT(s,(lsb))) << 0) | (((unsigned long)WORD2UINT(s,(lsb) + 2)) << 16)) // Components of those messages, abstracted from the string or byte array 's' (little endian; same as the default) #define LEBYTE2UINT(s,b) ((unsigned int)((unsigned char)(s)[b])) #define LEBYTE2INT(s,b) ((signed int)((signed char)(s)[b])) #define LEWORD2UINT(s,lsb) ((BYTE2UINT(s,(lsb)) << 0) | (BYTE2UINT(s,(lsb) + 1) << 8)) #define LEWORD2INT(s,lsb) ((signed int)((BYTE2UINT(s,(lsb)) << 0) | (BYTE2UINT(s,(lsb) + 1) << 8) | ((s[(lsb)+1]) & 0x80 ? 0xFFFF0000 : 0))) #define LEWORD2ULONG(s,lsb) ((((unsigned long)WORD2UINT(s,(lsb))) << 0) | (((unsigned long)WORD2UINT(s,(lsb) + 2)) << 16)) // Components of those messages, abstracted from the string or byte array 's' (big endian) #define BEBYTE2UINT(s,b) ((unsigned int)((unsigned char)(s)[b])) #define BEBYTE2INT(s,b) ((signed int)((signed char)(s)[b])) #define BEWORD2UINT(s,lsb) ((BEBYTE2UINT(s,(lsb)) << 8) | (BEBYTE2UINT(s,(lsb) + 1) << 0)) #define BEWORD2INT(s,lsb) ((signed int)((BEBYTE2UINT(s,(lsb)) << 8) | (BEBYTE2UINT(s,(lsb) + 1) << 0) | ((s[(lsb)]) & 0x80 ? 0xFFFF0000 : 0))) #define BEWORD2ULONG(s,lsb) ((((unsigned long)BEWORD2UINT(s,(lsb))) << 16) | (((unsigned long)BEWORD2UINT(s,(lsb) + 2)) << 0)) // Byte positions of the LSB #define MCURDPOS_STATUS_STATE 0 #define MCURDPOS_STATUS_LOCAL_STATE 2 #define MCURDPOS_STATUS_STARTUP 4 #define MCURDPOS_STATUS_BATTSEL 6 #define MCURDPOS_STATUS_BATT1LVL 8 #define MCURDPOS_STATUS_BATT2LVL 10 #define MCURDPOS_STATUS_INTTEMP 12 #define MCURDPOS_STATUS_EXTTEMP 13 #define MCURDPOS_STATUS_FLAGS 14 #define MCURDPOS_STATUS_CAL_B_A 16 #define MCURDPOS_STATUS_PWM 18 #define MCURDPOS_STATUS_AMPL 26 // for compatibility with the base module #define MCURDPOS_STATUS_RPGMCOUNT 20 #define MCURDPOS_STATUS_B_A 22 #define MCURDPOS_STATUS_RMS 24 #define MCURDPOS_STATUS_RC 28 #define MCURDPOS_STATUS_SW3000 30 #define MCURDPOS_STATUS_SW3000TEMP 32 #define MCURDPOS_STATUS_INTTEMP_FRAC 34 #define MCURDPOS_STATUS_EXTTEMP_FRAC 36 #define MCURDPOS_STATUS_SW3000TEMP_FRAC 38 #define MCURDPOS_STATUS_DETECTCOUNT 40 #define MCURDPOS_STATUS_DETECTDIR 42 #define MCURDPOS_STATUS_RESETREG 44 #define MCURDPOS_STATUS_EXTFLAGS 46 #define MCUWRPOS_STATUS_OFFSET 0 #define MCUWRPOS_STATUS_MASK 1 #define MCUWRPOS_STATUS_VALUE 3 #define MCURDPOS_VERSION_MAJOR 0 #define MCURDPOS_VERSION_MINOR 1 #define MCURDPOS_VERSION_BOARD 2 #define MCURDPOS_VERSION_DATECODE 3 // string #define MCURDPOS_VERSION_DEVTYPE (MCURDPOS_VERSION_DATECODE + 8) #define MCURDPOS_VERSION_FLAGS (MCURDPOS_VERSION_DATECODE + 9) #define MCURDPOS_VERSION_DEVID (MCURDPOS_VERSION_DATECODE + 10) #define MCURDPOS_SWVERSION_DMAJOR (MCURDPOS_VERSION_DATECODE + 14) #define MCURDPOS_SWVERSION_DMINOR (MCURDPOS_VERSION_DATECODE + 15) #define MCURDPOS_SWVERSION_DDATE (MCURDPOS_VERSION_DATECODE + 16) #define MCURDPOS_SWVERSION_MMAJOR (MCURDPOS_VERSION_DATECODE + 18) #define MCURDPOS_SWVERSION_MMINOR (MCURDPOS_VERSION_DATECODE + 19) #define MCURDPOS_SWVERSION_MDATE (MCURDPOS_VERSION_DATECODE + 20) #define MCURDPOS_ES_STARTUP 0 #define MCURDPOS_ES_RPGM 2 #define MCURDPOS_ES_STATE 4 #define MCURDPOS_ES_LOCAL_STATE 6 #define MCURDPOS_ES_FLAGS 8 #define MCURDPOS_ES_RC_STATE 10 #define MCURDPOS_ES_SW3000_STATE 12 #define MCURDPOS_ES_NR_SAMPLES 0 #define MCURDPOS_ES_B_A 2 #define MCURDPOS_ES_RMS_V_REF 4 #define MCURDPOS_ES_RMS_V_MEAS 6 #define MCURDPOS_ES_LATENCY 8 #define MCURDPOS_ES_T_SAMP 10 #define MCURDPOS_ES_CAL_B_A 14 #define MCURDPOS_ES_CAL_PWM 16 #define MCURDPOS_ES_CAL_AMPL 18 #define MCURDPOS_ES_DETECTION 20 #define MCURDPOS_ES_PWM 21 #define MCURDPOS_ES_AMPL 23 #define MCURDPOS_ES_DETECTCOUNT 25 #define MCURDPOS_ES_DETECTDIR 27 #define MCURD_ESDET_OK 0x01 // flags for MCURDPOS_ES_DETECTION #define MCURD_ESDET_SW3000_OK 0x02 // detection ok when the switch was turned on (or off) #define MCURD_ESDET_SW3000_ON 0x40 // switch turned on and section okay #define MCURD_ESDET_SW3000_ENABLED 0x80 // switch operational (key 'operational' and project not released) #define MCURDPOS_ES_BATTSTATUS 0 #define MCURDPOS_ES_BATTSEL 4 #define MCURDPOS_ES_BATT1LVL 6 #define MCURDPOS_ES_BATT2LVL 8 #define MCURDPOS_ES_V_BATT 10 #define MCURDPOS_ES_V_35 12 #define MCURDPOS_ES_V_50 14 #define MCURDPOS_ES_V_28 16 #define MCURDPOS_ES_V_18 18 #define MCURDPOS_ES_INTTEMP 0 #define MCURDPOS_ES_EXTTEMP 1 #define MCURDPOS_ES_SW3000TEMP 2 #define MCURDPOS_ES_INTTEMP_FRAC 4 #define MCURDPOS_ES_EXTTEMP_FRAC 6 #define MCURDPOS_ES_SW3000TEMP_FRAC 8 #define MCURDPOS_ES_LOGFILE_STATE 0 #define MCURDPOS_ES_LOGFILE_ASYNC 2 #define MCURDPOS_ES_LOGREPLAY_COUNT 4 #define MCURDPOS_ES_LOGREPLAY_STATE 6 #define MCURDPOS_ES_LOGFILE_ERROR 8 #define MCURDPOS_ES_PCM_WATCHDOG_TIMEOUT 0 #define MCURDPOS_ES_PCM_ONLINE_TIMEOUT 2 #define MCURDPOS_ES_PCM_NORMAL_RESET_COUNT 4 #define MCURDPOS_ES_PCM_ABNORMAL_RESET_COUNT 6 #define MCURDPOS_ES_PCM_POWERCYCLE_COUNT 8 #define MCURDPOS_TIMING_PWRSAVE 0 // Components of the status message, abstracted from the string or byte array 's' #define MCURD_STATUS_STATE(s) WORD2UINT(s,MCURDPOS_STATUS_STATE) #define MCURD_STATUS_LOCAL_STATE(s) WORD2UINT(s,MCURDPOS_STATUS_LOCAL_STATE) #define MCURD_STATUS_STARTUP(s) WORD2UINT(s,MCURDPOS_STATUS_STARTUP) #define MCURD_STATUS_BATTSEL(s) ((int)WORD2INT(s,MCURDPOS_STATUS_BATTSEL)) #define MCURD_STATUS_BATT1LVL(s) WORD2UINT(s,MCURDPOS_STATUS_BATT1LVL) #define MCURD_STATUS_BATT2LVL(s) WORD2UINT(s,MCURDPOS_STATUS_BATT2LVL) #define MCURD_STATUS_INTTEMP(s) ((signed char)s[MCURDPOS_STATUS_INTTEMP]) #define MCURD_STATUS_EXTTEMP(s) ((signed char)s[MCURDPOS_STATUS_EXTTEMP]) #define MCURD_STATUS_SW3000TEMP(s) ((signed char)s[MCURDPOS_STATUS_SW3000TEMP]) #define MCURD_STATUS_INTTEMP_FRAC(s) ((signed int)WORD2INT(s,MCURDPOS_STATUS_INTTEMP_FRAC)) #define MCURD_STATUS_EXTTEMP_FRAC(s) ((signed int)WORD2INT(s,MCURDPOS_STATUS_EXTTEMP_FRAC)) #define MCURD_STATUS_SW3000TEMP_FRAC(s) ((signed int)WORD2INT(s,MCURDPOS_STATUS_SW3000TEMP_FRAC)) #define MCURD_STATUS_FLAGS(s) WORD2UINT(s,MCURDPOS_STATUS_FLAGS) #define MCURD_STATUS_FLAGS_FULL(s) (((unsigned long)WORD2UINT(s,MCURDPOS_STATUS_FLAGS)) | (((unsigned long)WORD2UINT(s,MCURDPOS_STATUS_EXTFLAGS)) << 16)) #define MCURD_STATUS_CAL_B_A(s) WORD2UINT(s,MCURDPOS_STATUS_CAL_B_A) #define MCURD_STATUS_PWM(s) WORD2UINT(s,MCURDPOS_STATUS_PWM) #define MCURD_STATUS_AMPL(s) WORD2UINT(s,MCURDPOS_STATUS_AMPL) #define MCURD_STATUS_RPGMCOUNT(s) WORD2UINT(s,MCURDPOS_STATUS_RPGMCOUNT) #define MCURD_STATUS_B_A(s) WORD2UINT(s,MCURDPOS_STATUS_B_A) #define MCURD_STATUS_RMS(s) WORD2UINT(s,MCURDPOS_STATUS_RMS) #define MCURD_STATUS_RC(s) WORD2UINT(s,MCURDPOS_STATUS_RC) #define MCURD_STATUS_SW3000(s) WORD2UINT(s,MCURDPOS_STATUS_SW3000) #define MCURD_STATUS_DETECTCOUNT(s) WORD2UINT(s,MCURDPOS_STATUS_DETECTCOUNT) #define MCURD_STATUS_DETECTDIR(s) WORD2INT(s, MCURDPOS_STATUS_DETECTDIR) #define MCUWR_STATUS_OFFSET(s) BYTE2UINT(s,MCUWRPOS_STATUS_OFFSET) #define MCUWR_STATUS_MASK(s) WORD2UINT(s,MCUWRPOS_STATUS_MASK) #define MCUWR_STATUS_VALUE(s) WORD2UINT(s,MCUWRPOS_STATUS_VALUE) // Components of the version (Serial) message, abstracted from the string or byte array 's' #define MCURD_VERSION_MAJOR(s) BYTE2UINT(s,MCURDPOS_VERSION_MAJOR) #define MCURD_VERSION_MINOR(s) BYTE2UINT(s,MCURDPOS_VERSION_MINOR) #define MCURD_VERSION_BOARD(s) BYTE2UINT(s,MCURDPOS_VERSION_BOARD) #define MCURD_VERSION_DATECODE(s) ((char*)s + (MCURDPOS_VERSION_DATECODE)) #define MCURD_VERSION_DEVTYPE(s) BYTE2UINT(s,MCURDPOS_VERSION_DEVTYPE) #define MCURD_VERSION_FLAGS(s) BYTE2UINT(s,MCURDPOS_VERSION_FLAGS) #define MCURD_VERSION_DEVID(s) WORD2ULONG(s,MCURDPOS_VERSION_DEVID) #define MCURD_SWVERSION_DMAJOR(s) BYTE2UINT(s,MCURDPOS_SWVERSION_DMAJOR) #define MCURD_SWVERSION_DMINOR(s) BYTE2UINT(s,MCURDPOS_SWVERSION_DMINOR) #define MCURD_SWVERSION_DDATE(s) WORD2UINT(s,MCURDPOS_SWVERSION_DDATE) #define MCURD_SWVERSION_MMAJOR(s) BYTE2UINT(s,MCURDPOS_SWVERSION_MMAJOR) #define MCURD_SWVERSION_MMINOR(s) BYTE2UINT(s,MCURDPOS_SWVERSION_MMINOR) #define MCURD_SWVERSION_MDATE(s) WORD2UINT(s,MCURDPOS_SWVERSION_MDATE) // Log replay #define MCULOGREPLAY_RPGM(s) WORD2UINT(s,0) #define MCULOGREPLAY_STARTUP(s) WORD2UINT(s,2) #define MCULOGREPLAY_FILEPOS(s) WORD2ULONG(s,4) // Components of the measurement info buffer #define MCURD_ES_NR_SAMPLES(s) WORD2UINT(s,MCURDPOS_ES_NR_SAMPLES) #define MCURD_ES_B_A(s) WORD2UINT(s,MCURDPOS_ES_B_A) #define MCURD_ES_RMS_V_REF(s) WORD2UINT(s,MCURDPOS_ES_RMS_V_REF) #define MCURD_ES_RMS_V_MEAS(s) WORD2UINT(s,MCURDPOS_ES_RMS_V_MEAS) #define MCURD_ES_LATENCY(s) WORD2UINT(s,MCURDPOS_ES_LATENCY) #define MCURD_ES_T_SAMP(s) WORD2ULONG(s,MCURDPOS_ES_T_SAMP) #define MCURD_ES_CAL_B_A(s) WORD2UINT(s,MCURDPOS_ES_CAL_B_A) #define MCURD_ES_CAL_PWM(s) WORD2UINT(s,MCURDPOS_ES_CAL_PWM) #define MCURD_ES_CAL_AMPL(s) WORD2UINT(s,MCURDPOS_ES_CAL_AMPL) #define MCURD_ES_DETECTION(s) BYTE2UINT(s,MCURDPOS_ES_DETECTION) #define MCURD_ES_DETECTCOUNT(s) WORD2UINT(s,MCURDPOS_ES_DETECTCOUNT) #define MCURD_ES_DETECTDIR(s) WORD2INT(s,MCURDPOS_ES_DETECTDIR) // Extended status, temperature #define MCURD_ES_INTTEMP_FRAC(s) ((signed int)WORD2INT(s,MCURDPOS_ES_INTTEMP_FRAC)) #define MCURD_ES_EXTTEMP_FRAC(s) ((signed int)WORD2INT(s,MCURDPOS_ES_EXTTEMP_FRAC)) #define MCURD_ES_SW3000TEMP_FRAC(s) ((signed int)WORD2INT(s,MCURDPOS_ES_SW3000TEMP_FRAC)) // Extended status, log file #define MCURD_ES_LOGFILE_STATE(s) WORD2UINT(s,MCURDPOS_ES_LOGFILE_STATE) #define MCURD_ES_LOGFILE_ASYNC(s) WORD2UINT(s,MCURDPOS_ES_LOGFILE_ASYNC) #define MCURD_ES_LOGREPLAY_COUNT(s) WORD2UINT(s,MCURDPOS_ES_LOGREPLAY_COUNT) #define MCURD_ES_LOGREPLAY_STATE(s) WORD2UINT(s,MCURDPOS_ES_LOGREPLAY_STATE) #define MCURD_ES_LOGFILE_ERROR(s) WORD2INT(s,MCURDPOS_ES_LOGFILE_ERROR) // Extended status, power cycle module #define MCURD_ES_PCM_WATCHDOG_TIMEOUT(s) WORD2UINT(s,MCURDPOS_ES_PCM_WATCHDOG_TIMEOUT) #define MCURD_ES_PCM_ONLINE_TIMEOUT(s) WORD2UINT(s,MCURDPOS_ES_PCM_ONLINE_TIMEOUT) #define MCURD_ES_PCM_NORMAL_RESET_COUNT(s) WORD2UINT(s,MCURDPOS_ES_PCM_NORMAL_RESET_COUNT) #define MCURD_ES_PCM_ABNORMAL_RESET_COUNT(s) WORD2UINT(s,MCURDPOS_ES_PCM_ABNORMAL_RESET_COUNT) #define MCURD_ES_PCM_POWERCYCLE_COUNT(s) WORD2UINT(s,MCURDPOS_ES_PCM_POWERCYCLE_COUNT) // Timing parameters #define MCURD_TIMING_PWRSAVE(s) ((signed int)WORD2INT(s,MCURDPOS_TIMING_PWRSAVE)) // status for the ZKL3000 RC #define MCURD_SW3000_DONE(s) (s[0] & 0x01) #define MCURD_SW3000_ERROR(s) (s[0] & 0x80) #define MCURD_SW3000_ON(s) (((s[1] & 0x09) == 0x09) || ((s[1] & 0x06) == 0x06)) #define MCURD_SW3000_BATT(s) (s[2]) // Geofence commands (first byte of the I2C message from WCPU to MCU); also used // in the CP3000 commands from TCP Server to WCPU #define GEOFENCECMD_DESIGN 0 #define GEOFENCECMD_START (GEOFENCECMD_DESIGN) #define GEOFENCECMD_OBJECT 1 #define GEOFENCECMD_POINT 2 #define GEOFENCECMD_ACTION 3 #define GEOFENCECMD_END 6 #define GEOFENCECMD_DELETE 7 #define GEOFENCECMD_ENTER 8 #define GEOFENCECMD_EXIT 9 #define GEOFENCECMD_SET_ALERT 15 /* ** Adresses interpreted by the AFT2 */ #define AFT2AD_DETECT 0x00 // (write) 1 byte: mode (see "aft.h") // (read) 5 bytes, version major and minor, build (uint) // and current mode #define AFT2AD_MODE (AFT2AD_DETECT) // alias #define AFT2AD_DONE 0x01 // (Write) tests are complete // - 1 byte test result // 0 = ok // 1 = error // 2 = suspicious // 3 = timeout #define AFT2AD_BATT1_DIS 0x10 // (write) disable battery #1 #define AFT2AD_BATT1_EN 0x11 // (Write) enable battery #1 #define AFT2AD_BATT2_DIS 0x20 // (write) disable battery #2 #define AFT2AD_BATT2_EN 0x21 // (Write) enable battery #2 #define AFT2AD_RAIL_RLY_DIS 0x70 // (write) disable rail relay (break contact) #define AFT2AD_RAIL_RLY_EN 0x71 // (write) enable rail relay (make contact) #define AFT2AD_INFO 0x80 // (write) 2 + n bytes: // - 1 byte item code (as defined in "aft.h" // - 1 byte length (n) // - n bytes text to display #define AFT2AD_RESULT 0x81 // (write) 8 bytes: // - 1 byte item code (as defined in "aft.h") // - 1 byte test result // 0 = ok // 1 = error // 2 = suspicious // 3 = timeout // - 2 bytes result [int] // - 2 bytes lower bound [int] // - 2 bytes upper bound [int] /* ** Interrupt sources */ // SMS message requested (see MSG_xxx definitions below) #define MCUINT_MSG(msg_type) (1 << (msg_type)) /* ** Microcontroller status, as read from I2C address I2CAD_MCU_STATUS ** (low/first byte of MCU status) */ #define MCUSTAT_MEASUREMENT 0x0001 #define MCUSTAT_DETECTION_OK 0x0002 #define MCUSTAT_MEASUREMENT_FAIL 0x0004 #define MCUSTAT_RELAY_OPEN 0x0008 // system initialization errors and state #define MCUERR_NONE 0x0000 #define MCUERR_I2C 0x0010 // I2C failure (MCU->WCPU path) #define MCUERR_SPI (MCUERR_I2C) #define MCUERR_LOG 0x0020 // µALFAT or SD-card failure #define MCUERR_GSM 0x0040 // WCPU unreachable #define MCUERR_SMS 0x0080 // not used #define MCUERR_ANY 0x00F0 // battery status #define MCUSTAT_BATTERY_OK 0 #define MCUSTAT_BATTERY_LOW 1 #define MCUSTAT_BATTERY_CRITICAL 2 #define MCUSTAT_BATTERY_ABSENT 3 #define MCUSTAT_BATTERY_INIT 4 // will never be set in the MCU status; internal use only #define MCUSTAT_BATTERY_CHANGED 4 // internal state: battery status has changed #define MCUSTAT_BATTERY1_OK 0 // (placeholder) #define MCUSTAT_BATTERY1_LOW (1 << (MCUSTAT_BATTERY_LOW + 7)) #define MCUSTAT_BATTERY1_CRITICAL (1 << (MCUSTAT_BATTERY_CRITICAL + 7)) #define MCUSTAT_BATTERY1_ABSENT (1 << (MCUSTAT_BATTERY_ABSENT + 7)) #define MCUSTAT_BATTERY1_INIT (1 << (MCUSTAT_BATTERY_INIT + 7)) #define MCUSTAT_BATTERY1_CHANGED (1 << (MCUSTAT_BATTERY_CHANGED + 7)) #define MCUSTAT_BATTERY2_OK 0 // (placeholder) #define MCUSTAT_BATTERY2_LOW (1 << (MCUSTAT_BATTERY_LOW + 11)) #define MCUSTAT_BATTERY2_CRITICAL (1 << (MCUSTAT_BATTERY_CRITICAL + 11)) #define MCUSTAT_BATTERY2_ABSENT (1 << (MCUSTAT_BATTERY_ABSENT + 11)) #define MCUSTAT_BATTERY2_INIT (1 << (MCUSTAT_BATTERY_INIT + 11)) #define MCUSTAT_BATTERY2_CHANGED (1 << (MCUSTAT_BATTERY_CHANGED + 11)) #define MCUSTAT_BATTERY 0x7700 // combination of all battery status flags #define MCUSTAT_BATTERY1 0x0700 #define MCUSTAT_BATTERY2 0x7000 #define MCUSTAT_BATTERY_MASK 0xFF00 // MCU local state // Flags for 'sys_info.local_state' #define MCULOC_IN_SWEEP 0x0003 // sweep busy #define MCULOC_IN_FREQ_SWEEP 0x0001 // frequency sweep #define MCULOC_IN_AMPL_SWEEP 0x0002 // amplitude sweep #define MCULOC_IN_SERVICE 0x0004 // device is in service #define MCULOC_GPSPOWER 0x0008 // GPS power enabled (for trace & trace) #define MCULOC_GPS_RECEIVED 0x0010 // GPS co-ordinates received #define MCULOC_RTC_RECEIVED 0x0020 // clock data received #define MCULOC_LED 0x0040 // LED intensity is "high" / deprecated 20091111 #define MCULOC_LANTERN 0x0080 // lantern is "on" / deprecated 20091111 #define MCULOC_AUTOCAL 0x0100 // auto-calibration enabled #define MCULOC_AUTOCAL_FAIL 0x0200 // auto-calibration failed (internal state) #define MCULOC_EXT_CONTACT 0x0400 // external contact enabled #define MCULOC_RELAY_DRIVER 0x0800 // relay driver enabled #define MCULOC_MEASUREMENT 0x1000 // measurement taken #define MCULOC_GSM_ENABLED 0x2000 // registered to GSM network #define MCULOC_TCP_CONNECTED 0x4000 // logged in with TCP server #define MCULOC_INIT_DONE 0x8000 // MCU is initialized // ZKL 3000 RC (Switch3000 and Power Management 3000) state flags #define MCURC_MEASUREMENT_ON 0x0001 // transient state: measurements are turned on from MTinfo #define MCURC_DETECTION_OK 0x0002 // detection status at the moment the Switch3000 was turned on or off #define MCURC_KEY_SWITCH_ON 0x0004 // key for Switch3000 is "on" #define MCURC_KEY_SWITCH_OFF 0x0008 // key for Switch3000 is "off" #define MCURC_SW3000_ANY 0x000F // (mask for status updates) #define MCURCERR_SWI2C 0x0010 // software I2C error #define MCURCERR_SW1W 0x0020 // software 1-Wire error #define MCURCERR_SW3000 (MCURCERR_SW1W) #define MCURCERR_PM3000 0x0040 // PM3000 failure #define MCURCERR_ANY 0x0070 // (mask for status updates and others) #define MCURC_PM_SW3000_ON 0x0080 // Switch 3000 power always on #define MCURC_PM_SWITCH1 0x0100 // power management: switch 1 is "on" (Switch 3000) #define MCURC_PM_SWITCH2 0x0200 // power management: switch 2 is "on" (undefined) #define MCURC_PM_CHARGE 0x0400 // power management: charging LiIon battery #define MCURC_PM_BOOST 0x0800 // transient state: 9V boost for the analogue circuit enabled #define MCURC_GPS_POWER_ON 0x1000 // transient state: GPS (5V circuit) powered up #define MCURC_PM_CHARGE_MANUAL 0x2000 // battery charger controlled manually #define MCURC_SW3000_ONESHOT 0x4000 // Switch 3000: one shot measurement #define MCURC_STATUS_VALID 0x8000 // transient state: status is retrieved for Switch 3000 // and it ready to be read (the flag will disappear // immediately after that) #define MCURC_PM3000_ANY 0x7F80 // (mask for status updates) // configurable bits, mostly for debugging #define MCURC_CONFIGURATION (MCURCERR_ANY|MCURC_PM_SW3000_ON|MCURC_PM_SWITCH1|MCURC_PM_SWITCH2|MCURC_PM_CHARGE|MCURC_GPS_POWER_ON|MCURC_PM_CHARGE_MANUAL) // Switch3000 state flags #define MCUSW_SEC1_ON 0x0001 // section #1 is enabled #define MCUSW_SEC2_ON 0x0002 // section #2 is enabled #define MCUSW_SEC3_ON 0x0004 // section #3 is enabled #define MCUSW_SEC4_ON 0x0008 // section #4 is enabled #define MCUSW_SEC_NONE 0x0000 // (placeholder) #define MCUSW_SEC_ALL 0x000F // (all sections) #define MCUSW_SW3000_ON(s) (((s & 0x09) == 0x09) || ((s & 0x06) == 0x06)) #define MCUSWERR_TIMEOUT 0x0010 // time-out error #define MCUSWERR_ERROR 0x0020 // generic error, most likely in the 1-Wire signaling #define MCUSW_SEC1_BATT_OK 0x0100 // battery for section #1 is okay #define MCUSW_SEC2_BATT_OK 0x0200 // battery for section #2 is okay #define MCUSW_SEC3_BATT_OK 0x0400 // battery for section #3 is okay #define MCUSW_SEC4_BATT_OK 0x0800 // battery for section #4 is okay #define MCUSW_SECx_BATT_OK(s) (1 << ((s)+8)) #define MCUSW_SECE_BATT_OK 0x8000 // battery for emergency section is okay #define MCUSW_SEC_ALL_BATT 0x8F00 // (all batteries) // MCU flags (are recorded in flash memory) // Flags for 'sys_info.flags' #define MCUFLG_AUTOCAL_DONE 0x0001 // device is calibrated #define MCUFLG_DISABLE_CHARGER 0x0002 // don't use the charger on a PM3000 #define MCUFLG_STATLED_ALWAYS 0x0040 // always show the status LED #define MCUFLG_SW3000_AVAILABLE 0x0004 // device is equiped with a Switch3000 #define MCUFLG_PM3000_AVAILABLE 0x0008 // device is equiped with a Power Management 3000 module // (automatically detected) #define MCUFLG_MEASUREMENT 0x0010 // measurement busy #define MCUFLG_MEASUREMENT_RC 0x0020 // measurements turned on remotely #define MCUFLG_SW3000_ENABLED 0x0080 // Switch 3000 is enabled #define MCUFLG_BATTERY_MASK 0xFF00 // #define MCUFLG_BATTERY_TYPE(b,t,v) ((((t) << 2) | (v)) << (8 + (4*b))) // Battery voltage type, 'sys_info.flags' must be passed into the macros as 'f'), per battery 'b' #define MCUFLG_BATT_V(f,b) (((f) >> (8 + (b*4))) & 0x3) // Battery type #define MCUFLG_BATT_TYPE(f,b) (((f) >> (8 + 2 + (b*4))) & 0x3) #define MCUFLG_BATT_NiMH 0 // default: NiMH battery #define MCUFLG_BATT_FIXED 1 // option: fixed power supply (no level checking) #define MCUFLG_BATT_LiIon 2 // option: LiIon or LiPolymer battery #define MCUFLG_BATT_Alkaline 3 // option: alkaline battery (1.5V per cell instead of 1.2V) // (when MCUFLG_BATT_LiIon is _not_ set) #define MCUFLG_BATT_12V 0 // default: 12V battery #define MCUFLG_BATT_6V 1 // option: 6V battery #define MCUFLG_BATT_3V 2 // option: 3V battery #define MCUFLG_BATT_24V 3 // option: 24V battery // (when MCUFLG_BATT_LiIon is set - currently only MCUTYPE_ZKL3000_RC) // note that the names refer to 3.6V/cell LiIon batteries, but the algorithms // to detect if a battery is full or empty assume 3.2V/cell LiFePO4 batteries #define MCUFLG_BATT_7_2V 0 // default: 6.4V LiFePO4 battery #define MCUFLG_BATT_10_8V 1 // option: 9.6V LiFePO4 battery #define MCUFLG_BATT_14_4V 2 // option: 12.8V LiFePO4 battery #define MCUFLG_BATT_3_6V 3 // (not for ZKL, but other devices with a 3.6/3.7 V LiIon battery) // MCU flags, upper word (bits 16..31) #define MCUFLG_TD3000_AVAILABLE 0 // (placeholder for older source code) #define MCUFLGH_TD3000_AVAILABLE 0x0010 // device is equiped with a Train Detection module #define MCUFLGH_PCM3000_AVAILABLE 0x0020 // device is equiped with a Power Cycle module // Convert 16-bit flag to 32-bit flag register #define MCUFLG(flagh) (((unsigned long)flagh) << 16) // These items are programmable from an external application (MTinfo, RS-232, SD-card during AFT) #define MCUFLG_CONFIGURATION (MCUFLG_BATTERY_MASK|MCUFLG_PM3000_AVAILABLE|MCUFLG_SW3000_AVAILABLE|MCUFLG_DISABLE_CHARGER|MCUFLG_STATLED_ALWAYS) #define MCUFLGH_CONFIGURATION (MCUFLGH_PCM3000_AVAILABLE | MCUFLGH_TD3000_AVAILABLE) /* ** Motion status, encoded in the MSW (bits 31..16) of the MCU status ** (reserved for future use) */ #define MOTION_IDLE 0x00000000 // no motion detected #define MOTION_DETECT 0x00800000 // motion detected #define MOTION_START_STOP 0x00400000 // start (when combined with MOTION_DETECT) or stop // classification (6 bits) by motion footprint #define MOTION_CLASSIFY(c) (((c) << 16) | MOTION_DETECT) #define MOTION_UNCLASSIFIED 0 // unknown #define MOTION_TRANSPORT_FOOT 1 // transport by foot #define MOTION_TRANSPORT_CAR 2 // transport by car #define MOTION_DETECT_TRAIN 3 // train detected #define MOTION_DETECT_OTHER 4 // vehicle, other than a train, detected /* ** Wireless CPU status (used internally in the WCPU) */ #define WCPUERR_NONE 0x00000000 #define WCPUERR_INTERNAL 0x00000001 // WCPU internal datastructure failed to initialize #define WCPUERR_SECURE 0x00000001 // Security check not passed (programming of the device is locked) #define WCPUERR_GPRS 0x00000002 // GPRS or TCP failure #define WCPUERR_SMS 0x00000004 // SMS service couldn't be started #define WCPUERR_SIM 0x00000008 // SIM or SIM service failed #define WCPUERR_UART1 0x00000010 // UART1 failure (MCU->WCPU path) #define WCPUERR_UART2 0x00000020 // UART2 failure (WCPU<->GPS path) #define WCPUERR_I2C 0x00000040 // I2C error (WCPU->MCU path) #define WCPUERR_SPI 0x00000040 // SPI error #define WCPUERR_MCU 0x00000080 // MCU does not respond on I2C bus #define WCPUERR_BACKEND (WCPUERR_MCU) // Back-end (MCU, network behind a gateway) not responding #define WPCUERR_ANY 0x000000FF // Actived modules in the WCPU; will be sent in the response for AT+CVINIT #define GSMACTIVE_GSM 0x00000100 #define GSMACTIVE_SIM 0x00000200 #define GSMACTIVE_GPRS 0x00000400 #define GSMACTIVE_TCP 0x00000800 #define GSMACTIVE_GPS 0x00001000 #define GSMACTIVE_SMS 0x00002000 #define GSMACTIVE_SSL 0x00004000 #define GSMACTIVE_RTOS 0x00008000 // _never_ in wcpu_flags (feature only) // (this bit is used for WCPUSTAT_GPS_FIX) // Others #define WCPUERR_TEMP_ONBOARD 0x00100000 // on-board temperature over threshold #define WCPUERR_TEMP_EXT1 0x00200000 // temperature (external) sensor #1 over threshold #define WCPUERR_TEMP_EXT2 0x00400000 // temperature (external) sensor #2 over threshold #define WCPUERR_TEMP_SW3000 0x00800000 // Switch 3000 temperature over threshold #define WCPUERR_TILT 0x01000000 // tilt angle over threshold #define WCPUERR_RAIL_DETECT 0x02000000 // rail detect sensor (Hall sensor on CRT-M) #define WCPUSTAT_GPS_FIX 0x00008000 // GPS fix quality indicator set #define WCPUSTAT_IN_SERVICE 0x00010000 // device is in service #define WCPUSTAT_GPS_TIME 0x00040000 // GPS time received #define WCPUSTAT_GEOFENCE_INSIDE 0x00080000 // inside the geofence // Log replay state (for debugging purposes) #define WCPULOG_STALLED 0x00020000 // stalled because data cannot be sent immediately #define WCPULOG_REQ(req_state) ((u32)(req_state) << (16 + 8)) #define WCPULOG(full_state) ((full_state) >> (16+8)) #define WCPULOG_REQ_NEW 0x01 // pending request for new file, no reply #define WCPULOG_REQ_CONT 0x02 // pending request, same file, not yet replied #define WCPULOG_REQ_ABORT 0x03 // log reply is aborted #define WCPULOG_REQ_RETRY 0x04 // retrying current read after possible corruption #define WCPULOG_REQ_ERROR 0x08 // error detected #define WCPULOG_REQ_ACK 0x10 // request was acknowledge, orred with REQ_NEW or REQ_CONT #define WCPULOG_REQ_READING 0x20 // reading data from MCU, orred with REQ_NEW or REQ_CONT #define WCPULOG_REQ_PROCESSING 0x30 // processing log data #define WCPULOG_REQ_NEXT 0x40 // requesting next file from TCP-server #define WCPULOG_REQ_LISTING 0x80 // sending directory listing to TCP-server #define WCPULOG_REQ_DONE 0xF0 // current log file completed #define WCPULOG_REQ_IDLE 0x00 // log replay not yet started #define WCPULOG_REQ_MASK 0xF0 // mask for current state #define WCPULOG_REQ_FLAGS 0x0C // mask for the retry and error flags #define WCPULOG_REQ_STATEMASK 0x03 // mask for request state /* ** MCU firmware device type (i.e. for which type of device is the firmware intended) */ #define MCUTYPE_ZKL3000 0x0000 // ZKL 3000 #define MCUTYPE_GATEWAY3000 0x0001 // Gateway 3000 #define MCUTYPE_IMPULSE3000 0x0002 // Impulse 3000 #define MCUTYPE_TRT3000 0x0003 // Track&Trace 3000 #define MCUTYPE_ZKL3000_RC 0x0004 // ZKL 3000 with Switch 3000 #define MCUTYPE_REMOTE_SWITCH 0x0005 // Remote Switch 3000 (deprecated in favour of a Windows Mobile application) #define MCUTYPE_PG3000 0x0006 // Presence Guard 3000 #define MCUTYPE_AFTCTRL 0x0100 // AFT (version 1) controller #define MCUTYPE_AFT2CTRL 0x0101 // AFT2 controller #define MCUTYPE_AFT3CTRL 0x0102 // AFT3 controller #define MCUTYPE_SW3000_DRIVE 0x0180 // Switch3000, "drive" firmware #define MCUTYPE_SW3000_MEASURE 0x0181 // Switch3000, "measure" firmware #define MCUTYPE_GATEWAY 0x0190 // generic gateway #define MCUTYPE_XBEE_GATEWAY 0x0191 // CRT-M 3000 (only, currently), gateway (doesn't actually have an MCU) #define MCUTYPE_RS3000_WINMOBILE 0x0200 // Remote Switch 3000, Windows Mobile application #define MCUTYPE_TRT3000_WINMOBILE 0x0201 // Track&Trace 3000, Windows Mobile application #define MCUTYPE_MTT3000_WINMOBILE 0x0202 // Mobile Track&Trace 3000, Windows Mobile application #define MCUTYPE_RS3000_JAVA 0x0300 // Remote Switch 3000, Java application #define MCUTYPE_TRT3000_JAVA 0x0301 // Track&Trace 3000, Java application #define MCUTYPE_MTT3000_JAVA 0x0302 // Mobile Track&Trace 3000, Java application #define MCUTYPE_XBEE_DEVICE 0x0700 // (place holder; start ID for XBee devices) #define MCUTYPE_CRTM3000_SENSOR 0x0701 // CRT-M 3000 sensor #define MCUTYPE_SLIM_SENSOR 0x0702 // SLIM rail monitoring vibration sensor #define MCUTYPE_MARKER_LIGHT 0x0703 // Marker Light #define MCUTYPE_SPECIAL 0x8000 // specials, one-offies etc // "TRT" for installation on a generator; e-mail 20100927 #define MCUTYPE_SPECIAL_TRT_GENERATOR (MCUTYPE_SPECIAL | MCUTYPE_TRT3000) #define MCUTYPE_ZKL_BASED(t) (((t) & 0x7F00) == 0x0000) #define MCUTYPE_WINMOBILE(t) (((t) & 0x7F00) == 0x0200) #define MCUTYPE_JAVA(t) (((t) & 0x7F00) == 0x0300) #define MCUTYPE_ANDROID(t) (((t) & 0x7F00) == 0x0400) #define MCUTYPE_APPLE(t) (((t) & 0x7F00) == 0x0500) #define MCUTYPE_APP(t) (MCUTYPE_WINMOBILE(t) || MCUTYPE_JAVA(t) || MCUTYPE_ANDROID(t) || MCUTYPE_APPLE(t)) #define MCYTYPE_XBEE(t) (((t) & 0x7F00) == 0x0700) // Third party devices have an MCU type in the range 0x1000 to 0x7FFF in the database // table 'device' #define MCUTYPE_OTHER(t) (((t) & 0x7000) != 0x0000) #define MCUTYPE_UNKNOWN 0xFFFF // placeholder for unknown device type // device flags, at MCUAD_VERSION / MCURDPOS_VERSION_FLAGS #define MCUVERFLG_TEST_MODE 0x01 // configure for automatic testing #define MCUVERFLG_SPECIAL 0x80 // special firmware /* ** WCPU firmware device types (8-bit, used in the LSB of the feature) */ #define WCPUTYPE_ZKL 0x00 // WCPU firmware for ZKL, ZKL-RC, TRT, DU, etc #define WCPUTYPE_GATEWAY 0x01 // WCPU firmware for generic gateway device #define WCPUTYPE_XBEEGW 0x02 // WCPU firmware for XBee Gateway #define WCPUTYPE_SPECIAL 0x80 // specials, one-offies etc #define WCPUTYPE_GEOMANAGER 0x81 // Special WCPU firmware for the TNO Geo Manager #define WCPUTYPE_DEFAULT (WCPUTYPE_ZKL) /* ** WCPU features (compilation flags) */ #define WCPUFEATURE_GPRS 0x0000 // GSM and GPRS; default feature of the WCPU #define WCPUFEATURE_UMTS 0x0001 // UMTS #define WCPUFEATUREMASK_NETWORK 0x000F // mask for the above #define WCPUFEATURE_XBEE 0x0010 // gateway to XBee device for local connections #define WCPUFEATURE_WIFI 0x0020 // gateway to WiFi device for local connections #define WCPUFEATUREMASK_GATEWAY 0x00F0 // gateway to other devices #define WCPUFEATURE_MCU 0x0100 // MCU connected via I²C #define WCPUFEATURE_DETECTION 0x0200 // Device measures the rail short circuit #define WCPUFEATURE_GPS 0x1000 // GPS receiver via WCPU (built in or external) #define WCPUFEATURE_GPS_INT 0x0000 // internal GPS receiver (place holder) #define WCPUFEATURE_GPS_EXT 0x2000 // GPS receiver connected to UART #2 /* ** Notification (from Wavecom to MCU) ** 1 byte: the notification code below ** 1 byte: length of the parameters ** n bytes: parameters (max 254 bytes) */ #define MCUNOT_NOERROR 0x00 // (obsolete; isn't used anywhere) #define MCUNOT_GENERIC_STRING 0x00 // log a generic string #define MCUNOT_GSM_DETAILS 0x01 // GSM details (network registration, operator, etc) #define MCUNOT_SMS_SENT 0x02 // message succesfully sent #define MCUNOT_SMS_ERROR 0x03 // send error #define MCUNOT_SMS_RECV 0x04 // message received #define MCUNOT_SMS_TEXT 0x05 // text of an sms #define MCUNOT_GPRS_OK 0x06 // GPRS connected; own IP-address, gateway and 2x DNS #define MCUNOT_GPRS_ERROR 0x07 // GPRS error code (int from openat-errno.h) #define MCUNOT_TCP_ERROR 0x08 // TCP success or error #define MCUNOT_TCP_CMD 0x09 // TCP command (received by WCPU) #define MCUNOT_TCP_REPLY 0x0A // TCP reply (sent by WCPU) #define MCUNOT_TCP_SVRCMD 0x0B // TCP command (sent by WCPU to server) #define MCUNOT_TCP_SVRREPLY 0x0C // TCP reply (received by WCPU from server) #define MCUNOT_WAVECOM_BACKTRACE 0x0E // Wavecom error backtrace; consecutive entries // must be concatenated #define MCUNOT_GSM_OPERATOR 0x10 // operator (string) #define MCUNOT_GSM_LAC_CELLID 0x11 // location area code (16-bit) and cell ID (16-bit) #define MCUNOT_TCP_DETAILS 0x12 // host:port (string) #define MCUNOT_LOGREPLAY_ERROR 0x13 // log replay error or warning, error (16-bit signed), // rpgm, startup (16-bit), filepos (32-bit) #define MCUNOT_GPS_ERROR 0x14 // GPS error code (int from i2c-errno.h) /* ** GSM notification (from Wavecom to MCU) */ #define GSMNOT_SIM_REMOVED 0x00 // SIM removed #define GSMNOT_SIM_READY 0x01 // SIM initialized #define GSMNOT_RESET 0x08 // reset requested #define GSMNOT_NOT_REGISTERED 0x10 // not registered to the GSM network #define GSMNOT_REGISTERED_HOME 0x11 // registered to the home GSM network #define GSMNOT_REGISTERED_ROAMING 0x12 // registered to a foreign GSM network #define GSMNOT_SEARCHING 0x13 // searching for a GSM network #define GSMNOT_REFUSED 0x14 // registration refused #define GSMNOT_REREGISTER 0x15 // re-registration forced by WCPU #define GSMNOT_DEREGISTER 0x16 // deregistration forced by WCPU #define GSMNOT_NOT_CONNECTED 0x20 // not connected to the TCP server #define GSMNOT_CONNECTED 0x21 // connected to the TCP server #define GSMNOT_GPRS_STOPPED 0x22 // GPRS subsystem stopped #define GSMNOT_TCP_WATCHDOG 0x23 // TCP connection watchdog reset #define GSMNOT_SECURE_ERROR 0x24 // TCP security error #define GSMNOT_SECURE_WARNING 0x25 // TCP security warning #define GSMNOT_SECURE_NEW_KEY 0x26 // TCP security key exchange succesful #define GSMNOT_PWRUP_POWER_ON 0x30 // GSM power up: power on #define GSMNOT_PWRUP_EXCEPTION 0x31 // GSM power up: exception #define GSMNOT_PWRUP_DOWNLOAD_OK 0x32 // GSM power up: download (ok) #define GSMNOT_PWRUP_DOWNLOAD_ERROR 0x33 // GSM power up: download (error) #define GSMNOT_PWRUP_RTC_ALARM 0x34 // GSM power up: RTC alarm #define GSMNOT_PWRUP_OTHER 0x35 // GSM power up: undocumented value (qdf?) #define GSMNOT_WATCHDOG_TIMEOUT 0x36 // GSM software watchdog times out (WCPU is reset) #define GSMNOT_TIMEOUT 0x37 // GSM not responding after power up #define GSMNOT_PWROFF 0x38 // GSM powering off /* ** SMS types */ #define MSG_DEVICE_ON 0 #define MSG_DEVICE_OFF 1 #define MSG_BATTERY_LOW 2 #define MSG_RELAY_OPEN 3 #define MSG_SHORT_FAIL 4 #define MSG_SEND_STATUS 5 // note: never sent by the MCU #define MSG_SYSTEM_UP 6 // note: not used #define MSG_SYSTEM_DOWN 7 // note: not used #define MSG_MEASURE_FAIL 8 // measurement values out of bounds #define MSG_DISK_FULL 9 // black box logging out of capacity #define MSG_DISK_ERROR 10 // black box logging generated an error #define MSG_SEND_SERVER_STATUS 11 // note: never sent by the MCU #define MSG_WCPU_FAIL 12 // generic failure of the WCPU #define MSG_MCU_FAIL 13 // generic failure of the MCU #define MSG_GPS_FAIL 14 // no GPS co-ordinates received with the specified time-out (5 min) #define MSG_TEMP_FAIL 15 // temperature above threshold #define MSG_GEOFENCE_ENTER 16 // entering a geofence #define MSG_GEOFENCE_EXIT 17 // exiting a geofence #define MSG_DETECT_TRAIN 18 // train detected by a DU 3000 device #define MSG_SECURITY 19 // security warning or error #define MSG_TEMP_FAIL_ABOVE 20 // temperature above threshold (replaces MSG_TEMP_FAIL) #define MSG_TEMP_FAIL_BELOW 21 // temperature below threshold (replaces MSG_TEMP_FAIL) #define MSG_ALERT 22 // gneric alert; 'state' contains msg identifier /* ** GPRS actions */ #define GPRSREQ_RESTART 0 // restart GPRS (and TCP) #define GPRSREQ_SHUTDOWN 1 // shutdown GPRS (and TCP) #define GPRSREQ_POWERCYCLE 2 // power-cycle (via external hardware) /* ** Switch 3000 and Remote Control 3000 commands in general */ #define SWCMDLEN 2 // bits sent over 1-Wire, excluding parity bit #define SWCMD_STATUS 0 // status request #define SWCMD_SW3000_OFF 1 // Switch 3000: break circuit #define SWCMD_SW3000_ON 2 // Switch 3000: close circuit #define SWCMD_MEASUREMENT_OFF 3 // detection turned off #define SWCMD_MEASUREMENT_ON 4 // detection turned on #define SWCMD_DISABLE_SWITCH 5 // disable commands 1..4 #define SWCMD_ENABLE_SWITCH 6 // enable commands 1..4 #define SWCMD_GET_VERSION 7 // get firmware version / command `11' to the Switch itself! // version is read at start-up; sending the command via // CP3000 behaves like SWCMD_STATUS #define SWCMD_SW3000_POWER_OFF 11 // (re)enable power management for the Switch 3000 (normal operation) #define SWCMD_SW3000_POWER_ON 12 // disable power management for the Switch 3000 (power always on) #define SWCMD_CHARGE_OFF 13 // disable battery charger #define SWCMD_CHARGE_ON 14 // enable battery charger #define SWCMD_CHARGE_MANUAL 15 // enable manual control of the battery charger // for sending the command from server to ZKL #define SWITCH_COMMAND(cmd) ((cmd) | ((~(cmd) & 0xF) << 4)) /* ** Switch 3000 status and version lengths */ #define SWSTATLEN 17 // bits, excluding parity bit #define SWVERSIONLEN 44 // bits, excluding parity bit /* ** Power Cycle Module */ #define PWRCYCAD_NORMAL_RESET_CNT 0xD2 // normal reset counter (read; 2 bytes payload) #define PWRCYCAD_ABNORMAL_RESET_CNT 0x55 // abnormal reset counter (read; 2 bytes payload) #define PWRCYCAD_ZKL_POWERCYC_CNT 0x87 // ZKL power cycle counter (read; 2 bytes payload) #define PWRCYCAD_WATCHDOG_TIMEOUT 0x99 // time-out value register (read/write; 2 bytes payload) #define PWRCYCAD_ONLINE_TIMEOUT 0x4B // time-out value for the heartbeats from the TCP server (") #define PWRCYCAD_HEARTBEAT 0xAA // heartbeat register (write) #define PWRCYCAD_CONNECTION 0x2D // heartbeat register (write) #define PWRCYCAD_FORCE_POWERCYC 0xE1 // reset and power cycle the system (write) /* ** MCU log file internal state */ // MCU log file state (MCURD_ES_LOGFILE_STATE) #define LFS_WROPEN 0x0001 // log file is open for writing #define LFS_RDOPEN 0x0002 // log file is open for reading #define LFS_HIBERNATE 0x0004 // uALFAT is hibernating #define LFS_uALFAT_OK 0x0008 // uALFAT is accessible and SD-card present #define LFS_HAS_DATA 0x0010 // data written to uALFAT; flush needed #define LFS_READREQ 0x0020 // read request posted by WCPU #define LFS_READNEW 0x0040 // read request posted for new log file (close old one) #define LFS_BUSY 0x0080 // command to the uALFAT; waiting for reply #define LFS_SDCARD_ERROR 0x0800 // SD-card cannot be mounted // asynchronous commands (MCURD_ES_LOGFILE_STATE) #define LFS_ASYNC_BUSY 0x0100 // any of the asynchronous commands below is busy #define LFS_DIR_BUSY 0x0200 // directory listing is busy #define LFS_OPEN_BUSY 0x0400 // opening logfile for reading // other commands (MCURD_ES_LOGFILE_STATE) #define LFS_ASYNC_INT 0x1000 // timer expired (not necessarily a time-out) #define LFS_RDCLOSE 0x2000 // close the read handle to abort the replay #define LFS_DIRINIT 0x4000 // start reading the directory listing #define LFS_DIR 0x8000 // read the next directory entry // asynchronous commands (MCURD_ES_LOGFILE_ASYNC) #define LFS_IDLE 0 #define LFS_FLUSH 1 // asynchronous flush is busy #define LFS_SEEK 2 // asynchronous seek is busy #define LFS_RDCMD 3 // asynchronous read (command phase) is busy #define LFS_RDDATA 4 // asynchronous read (data phase) is busy #define LFS_RDOPENFILE 5 // asynchrounous file open #define LFS_INIT_WELCOME 6 // initialization: wait for welcome message #define LFS_INIT_MOUNT 7 // mount SD-card #define LFS_INIT_WROPEN 8 // open the log file for writing // MCU log replay state (MCURD_ES_LOGREPLAY_STATE) #define LFS_STALLED 0x01 // MCU read back is waiting for new data #define LFS_READY 0x02 // MCU read buffer is ready to be transferred to WCPU #define LFS_ABORTED 0x04 // Log replay is aborted /* ** WCPU status updates (for the real-time status in MTinfo) */ // flags for changed items, and also the enable flags for the key SYSTEM[STATUPDATE] #define STATUPDATE_STATE 0x0001 // system state #define STATUPDATE_WCPU_STATE 0x0002 // modem state (or communication device in general) #define STATUPDATE_PMGT 0x0004 // power management #define STATUPDATE_SWITCH 0x0008 // switch state #define STATUPDATE_RMS 0x0010 // measurement, RMS^2 #define STATUPDATE_B_A 0x0020 // measurement, b/a #define STATUPDATE_NATWS 0x0040 // measurement, detection counter and direction #define STATUPDATE_AUTOCAL 0x0080 // measurement, calibrated b/a and frequency #define STATUPDATE_BATTSEL 0x0800 // battery selection #define STATUPDATE_BATT1LVL 0x0100 // battery #1 level (V) #define STATUPDATE_BATT2LVL 0x0200 // battery #2 level (V) #define STATUPDATE_INTTEMP 0x1000 // internal temperature sensor (ºC; on-board sensor on ZKL3000) #define STATUPDATE_EXTTEMP 0x2000 // external temperature sensor(s) (ºC; external NTC on ZKL3000) #define STATUPDATE_GPS 0x4000 // GPS co-ordinates and additional info #define STATUPDATE_GSM 0x8000 // GSM RSSI and BER #define STATUPDATE_NEW 0 // (flag for internal use) #define STATUPDATE_ON_CHANGE 0 // (flag for internal use) #define STATUPDATE_NONE 0 // definition for SYSTEM[STATUPDATE] #define STATUPDATE_ANY 0x7FFFFFFF // flag for internal use and SYSTEM[STATUPDATE] #define STATUPDATE_DEFAULT 0x0001FBB3 // flag for internal use: items in ZKL3000 status string // (PGMT, SWITCH and NATWS are combined with other itmes) #define STATUPDATE_MCUFLAGS 0x00003BFD // status items that originate from the MCU #define STATUPDATE_MEASUREMENT 0x000000F0 // flags relating to the measurements/detection // extended flags #define STATUPDATE_TIME 0x00010000 // time field present #define STATUPDATE_TIMESRC 0x00020000 // ime source present in time field (internal use) #define STATUPDATE_SW3000TEMP 0x00100000 // temperature sensor of the Switch 3000 #define STATUPDATE_TILT 0x00200000 // tilt sensor #define STATUPDATE_VIBR 0x00400000 // vibration sensor #define STATUPDATE_GATEWAY 0x40000000 // network behind the gateway changed (nodes added or removed) #define STATUPDATE_CHANGE_ALWAYS 0x70000000 // mask for flags that always cause a "change" #define STATUPDATE_NONMASKABLE 0x80000000 // always send updates (flag for internal use) #define STATUPDATE_SEND 0x80000000 // always send updates (flag for internal use) #define STATUPDATE_ORDERED 0x80000000 // internal use: fields are in correct bit order /* ** AT commands */ #define ATCMD_INIT "+CVINIT" // sync init with mcu (no parameters) #define ATCMD_REG "+CVREG" // register with the GSM network (no parameters) #define ATCMD_STATUS "+CVSTAT" // request status (no parameters) #define ATCMD_SENDSMS "+CVSEND" // send an sms (msg_id, mcu_state, mcu_local_state) #define ATCMD_FLASHSTORE "+CVSTOR" // program a value (key, value) #define ATCMD_FLASHRETRIEVE "+CVRETR" // retrieve a value (key) #define ATCMD_ALARM "+CVALRM" // obsolete; not implemented (timestamp, major and minor id) #define ATCMD_LOGDATA "+CVLOG" // log sync (nr_bytes in data buffer _or_ checkpoint when byte count < 0) #define ATCMD_LOGFILE "+CVDIR" // directory listing ("filename attributes file_size") #define ATCMD_STATUS_UPDATE "+CVUPD" // internal state changed; send a status update to the host #define ATCMD_TCP "+CVTCP" // GPRS/TCP action required (currently only request to restart) #endif // _ZKL_COMMON_H