/* ************************************************************************ ** ** Copyright (c) 2013..2014 by ** Core|Vision B.V. ** Cereslaan 10b ** 5384 VT Heesch ** The Netherlands ** ** All Rights Reserved ** ************************************************************************ */ /* ************************************************************************ ** ** Project name: Dual Inventive: XBee Gateway ** Module 1 ** Filename: zkl-common.h ** Author: Jack Weeland ** Date: July 23, 2013 ** File version: $Revision: 1.14 $ ** $Date: 2015/05/12 14:39:46 $ ** ************************************************************************ */ /* ************************************************************************ ** ** Common definitions for XBee based devices ** ** Must be included _after_ "zkl-common.h" ** ************************************************************************ */ #ifndef _XBEE_COMMON_H #define _XBEE_COMMON_H /* ** Digi XBee data items */ // Digi XBee API mode frame types #define XBEEFT_AT_COMMAND 0x08 #define XBEEFT_AT_COMMAND_QUEUE_PARAMETER_VALUE 0x09 #define XBEEFT_TRANSMIT_REQUEST 0x10 #define XBEEFT_EXPLICIT_ADDRESSING_COMMAND_FRAME 0x11 #define XBEEFT_REMOTE_AT_COMMAND_REQUEST 0x17 #define XBEEFT_AT_COMMAND_RESPONSE 0x88 #define XBEEFT_MODEM_STATUS 0x8A #define XBEEFT_TRANSMIT_STATUS 0x8B #define XBEEFT_ROUTE_INFORMATION_PACKET 0x8D #define XBEEFT_AGGREGATE_ADDRESSING_UPDATE 0x8E #define XBEEFT_RECEIVE_PACKET 0x90 #define XBEEFT_EXPLICIT_RX_INDICATOR 0x91 #define XBEEFT_NODE_IDENTIFICATION_INDICATOR 0x95 #define XBEEFT_REMOTE_COMMAND_RESPONSE 0x97 // mask and response classes #define XBEEFT_MASK 0xF0 #define XBEEFT_LOCAL_REQUEST 0x00 #define XBEEFT_REMOTE_REQUEST 0x10 #define XBEEFT_LOCAL_RESPONSE 0x80 #define XBEEFT_REMOTE_RESPONSE 0x90 // Endpoints #define XBEE_ENDPOINT_LINK_TEST 0xE6 #define XBEE_ENDPOINT_DIGI_DATA 0xE8 // Cluster IDs #define XBEE_CLUSTERID_TRANSPARENT_DATA 0x0011 #define XBEE_CLUSTERID_LINK_TEST 0x0012 #define XBEE_CLUSTERID_LINK_QUALITY_TEST 0x0014 // Addresses #define XBEEAD_BROADCAST 0x000000000000FFFFull #define XBEEAD_INVALID_ADDRESS 0x000000000000FFFEull // Options for AT command frames #define XBEEOPT_NONE 0x00 #define XBEEOPT_APPLY_CHANGES 0x02 // AT command status #define XBEESTAT_OK 0x00 #define XBEESTAT_ERROR 0x01 #define XBEESTAT_INVALID_COMMAND 0x02 #define XBEESTAT_INVALID_PARAMETER 0x03 #define XBEESTAT_INVALID_RESPONSE 0x04 // Data frame start delimiter #define XBEE_FRAME_START 0x7E /* ** Custom (our) frame types in the RF data */ #define XBEEFT_IDENTIFY 0x00 // identify device #define XBEEFT_RESET_FLAGS 0x10 // reset flags (payload consists of the frame type followed // by device specific bits to clear; a '1' clears // the corresponding flag; the number of bytes is // determined by the frame size) #define XBEEFT_CALIBRATE 0x12 // (re)calibrate the device #define XBEEFT_SENSOR_CRTM 0x18 // CRT-M 3000 status update (XBLEN + CRTMLEN bytes) #define XBEEFT_REQUEST_CRTM 0x19 // Request (pull) CRT-M 3000 status update (no payload) #define XBEEFT_SET_TIMING 0x1A // Set marker light timing (period, duty cycle, timeout) #define XBEEFT_RESET_CONFIG 0x70 // clears the configuration, which puts the device // in "factory new" state (no payload; only the frame type) #define XBEEFT_SLEEP 0x71 // network is going into a (deep) sleep #define XBEEFT_ANNOUNCE 0x72 // announce frame for an XBee child device (payload is // XBLEN bytes containing the device's firmware version) #define XBEEFT_IN_SLEEP (XBEEFT_SLEEP + XBEEFT_REMOTE_RESPONSE) /* ** Data packet fields (originating from gateway) */ // Marker Light timing data packet #define MLTIMINGLEN 7 #define MLTIMINGPOS_FRAME_TYPE 0 // XBEEFT_SET_TIMING #define MLTIMINGPOS_FLAGS 1 // MLFLG_xxx #define MLTIMINGPOS_PERIOD 2 // period; currently _not_ used (period is defined by sleep/wake cycle) #define MLTIMINGPOS_DUTY 4 // duty period; time that the lights are "on" #define MLTIMINGPOS_TIMEOUT 6 // time-out; lights do not blink after this time-out // definitions for the flags #define MLFLG_AUTONOMOUS 0x01 // do not sync on ON_SLEEPn #define MLFLG_DISABLE 0x80 // disable the marker lights // macros to access the fields #define IS_MLTIMING_FRAME(s) (((s)[MLTIMINGPOS_FRAME_TYPE]) == XBEEFT_SET_TIMING) #define MLTIMING_FLAGS(s) ((s)[MLTIMINGPOS_FLAGS) #define MLTIMING_PERIOD(s) BEWORD2UINT(s,MLTIMINGPOS_PERIOD) #define MLTIMING_DUTY(s) BEWORD2UINT(s,MLTIMINGPOS_DUTY) #define MLTIMING_TIMEOUT(s) BEWORD2UINT(s,MLTIMINGPOS_TIMEOUT) /* ** Data packet fields (within a XBEEFT_RECEIVE_PACKET frame, originating from sensor) */ // XBee data packet definitions; generic 10-byte header #define XBLEN 10 #define XBPOS_FRAME_TYPE 0 // custom frame type; see above #define XBPOS_FLAGS 1 // flags (t.b.d.) #define XBPOS_VER_MAJOR 2 // major version #define XBPOS_VER_MINOR 3 // minor version #define XBPOS_VER_DATECODE 4 // 4-byte hex datecode #define XBPOS_VER_DEVTYPE 8 // 2-byte firmware type (MCUTYPE_xxx) #define XBPOS_LAST (XBLEN) // start of device specific data // definitions for the flags #define XBFLG_NOT_SENSOR 0x01 // device is not a sensor, i.e. won't reply to XBEEFT_REQUEST_CRTM // macros to extract the version info from a byte array #define XBEE_FRAME_TYPE(s) ((s)[XBPOS_FRAME_TYPE]) #define XBEE_FLAGS(s) ((s)[XBPOS_FLAGS); #define XBEE_VER_MAJOR(s) (int)((s)[XBPOS_VER_MAJOR]) #define XBEE_VER_MINOR(s) (int)((s)[XBPOS_VER_MAJOR]) #define XBEE_VER_DATECODE(s) BEWORD2ULONG(s,XBPOS_VER_DATECODE) #define XBEE_VER_DEVTYPE(s) BEWORD2UINT(s,XBPOS_VER_DEVTYPE) // CRT-M 3000 data packet definitions, following the header #define CRTMLEN ((XBLEN) + 14) #define CRTMPOS_BATT ((XBPOS_LAST) + 0) // battery; ADC read-out #define CRTMPOS_T1 ((XBPOS_LAST) + 2) // temperature sensor #1, ADC read-out #define CRTMPOS_T2 ((XBPOS_LAST) + 4) // temperature sensor #2, ADC read-out #define CRTMPOS_TILTX ((XBPOS_LAST) + 6) // tilt sensor, X co-ordinate; ADC read-out #define CRTMPOS_TILTY ((XBPOS_LAST) + 8) // tilt sensor, Y co-ordinate; ADC read-out #define CRTMPOS_TILTZ ((XBPOS_LAST) + 10) // tilt sensor, Z co-ordinate; ADC read-out #define CRTMPOS_FLAGS ((XBPOS_LAST) + 12) // 2-byte device flags #define CRTMFLG_RAILSENSOR_ALERT 0x0001 // device was removed from the rail #define CRTMFLG_RAILSENSOR_ACTIVE 0x0002 // device was installed on the rail #define CRTMFLG_SPI_OVERRUN 0x0010 // overrun of the internal data buffer #define CRTMFLG_SPI_DATA_ERROR 0x0020 // checksum error, out of sync, etc #define CRTMFLG_IS_CALIBRATED 0x0040 // temperature sensors are calibrated #define CRTMFLG_IS_CONFIGURED 0x0080 // device is configured #define CRTMFLG_RAILSENSOR 0x0100 // current detection status #define CRTMFLG_VIBRATION_START 0x1000 // start of a new detection #define CRTMFLG_VIBRATION_END 0x2000 // last entry for a vibration detection #define CRTMMSK_SWRESET 0x0033 // (software resetable flags) // macros to extract the version info from a byte array #define IS_CRTM_FRAME(x) (((s)[XBPOS_FRAME_TYPE]) == XBEEFT_SENSOR_CRTM) #define CRTM_VER_MAJOR(s) (int)((s)[XBPOS_VER_MAJOR]) #define CRTM_VER_MINOR(s) (int)((s)[XBPOS_VER_MINOR]) #define CRTM_VER_DATECODE(s) BEWORD2ULONG(s,XBPOS_VER_DATECODE) #define CRTM_VER_DEVTYPE(s) BEWORD2UINT(s,XBPOS_VER_DEVTYPE) #define CRTM_BATT(s) BEWORD2UINT(s,CRTMPOS_BATT) #define CRTM_T1(s) BEWORD2UINT(s,CRTMPOS_T1) #define CRTM_T2(s) BEWORD2UINT(s,CRTMPOS_T2) #define CRTM_TILTX(s) BEWORD2UINT(s,CRTMPOS_TILTX) #define CRTM_TILTY(s) BEWORD2UINT(s,CRTMPOS_TILTY) #define CRTM_TILTZ(s) BEWORD2UINT(s,CRTMPOS_TILTZ) #define CRTM_FLAGS(s) BEWORD2UINT(s,CRTMPOS_FLAGS) /* ** Status flags as reported by the gateway */ // Internal status #define XBEEFL_SLEEP_ENABLED 0x00000001 // device is sleep co-ordinator (root only), so // network sleep mode is active #define XBEEFL_NETWORK_IN_SLEEP 0x00000002 // network is sleeping #define XBEEFL_IS_CHILD_DEVICE 0x00000004 // this device is a child device with CRTM or similar firmware #define XBEEFL_IS_ROOT_DEVICE 0x00000008 // this device is the root device #define XBEEFL_SCAN_NETWORK 0x00000010 // scan/discover network (transient gateway flag) #define XBEEFL_REBUILD_ROUTING 0x00000020 // rebuild routing table (transient gateway flag) #define XBEEFL_NETWORK_TIMING 0x00000040 // network timing changed (transient gateway flag) #define XBEEFL_FAST_TIMING 0x00000080 // apply special fast timing parameters #define XBEEFL_ADD_DEVICE 0x00000100 // newly added node must be configured #define XBEEFL_DELETE_DEVICE 0x00000200 // node is to be deleted #define XBEEFL_ADD_AUTO 0x00000400 // node was added automatically (TCP-server must add it to the database) #define XBEEFL_ADD_FAILED 0x00000800 // adding a new node failed; must retry #define XBEEFL_UPDATE_IDCODE 0x00001000 // update pending for the ID-code in the device #define XBEEFL_REINIT_DEVICE 0x00002000 // re-initialize the device (i.e. clear sticky flags) #define XBEEFL_RECALIBRATE 0x00004000 // re-calibrate the device #define XBEEFL_IN_SYNC 0x00010000 // device is in sync #define XBEEFL_IS_SLEEP_COORDINATOR \ 0x00020000 // device is the sleep co-ordinator #define XBEEFL_NODE_IDENTIFIED 0x00040000 // device sent "node identification" frame (mostly // for debugging #define XBEEFL_HAS_DATA 0x00080000 // device sent data #define XBEEFL_NETWORK_SYNCS 0x08000000 // network is synchronized (but not necessarily in sync) // Special flags; shouldn't be set for an actual device #define XBEEFL_SPECIAL 0xF0000000 // (mask) #define XBEEFL_FIND_BY_FLAGS 0x80000000 // find by flag(s); orred with the flags to match #endif /* _XBEE_COMMON_H */