Skip to content

Commit 4abe6a1

Browse files
Add ZBExplicitTxRequest
This allows sending "Explicit Addressing ZigBee Command" API frames, that allow specifying the endpoints, profile id and cluster id for a transmitted message, e.g. to interact through standard Zigbee protocols.
1 parent 5fccf2e commit 4abe6a1

File tree

2 files changed

+147
-1
lines changed

2 files changed

+147
-1
lines changed

XBee.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,93 @@ void ZBTxRequest::setOption(uint8_t option) {
11391139
_option = option;
11401140
}
11411141

1142+
1143+
1144+
ZBExplicitTxRequest::ZBExplicitTxRequest() : ZBTxRequest() {
1145+
_srcEndpoint = DEFAULT_ENDPOINT;
1146+
_dstEndpoint = DEFAULT_ENDPOINT;
1147+
_profileId = DEFAULT_PROFILE_ID;
1148+
_clusterId = DEFAULT_CLUSTER_ID;
1149+
setApiId(ZB_EXPLICIT_TX_REQUEST);
1150+
}
1151+
1152+
ZBExplicitTxRequest::ZBExplicitTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId, uint8_t srcEndpoint, uint8_t dstEndpoint, uint16_t clusterId, uint16_t profileId)
1153+
: ZBTxRequest(addr64, addr16, broadcastRadius, option, payload, payloadLength, frameId) {
1154+
_srcEndpoint = srcEndpoint;
1155+
_dstEndpoint = dstEndpoint;
1156+
_profileId = profileId;
1157+
_clusterId = clusterId;
1158+
setApiId(ZB_EXPLICIT_TX_REQUEST);
1159+
}
1160+
1161+
ZBExplicitTxRequest::ZBExplicitTxRequest(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength)
1162+
: ZBTxRequest(addr64, payload, payloadLength) {
1163+
_srcEndpoint = DEFAULT_ENDPOINT;
1164+
_dstEndpoint = DEFAULT_ENDPOINT;
1165+
_profileId = DEFAULT_PROFILE_ID;
1166+
_clusterId = DEFAULT_CLUSTER_ID;
1167+
setApiId(ZB_EXPLICIT_TX_REQUEST);
1168+
}
1169+
1170+
uint8_t ZBExplicitTxRequest::getFrameData(uint8_t pos) {
1171+
if (pos < 10) {
1172+
return ZBTxRequest::getFrameData(pos);
1173+
} else if (pos == 10) {
1174+
return _srcEndpoint;
1175+
} else if (pos == 11) {
1176+
return _dstEndpoint;
1177+
} else if (pos == 12) {
1178+
return (_clusterId >> 8) & 0xff;
1179+
} else if (pos == 13) {
1180+
return _clusterId & 0xff;
1181+
} else if (pos == 14) {
1182+
return (_profileId >> 8) & 0xff;
1183+
} else if (pos == 15) {
1184+
return _profileId & 0xff;
1185+
} else if (pos == 16) {
1186+
return _broadcastRadius;
1187+
} else if (pos == 17) {
1188+
return _option;
1189+
} else {
1190+
return getPayload()[pos - ZB_EXPLICIT_TX_API_LENGTH];
1191+
}
1192+
}
1193+
1194+
uint8_t ZBExplicitTxRequest::getFrameDataLength() {
1195+
return ZB_EXPLICIT_TX_API_LENGTH + getPayloadLength();
1196+
}
1197+
1198+
uint8_t ZBExplicitTxRequest::getSrcEndpoint() {
1199+
return _srcEndpoint;
1200+
}
1201+
1202+
uint8_t ZBExplicitTxRequest::getDstEndpoint() {
1203+
return _dstEndpoint;
1204+
}
1205+
1206+
uint16_t ZBExplicitTxRequest::getClusterId() {
1207+
return _clusterId;
1208+
}
1209+
1210+
uint16_t ZBExplicitTxRequest::getProfileId() {
1211+
return _profileId;
1212+
}
1213+
1214+
void ZBExplicitTxRequest::setSrcEndpoint(uint8_t endpoint) {
1215+
_srcEndpoint = endpoint;
1216+
}
1217+
1218+
void ZBExplicitTxRequest::setDstEndpoint(uint8_t endpoint) {
1219+
_dstEndpoint = endpoint;
1220+
}
1221+
1222+
void ZBExplicitTxRequest::setClusterId(uint16_t clusterId) {
1223+
_clusterId = clusterId;
1224+
}
1225+
1226+
void ZBExplicitTxRequest::setProfileId(uint16_t profileId) {
1227+
_profileId = profileId;
1228+
}
11421229
#endif
11431230

