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/sgEncodeInstall.c
Views: 1799
/**1* @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved.2*3* @file sgEncodeInstall.c4* @author Jacob.Garrison5*6* @date Feb 23, 20217*8* This file receives a populated installation message struct and9* converts it into a installation message buffer.10*/1112#include <ctype.h>13#include <string.h>14#include <stdbool.h>1516#include "sg.h"17#include "sgUtil.h"1819#define SG_PAYLOAD_LEN_INSTALL SG_MSG_LEN_INSTALL - 5 /// the payload length.2021#define PBASE 4 /// the payload offset.22#define OFFSET_ICAO 0 /// the icao address offset in the payload.23#define OFFSET_REG 3 /// the registration offset in the payload.24#define OFFSET_RSVD1 10 /// the first reserved field offset in the payload.25#define OFFSET_COM0 12 /// the COM port 0 offset in the payload.26#define OFFSET_COM1 13 /// the COM port 1 offset in the payload.27#define OFFSET_IP 14 /// the IP address offset in the payload.28#define OFFSET_MASK 18 /// the net mask offset in the payload.29#define OFFSET_PORT 22 /// the port number offset in the payload.30#define OFFSET_GPS 24 /// the GPS integrity offset in the payload.31#define OFFSET_EMIT_SET 25 /// the emitter category offset in the payload.32#define OFFSET_EMIT_TYPE 26 /// the emitter type offset in the payload.33#define OFFSET_SIZE 27 /// the aircraft size offset in the payload.34#define OFFSET_SPEED 28 /// the maximum airspeed offset in the payload.35#define OFFSET_ENCODER 29 /// the altitude-encoder-offset offset in the payload.36#define OFFSET_RSVD2 31 /// the second reserved field offset in the payload.37#define OFFSET_CONFIG 33 /// the configuration offset in the payload.38#define OFFSET_RSVD3 34 /// the third reserved field offset in the payload.3940#define REG_LEN 7 /// the registration field length.41/*42* Documented in the header file.43*/44bool sgEncodeInstall(uint8_t *buffer, sg_install_t *stl, uint8_t msgId)45{46// populate header47buffer[0] = SG_MSG_START_BYTE;48buffer[1] = SG_MSG_TYPE_HOST_INSTALL;49buffer[2] = msgId;50buffer[3] = SG_PAYLOAD_LEN_INSTALL;5152// populate icao address53icao2Buf(&buffer[PBASE + OFFSET_ICAO], stl->icao);5455// populate aircraft registration56charArray2Buf(&buffer[PBASE + OFFSET_REG], stl->reg, REG_LEN);5758// populate reserved fields59uint162Buf(&buffer[PBASE + OFFSET_RSVD1], 0);6061// populate COM port 0, correct enum offset62buffer[PBASE + OFFSET_COM0] = stl->com0;6364// populate COM port 1, correct enum offset65buffer[PBASE + OFFSET_COM1] = stl->com1;6667// populate IP address68uint322Buf(&buffer[PBASE + OFFSET_IP], stl->eth.ipAddress);6970// populate net mask71uint322Buf(&buffer[PBASE + OFFSET_MASK], stl->eth.subnetMask);7273// populate port number74uint162Buf(&buffer[PBASE + OFFSET_PORT], stl->eth.portNumber);7576// populate gps integrity77buffer[PBASE + OFFSET_GPS] = stl->sil << 4 |78stl->sda;7980// populate emitter category set and type81uint8_t emitSet;82uint8_t emitType;83if (stl->emitter < SG_EMIT_OFFSET_B) // group A84{85emitSet = SG_EMIT_GROUP_A;86emitType = stl->emitter - SG_EMIT_OFFSET_A;87}88else if (stl->emitter < SG_EMIT_OFFSET_C) // group B89{90emitSet = SG_EMIT_GROUP_B;91emitType = stl->emitter - SG_EMIT_OFFSET_B;92}93else if (stl->emitter < SG_EMIT_OFFSET_D) // group C94{95emitSet = SG_EMIT_GROUP_C;96emitType = stl->emitter - SG_EMIT_OFFSET_C;97}98else // group D99{100emitSet = SG_EMIT_GROUP_D;101emitType = stl->emitter - SG_EMIT_OFFSET_D;102}103buffer[PBASE + OFFSET_EMIT_SET] = emitSet;104buffer[PBASE + OFFSET_EMIT_TYPE] = emitType;105106// populate aircraft size107buffer[PBASE + OFFSET_SIZE] = stl->size;108109// populate max airspeed110buffer[PBASE + OFFSET_SPEED] = stl->maxSpeed;111112// populate altitude encoder offset113uint162Buf(&buffer[PBASE + OFFSET_ENCODER], stl->altOffset);114115// populate reserved fields116uint162Buf(&buffer[PBASE + OFFSET_RSVD2], 0);117118// populate install configuration119buffer[PBASE + OFFSET_CONFIG] = stl->wowConnected << 7 |120stl->heater << 6 |121stl->airspeedTrue << 5 |122stl->hdgTrueNorth << 4 |123stl->altRes100 << 3 |124stl->antenna;125126// populate reserved fields127uint162Buf(&buffer[PBASE + OFFSET_RSVD3], 0);128129// populate checksum130appendChecksum(buffer, SG_MSG_LEN_INSTALL);131132return true;133}134135136