Rebiuld of timer structure. Now Gpsd and Nmea data are evaluated.
This commit is contained in:
parent
af9e04bf82
commit
6d1619a10a
|
|
@ -119,8 +119,8 @@ using namespace SvxLink;
|
|||
|
||||
AprsTcpClient::AprsTcpClient(LocationInfo::Cfg &loc_cfg,
|
||||
const std::string &server, int port)
|
||||
: loc_cfg(loc_cfg), server(server), port(port), con(0), beacon_timer(0),
|
||||
reconnect_timer(0), offset_timer(0), num_connected(0)
|
||||
: loc_cfg(loc_cfg), server(server), port(port), con(0), reconnect_timer(0),
|
||||
num_connected(0)
|
||||
{
|
||||
StrList str_list;
|
||||
|
||||
|
|
@ -135,15 +135,6 @@ AprsTcpClient::AprsTcpClient(LocationInfo::Cfg &loc_cfg,
|
|||
con->dataReceived.connect(mem_fun(*this, &AprsTcpClient::tcpDataReceived));
|
||||
con->connect();
|
||||
|
||||
beacon_timer = new Timer(loc_cfg.interval, Timer::TYPE_PERIODIC);
|
||||
beacon_timer->setEnable(false);
|
||||
beacon_timer->expired.connect(mem_fun(*this, &AprsTcpClient::sendAprsBeacon));
|
||||
|
||||
offset_timer = new Timer(10000, Timer::TYPE_ONESHOT);
|
||||
offset_timer->setEnable(false);
|
||||
offset_timer->expired.connect(mem_fun(*this,
|
||||
&AprsTcpClient::startNormalSequence));
|
||||
|
||||
reconnect_timer = new Timer(5000);
|
||||
reconnect_timer->setEnable(false);
|
||||
reconnect_timer->expired.connect(mem_fun(*this,
|
||||
|
|
@ -155,8 +146,6 @@ AprsTcpClient::~AprsTcpClient(void)
|
|||
{
|
||||
delete con;
|
||||
delete reconnect_timer;
|
||||
delete offset_timer;
|
||||
delete beacon_timer;
|
||||
} /* AprsTcpClient::~AprsTcpClient */
|
||||
|
||||
|
||||
|
|
@ -362,19 +351,9 @@ void AprsTcpClient::tcpConnected(void)
|
|||
" on port " << con->remotePort() << endl;
|
||||
|
||||
aprsLogin(); // login
|
||||
offset_timer->reset(); // reset the offset_timer
|
||||
offset_timer->setEnable(true); // restart the offset_timer
|
||||
} /* AprsTcpClient::tcpConnected */
|
||||
|
||||
|
||||
void AprsTcpClient::startNormalSequence(Timer *t)
|
||||
{
|
||||
sendAprsBeacon(t);
|
||||
beacon_timer->setEnable(true); // start the beaconinterval
|
||||
} /* AprsTcpClient::startNormalSequence */
|
||||
|
||||
|
||||
|
||||
// ToDo: possible interaction of SvxLink on commands sended via
|
||||
// APRS-net
|
||||
int AprsTcpClient::tcpDataReceived(TcpClient<>::TcpConnection *con,
|
||||
|
|
@ -390,10 +369,7 @@ void AprsTcpClient::tcpDisconnected(TcpClient<>::TcpConnection *con,
|
|||
{
|
||||
cout << "*** WARNING: Disconnected from APRS server" << endl;
|
||||
|
||||
beacon_timer->setEnable(false); // no beacon while disconnected
|
||||
reconnect_timer->setEnable(true); // start the reconnect-timer
|
||||
offset_timer->setEnable(false);
|
||||
offset_timer->reset();
|
||||
} /* AprsTcpClient::tcpDisconnected */
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -134,9 +134,8 @@ class AprsTcpClient : public AprsClient, public sigc::trackable
|
|||
std::string server;
|
||||
int port;
|
||||
Async::TcpClient<>* con;
|
||||
Async::Timer *beacon_timer;
|
||||
Async::Timer *reconnect_timer;
|
||||
Async::Timer *offset_timer;
|
||||
|
||||
|
||||
int num_connected;
|
||||
|
||||
|
|
@ -157,7 +156,6 @@ class AprsTcpClient : public AprsClient, public sigc::trackable
|
|||
void tcpDisconnected(Async::TcpClient<>::TcpConnection *con,
|
||||
Async::TcpClient<>::DisconnectReason reason);
|
||||
void reconnectAprsServer(Async::Timer *t);
|
||||
void startNormalSequence(Async::Timer *t);
|
||||
void sendABeacon(void);
|
||||
|
||||
}; /* class AprsTcpClient */
|
||||
|
|
|
|||
|
|
@ -178,7 +178,6 @@ bool LocationInfo::initialize(const Async::Config &cfg, const std::string &cfg_n
|
|||
}
|
||||
else if (cfg.getValue(cfg_name, "GPSD", value))
|
||||
{
|
||||
cout << "connecting GPSD" << endl;
|
||||
init_ok &= LocationInfo::_instance->initGpsdClient(cfg, cfg_name);
|
||||
}
|
||||
else
|
||||
|
|
@ -202,6 +201,8 @@ bool LocationInfo::initialize(const Async::Config &cfg, const std::string &cfg_n
|
|||
value = cfg.getValue(cfg_name, "PTY_PATH");
|
||||
LocationInfo::_instance->initExtPty(value);
|
||||
|
||||
LocationInfo::_instance->beacontimer(cfg, cfg_name);
|
||||
|
||||
if( !init_ok )
|
||||
{
|
||||
delete LocationInfo::_instance;
|
||||
|
|
@ -461,19 +462,6 @@ bool LocationInfo::parseStationHW(const Async::Config &cfg, const string &name)
|
|||
success = false;
|
||||
}
|
||||
|
||||
int interval = 10;
|
||||
int max = numeric_limits<int>::max();
|
||||
if (!cfg.getValue(name, "BEACON_INTERVAL", 10, max, interval, true))
|
||||
{
|
||||
print_error(name, "BEACON_INTERVAL", cfg.getValue(name, "BEACON_INTERVAL"),
|
||||
"BEACON_INTERVAL=10");
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
loc_cfg.interval = 60 * 1000 * interval;
|
||||
}
|
||||
|
||||
loc_cfg.range = calculateRange(loc_cfg);
|
||||
|
||||
return success;
|
||||
|
|
@ -758,7 +746,6 @@ void LocationInfo::handleNmea(std::string message)
|
|||
|
||||
if (rmatch(message, reg))
|
||||
{
|
||||
Position pos;
|
||||
getNextStr(message); // GPRMC
|
||||
getNextStr(message); // Time Stamp
|
||||
std::string valid = getNextStr(message); // validity A - ok, V - invalid
|
||||
|
|
@ -773,64 +760,98 @@ void LocationInfo::handleNmea(std::string message)
|
|||
if (ns[0] == 'S') pos.lat *= -1.0;
|
||||
pos.lon = atoi(lon.substr(0,3).c_str()) + atof(lon.substr(3,8).c_str())/60.0;
|
||||
if (ew[0] == 'W') pos.lon *= -1.0;
|
||||
|
||||
sendAprsPosition(pos);
|
||||
checkPosition();
|
||||
}
|
||||
} /* LocationInfo::handleNmea */
|
||||
|
||||
void LocationInfo::sendAprsPosition(const Position pos)
|
||||
|
||||
void LocationInfo::beacontimer(const Config &cfg, const std::string &name)
|
||||
{
|
||||
|
||||
int interval = 10;
|
||||
int max = numeric_limits<int>::max();
|
||||
|
||||
if (!cfg.getValue(name, "BEACON_INTERVAL", 10, max, interval, true))
|
||||
{
|
||||
print_error(name, "BEACON_INTERVAL", cfg.getValue(name, "BEACON_INTERVAL"),
|
||||
"BEACON_INTERVAL=10");
|
||||
}
|
||||
else
|
||||
{
|
||||
loc_cfg.interval = 60 * 1000 * interval;
|
||||
}
|
||||
beacon_timer = new Timer(loc_cfg.interval , Timer::TYPE_PERIODIC);
|
||||
beacon_timer->setEnable(false);
|
||||
beacon_timer->expired.connect(mem_fun(*this, &LocationInfo::sendAprsBeacon));
|
||||
|
||||
offset_timer = new Timer(5000, Timer::TYPE_ONESHOT);
|
||||
offset_timer->setEnable(true);
|
||||
offset_timer->expired.connect(mem_fun(*this,
|
||||
&LocationInfo::startNormalSequence));
|
||||
} /* LocationInfo::beacontimer */
|
||||
|
||||
|
||||
void LocationInfo::startNormalSequence(Async::Timer *t)
|
||||
{
|
||||
sendAprsPosition();
|
||||
beacon_timer->setEnable(true);
|
||||
} /* LocationInfo::startNormalSequence */
|
||||
|
||||
|
||||
void LocationInfo::checkPosition(void)
|
||||
{
|
||||
if (stored_lat == 0.0) stored_lat = pos.lat;
|
||||
if (stored_lon == 0.0) stored_lon = pos.lon;
|
||||
|
||||
float dist = calcDistance(pos.lat, pos.lon, stored_lat, stored_lon);
|
||||
if (dist > 0.5)
|
||||
{
|
||||
if (pos.lat >= 0)
|
||||
{
|
||||
loc_cfg.lat_pos.dir = 'N';
|
||||
}
|
||||
else
|
||||
{
|
||||
loc_cfg.lat_pos.dir = 'S';
|
||||
}
|
||||
if (pos.lon >= 0)
|
||||
{
|
||||
loc_cfg.lon_pos.dir = 'E';
|
||||
}
|
||||
else
|
||||
{
|
||||
loc_cfg.lon_pos.dir = 'W';
|
||||
}
|
||||
sendAprsPosition();
|
||||
}
|
||||
} /* LocationInfo::checkPosition */
|
||||
|
||||
loc_cfg.lat_pos.deg = int(abs(pos.lat));
|
||||
loc_cfg.lat_pos.min = int(60*(abs(pos.lat)-int(abs(pos.lat))));
|
||||
loc_cfg.lat_pos.sec = 60*(60*(abs(pos.lat)-int(abs(pos.lat))) - loc_cfg.lat_pos.min);
|
||||
|
||||
loc_cfg.lon_pos.deg = abs(int(pos.lon));
|
||||
loc_cfg.lon_pos.min = int(60*(abs(pos.lon)-int(abs(pos.lon))));
|
||||
loc_cfg.lon_pos.sec = 60*(60*(abs(pos.lon)-int(abs(pos.lon))) - loc_cfg.lon_pos.min);
|
||||
void LocationInfo::sendAprsBeacon(Async::Timer *t)
|
||||
{
|
||||
sendAprsPosition();
|
||||
} /* LocationInfo::sendAprsBeacon */
|
||||
|
||||
// loc_cfg.lat_pos.min = atoi(lat.substr(2,2).c_str());
|
||||
// loc_cfg.lat_pos.sec = 60*atoi(lat.substr(5,4).c_str())/10000;
|
||||
// loc_cfg.lat_pos.dir = ns[0];
|
||||
|
||||
// float lat_dec = loc_cfg.lat_pos.deg + atof(lat.substr(2,8).c_str())/60.0;
|
||||
// loc_cfg.lon_pos.deg = atoi(lon.substr(0,3).c_str());
|
||||
// loc_cfg.lon_pos.min = atoi(lon.substr(3,2).c_str());
|
||||
// loc_cfg.lon_pos.sec = 60*atoi(lon.substr(6,4).c_str())/10000;
|
||||
// loc_cfg.lon_pos.dir = ew[0];
|
||||
|
||||
stored_lat = pos.lat;
|
||||
stored_lon = pos.lon;
|
||||
|
||||
ClientList::const_iterator it;
|
||||
for (it = clients.begin(); it != clients.end(); it++)
|
||||
{
|
||||
(*it)->sendBeacon();
|
||||
}
|
||||
}
|
||||
void LocationInfo::sendAprsPosition(void)
|
||||
{
|
||||
if (pos.lat >= 0)
|
||||
{
|
||||
loc_cfg.lat_pos.dir = 'N';
|
||||
}
|
||||
else
|
||||
{
|
||||
loc_cfg.lat_pos.dir = 'S';
|
||||
}
|
||||
if (pos.lon >= 0)
|
||||
{
|
||||
loc_cfg.lon_pos.dir = 'E';
|
||||
}
|
||||
else
|
||||
{
|
||||
loc_cfg.lon_pos.dir = 'W';
|
||||
}
|
||||
|
||||
loc_cfg.lat_pos.deg = int(abs(pos.lat));
|
||||
loc_cfg.lat_pos.min = int(60*(abs(pos.lat)-int(abs(pos.lat))));
|
||||
loc_cfg.lat_pos.sec = 60*(60*(abs(pos.lat)-int(abs(pos.lat))) - loc_cfg.lat_pos.min);
|
||||
|
||||
loc_cfg.lon_pos.deg = abs(int(pos.lon));
|
||||
loc_cfg.lon_pos.min = int(60*(abs(pos.lon)-int(abs(pos.lon))));
|
||||
loc_cfg.lon_pos.sec = 60*(60*(abs(pos.lon)-int(abs(pos.lon))) - loc_cfg.lon_pos.min);
|
||||
|
||||
stored_lat = pos.lat;
|
||||
stored_lon = pos.lon;
|
||||
|
||||
ClientList::const_iterator it;
|
||||
for (it = clients.begin(); it != clients.end(); it++)
|
||||
{
|
||||
(*it)->sendBeacon();
|
||||
}
|
||||
} /* LocationInfo::sendAprsMessage */
|
||||
|
||||
|
||||
|
|
@ -926,9 +947,10 @@ bool LocationInfo::initGpsdClient(const Config &cfg, const std::string &name)
|
|||
} /* LocationInfo::initGpsdClient */
|
||||
|
||||
|
||||
void LocationInfo::gpsdDataReceived(const Position pos)
|
||||
void LocationInfo::gpsdDataReceived(const Position ownpos)
|
||||
{
|
||||
sendAprsPosition(pos);
|
||||
pos = ownpos;
|
||||
checkPosition();
|
||||
} /* LocationInfo::gpsdReceived */
|
||||
|
||||
// Put all locally defined functions in an anonymous namespace to make them
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
#include <vector>
|
||||
#include <list>
|
||||
#include <sys/time.h>
|
||||
//#include <json/json.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -211,9 +210,14 @@ class LocationInfo
|
|||
private:
|
||||
static LocationInfo* _instance;
|
||||
LocationInfo() : sequence(0), aprs_stats_timer(0), sinterval(0), nmeadev(0),
|
||||
stored_lat(0), stored_lon(0) {}
|
||||
stored_lat(0), stored_lon(0), beacon_timer(0), offset_timer(0) {}
|
||||
LocationInfo(const LocationInfo&);
|
||||
~LocationInfo(void) { delete aprs_stats_timer; delete nmeadev; };
|
||||
~LocationInfo(void) {
|
||||
delete aprs_stats_timer;
|
||||
delete offset_timer;
|
||||
delete beacon_timer;
|
||||
delete nmeadev;
|
||||
};
|
||||
|
||||
typedef std::list<AprsClient*> ClientList;
|
||||
|
||||
|
|
@ -226,11 +230,13 @@ class LocationInfo
|
|||
Async::Serial *nmeadev;
|
||||
float stored_lat;
|
||||
float stored_lon;
|
||||
Async::Timer *beacon_timer;
|
||||
Async::Timer *offset_timer;
|
||||
Position pos;
|
||||
|
||||
bool parsePosition(const Async::Config &cfg, const std::string &name);
|
||||
bool parseLatitude(Coordinate &pos, const std::string &value);
|
||||
bool parseLongitude(Coordinate &pos, const std::string &value);
|
||||
|
||||
bool parseStationHW(const Async::Config &cfg, const std::string &name);
|
||||
bool parsePath(const Async::Config &cfg, const std::string &name);
|
||||
int calculateRange(const Cfg &cfg);
|
||||
|
|
@ -238,18 +244,22 @@ class LocationInfo
|
|||
bool parseClientStr(std::string &host, int &port, const std::string &val);
|
||||
bool parseClients(const Async::Config &cfg, const std::string &name);
|
||||
void startStatisticsTimer(int interval);
|
||||
void startNormalSequence(Async::Timer *t);
|
||||
void sendAprsStatistics(Async::Timer *t);
|
||||
void initExtPty(std::string ptydevice);
|
||||
void mesReceived(std::string message);
|
||||
void onNmeaReceived(char *buf, int count);
|
||||
void checkPosition(void);
|
||||
void handleNmea(std::string message);
|
||||
std::string getNextStr(std::string& h);
|
||||
void beacontimer(const Async::Config &cfg, const std::string &name);
|
||||
float calcDistance(float lat1, float lon1, float lat2, float lon2);
|
||||
bool initNmeaDev(const Async::Config &cfg, const std::string &name);
|
||||
bool rmatch(std::string tok, std::string pattern);
|
||||
bool initGpsdClient(const Async::Config &cfg, const std::string &name);
|
||||
void gpsdDataReceived(const Position pos);
|
||||
void sendAprsPosition(const Position pos);
|
||||
void sendAprsPosition(void);
|
||||
void sendAprsBeacon(Async::Timer *t);
|
||||
|
||||
}; /* class LocationInfo */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue