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