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/sgEncodeGPS.c
Views: 1799
/**1* @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved.2*3* @file sgEncodeGPS.c4* @author Jacob.Garrison5*6* @date Mar 1, 20217*8* This file receives a populated GPS message struct and9* converts it into a GPS message buffer.10*/1112#include <stdbool.h>13#include <stdlib.h>1415#include "sg.h"16#include "sgUtil.h"1718#define SG_PAYLOAD_LEN_GPS SG_MSG_LEN_GPS - 5 /// the payload length.19#define _UNUSED(x) ((void)(x))2021#define PBASE 4 /// the payload offset.22#define OFFSET_LONGITUDE 0 /// the longitude offset in the payload.23#define OFFSET_LATITUDE 11 /// the latitude offset in the payload.24#define OFFSET_SPEED 21 /// the ground speed offset in the payload.25#define OFFSET_TRACK 27 /// the ground track offset in the payload.26#define OFFSET_STATUS 35 /// the hemisphere/data status offset in the payload.27#define OFFSET_TIME 36 /// the time of fix offset in the payload.28#define OFFSET_HEIGHT 46 /// the GNSS height offset in the payload.29#define OFFSET_HPL 50 /// the horizontal protection limit offset in the payload.30#define OFFSET_HFOM 54 /// the horizontal figure of merit offset in the payload.31#define OFFSET_VFOM 58 /// the vertical figure of merit offset in the payload.32#define OFFSET_NACV 62 /// the navigation accuracy for velocity offset in the payload.3334#define LEN_LNG 11 /// bytes in the longitude field35#define LEN_LAT 10 /// bytes in the latitude field36#define LEN_SPD 6 /// bytes in the speed over ground field37#define LEN_TRK 8 /// bytes in the ground track field38#define LEN_TIME 10 /// bytes in the time of fix field3940/*41* Documented in the header file.42*/43bool sgEncodeGPS(uint8_t *buffer, sg_gps_t *gps, uint8_t msgId)44{45// populate header46buffer[0] = SG_MSG_START_BYTE;47buffer[1] = SG_MSG_TYPE_HOST_GPS;48buffer[2] = msgId;49buffer[3] = SG_PAYLOAD_LEN_GPS;5051// populate longitude52charArray2Buf(&buffer[PBASE + OFFSET_LONGITUDE], gps->longitude, LEN_LNG);5354// populate latitude55charArray2Buf(&buffer[PBASE + OFFSET_LATITUDE], gps->latitude, LEN_LAT);5657// populate ground speed58charArray2Buf(&buffer[PBASE + OFFSET_SPEED], gps->grdSpeed, LEN_SPD);5960// populate ground track61charArray2Buf(&buffer[PBASE + OFFSET_TRACK], gps->grdTrack, LEN_TRK);6263// populate hemisphere/data status64buffer[PBASE + OFFSET_STATUS] = !gps->gpsValid << 7 |65gps->fdeFail << 6 |66gps->lngEast << 1 |67gps->latNorth;6869// populate time of fix70charArray2Buf(&buffer[PBASE + OFFSET_TIME], gps->timeOfFix, LEN_TIME);7172// populate gnss height73float2Buf(&buffer[PBASE + OFFSET_HEIGHT], gps->height);7475// populate HPL76float2Buf(&buffer[PBASE + OFFSET_HPL], gps->hpl);7778// populate HFOM79float2Buf(&buffer[PBASE + OFFSET_HFOM], gps->hfom);8081// populate VFOM82float2Buf(&buffer[PBASE + OFFSET_VFOM], gps->vfom);8384// populate NACv85buffer[PBASE + OFFSET_NACV] = gps->nacv << 4;8687// populate checksum88appendChecksum(buffer, SG_MSG_LEN_GPS);8990return true;91}929394