Skip to content

Commit

Permalink
Added watchdog to monitor USRP/GN3S. Attempts to restart USRP/GN3S dr…
Browse files Browse the repository at this point in the history
…iver if no reads have occured for 1 second.
  • Loading branch information
gpssim committed Sep 14, 2009
1 parent e1a696e commit 271efd1
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 16 deletions.
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 > 1000)
if(pchan->count > 2000)
{

str2.Clear();
Expand Down
1 change: 1 addition & 0 deletions includes/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ EXTERN class SV_Select *pSV_Select; //!< Contains the channels and drives t
EXTERN class Telemetry *pTelemetry; //!< Simple ncurses interface
EXTERN class Commando *pCommando; //!< Process and execute commands
EXTERN class GPS_Source *pSource; //!< Get the GPS data from somewhere
EXTERN class Patience *pPatience; //!< Watchdog for GPS Source
/*----------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------*/
Expand Down
12 changes: 9 additions & 3 deletions main/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "commando.h" //!< Command interface
#include "sv_select.h" //!< Drives acquisition/reacquisition process
#include "gps_source.h" //!< Get GPS IF data from where?
#include "patience.h"
/*----------------------------------------------------------------------------------------------*/


Expand Down Expand Up @@ -290,11 +291,11 @@ int32 Object_Init(void)
for(lcv = 0; lcv < MAX_CHANNELS; lcv++)
pChannels[lcv] = new Channel(lcv);

/* Get data from either the USRP or disk */
/* Get data from either the USRP/GN3S/disk */
pFIFO = new FIFO;

/* Draw the GPS data from somewhere */
pSource = new GPS_Source(&gopt);
/* Startup Watchdog */
pPatience = new Patience;

pCorrelator = new Correlator();

Expand Down Expand Up @@ -393,6 +394,11 @@ int32 Thread_Init(void)
/* Start up the FIFO */
pFIFO->Start();

sleep(1);

/* Start up the Watchdog */
pPatience->Start();

return(1);

}
Expand Down
6 changes: 5 additions & 1 deletion main/shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "commando.h" //!< Command interface
#include "sv_select.h" //!< Drives acquisition/reacquisition process
#include "gps_source.h" //!< Get GPS data
#include "patience.h"
/*----------------------------------------------------------------------------------------------*/


Expand All @@ -50,6 +51,9 @@ void Thread_Shutdown(void)
/* Start the keyboard thread to handle user input from stdio */
pKeyboard->Stop();

/* Stop the WatchDog */
pPatience->Stop();

/* Stop the FIFO */
pFIFO->Stop();