11441231
#ifdef SERIES_1

XBee.h

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
// the non-variable length of the frame data (not including frame id or api id or variable data size (e.g. payload, at command set value)
5454
#define ZB_TX_API_LENGTH 12
55+
#define ZB_EXPLICIT_TX_API_LENGTH 18
5556
#define TX_16_API_LENGTH 3
5657
#define TX_64_API_LENGTH 9
5758
#define AT_COMMAND_API_LENGTH 2
@@ -68,6 +69,12 @@
6869
#define DEFAULT_FRAME_ID 1
6970
#define NO_RESPONSE_FRAME_ID 0
7071

72+
// These are the parameters used by the XBee ZB modules when you do a
73+
// regular "ZB TX request".
74+
#define DEFAULT_ENDPOINT 232
75+
#define DEFAULT_CLUSTER_ID 0x0011
76+
#define DEFAULT_PROFILE_ID 0xc105
77+
7178
// TODO put in tx16 class
7279
#define ACK_OPTION 0
7380
#define DISABLE_ACK_OPTION 1
@@ -879,13 +886,65 @@ class ZBTxRequest : public PayloadRequest {
879886
// declare virtual functions
880887
uint8_t getFrameData(uint8_t pos);
881888
uint8_t getFrameDataLength();
882-
private:
883889
XBeeAddress64 _addr64;
884890
uint16_t _addr16;
885891
uint8_t _broadcastRadius;
886892
uint8_t _option;
887893
};
888894

895+
/**
896+
* Represents a Series 2 TX packet that corresponds to Api Id: ZB_EXPLICIT_TX_REQUEST
897+
*
898+
* See the warning about maximum packet size for ZBTxRequest above,
899+
* which probably also applies here as well.
900+
*
901+
* Note that to distinguish reply packets from non-XBee devices, set
902+
* AO=1 to enable reception of ZBExplicitRxResponse packets.
903+
*/
904+
class ZBExplicitTxRequest : public ZBTxRequest {
905+
public:
906+
/**
907+
* Creates a unicast ZBExplicitTxRequest with the ACK option and
908+
* DEFAULT_FRAME_ID.
909+
*
910+
* It uses the Maxstream profile (0xc105), both endpoints 232
911+
* and cluster 0x0011, resulting in the same packet as sent by a
912+
* normal ZBTxRequest.
913+
*/
914+
ZBExplicitTxRequest(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength);
915+
/**
916+
* Create a ZBExplicitTxRequest, specifying all fields.
917+
*/
918+
ZBExplicitTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId, uint8_t srcEndpoint, uint8_t dstEndpoint, uint16_t clusterId, uint16_t profileId);
919+
/**
920+
* Creates a default instance of this class. At a minimum you
921+
* must specify a payload, payload length and a destination
922+
* address before sending this request.
923+
*
924+
* Furthermore, it uses the Maxstream profile (0xc105), both
925+
* endpoints 232 and cluster 0x0011, resulting in the same
926+
* packet as sent by a normal ZBExplicitTxRequest.
927+
*/
928+
ZBExplicitTxRequest();
929+
uint8_t getSrcEndpoint();
930+
uint8_t getDstEndpoint();
931+
uint16_t getClusterId();
932+
uint16_t getProfileId();
933+
void setSrcEndpoint(uint8_t endpoint);
934+
void setDstEndpoint(uint8_t endpoint);
935+
void setClusterId(uint16_t clusterId);
936+
void setProfileId(uint16_t profileId);
937+
protected:
938+
// declare virtual functions
939+
uint8_t getFrameData(uint8_t pos);
940+
uint8_t getFrameDataLength();
941+
private:
942+
uint8_t _srcEndpoint;
943+
uint8_t _dstEndpoint;
944+
uint16_t _profileId;
945+
uint16_t _clusterId;
946+
};
947+
889948
#endif
890949

891950
/**

0 commit comments

Comments
 (0)