2013-04-05 22:46:56 +02:00
|
|
|
/**
|
2013-05-19 16:37:30 +02:00
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup OpenPilotSystem OpenPilot System
|
|
|
|
* @{
|
|
|
|
* @addtogroup OpenPilotLibraries OpenPilot System Libraries
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file packet_handler.h
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
|
|
|
* @brief A packet handler for handeling radio packet transmission.
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2013-04-05 22:46:56 +02:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PACKET_HANDLER_H__
|
|
|
|
#define __PACKET_HANDLER_H__
|
|
|
|
|
|
|
|
#include <uavobjectmanager.h>
|
|
|
|
#include <gcsreceiver.h>
|
|
|
|
#include <oplinksettings.h>
|
|
|
|
#include <pios_rfm22b_rcvr.h>
|
|
|
|
|
|
|
|
// Public defines / macros
|
2013-05-19 16:37:30 +02:00
|
|
|
#define PHPacketSize(p) ((uint8_t *)(p->data) + p->header.data_size - (uint8_t *)p)
|
|
|
|
#define PHPacketSizeECC(p) ((uint8_t *)(p->data) + p->header.data_size + RS_ECC_NPARITY - (uint8_t *)p)
|
2013-04-05 22:46:56 +02:00
|
|
|
|
|
|
|
// Public types
|
|
|
|
typedef enum {
|
2013-05-04 17:50:08 +02:00
|
|
|
PACKET_TYPE_NONE = 0,
|
2013-05-19 16:37:30 +02:00
|
|
|
PACKET_TYPE_STATUS, // broadcasts status of this modem
|
|
|
|
PACKET_TYPE_CON_REQUEST, // request a connection to another modem
|
|
|
|
PACKET_TYPE_DATA, // data packet (packet contains user data)
|
|
|
|
PACKET_TYPE_DUPLICATE_DATA, // a duplicate data packet
|
|
|
|
PACKET_TYPE_PPM, // PPM relay values
|
|
|
|
PACKET_TYPE_ACK, // Acknowlege the receipt of a packet
|
|
|
|
PACKET_TYPE_NACK, // Acknowlege the receipt of an uncorrectable packet
|
2013-04-05 22:46:56 +02:00
|
|
|
} PHPacketType;
|
|
|
|
|
|
|
|
typedef struct {
|
2013-05-19 16:37:30 +02:00
|
|
|
uint32_t destination_id;
|
2013-05-04 17:50:08 +02:00
|
|
|
portTickType prev_tx_time;
|
2013-05-19 16:37:30 +02:00
|
|
|
uint16_t seq_num;
|
2013-05-04 17:50:08 +02:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t data_size;
|
2013-04-05 22:46:56 +02:00
|
|
|
} PHPacketHeader;
|
|
|
|
|
|
|
|
#define PH_MAX_DATA (PIOS_PH_MAX_PACKET - sizeof(PHPacketHeader) - RS_ECC_NPARITY)
|
2013-05-19 16:37:30 +02:00
|
|
|
#define PH_PACKET_SIZE(p) ((p)->data + (p)->header.data_size - (uint8_t *)(p) + RS_ECC_NPARITY)
|
2013-04-05 22:46:56 +02:00
|
|
|
typedef struct {
|
2013-05-04 17:50:08 +02:00
|
|
|
PHPacketHeader header;
|
|
|
|
uint8_t data[PH_MAX_DATA + RS_ECC_NPARITY];
|
2013-04-05 22:46:56 +02:00
|
|
|
} PHPacket, *PHPacketHandle;
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
#define PH_ACK_NACK_DATA_SIZE(p) ((uint8_t *)((p)->ecc) - (uint8_t *)(((PHPacketHandle)(p))->data))
|
2013-04-05 22:46:56 +02:00
|
|
|
typedef struct {
|
2013-05-04 17:50:08 +02:00
|
|
|
PHPacketHeader header;
|
|
|
|
uint8_t ecc[RS_ECC_NPARITY];
|
2013-04-05 22:46:56 +02:00
|
|
|
} PHAckNackPacket, *PHAckNackPacketHandle;
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
#define PH_PPM_DATA_SIZE(p) ((uint8_t *)((p)->ecc) - (uint8_t *)(((PHPacketHandle)(p))->data))
|
2013-04-05 22:46:56 +02:00
|
|
|
typedef struct {
|
2013-05-04 17:50:08 +02:00
|
|
|
PHPacketHeader header;
|
|
|
|
int16_t channels[PIOS_RFM22B_RCVR_MAX_CHANNELS];
|
|
|
|
uint8_t ecc[RS_ECC_NPARITY];
|
2013-04-05 22:46:56 +02:00
|
|
|
} PHPpmPacket, *PHPpmPacketHandle;
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
#define PH_STATUS_DATA_SIZE(p) ((uint8_t *)((p)->ecc) - (uint8_t *)(((PHPacketHandle)(p))->data))
|
2013-04-05 22:46:56 +02:00
|
|
|
typedef struct {
|
2013-05-04 17:50:08 +02:00
|
|
|
PHPacketHeader header;
|
|
|
|
uint32_t source_id;
|
2013-05-19 16:37:30 +02:00
|
|
|
uint8_t link_quality;
|
|
|
|
int8_t received_rssi;
|
|
|
|
uint8_t ecc[RS_ECC_NPARITY];
|
2013-04-05 22:46:56 +02:00
|
|
|
} PHStatusPacket, *PHStatusPacketHandle;
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
#define PH_CONNECTION_DATA_SIZE(p) ((uint8_t *)((p)->ecc) - (uint8_t *)(((PHPacketHandle)(p))->data))
|
2013-04-05 22:46:56 +02:00
|
|
|
typedef struct {
|
2013-05-04 17:50:08 +02:00
|
|
|
PHPacketHeader header;
|
2013-05-19 16:37:30 +02:00
|
|
|
uint32_t source_id;
|
|
|
|
uint32_t min_frequency;
|
|
|
|
uint32_t max_frequency;
|
|
|
|
uint32_t channel_spacing;
|
2013-05-04 17:50:08 +02:00
|
|
|
portTickType status_rx_time;
|
2013-05-19 16:37:30 +02:00
|
|
|
OPLinkSettingsMainPortOptions main_port;
|
2013-05-04 17:50:08 +02:00
|
|
|
OPLinkSettingsFlexiPortOptions flexi_port;
|
2013-05-19 16:37:30 +02:00
|
|
|
OPLinkSettingsVCPPortOptions vcp_port;
|
|
|
|
OPLinkSettingsComSpeedOptions com_speed;
|
2013-05-04 17:50:08 +02:00
|
|
|
uint8_t ecc[RS_ECC_NPARITY];
|
2013-04-05 22:46:56 +02:00
|
|
|
} PHConnectionPacket, *PHConnectionPacketHandle;
|
|
|
|
|
|
|
|
#endif // __PACKET_HANDLER_H__
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|