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 * 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 * it under the terms of the GNU General Public License as published by
@ -24,6 +24,8 @@
#include <termios.h> #include <termios.h>
#include <time.h> #include <time.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/select.h>
#include "DVAPDongle.h" #include "DVAPDongle.h"
extern void traceit(const char *fmt,...); extern void traceit(const char *fmt,...);

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -24,6 +24,9 @@
#include <netdb.h> #include <netdb.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <thread>
#include <chrono>
#include "aprs.h" #include "aprs.h"
// This is called when header comes in from repeater // This is called when header comes in from repeater
@ -253,8 +256,6 @@ unsigned int CAPRS::GetData(short int rptr_idx, unsigned char *data, unsigned in
void CAPRS::Open(const std::string OWNER) void CAPRS::Open(const std::string OWNER)
{ {
struct timespec req;
fd_set fdset; fd_set fdset;
struct timeval tv; struct timeval tv;
short int MAX_WAIT = 15; /* 15 seconds wait time MAX */ 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 (rc < 0) {
if (errno == EWOULDBLOCK) { if (errno == EWOULDBLOCK) {
recv(aprs_sock, rcv_buf, sizeof(rcv_buf), 0); recv(aprs_sock, rcv_buf, sizeof(rcv_buf), 0);
req.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(100));
req.tv_nsec = 100000000; // 100 milli
nanosleep(&req, NULL);
} else { } else {
traceit("APRS login command failed, error=%d\n", errno); traceit("APRS login command failed, error=%d\n", errno);
break; break;

@ -32,7 +32,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <signal.h> #include <signal.h>
#include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -43,6 +42,8 @@
#include <atomic> #include <atomic>
#include <future> #include <future>
#include <exception> #include <exception>
#include <thread>
#include <chrono>
#include <string> #include <string>
#include <libconfig.h++> #include <libconfig.h++>
using namespace libconfig; using namespace libconfig;
@ -759,7 +760,6 @@ static void RptrAckThread(SDVAP_ACK_ARG *parg)
time_t tnow = 0; time_t tnow = 0;
unsigned char silence[12] = { 0x4e,0x8d,0x32,0x88,0x26,0x1a,0x3f,0x61,0xe8,0x70,0x4f,0x93 }; unsigned char silence[12] = { 0x4e,0x8d,0x32,0x88,0x26,0x1a,0x3f,0x61,0xe8,0x70,0x4f,0x93 };
unsigned int aseed_ack = 0; unsigned int aseed_ack = 0;
struct timespec nanos;
act.sa_handler = sig_catch; act.sa_handler = sig_catch;
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
@ -800,9 +800,7 @@ static void RptrAckThread(SDVAP_ACK_ARG *parg)
memcpy(dr.frame.hdr.sfx, (unsigned char *)" ", 4); memcpy(dr.frame.hdr.sfx, (unsigned char *)" ", 4);
calcPFCS(dr.frame.hdr.flag, dr.frame.hdr.pfcs); calcPFCS(dr.frame.hdr.flag, dr.frame.hdr.pfcs);
dongle.SendRegister(dr); dongle.SendRegister(dr);
nanos.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_BETWEEN));
nanos.tv_nsec = DELAY_BETWEEN * 1000000;
nanosleep(&nanos,0);
// SYNC // SYNC
dr.header = 0xc012u; dr.header = 0xc012u;
@ -869,11 +867,8 @@ static void RptrAckThread(SDVAP_ACK_ARG *parg)
} }
memcpy(&dr.frame.vad.voice, silence, 12); memcpy(&dr.frame.vad.voice, silence, 12);
dongle.SendRegister(dr); dongle.SendRegister(dr);
if (i < 9) { if (i < 9)
nanos.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_BETWEEN));
nanos.tv_nsec = DELAY_BETWEEN * 1000000;
nanosleep(&nanos,0);
}
} }
return; return;
} }

