|
|
|
@ -36,7 +36,10 @@ m_latitude(0.0F),
|
|
|
|
|
m_longitude(0.0F),
|
|
|
|
|
m_height(0),
|
|
|
|
|
m_desc(),
|
|
|
|
|
m_suffix(suffix)
|
|
|
|
|
m_suffix(suffix),
|
|
|
|
|
m_mobileGPSAddress(),
|
|
|
|
|
m_mobileGPSPort(0U),
|
|
|
|
|
m_socket(NULL)
|
|
|
|
|
{
|
|
|
|
|
assert(!callsign.empty());
|
|
|
|
|
assert(!password.empty());
|
|
|
|
@ -65,9 +68,33 @@ void CAPRSWriter::setInfo(unsigned int txFrequency, unsigned int rxFrequency, fl
|
|
|
|
|
m_desc = desc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAPRSWriter::setMobileGPS(const std::string& address, unsigned int port)
|
|
|
|
|
{
|
|
|
|
|
assert(!address.empty());
|
|
|
|
|
assert(port > 0U);
|
|
|
|
|
|
|
|
|
|
m_mobileGPSAddress = CUDPSocket::lookup(address);
|
|
|
|
|
m_mobileGPSPort = port;
|
|
|
|
|
|
|
|
|
|
m_socket = new CUDPSocket;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CAPRSWriter::open()
|
|
|
|
|
{
|
|
|
|
|
if (m_socket != NULL) {
|
|
|
|
|
bool ret = m_socket->open();
|
|
|
|
|
if (!ret) {
|
|
|
|
|
delete m_socket;
|
|
|
|
|
m_socket = NULL;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Poll the GPS every minute
|
|
|
|
|
m_idTimer.setTimeout(60U);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_idTimer.start();
|
|
|
|
|
|
|
|
|
|
return m_thread->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -135,18 +162,39 @@ void CAPRSWriter::clock(unsigned int ms)
|
|
|
|
|
{
|
|
|
|
|
m_idTimer.clock(ms);
|
|
|
|
|
|
|
|
|
|
if (m_socket != NULL) {
|
|
|
|
|
if (m_idTimer.hasExpired()) {
|
|
|
|
|
pollGPS();
|
|
|
|
|
m_idTimer.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendIdFrameMobile();
|
|
|
|
|
} else {
|
|
|
|
|
if (m_idTimer.hasExpired()) {
|
|
|
|
|
sendIdFrames();
|
|
|
|
|
sendIdFrameFixed();
|
|
|
|
|
m_idTimer.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAPRSWriter::close()
|
|
|
|
|
{
|
|
|
|
|
if (m_socket != NULL) {
|
|
|
|
|
m_socket->close();
|
|
|
|
|
delete m_socket;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_thread->stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAPRSWriter::sendIdFrames()
|
|
|
|
|
bool CAPRSWriter::pollGPS()
|
|
|
|
|
{
|
|
|
|
|
assert(m_socket != NULL);
|
|
|
|
|
|
|
|
|
|
return m_socket->write((unsigned char*)"YSFGateway", 10U, m_mobileGPSAddress, m_mobileGPSPort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAPRSWriter::sendIdFrameFixed()
|
|
|
|
|
{
|
|
|
|
|
if (!m_thread->isConnected())
|
|
|
|
|
return;
|
|
|
|
@ -211,3 +259,92 @@ void CAPRSWriter::sendIdFrames()
|
|
|
|
|
|
|
|
|
|
m_idTimer.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAPRSWriter::sendIdFrameMobile()
|
|
|
|
|
{
|
|
|
|
|
// Grab GPS data if it's available
|
|
|
|
|
unsigned char buffer[200U];
|
|
|
|
|
in_addr address;
|
|
|
|
|
unsigned int port;
|
|
|
|
|
int ret = m_socket->read(buffer, 200U, address, port);
|
|
|
|
|
if (ret <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!m_thread->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
buffer[ret] = '\0';
|
|
|
|
|
|
|
|
|
|
// Parse the GPS data
|
|
|
|
|
char* p1 = ::strtok((char*)buffer, ","); // Latitude
|
|
|
|
|
char* p2 = ::strtok(NULL, ","); // Longitude
|
|
|
|
|
char* p3 = ::strtok(NULL, ","); // Altitude (m)
|
|
|
|
|
char* p4 = ::strtok(NULL, ","); // Speed (kms/h)
|
|
|
|
|
char* p5 = ::strtok(NULL, "\n"); // Bearing
|
|
|
|
|
|
|
|
|
|
if (p1 == NULL || p2 == NULL || p3 == NULL || p4 == NULL || p5 == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
float rawLatitude = ::atof(p1);
|
|
|
|
|
float rawLongitude = ::atof(p2);
|
|
|
|
|
float rawAltitude = ::atof(p3);
|
|
|
|
|
float rawSpeed = ::atof(p4);
|
|
|
|
|
float rawBearing = ::atof(p5);
|
|
|
|
|
|
|
|
|
|
char desc[200U];
|
|
|
|
|
if (m_txFrequency != 0U) {
|
|
|
|
|
float offset = float(int(m_rxFrequency) - int(m_txFrequency)) / 1000000.0F;
|
|
|
|
|
::sprintf(desc, "MMDVM Voice %.5LfMHz %c%.4lfMHz%s%s",
|
|
|
|
|
(long double)(m_txFrequency) / 1000000.0F,
|
|
|
|
|
offset < 0.0F ? '-' : '+',
|
|
|
|
|
::fabs(offset), m_desc.empty() ? "" : ", ", m_desc.c_str());
|
|
|
|
|
} else {
|
|
|
|
|
::sprintf(desc, "MMDVM Voice%s%s", m_desc.empty() ? "" : ", ", m_desc.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* band = "4m";
|
|
|
|
|
if (m_txFrequency >= 1200000000U)
|
|
|
|
|
band = "1.2";
|
|
|
|
|
else if (m_txFrequency >= 420000000U)
|
|
|
|
|
band = "440";
|
|
|
|
|
else if (m_txFrequency >= 144000000U)
|
|
|
|
|
band = "2m";
|
|
|
|
|
else if (m_txFrequency >= 50000000U)
|
|
|
|
|
band = "6m";
|
|
|
|
|
else if (m_txFrequency >= 28000000U)
|
|
|
|
|
band = "10m";
|
|
|
|
|
|
|
|
|
|
double tempLat = ::fabs(rawLatitude);
|
|
|
|
|
double tempLong = ::fabs(rawLongitude);
|
|
|
|
|
|
|
|
|
|
double latitude = ::floor(tempLat);
|
|
|
|
|
double longitude = ::floor(tempLong);
|
|
|
|
|
|
|
|
|
|
latitude = (tempLat - latitude) * 60.0 + latitude * 100.0;
|
|
|
|
|
longitude = (tempLong - longitude) * 60.0 + longitude * 100.0;
|
|
|
|
|
|
|
|
|
|
char lat[20U];
|
|
|
|
|
::sprintf(lat, "%07.2lf", latitude);
|
|
|
|
|
|
|
|
|
|
char lon[20U];
|
|
|
|
|
::sprintf(lon, "%08.2lf", longitude);
|
|
|
|
|
|
|
|
|
|
std::string server = m_callsign;
|
|
|
|
|
size_t pos = server.find_first_of('-');
|
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
|
server.append("-S");
|
|
|
|
|
else
|
|
|
|
|
server.append("S");
|
|
|
|
|
|
|
|
|
|
char output[500U];
|
|
|
|
|
::sprintf(output, "%s>APDG03,TCPIP*,qAC,%s:!%s%cD%s%c&%03.0f/%03.0f/A=%06.0f%s %s",
|
|
|
|
|
m_callsign.c_str(), server.c_str(),
|
|
|
|
|
lat, (rawLatitude < 0.0F) ? 'S' : 'N',
|
|
|
|
|
lon, (rawLongitude < 0.0F) ? 'W' : 'E',
|
|
|
|
|
rawBearing, rawSpeed * 0.539957F,
|
|
|
|
|
float(rawAltitude) * 3.28F, band, desc);
|
|
|
|
|
|
|
|
|
|
m_thread->write(output);
|
|
|
|
|
|
|
|
|
|
m_idTimer.start();
|
|
|
|
|
}
|
|
|
|
|