Expand Down Expand Up @@ -132,11 +136,11 @@ void Object_Shutdown(void)
delete pAcquisition;
delete pEphemeris;
delete pFIFO;
delete pSource;
delete pSV_Select;
delete pTelemetry;
delete pPVT;
delete pCommando;
delete pPatience;

}
/*----------------------------------------------------------------------------------------------*/
Expand Down
20 changes: 10 additions & 10 deletions objects/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,12 @@ void Channel::FrequencyLock()
void Channel::DLL()
{

float code_err;
float ep, lp, sp;
double code_err;
double ep, lp, sp;

ep = sqrt(float(P[0]));
lp = sqrt(float(P[2]));
sp = sqrt(float(P_avg));
ep = sqrt(double(P[0]));
lp = sqrt(double(P[2]));
sp = sqrt(double(P[2] + P[0]));

code_err = (ep - lp) / sp;

Expand All @@ -452,10 +452,10 @@ void Channel::DLL()
void Channel::PLL()
{

float df;
float dp;
float dot;
float cross;
double df;
double dp;
double dot;
double cross;
int32 I1, I2, Q1, Q2, lcv;

df = dp = 0;
Expand All @@ -479,7 +479,7 @@ void Channel::PLL()
/* PLL discriminator */
if(I[1] != 0)
{
dp = atan((float)Q[1]/(float)I[1])/TWO_PI;
dp = atan((double)Q[1]/(double)I[1])/TWO_PI;
}

/* Lock indicators */
Expand Down
32 changes: 31 additions & 1 deletion objects/fifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ void *FIFO_Thread(void *_arg)

FIFO *aFIFO = pFIFO;

/* This thread must be cancellable by the watchdog */
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

while(grun)
{
aFIFO->Import();
Expand Down Expand Up @@ -60,6 +64,7 @@ void FIFO::Start()
/*----------------------------------------------------------------------------------------------*/
FIFO::FIFO():Threaded_Object("FIFTASK")
{

int32 lcv;

/* Create the buffer */
Expand All @@ -79,6 +84,9 @@ FIFO::FIFO():Threaded_Object("FIFTASK")
sem_init(&sem_full, NULL, 0);
sem_init(&sem_empty, NULL, FIFO_DEPTH);

pSource = NULL;
ResetSource();

if(gopt.verbose)
fprintf(stdout,"Creating FIFO\n");

Expand All @@ -96,6 +104,9 @@ FIFO::~FIFO()

delete [] buff;

if(pSource != NULL)
delete pSource;

if(gopt.verbose)
fprintf(stdout,"Destructing FIFO\n");

Expand All @@ -110,7 +121,8 @@ void FIFO::Import()
IncStartTic();

/* Read from the GPS source */
pSource->Read(head);
if(pSource != NULL)
pSource->Read(head);

Enqueue();

Expand Down Expand Up @@ -155,3 +167,21 @@ void FIFO::Dequeue(ms_packet *p)
}
/*----------------------------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------------------------*/
void FIFO::ResetSource()
{

if(pSource != NULL)
{
delete pSource;
pSource = new GPS_Source(&gopt);
}
else
{
pSource = new GPS_Source(&gopt);
}

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

104 changes: 104 additions & 0 deletions objects/patience.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*----------------------------------------------------------------------------------------------*/
/*! \file keyboard.cpp
//
// FILENAME: keyboard.cpp
//
// DESCRIPTION: Defines the keyboard class.
//
// DEVELOPERS: Gregory W. Heckler (2003-2009)
//
// LICENSE TERMS: Copyright (c) Gregory W. Heckler 2009
//
// This file is part of the GPS Software Defined Radio (GPS-SDR)
//
// The GPS-SDR 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 2 of
// the License, or (at your option) any later version. The GPS-SDR 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.
//
// Note: Comments within this file follow a syntax that is compatible with
// DOXYGEN and are utilized for automated document extraction
//
// Reference:
*/
/*----------------------------------------------------------------------------------------------*/

#include "patience.h"

/*----------------------------------------------------------------------------------------------*/
void *Patience_Thread(void *_arg)
{

Patience *aPatience = pPatience;

while(grun)
{
aPatience->PetMe();
}

pthread_exit(0);

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


/*----------------------------------------------------------------------------------------------*/
void Patience::Start()
{
Start_Thread(Patience_Thread, NULL);

if(gopt.verbose)
fprintf(stdout,"Patience thread started\n");
}
/*----------------------------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------------------------*/
Patience::Patience():Threaded_Object("KEYTASK")
{

last_tic = 0;

if(gopt.verbose)
fprintf(stdout,"Creating Patience\n");
}
/*----------------------------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------------------------*/
Patience::~Patience()
{
if(gopt.verbose)
fprintf(stdout,"Destructing Patience\n");
}
/*----------------------------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------------------------*/
void Patience::PetMe()
{

uint32 new_tic;

if(pFIFO != NULL)
{
new_tic = pFIFO->getExecTic();
if(new_tic == last_tic)
{
fprintf(stdout, "Watchdog Tripped!\n");
pFIFO->Stop();
pFIFO->ResetSource();
pFIFO->Start();
last_tic = 0;
}
else
{
last_tic = new_tic;
}
}

sleep(1);
}
/*----------------------------------------------------------------------------------------------*/
53 changes: 53 additions & 0 deletions objects/patience.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------------------------*/
/*! \file patience.h
//
// FILENAME: patience.h
//
// DESCRIPTION: Defines the patience class.
//
// DEVELOPERS: Gregory W. Heckler (2003-2009)
//
// LICENSE TERMS: Copyright (c) Gregory W. Heckler 2009
//
// This file is part of the GPS Software Defined Radio (GPS-SDR)
//
// The GPS-SDR 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 2 of
// the License, or (at your option) any later version. The GPS-SDR 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.
//
// Note: Comments within this file follow a syntax that is compatible with
// DOXYGEN and are utilized for automated document extraction
//
// Reference:
*/
/*----------------------------------------------------------------------------------------------*/

#ifndef PATIENCE_H_
#define PATIENCE_H_

#include "includes.h"
#include "fifo.h"

/*! \ingroup CLASSES
*
*/
class Patience : public Threaded_Object
{

private:

uint32 last_tic;

public:

Patience();
~Patience();
void Start();
void PetMe();

};

#endif /* PATIENCE_H_ */

0 comments on commit 271efd1

Please sign in to comment.