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