![](/media/cache/profiles/91e091bec08dc4efd2982e61547a0a02.jpg.50x50_q85.jpg)
Fork of my MQTTGateway
XbeeMonitor/XBeeLib/Frames/802_Frames.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 "802_Frames.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 OPTIONS_LEN 1 |
vpcola | 0:f1d3878b8dd9 | 19 | #define TX_REQUEST_OVERHEAD (FRAME_ID_LEN + ADDR64_LEN + OPTIONS_LEN) |
vpcola | 0:f1d3878b8dd9 | 20 | #define TX_REQUEST_OVERHEAD2 (FRAME_ID_LEN + ADDR16_LEN + OPTIONS_LEN) |
vpcola | 0:f1d3878b8dd9 | 21 | |
vpcola | 0:f1d3878b8dd9 | 22 | /** Class constructor */ |
vpcola | 0:f1d3878b8dd9 | 23 | TxFrame802::TxFrame802(uint64_t addr, uint8_t tx_options, |
vpcola | 0:f1d3878b8dd9 | 24 | const uint8_t *const data, uint16_t len) |
vpcola | 0:f1d3878b8dd9 | 25 | { |
vpcola | 0:f1d3878b8dd9 | 26 | uint8_t frame_data[TX_REQUEST_OVERHEAD + len]; |
vpcola | 0:f1d3878b8dd9 | 27 | |
vpcola | 0:f1d3878b8dd9 | 28 | _frame_id = get_next_frame_id(); |
vpcola | 0:f1d3878b8dd9 | 29 | |
vpcola | 0:f1d3878b8dd9 | 30 | /* copy the frame id, the 64bit remote address, the tx options byte |
vpcola | 0:f1d3878b8dd9 | 31 | * and the frame data */ |
vpcola | 0:f1d3878b8dd9 | 32 | |
vpcola | 0:f1d3878b8dd9 | 33 | frame_data[0] = _frame_id; |
vpcola | 0:f1d3878b8dd9 | 34 | rmemcpy(&frame_data[1], (const uint8_t *)&addr, sizeof addr); |
vpcola | 0:f1d3878b8dd9 | 35 | frame_data[9] = tx_options; |
vpcola | 0:f1d3878b8dd9 | 36 | |
vpcola | 0:f1d3878b8dd9 | 37 | if (len) { |
vpcola | 0:f1d3878b8dd9 | 38 | memcpy(&frame_data[10], data, len); |
vpcola | 0:f1d3878b8dd9 | 39 | } |
vpcola | 0:f1d3878b8dd9 | 40 | |
vpcola | 0:f1d3878b8dd9 | 41 | set_api_frame(TxReq64Bit, frame_data, TX_REQUEST_OVERHEAD + len); |
vpcola | 0:f1d3878b8dd9 | 42 | } |
vpcola | 0:f1d3878b8dd9 | 43 | |
vpcola | 0:f1d3878b8dd9 | 44 | /** Class constructor */ |
vpcola | 0:f1d3878b8dd9 | 45 | TxFrame802::TxFrame802(uint16_t addr16, uint8_t tx_options, |
vpcola | 0:f1d3878b8dd9 | 46 | const uint8_t *const data, uint16_t len) |
vpcola | 0:f1d3878b8dd9 | 47 | { |
vpcola | 0:f1d3878b8dd9 | 48 | uint8_t frame_data[TX_REQUEST_OVERHEAD2 + len]; |
vpcola | 0:f1d3878b8dd9 | 49 | |
vpcola | 0:f1d3878b8dd9 | 50 | _frame_id = get_next_frame_id(); |
vpcola | 0:f1d3878b8dd9 | 51 | |
vpcola | 0:f1d3878b8dd9 | 52 | /* copy the frame id, the 16bit remote address, the tx options byte |
vpcola | 0:f1d3878b8dd9 | 53 | * and the frame data */ |
vpcola | 0:f1d3878b8dd9 | 54 | |
vpcola | 0:f1d3878b8dd9 | 55 | frame_data[0] = _frame_id; |
vpcola | 0:f1d3878b8dd9 | 56 | frame_data[1] = (uint8_t)(addr16 >> 8); |
vpcola | 0:f1d3878b8dd9 | 57 | frame_data[2] = (uint8_t)addr16; |
vpcola | 0:f1d3878b8dd9 | 58 | frame_data[3] = tx_options; |
vpcola | 0:f1d3878b8dd9 | 59 | |
vpcola | 0:f1d3878b8dd9 | 60 | if (len) { |
vpcola | 0:f1d3878b8dd9 | 61 | memcpy(&frame_data[4], data, len); |
vpcola | 0:f1d3878b8dd9 | 62 | } |
vpcola | 0:f1d3878b8dd9 | 63 | |
vpcola | 0:f1d3878b8dd9 | 64 | set_api_frame(TxReq16Bit, frame_data, TX_REQUEST_OVERHEAD2 + len); |
vpcola | 0:f1d3878b8dd9 | 65 | } |