replaced nanosleep with std::this_thread::sleep_for

pull/1/head
Tom Early 8 years ago
parent 32afce0de3
commit ae312549ab

@ -1,5 +1,5 @@
/*
* Copyright 2017 by Thomas Early, N7TAE
* Copyright 2017-2018 by Thomas Early, N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -24,6 +24,8 @@
#include <termios.h>
#include <time.h>
#include <sys/file.h>
#include <sys/select.h>
#include "DVAPDongle.h"
extern void traceit(const char *fmt,...);
@ -303,7 +305,7 @@ bool CDVAPDongle::get_ser(char *dvp, char *dvap_serial_number)
if (0 == strcmp(dvapreg.param.sstr, dvap_serial_number)) {
traceit("Using %s: %s, because serial number matches your dvap_rptr.cfg\n", dvp, dvap_serial_number);
return true;
}
}
traceit("Device %s has serial %s, but does not match your config value %s\n", dvp, dvapreg.param.sstr, dvap_serial_number);
return false;
}
@ -434,7 +436,7 @@ bool CDVAPDongle::set_sql(int squelch)
{
unsigned cnt = 0;
REPLY_TYPE reply;
dvapreg.header = 0x5u;
dvapreg.param.control = 0x80u;
if (squelch < -128) {
@ -471,7 +473,7 @@ bool CDVAPDongle::set_pwr(int power)
{
unsigned cnt = 0;
REPLY_TYPE reply;
dvapreg.header = 0x6u;
dvapreg.param.control = 0x138u;
if (power < -12) {
@ -582,7 +584,7 @@ bool CDVAPDongle::set_freq(int frequency)
dvapreg.header = 0x8u;
dvapreg.param.control = 0x220u;
dvapreg.param.dword = frequency;
rc = write_to_dvp(&dvapreg, 8);
if (rc != 8) {
traceit("Failed to send request to set dvap frequency\n");

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 by Thomas A. Early N7TAE
* Copyright (C) 2016-2018 by Thomas A. Early N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -24,6 +24,9 @@
#include <netdb.h>
#include <netinet/tcp.h>
#include <thread>
#include <chrono>
#include "aprs.h"
// This is called when header comes in from repeater
@ -152,7 +155,7 @@ void CAPRS::Init()
aprs_streamID[i].streamID = 0;
aprs_streamID[i].last_time = 0;
}
/* Initialize the APRS host */
memset(&aprs_addr,0,sizeof(struct sockaddr_in));
aprs_addr_len = sizeof(aprs_addr);
@ -253,8 +256,6 @@ unsigned int CAPRS::GetData(short int rptr_idx, unsigned char *data, unsigned in
void CAPRS::Open(const std::string OWNER)
{
struct timespec req;
fd_set fdset;
struct timeval tv;
short int MAX_WAIT = 15; /* 15 seconds wait time MAX */
@ -356,9 +357,7 @@ void CAPRS::Open(const std::string OWNER)
if (rc < 0) {
if (errno == EWOULDBLOCK) {
recv(aprs_sock, rcv_buf, sizeof(rcv_buf), 0);
req.tv_sec = 0;
req.tv_nsec = 100000000; // 100 milli
nanosleep(&req, NULL);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
} else {
traceit("APRS login command failed, error=%d\n", errno);
break;
@ -501,7 +500,7 @@ ssize_t CAPRS::WriteSock(char *buffer, size_t n)
ssize_t num_written = 0;
size_t tot_written = 0;
char *buf = buffer;
for (tot_written = 0; tot_written < n;) {
num_written = write(aprs_sock, buf, n - tot_written);
if (num_written <= 0) {

@ -32,7 +32,6 @@
#include <fcntl.h>
#include <arpa/inet.h>
#include <signal.h>
#include <time.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/ioctl.h>
@ -43,6 +42,8 @@
#include <atomic>
#include <future>
#include <exception>
#include <thread>
#include <chrono>
#include <string>
#include <libconfig.h++>
using namespace libconfig;
@ -276,7 +277,7 @@ static int read_config(const char *cfgFile)
traceit("%s.login is not defined!\n", dvap_path.c_str());
return 1;
}
if (cfg.lookupValue("ircddb.login", value)) {
int l = value.length();
if (l<3 || l>CALL_SIZE-2) {
@ -720,7 +721,7 @@ int main(int argc, const char **argv)
keep_running = false;
}
traceit("Started ReadDVAPThread()\n");
while (keep_running) {
time(&tnow);
if ((tnow - ackpoint) > 2) {
@ -759,7 +760,6 @@ static void RptrAckThread(SDVAP_ACK_ARG *parg)
time_t tnow = 0;
unsigned char silence[12] = { 0x4e,0x8d,0x32,0x88,0x26,0x1a,0x3f,0x61,0xe8,0x70,0x4f,0x93 };
unsigned int aseed_ack = 0;
struct timespec nanos;
act.sa_handler = sig_catch;
sigemptyset(&act.sa_mask);
@ -800,9 +800,7 @@ static void RptrAckThread(SDVAP_ACK_ARG *parg)
memcpy(dr.frame.hdr.sfx, (unsigned char *)" ", 4);
calcPFCS(dr.frame.hdr.flag, dr.frame.hdr.pfcs);
dongle.SendRegister(dr);
nanos.tv_sec = 0;
nanos.tv_nsec = DELAY_BETWEEN * 1000000;
nanosleep(&nanos,0);
std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_BETWEEN));
// SYNC
dr.header = 0xc012u;
@ -869,11 +867,8 @@ static void RptrAckThread(SDVAP_ACK_ARG *parg)
}
memcpy(&dr.frame.vad.voice, silence, 12);
dongle.SendRegister(dr);
if (i < 9) {
nanos.tv_sec = 0;
nanos.tv_nsec = DELAY_BETWEEN * 1000000;
nanosleep(&nanos,0);
}
if (i < 9)
std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_BETWEEN));
}
return;
}
@ -984,7 +979,7 @@ static void ReadDVAPThread()
if (ok) {
if ((dr.frame.hdr.flag[0] != 0x00) && (dr.frame.hdr.flag[0] != 0x08) && // net
(dr.frame.hdr.flag[0] != 0x20) && (dr.frame.hdr.flag[0] != 0x28) && // flags
(dr.frame.hdr.flag[0] != 0x40) && (dr.frame.hdr.flag[0] != 0x48) && // rptr
(dr.frame.hdr.flag[0] != 0x60) && (dr.frame.hdr.flag[0] != 0x68)) // flags
ok = false;

@ -36,7 +36,6 @@
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <math.h>
#include <sys/time.h>
#include <sys/stat.h>
@ -53,6 +52,8 @@
#include <future>
#include <exception>
#include <string>
#include <thread>
#include <chrono>
#include <map>
#include <libconfig.h++>
using namespace libconfig;
@ -519,15 +520,13 @@ static int open_port(const SPORTIP &pip)
close(sock);
return -1;
}
return sock;
}
/* receive data from the irc server and save it */
static void GetIRCDataThread()
{
struct timespec req;
std::string user, rptr, gateway, ipaddr;
DSTAR_PROTOCOL proto;
IRCDDB_RESPONSE_TYPE type;
@ -632,9 +631,7 @@ static void GetIRCDataThread()
}
}
}
req.tv_sec = 0;
req.tv_nsec = 500000000; // 500 milli
nanosleep(&req, NULL);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
traceit("GetIRCDataThread exiting...\n");
return;
@ -1139,7 +1136,7 @@ static void runit()
int dtmf_last_frame[3] = { 0, 0, 0 };
unsigned int dtmf_counter[3] = { 0, 0, 0 };
if (recvlen == 58) {
if (bool_qso_details)
traceit("START from rptr: cntr=%04x, streamID=%04x, flags=%02x:%02x:%02x, my=%.8s, sfx=%.4s, ur=%.8s, rpt1=%.8s, rpt2=%.8s, %d bytes fromIP=%s\n",
rptrbuf.counter,
@ -2234,8 +2231,6 @@ static void compute_aprs_hash()
void APRSBeaconThread()
{
struct timespec req;
char snd_buf[512];
char rcv_buf[512];
time_t tnow = 0;
@ -2350,9 +2345,7 @@ void APRSBeaconThread()
close(aprs->GetSock());
aprs->SetSock( -1 );
} else if (errno == EWOULDBLOCK) {
req.tv_sec = 0;
req.tv_nsec = 100000000; // 100 milli
nanosleep(&req, NULL);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
} else {
/* Cant do nothing about it */
traceit("send_aprs_beacon failed, error=%d\n", errno);
@ -2401,9 +2394,7 @@ void APRSBeaconThread()
} else
THRESHOLD_COUNTDOWN = 15;
req.tv_sec = 0;
req.tv_nsec = 100000000; // 100 milli
nanosleep(&req, NULL);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
/* 20 seconds passed already ? */
time(&tnow);
@ -2429,8 +2420,6 @@ void APRSBeaconThread()
static void PlayFileThread(char *file)
{
struct timespec req;
unsigned short rlen = 0;
unsigned char dstar_buf[56];
unsigned char rptr_buf[58];
@ -2533,9 +2522,7 @@ static void PlayFileThread(char *file)
toRptr[i].G2_COUNTER ++;
req.tv_sec = 0;
req.tv_nsec = play_delay * 1000000;
nanosleep(&req, NULL);
std::this_thread::sleep_for(std::chrono::milliseconds(play_delay));
}
}
fclose(fp);
@ -2687,7 +2674,7 @@ int main(int argc, char **argv)
recd[i].fd = -1;
memset(recd[i].file, 0, sizeof(recd[i].file));
// recording for voicemail on local repeater modules
// recording for voicemail on local repeater modules
vm[i].last_time = 0;
vm[i].streamid = 0;
vm[i].fd = -1;

@ -1,8 +1,7 @@
/*
* Copyright (C) 2010 by Scott Lawson KI4LKF
* Additional:
* Copyright (C) 2015 by Thomas A. Early N7TAE
* Copyright (C) 2015,2018 by Thomas A. Early N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -31,8 +30,6 @@
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <regex.h>
#include <sys/stat.h>
@ -52,6 +49,8 @@
#include <set>
#include <map>
#include <utility>
#include <thread>
#include <chrono>
#include <libconfig.h++>
#include "versions.h"
using namespace libconfig;
@ -327,7 +326,6 @@ static void RptrAckThread(char *arg)
char RADIO_ID[21];
memcpy(RADIO_ID, arg + 1, 21);
unsigned char buf[56];
struct timespec nanos;
unsigned int aseed;
time_t tnow = 0;
unsigned char silence[12] = { 0x4e,0x8d,0x32,0x88,0x26,0x1a,0x3f,0x61,0xe8,0x70,0x4f,0x93 };
@ -386,9 +384,7 @@ static void RptrAckThread(char *arg)
memcpy(buf + 50, "RPTR", 4);
calcPFCS(buf,56);
sendto(rptr_sock, buf, 56, 0, (struct sockaddr *)&toLocalg2, sizeof(toLocalg2));
nanos.tv_sec = 0;
nanos.tv_nsec = delay_between * 1000000;
nanosleep(&nanos,0);
std::this_thread::sleep_for(std::chrono::milliseconds(delay_between));
buf[4] = 0x20;
memcpy(buf + 15, silence, 9);
@ -452,11 +448,8 @@ static void RptrAckThread(char *arg)
break;
}
sendto(rptr_sock, buf, 27, 0, (struct sockaddr *)&toLocalg2, sizeof(toLocalg2));
if (i < 9) {
nanos.tv_sec = 0;
nanos.tv_nsec = delay_between * 1000000;
nanosleep(&nanos,0);
}
if (i < 9)
std::this_thread::sleep_for(std::chrono::milliseconds(delay_between));
}
}
@ -910,7 +903,7 @@ static bool read_config(char *cfgFile)
timer *= 60;
rf_inactivity_timer[i] = timer;
}
return true;
}
@ -1551,7 +1544,7 @@ static void runit()
} else if (recvlen2 == (CALL_SIZE + 6)) {
/* A packet of length (CALL_SIZE + 6) is either an ACK or a NAK from repeater-reflector */
/* Because we sent a request before asking to link */
for (i = 0; i < 3; i++) {
if ((fromDst4.sin_addr.s_addr == to_remote_g2[i].toDst4.sin_addr.s_addr) &&
(to_remote_g2[i].toDst4.sin_port == htons(rmt_xrf_port))) {
@ -1603,7 +1596,7 @@ static void runit()
A packet of length (CALL_SIZE + 3) is a request
from a remote repeater to link-unlink with our repeater
*/
/* Check our linked repeaters/reflectors */
for (i = 0; i < 3; i++) {
if ((fromDst4.sin_addr.s_addr == to_remote_g2[i].toDst4.sin_addr.s_addr) &&
@ -3889,7 +3882,6 @@ static void AudioNotifyThread(char *arg)
char mod;
char *p = NULL;
u_int16_t streamid_raw = 0;
struct timespec nanos;
unsigned int aseed;
time_t tnow = 0;
struct sigaction act;
@ -4070,9 +4062,7 @@ static void AudioNotifyThread(char *arg)
}
sendto(rptr_sock, dstar_buf, rlen, 0, (struct sockaddr *)&toLocalg2,sizeof(struct sockaddr_in));
}
nanos.tv_sec = 0;
nanos.tv_nsec = delay_between * 1000000;
nanosleep(&nanos,0);
std::this_thread::sleep_for(std::chrono::milliseconds(delay_between));
}
fclose(fp);
return;

@ -1,6 +1,6 @@
// version strings must be 55 characters or less!
#define IRCDDB_VERSION "linux-g2_ircddb-5.1.0"
#define IRCDDB_VERSION "linux-g2_ircddb-5.1.1"
#define LINK_VERSION "5.10"
#define DVAP_VERSION "linux-dvap_rptr-5.1.0"
#define DVAP_VERSION "linux-dvap_rptr-5.1.1"
#define DVRPTR_VERSION "linux-dvrptr-5.1.0"
#define MMDVM_VERSION "mmdvm-dvmega-0.0.0"

Loading…
Cancel
Save

Powered by TurnKey Linux.