Vergil Cola
/
MQTTGateway2
Fork of my original MQTTGateway
XbeeMonitor/XBeeLib/Frames/DigiMeshFrames.cpp@0:a1734fe1ec4b, 2017-04-08 (annotated)
- Committer:
- vpcola
- Date:
- Sat Apr 08 14:43:14 2017 +0000
- Revision:
- 0:a1734fe1ec4b
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vpcola | 0:a1734fe1ec4b | 1 | /** |
vpcola | 0:a1734fe1ec4b | 2 | * Copyright (c) 2015 Digi International Inc., |
vpcola | 0:a1734fe1ec4b | 3 | * All rights not expressly granted are reserved. |
vpcola | 0:a1734fe1ec4b | 4 | * |
vpcola | 0:a1734fe1ec4b | 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
vpcola | 0:a1734fe1ec4b | 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
vpcola | 0:a1734fe1ec4b | 7 | * You can obtain one at http://mozilla.org/MPL/2.0/. |
vpcola | 0:a1734fe1ec4b | 8 | * |
vpcola | 0:a1734fe1ec4b | 9 | * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 |
vpcola | 0:a1734fe1ec4b | 10 | * ======================================================================= |
vpcola | 0:a1734fe1ec4b | 11 | */ |
vpcola | 0:a1734fe1ec4b | 12 | |
vpcola | 0:a1734fe1ec4b | 13 | #include "DigiMeshFrames.h" |
vpcola | 0:a1734fe1ec4b | 14 | |
vpcola | 0:a1734fe1ec4b | 15 | #define FRAME_ID_LEN 1 |
vpcola | 0:a1734fe1ec4b | 16 | #define ADDR64_LEN 8 |
vpcola | 0:a1734fe1ec4b | 17 | #define ADDR16_LEN 2 |
vpcola | 0:a1734fe1ec4b | 18 | #define BROADCAST_RADIOUS_LEN 1 |
vpcola | 0:a1734fe1ec4b | 19 | #define OPTIONS_LEN 1 |
vpcola | 0:a1734fe1ec4b | 20 | #define TX_REQUEST_OVERHEAD (FRAME_ID_LEN + ADDR64_LEN + \ |
vpcola | 0:a1734fe1ec4b | 21 | ADDR16_LEN + BROADCAST_RADIOUS_LEN + \ |
vpcola | 0:a1734fe1ec4b | 22 | OPTIONS_LEN) |
vpcola | 0:a1734fe1ec4b | 23 | #define SOURCE_EP_LEN 1 |
vpcola | 0:a1734fe1ec4b | 24 | #define DEST_EP_LEN 1 |
vpcola | 0:a1734fe1ec4b | 25 | #define CLUSTER_ID_LEN 2 |
vpcola | 0:a1734fe1ec4b | 26 | #define PROFILE_ID_LEN 2 |
vpcola | 0:a1734fe1ec4b | 27 | |
vpcola | 0:a1734fe1ec4b | 28 | #define EXP_ADDR_OVERHEAD (TX_REQUEST_OVERHEAD + SOURCE_EP_LEN + \ |
vpcola | 0:a1734fe1ec4b | 29 | DEST_EP_LEN + CLUSTER_ID_LEN + \ |
vpcola | 0:a1734fe1ec4b | 30 | PROFILE_ID_LEN) |
vpcola | 0:a1734fe1ec4b | 31 | |
vpcola | 0:a1734fe1ec4b | 32 | /** Class constructor */ |
vpcola | 0:a1734fe1ec4b | 33 | TxFrameDM::TxFrameDM(uint64_t addr, uint16_t addr16, uint8_t broadcast_rad, uint8_t tx_opt, |
vpcola | 0:a1734fe1ec4b | 34 | const uint8_t *const data, uint16_t len) |
vpcola | 0:a1734fe1ec4b | 35 | { |
vpcola | 0:a1734fe1ec4b | 36 | uint8_t frame_data[TX_REQUEST_OVERHEAD + len]; |
vpcola | 0:a1734fe1ec4b | 37 | |
vpcola | 0:a1734fe1ec4b | 38 | _frame_id = get_next_frame_id(); |
vpcola | 0:a1734fe1ec4b | 39 | |
vpcola | 0:a1734fe1ec4b | 40 | /* copy the frame id, the 64bit remote address, the 16bit network address, |
vpcola | 0:a1734fe1ec4b | 41 | * the broad cast radious, the options byte and the frame data */ |
vpcola | 0:a1734fe1ec4b | 42 | |
vpcola | 0:a1734fe1ec4b | 43 | frame_data[0] = _frame_id; |
vpcola | 0:a1734fe1ec4b | 44 | rmemcpy(&frame_data[1], (const uint8_t *)&addr, sizeof addr); |
vpcola | 0:a1734fe1ec4b | 45 | frame_data[9] = (uint8_t)(addr16 >> 8); |
vpcola | 0:a1734fe1ec4b | 46 | frame_data[10] = (uint8_t)addr16; |
vpcola | 0:a1734fe1ec4b | 47 | frame_data[11] = broadcast_rad; |
vpcola | 0:a1734fe1ec4b | 48 | frame_data[12] = tx_opt; |
vpcola | 0:a1734fe1ec4b | 49 | |
vpcola | 0:a1734fe1ec4b | 50 | if (len) { |
vpcola | 0:a1734fe1ec4b | 51 | memcpy(&frame_data[13], data, len); |
vpcola | 0:a1734fe1ec4b | 52 | } |
vpcola | 0:a1734fe1ec4b | 53 | |
vpcola | 0:a1734fe1ec4b | 54 | set_api_frame(TxReqZBDM, frame_data, TX_REQUEST_OVERHEAD + len); |
vpcola | 0:a1734fe1ec4b | 55 | } |
vpcola | 0:a1734fe1ec4b | 56 | |
vpcola | 0:a1734fe1ec4b | 57 | /** Class constructor */ |
vpcola | 0:a1734fe1ec4b | 58 | TxFrameDM::TxFrameDM(uint64_t addr, uint16_t addr16, uint8_t source_ep, uint8_t dest_ep, |
vpcola | 0:a1734fe1ec4b | 59 | uint16_t cluster_id, uint16_t profile_id, uint8_t broadcast_rad, |
vpcola | 0:a1734fe1ec4b | 60 | uint8_t tx_opt, const uint8_t *const data, uint16_t len) |
vpcola | 0:a1734fe1ec4b | 61 | { |
vpcola | 0:a1734fe1ec4b | 62 | uint8_t frame_data[EXP_ADDR_OVERHEAD + len]; |
vpcola | 0:a1734fe1ec4b | 63 | |
vpcola | 0:a1734fe1ec4b | 64 | _frame_id = get_next_frame_id(); |
vpcola | 0:a1734fe1ec4b | 65 | |
vpcola | 0:a1734fe1ec4b | 66 | /* copy the frame id, the 64bit remote address, the 16bit network address, |
vpcola | 0:a1734fe1ec4b | 67 | * the end point source and destination addresses, the cluster and profile IDs, |
vpcola | 0:a1734fe1ec4b | 68 | * the broad cast radious, the options byte and the frame data */ |
vpcola | 0:a1734fe1ec4b | 69 | |
vpcola | 0:a1734fe1ec4b | 70 | frame_data[0] = _frame_id; |
vpcola | 0:a1734fe1ec4b | 71 | rmemcpy(&frame_data[1], (const uint8_t *)&addr, sizeof addr); |
vpcola | 0:a1734fe1ec4b | 72 | frame_data[9] = (uint8_t)(addr16 >> 8); |
vpcola | 0:a1734fe1ec4b | 73 | frame_data[10] = (uint8_t)addr16; |
vpcola | 0:a1734fe1ec4b | 74 | frame_data[11] = source_ep; |
vpcola | 0:a1734fe1ec4b | 75 | frame_data[12] = dest_ep; |
vpcola | 0:a1734fe1ec4b | 76 | frame_data[13] = (uint8_t)(cluster_id >> 8); |
vpcola | 0:a1734fe1ec4b | 77 | frame_data[14] = (uint8_t)cluster_id; |
vpcola | 0:a1734fe1ec4b | 78 | frame_data[15] = (uint8_t)(profile_id >> 8); |
vpcola | 0:a1734fe1ec4b | 79 | frame_data[16] = (uint8_t)profile_id; |
vpcola | 0:a1734fe1ec4b | 80 | frame_data[17] = broadcast_rad; |
vpcola | 0:a1734fe1ec4b | 81 | frame_data[18] = tx_opt; |
vpcola | 0:a1734fe1ec4b | 82 | |
vpcola | 0:a1734fe1ec4b | 83 | if (len) { |
vpcola | 0:a1734fe1ec4b | 84 | memcpy(&frame_data[19], data, len); |
vpcola | 0:a1734fe1ec4b | 85 | } |
vpcola | 0:a1734fe1ec4b | 86 | |
vpcola | 0:a1734fe1ec4b | 87 | set_api_frame(ExpAddrCmd, frame_data, EXP_ADDR_OVERHEAD + len); |
vpcola | 0:a1734fe1ec4b | 88 | } |