pub const SYS: u8 = 0x21; pub const MAC: u8 = 0x22; pub const NWK: u8 = 0x26; pub const AF: u8 = 0x24; pub const ZDO: u8 = 0x25; pub const SAPI: u8 = 0x2F; pub const UTIL: u8 = 0x27; pub const APP_CNF: u8 = 0x26; pub const APP: u8 = 0x29;
pub const SYS_RESET_REQ: u8 = 0x09; pub const SYS_RESET_IND: u8 = 0x80; pub const SYS_VERSION: u8 = 0x02; pub const SYS_PING: u8 = 0x01; pub const SYS_OSAL_NV_READ: u8 = 0x08; pub const SYS_OSAL_NV_WRITE: u8 = 0x09; pub const SYS_GET_EXTADDR: u8 = 0x04;
pub const ZDO_STARTUP_FROM_APP: u8 = 0x40; pub const ZDO_NODE_DESC_REQ: u8 = 0x02;
pub const ZDO_ACTIVE_EP_REQ: u8 = 0x05;
pub const ZDO_SIMPLE_DESC_REQ: u8 = 0x04;
pub const ZDO_END_DEVICE_ANNCE_IND: u8 = 0xFF; pub const ZDO_TC_DEV_IND: u8 = 0xCA; pub const ZDO_PERMIT_JOIN_REQ: u8 = 0x36;
pub const ZDO_PERMIT_JOIN_IND: u8 = 0xCB; pub const ZDO_NWK_ADDR_RSP: u8 = 0x80;
pub const ZDO_IEEE_ADDR_RSP: u8 = 0x81;
pub const ZDO_STATE_CHANGE_IND: u8 = 0xC0; pub const ZDO_LEAVE_IND: u8 = 0xC9;
pub const AF_REGISTER: u8 = 0x00; pub const AF_DATA_REQUEST: u8 = 0x01; pub const AF_DATA_CONFIRM: u8 = 0x05; pub const AF_INCOMING_MSG: u8 = 0x81; pub const AF_DATA_REQUEST_EXT: u8 = 0x02;
pub const APP_CNF_BDB_START_COMMISSIONING: u8 = 0x00; pub const APP_CNF_BDB_SET_CHANNEL: u8 = 0x08; pub const APP_CNF_BDB_COMMISSIONING_NOTIFICATION: u8 = 0x80;
pub const DEV_COORDINATOR: u8 = 0x09;
pub const DEV_ROUTER: u8 = 0x08;
pub const DEV_END_DEVICE: u8 = 0x07;
pub const DEV_HOLD: u8 = 0x00;
pub const DEV_INIT: u8 = 0x01;
pub const ZNP_STATUS_SUCCESS: u8 = 0x00;
pub const ZNP_STATUS_FAILED: u8 = 0x01;
pub const ZNP_STATUS_INVALID_PARAM: u8 = 0x02;
pub fn startup_payload(start_delay_ms: u16) -> Vec<u8> {
start_delay_ms.to_le_bytes().to_vec()
}
pub fn af_data_request(
dst_nwk: u16,
dst_ep: u8,
src_ep: u8,
cluster_id: u16,
trans_id: u8,
data: &[u8],
) -> Vec<u8> {
let mut buf = Vec::new();
buf.extend_from_slice(&dst_nwk.to_le_bytes());
buf.push(dst_ep);
buf.push(src_ep);
buf.extend_from_slice(&cluster_id.to_le_bytes());
buf.push(trans_id);
buf.push(0x00); buf.push(0x0F); buf.push(data.len() as u8);
buf.extend_from_slice(data);
buf
}
pub fn permit_join_payload(dest: u16, duration: u8) -> Vec<u8> {
let mut buf = dest.to_le_bytes().to_vec();
buf.push(duration);
buf.push(0); buf
}
pub fn decode_af_incoming(params: &[u8]) -> Option<(u16, u16, u16, u8, u8, u8, &[u8])> {
if params.len() < 11 {
return None;
}
let group_id = u16::from_le_bytes([params[0], params[1]]);
let cluster_id = u16::from_le_bytes([params[2], params[3]]);
let src_addr = u16::from_le_bytes([params[4], params[5]]);
let src_ep = params[6];
let dst_ep = params[7];
let trans_id = params[8];
let data_len = *params.get(11)? as usize;
let data = params.get(12..12 + data_len)?;
Some((
group_id, cluster_id, src_addr, src_ep, dst_ep, trans_id, data,
))
}