Skip to content

Commit

Permalink
Whoa, lotsa changes. Normalized noise floors of GN3S and USRP. Code s…
Browse files Browse the repository at this point in the history
…hould work equally well with both devices. Played with the GN3S filter. Added a checksum (adler) to the communication with the GUI.
  • Loading branch information
gpssim committed Jul 31, 2009
1 parent 51b78da commit 72a7fab
Show file tree
Hide file tree
Showing 21 changed files with 412 additions and 261 deletions.
67 changes: 19 additions & 48 deletions accessories/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,40 +170,6 @@ void wipeoff_gen(MIX *_dest, double _f, double _fs, int32 _samps)
/*----------------------------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------------------------*/
/*!
* resample, resample a vector where _samps is from _dest
* */
void resample(CPX *_dest, CPX *_source, double _fdest, double _fsource, int32 _samps)
{
//
// int32 lcv, k;
// float phase, phase_step;
//
// uint32 phase_step;
// uint32 phase;
//
// phase_step = 0xffffffff/_fsource;
// phase_step *= _fdest;
//
// for(lcv = 0; lcv < _samps; lcv++)
// {
// /* Take advantage of addition rollover */
// phase += phase_step;
//
// if(phase < lphase)
// _dest[k] = _source[lcv];
//
//
// k = (int32) floor(phase);
//
// phase += phase_step;
//}

}
/*----------------------------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------------------------*/
void downsample(CPX *_dest, CPX *_source, double _fdest, double _fsource, int32 _samps)
{
Expand Down Expand Up @@ -257,30 +223,35 @@ int32 round_2(int32 _N)
/*!
* Gather statistics and run AGC
* */
int32 run_agc(CPX *_buff, int32 _samps, int32 bits, int32 scale)
int32 run_agc(CPX *_buff, int32 _samps, int32 _bits, int32 _scale)
{
int32 lcv, num;
int16 max, *p;
int16 lscale;
int16 shift;
int16 val;

p = (int16 *)&_buff[0];

/* Get rid of the divide, replace with a multiply to scale to 2^15, then right shift to get
* back into AGC_BITS of magnitude */
// lscale = (1 << 14) / scale;
// shift = 14 - bits;
max = 1 << bits;
val = (1 << _scale - 1);
max = 1 << _bits;
num = 0;

// x86_muls((int16 *)_buff, &lscale, 2*_samps, shift);

for(lcv = 0; lcv < 2*_samps; lcv++)
if(_scale)
{
for(lcv = 0; lcv < 2*_samps; lcv++)
{
p[lcv] += val;
p[lcv] >>= _scale;
if(abs(p[lcv]) > max)
num++;
}
}
else
{
p[lcv] >>= 7;
if(abs(p[lcv]) > max)
num++;
for(lcv = 0; lcv < 2*_samps; lcv++)
{
if(abs(p[lcv]) > max)
num++;
}
}

return(num);
Expand Down
4 changes: 2 additions & 2 deletions gse/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ INCPATH = -I. \
-I../includes \
-I../objects

WX_FLAGS = `wx-config --libs`
WX_FLAGS = `wx-config --libs`
LDFLAGS = -lpthread
CFLAGS = -D_FORTIFY_SOURCE=0 `wx-config --cxxflags` -g3 $(INCPATH)
CFLAGS = -D_FORTIFY_SOURCE=0 `wx-config --cxxflags` $(INCPATH)

SRC = $(wildcard src/*.cpp)
SRC += gui_classes.cpp
Expand Down
Binary file modified gse/gps-gse
Binary file not shown.
1 change: 1 addition & 0 deletions gse/include/gui_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class GUI_Serial : public Threaded_Object
uint32 command_sent; //!< Flag to indicate command was transmitted
uint32 command_ack; //!< Flag to indicate command was executed
uint32 command_count; //!< Used to detect a command ack
uint8 packet_body[2048]; //!< Complete packet body

Message_Struct messages; //!< Hold all the messages
Message_Union message_body; //!< Union for messages
Expand Down
2 changes: 1 addition & 1 deletion gse/src/gui_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void GUI_Channel::render(wxDC& dc)

tChannel->SetDefaultStyle(style);

if(pchan->count > 2000)
if(pchan->count > 1000)
{

str2.Clear();
Expand Down
93 changes: 81 additions & 12 deletions gse/src/gui_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1
#include "gui_serial.h"
#define SWAP64(X) *((long long *)(&X)) = (((*((long long *)(&X)) & (0x00000000ffffffffLLU)) << 32) | ((*((long long *)(&X)) & (0xffffffff00000000LLU)) >> 32))

/*----------------------------------------------------------------------------------------------*/
#define MOD_ADLER 65521
/* Data is input buffer, len is in bytes! */
uint32 adler(uint8 *data, int32 len)
{

uint32 a, b;
int32 tlen;

a = 1; b = 0;

if(len < 5552)
{
do
{
a += *data++;
b += a;
} while (--len);

a %= MOD_ADLER;
b %= MOD_ADLER;
}

return (b << 16) | a;

}
/*----------------------------------------------------------------------------------------------*/

static uint32 SIZEOF_M[LAST_M_ID + 1] =
{
0,
Expand Down Expand Up @@ -373,21 +401,30 @@ void endian_swap(void *_b, int32 _bytes, int32 _flag)
int GUI_Serial::Read(void *_b, int32 _bytes)
{

int32 nbytes, bread;
int32 nbytes, bread, k;
uint8 *buff;

nbytes = 0; bread = 0;
k = 0; nbytes = 0; bread = 0;
buff = (uint8 *)_b;

while((nbytes < _bytes) && grun && npipe_open)
{
bread = read(npipe[READ], buff, _bytes - nbytes);

if(bread > -1)
{
nbytes += bread;
buff += bread;
}

if(k++ > 5000)
{
closePipe();
return(0);
}

usleep(100);

}

//endian_swap(_b, _bytes, _bytes <= 6);
Expand Down Expand Up @@ -418,6 +455,7 @@ int GUI_Serial::Write(void *_b, int32 _bytes)
/*----------------------------------------------------------------------------------------------*/
void GUI_Serial::readGPS()
{
uint32 checksumc, checksumr;
int32 nbytes, bread, k, chan;
uint8 v;

Expand Down Expand Up @@ -478,8 +516,24 @@ void GUI_Serial::readGPS()
/* Read in the message */
Read(src, decoded_packet.length);

/* Assemble into a complete packet for the checksum */
memcpy(&packet_body[0], &packet_header, 6); //!< CCSDS Header
memcpy(&packet_body[6], src, decoded_packet.length); //!< Body
checksumc = adler(&packet_body[0], 6 + decoded_packet.length);

/* Read in the checksum */
byte_count += Read(&checksumr, sizeof(uint32));

/* Now verify the checksum */
if(checksumc != checksumr)
{
message_sync = 0;
packet_count[LAST_M_ID]++;
return;
}

/* Read in the postword */
Read(&postword, sizeof(uint32));
byte_count += Read(&postword, sizeof(uint32));

if(postword != 0xBBBBBBBB)
{
Expand Down Expand Up @@ -674,6 +728,7 @@ void GUI_Serial::readGPS()
if(CheckPacket(&decoded_packet) == true)
{
Read(&buff[0], decoded_packet.length);
Read(&checksumr, sizeof(uint32));
Read(&postword, sizeof(uint32));
if(postword != 0xBBBBBBBB)
{
Expand All @@ -699,13 +754,16 @@ void GUI_Serial::readGPS()
bool GUI_Serial::CheckPacket(CCSDS_Decoded_Header *_p)
{

bool val;
bool val = true;

/* Now copy in the body */
if(SIZEOF_M[_p->id] == _p->length)
val = true;
else
if((_p->id >= LAST_M_ID) || (_p->id <= FIRST_M_ID))
{
val = false;
}
else if(SIZEOF_M[_p->id] != _p->length)
{
val = false;
}

return(val);
}
Expand All @@ -729,18 +787,29 @@ void GUI_Serial::FixDoubles(void *_b, int32 _num)
void GUI_Serial::writeGPS()
{

uint32 preamble = 0xAAAAAAAA;
uint8 *sbuff;
uint32 pre = 0xAAAAAAAA;
uint32 post = 0xBBBBBBBB;
uint32 checksum;

Lock();

// endian_swap(&command_header, sizeof(CCSDS_Packet_Header), 1);
// endian_swap(&command_body, decoded_command.length, 0);

sbuff = &packet_body[0];

if(command_ready && (command_sent == 0))
{
Write(&preamble, sizeof(uint32));
Write(&command_header, sizeof(CCSDS_Packet_Header));
Write(&command_body, decoded_command.length);
/* Assemble into a complete packet */
memcpy(sbuff, &pre, 4); sbuff += 4; //!< Prefix
memcpy(sbuff, &command_header, 6); sbuff += 6; //!< CCSDS Header
memcpy(sbuff, &command_body, decoded_command.length); sbuff += decoded_command.length; //!< Payload
checksum = adler(&packet_body[4], 6 + decoded_command.length);
memcpy(sbuff, &checksum, 4); sbuff += 4; //!< Checksum
memcpy(sbuff, &post, 4); sbuff += 4; //!< Postfix

Write(&packet_body[0], decoded_command.length + 18);
command_sent = 1;
}

Expand Down
29 changes: 8 additions & 21 deletions includes/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@
/*----------------------------------------------------------------------------------------------*/


/* What stuff to log */
/*----------------------------------------------------------------------------------------------*/
#define CHANNEL_DEBUG (1) //!< Log channel data to HD
#define CHANNEL_INVESTIGATE (0) //!< Try to figure out Nav bug
#define LOG_PSEUDO (0) //!< Pseudoranges
#define LOG_SV (0) //!< SV Navigation data
#define LOG_NAV (1) //!< Nav Output
/*----------------------------------------------------------------------------------------------*/


/* MISC GPS Constants */
/*----------------------------------------------------------------------------------------------*/
#define MAX_SV (32) //!< Number of PRN codes
Expand All @@ -70,7 +60,7 @@
/*----------------------------------------------------------------------------------------------*/
#define MASK_ANGLE (0) //!< Add this many degrees to altitude dependant mask
#define ACQ_MODULO_WEAK (8) //!< Do this many weak acqs per 32 PRN strong search
#define MAX_ACQS_PER_PVT (12) //!< Max # of acquisitions per PVT
#define MAX_ACQS_PER_PVT (1) //!< Max # of acquisitions per PVT
#define MAX_DOPPLER_ABSOLUTE (15000) //!< Limit any and all Dopplers the be within this range
#define MAX_DOPPLER_STRONG (15000) //!< Cold Doppler search space for strong signal
#define MAX_DOPPLER_MEDIUM (15000) //!< Cold Doppler search space for strong signal
Expand All @@ -87,11 +77,9 @@

/* Correlator Defines */
/*----------------------------------------------------------------------------------------------*/
#define CORR_DELAYS (1) //!< Number of delays to calculate (plus-minus)
#define CORR_SPACING (.5) //!< How far should the correlators be spaced (chips)
#define FRAME_SIZE_PLUS_2 (12) //!< 10 words per frame, 12 = 10 + 2
#define CODE_BINS (20) //!< Partial code offset bins code resolution -> 1 chip/X bins
#define CARRIER_SPACING (20) //!< Spacing of bins (Hz)
#define CODE_BINS (50) //!< Partial code offset bins code resolution -> 1 chip/X bins
#define CARRIER_SPACING (10) //!< Spacing of bins (Hz)
#define CARRIER_BINS (MAX_DOPPLER_ABSOLUTE/CARRIER_SPACING) //!< Number of pre-sampled carrier wipeoff bins
/*----------------------------------------------------------------------------------------------*/

Expand All @@ -108,14 +96,13 @@
/*----------------------------------------------------------------------------------------------*/


/* Channel defines */
/* AGC Control */
/*----------------------------------------------------------------------------------------------*/
#define CARRIER_AIDING (1) //!< Carrier aid the DLL
#define PLL_BN (15) //!< PLL Bandwidth
#define FLL_BN (10) //!< FLL Bandwidth
#define AGC_BITS (6) //!< AGC to this bit depth
#define OVERFLOW_LOW (4) //!< Overflow low
#define OVERFLOW_HIGH (64) //!< Overflow high
//#define OVERFLOW_LOW (256) //!< Overflow low
//#define OVERFLOW_HIGH (1024) //!< Overflow high
#define OVERFLOW_LOW (64) //!< Overflow low
#define OVERFLOW_HIGH (256) //!< Overflow high
/*----------------------------------------------------------------------------------------------*/


Expand Down
1 change: 1 addition & 0 deletions includes/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ typedef unsigned int uint32;
#ifndef SPEED_OF_LIGHT
#define SPEED_OF_LIGHT (2.99792458e8) //!< Speed of light (m/s) as specified in IS-GPS-200D
#endif
#define INVERSE_L1 (6.347513678891978e-10) //!< 1/L1
#define INVERSE_SPEED_OF_LIGHT (3.33564095198152049576e-9) //!< Inverse speed of light
#define CODE_RATE (1.023e6) //!< L1 C/A code chipping rate
#define INVERSE_CODE_RATE (9.775171065493646e-07) //!< 1/L1 C/A code chipping rate
Expand Down
1 change: 0 additions & 1 deletion includes/protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ int32 code_gen(CPX *_dest, int32 _prn);
void sine_gen(CPX *_dest, double _f, double _fs, int32 _samps);
void sine_gen(CPX *_dest, double _f, double _fs, int32 _samps, double _p);
void wipeoff_gen(MIX *_dest, double _f, double _fs, int32 _samps);
void resample(CPX *_dest, CPX *_source, double _fdest, double _fsource, int32 _samps);
void downsample(CPX *_dest, CPX *_source, double _fdest, double _fsource, int32 _samps);
void init_agc(CPX *_buff, int32 _samps, int32 bits, int32 *scale);
int32 run_agc(CPX *_buff, int32 _samps, int32 bits, int32 scale);
Expand Down
2 changes: 1 addition & 1 deletion main/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void Parse_Arguments(int32 argc, char* argv[])
gopt.tlm_type = TELEM_NAMED_PIPE;
gopt.mode = 0; //!< Single board L1 mode by default
gopt.decimate = 16; //!< Default to work with both 65.536 and 64 MHz clocks
gopt.gr = 40; //!< 40 dB of RF gain
gopt.gr = 30; //!< 40 dB of RF gain
gopt.gi = 10; //!< 10 dB of IF gain
gopt.f_lo_a = L1 - IF_FREQUENCY; //!< Board A L1 by default
gopt.f_ddc_a = 0; //!< no DDC correction
Expand Down
Binary file added matlab/matlab.mat
Binary file not shown.
Loading

0 comments on commit 72a7fab

Please sign in to comment.