@ -36,7 +36,6 @@
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
#include <time.h>
#include <math.h> #include <math.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -53,6 +52,8 @@
#include <future> #include <future>
#include <exception> #include <exception>
#include <string> #include <string>
#include <thread>
#include <chrono>
#include <map> #include <map>
#include <libconfig.h++> #include <libconfig.h++>
using namespace libconfig; using namespace libconfig;
@ -526,8 +527,6 @@ static int open_port(const SPORTIP &pip)
/* receive data from the irc server and save it */ /* receive data from the irc server and save it */
static void GetIRCDataThread() static void GetIRCDataThread()
{ {
struct timespec req;
std::string user, rptr, gateway, ipaddr; std::string user, rptr, gateway, ipaddr;
DSTAR_PROTOCOL proto; DSTAR_PROTOCOL proto;
IRCDDB_RESPONSE_TYPE type; IRCDDB_RESPONSE_TYPE type;
@ -632,9 +631,7 @@ static void GetIRCDataThread()
} }
} }
} }
req.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(500));
req.tv_nsec = 500000000; // 500 milli
nanosleep(&req, NULL);
} }
traceit("GetIRCDataThread exiting...\n"); traceit("GetIRCDataThread exiting...\n");
return; return;
@ -2234,8 +2231,6 @@ static void compute_aprs_hash()
void APRSBeaconThread() void APRSBeaconThread()
{ {
struct timespec req;
char snd_buf[512]; char snd_buf[512];
char rcv_buf[512]; char rcv_buf[512];
time_t tnow = 0; time_t tnow = 0;
@ -2350,9 +2345,7 @@ void APRSBeaconThread()
close(aprs->GetSock()); close(aprs->GetSock());
aprs->SetSock( -1 ); aprs->SetSock( -1 );
} else if (errno == EWOULDBLOCK) { } else if (errno == EWOULDBLOCK) {
req.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(100));
req.tv_nsec = 100000000; // 100 milli
nanosleep(&req, NULL);
} else { } else {
/* Cant do nothing about it */ /* Cant do nothing about it */
traceit("send_aprs_beacon failed, error=%d\n", errno); traceit("send_aprs_beacon failed, error=%d\n", errno);
@ -2401,9 +2394,7 @@ void APRSBeaconThread()
} else } else
THRESHOLD_COUNTDOWN = 15; THRESHOLD_COUNTDOWN = 15;
req.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(100));
req.tv_nsec = 100000000; // 100 milli
nanosleep(&req, NULL);
/* 20 seconds passed already ? */ /* 20 seconds passed already ? */
time(&tnow); time(&tnow);
@ -2429,8 +2420,6 @@ void APRSBeaconThread()
static void PlayFileThread(char *file) static void PlayFileThread(char *file)
{ {
struct timespec req;
unsigned short rlen = 0; unsigned short rlen = 0;
unsigned char dstar_buf[56]; unsigned char dstar_buf[56];
unsigned char rptr_buf[58]; unsigned char rptr_buf[58];
@ -2533,9 +2522,7 @@ static void PlayFileThread(char *file)
toRptr[i].G2_COUNTER ++; toRptr[i].G2_COUNTER ++;
req.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(play_delay));
req.tv_nsec = play_delay * 1000000;
nanosleep(&req, NULL);
} }
} }
fclose(fp); fclose(fp);

@ -1,8 +1,7 @@
/* /*
* Copyright (C) 2010 by Scott Lawson KI4LKF * Copyright (C) 2010 by Scott Lawson KI4LKF
* Additional: * Copyright (C) 2015,2018 by Thomas A. Early N7TAE
* Copyright (C) 2015 by Thomas A. Early N7TAE
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -31,8 +30,6 @@
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
#include <time.h>
#include <regex.h> #include <regex.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -52,6 +49,8 @@
#include <set> #include <set>
#include <map> #include <map>
#include <utility> #include <utility>
#include <thread>
#include <chrono>
#include <libconfig.h++> #include <libconfig.h++>
#include "versions.h" #include "versions.h"
using namespace libconfig; using namespace libconfig;
@ -327,7 +326,6 @@ static void RptrAckThread(char *arg)
char RADIO_ID[21]; char RADIO_ID[21];
memcpy(RADIO_ID, arg + 1, 21); memcpy(RADIO_ID, arg + 1, 21);
unsigned char buf[56]; unsigned char buf[56];
struct timespec nanos;
unsigned int aseed; unsigned int aseed;
time_t tnow = 0; time_t tnow = 0;
unsigned char silence[12] = { 0x4e,0x8d,0x32,0x88,0x26,0x1a,0x3f,0x61,0xe8,0x70,0x4f,0x93 }; 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); memcpy(buf + 50, "RPTR", 4);
calcPFCS(buf,56); calcPFCS(buf,56);
sendto(rptr_sock, buf, 56, 0, (struct sockaddr *)&toLocalg2, sizeof(toLocalg2)); sendto(rptr_sock, buf, 56, 0, (struct sockaddr *)&toLocalg2, sizeof(toLocalg2));
nanos.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(delay_between));
nanos.tv_nsec = delay_between * 1000000;
nanosleep(&nanos,0);
buf[4] = 0x20; buf[4] = 0x20;
memcpy(buf + 15, silence, 9); memcpy(buf + 15, silence, 9);
@ -452,11 +448,8 @@ static void RptrAckThread(char *arg)
break; break;
} }
sendto(rptr_sock, buf, 27, 0, (struct sockaddr *)&toLocalg2, sizeof(toLocalg2)); sendto(rptr_sock, buf, 27, 0, (struct sockaddr *)&toLocalg2, sizeof(toLocalg2));
if (i < 9) { if (i < 9)
nanos.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(delay_between));
nanos.tv_nsec = delay_between * 1000000;
nanosleep(&nanos,0);
}
} }
} }
@ -3889,7 +3882,6 @@ static void AudioNotifyThread(char *arg)
char mod; char mod;
char *p = NULL; char *p = NULL;
u_int16_t streamid_raw = 0; u_int16_t streamid_raw = 0;
struct timespec nanos;
unsigned int aseed; unsigned int aseed;
time_t tnow = 0; time_t tnow = 0;
struct sigaction act; 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)); sendto(rptr_sock, dstar_buf, rlen, 0, (struct sockaddr *)&toLocalg2,sizeof(struct sockaddr_in));
} }
nanos.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds(delay_between));
nanos.tv_nsec = delay_between * 1000000;
nanosleep(&nanos,0);
} }
fclose(fp); fclose(fp);
return; return;

@ -1,6 +1,6 @@
// version strings must be 55 characters or less! // 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 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 DVRPTR_VERSION "linux-dvrptr-5.1.0"
#define MMDVM_VERSION "mmdvm-dvmega-0.0.0" #define MMDVM_VERSION "mmdvm-dvmega-0.0.0"

Loading…
Cancel
Save

Powered by TurnKey Linux.