Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_ADSB/sagetech-sdk/sgDecodeAck.c
Views: 1799
/**1* @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved.2*3* @file sgDecodeAck.c4* @author jimb5*6* @date Feb 10, 20217*8* This file receives a raw Acknowledge message buffer and9* parses the payload into a data struct.10*/1112#include <string.h>13#include <stdbool.h>14#include <math.h>1516#include "sg.h"17#include "sgUtil.h"1819#define SG_ACK_XPNDR_FAIL 0x0120#define SG_ACK_SYSTEM_FAIL 0x0221#define SG_ACK_CRYPTO_FAIL 0x0422#define SG_ACK_WOW 0x0823#define SG_ACK_MAINT 0x1024#define SG_ACK_ALT_SOURCE 0x2025#define SG_ACK_OP_MODE 0xC02627typedef struct __attribute__((packed))28{29uint8_t start;30uint8_t type;31uint8_t id;32uint8_t payloadLen;33uint8_t ackType;34uint8_t ackId;35uint8_t state;36uint8_t alt[3];37uint8_t checksum;38} ack_t;3940/*41* Documented in the header file.42*/43bool sgDecodeAck(uint8_t *buffer, sg_ack_t *ack)44{45ack_t sgAck;46memcpy(&sgAck, buffer, sizeof(ack_t));4748ack->ackType = sgAck.ackType;49ack->ackId = sgAck.ackId;50ack->failXpdr = (sgAck.state & SG_ACK_XPNDR_FAIL) > 0;51ack->failSystem = (sgAck.state & SG_ACK_SYSTEM_FAIL) > 0;52ack->failCrypto = (sgAck.state & SG_ACK_CRYPTO_FAIL) > 0;53ack->wow = (sgAck.state & SG_ACK_WOW) > 0;54ack->maint = (sgAck.state & SG_ACK_MAINT) > 0;55ack->isHostAlt = (sgAck.state & SG_ACK_ALT_SOURCE) > 0;56ack->opMode = (sgAck.state & SG_ACK_OP_MODE) >> 6;5758int32_t int24 = toInt32(sgAck.alt);5960// Bitmask altitude field to determine if alt = invalid61if ((int24 & 0x00FFFFFF) == 0x00800000)62{63ack->alt = 0;64ack->altValid = false;65}66else67{68ack->alt = int24;69ack->altValid = true;70}7172return true;73}747576