Skip to content

Commit

Permalink
Rename the_time to time_mono
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Randolf committed Jul 12, 2017
1 parent ff7a18b commit 874929e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
8 changes: 5 additions & 3 deletions channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ uint32_t channel_get_remaining_dwell_time(void)
return UINT32_MAX;

int64_t ret = (int64_t)conf.channel_time
- (the_time.tv_sec - last_channelchange.tv_sec) * 1000000
- (the_time.tv_nsec - last_channelchange.tv_nsec) / 1000;
- (time_mono.tv_sec - last_channelchange.tv_sec) * 1000000
- (time_mono.tv_nsec - last_channelchange.tv_nsec) / 1000;

if (ret < 0)
return 0;
Expand Down Expand Up @@ -178,17 +178,19 @@ bool channel_change(int idx, enum chan_width width, bool ht40plus)
return false;
}

#if 0
printlog("Set CH %d (%d MHz) %s center %d after %ldms",
channels.chan[idx].chan, channels.chan[idx].freq,
channel_width_string(width, ht40plus),
center1, (the_time.tv_sec - last_channelchange.tv_sec) * 1000
+ (the_time.tv_nsec - last_channelchange.tv_nsec) / 1000000);
#endif

conf.channel_idx = idx;
conf.channel_width = width;
conf.channel_ht40plus = ht40plus;
conf.max_phy_rate = get_phy_thruput(width, channel_get_band_from_idx(idx).streams_rx);
last_channelchange = the_time;
last_channelchange = time_mono;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion display-essid.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void update_essid_win(WINDOW *win)
if (line > LINES-3)
break;

if (n->last_seen > (the_time.tv_sec - conf.node_timeout / 2))
if (n->last_seen > (time_mono.tv_sec - conf.node_timeout / 2))
wattron(win, A_BOLD);
else
wattroff(win, A_BOLD);
Expand Down
2 changes: 1 addition & 1 deletion display-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static void print_node_list_line(int line, struct node_info* n)

if (n->pkt_types & PKT_TYPE_OLSR)
wattron(list_win, GREEN);
if (n->last_seen > (the_time.tv_sec - conf.node_timeout / 2))
if (n->last_seen > (time_mono.tv_sec - conf.node_timeout / 2))
wattron(list_win, A_BOLD);
else
wattron(list_win, A_NORMAL);
Expand Down
20 changes: 10 additions & 10 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ void get_per_second(unsigned long bytes, unsigned long duration,
float timediff;

/* reacalculate only every second or more */
timediff = (the_time.tv_sec + the_time.tv_nsec/1000000000.0) -
timediff = (time_mono.tv_sec + time_mono.tv_nsec/1000000000.0) -
(last.tv_sec + last.tv_nsec/1000000000.0);
if (timediff >= 1.0) {
last_dps = (1.0*(duration - last_dur)) / timediff;
last_bps = (1.0*(bytes - last_bytes)) / timediff;
last_pps = (1.0*(packets - last_pkts)) / timediff;
last_rps = (1.0*(retries - last_retr)) / timediff;
last = the_time;
last = time_mono;
last_dur = duration;
last_bytes = bytes;
last_pkts = packets;
Expand Down Expand Up @@ -238,7 +238,7 @@ static void update_menu(void)
wattroff(stdscr, BLACKONWHITE);

update_mini_status();
update_clock(&the_time.tv_sec);
update_clock(&time_mono.tv_sec);
}

/******************* WINDOW MANAGEMENT / UPDATE *******************/
Expand Down Expand Up @@ -305,8 +305,8 @@ static void show_conf_window(int key)
void update_display_clock(void)
{
/* helper to update just the clock every second */
if (the_time.tv_sec > last_time.tv_sec) {
update_clock(&the_time.tv_sec);
if (time_mono.tv_sec > time_mono.tv_sec) {
update_clock(&time_mono.tv_sec);
doupdate();
}
}
Expand All @@ -323,8 +323,8 @@ void update_display(struct packet_info* pkt)
* if pkt is NULL we want to force an update
*/
if (pkt != NULL &&
the_time.tv_sec == last_time.tv_sec &&
(the_time.tv_nsec - last_time.tv_nsec) / 1000 < conf.display_interval ) {
time_mono.tv_sec == last_time.tv_sec &&
(time_mono.tv_nsec - last_time.tv_nsec) / 1000 < conf.display_interval ) {
/* just add the line to dump win so we don't loose it */
update_dump_win(pkt);
return;
Expand All @@ -338,10 +338,10 @@ void update_display(struct packet_info* pkt)
update_menu();

/* update clock every second */
if (the_time.tv_sec > last_time.tv_sec)
update_clock(&the_time.tv_sec);
if (time_mono.tv_sec > time_mono.tv_sec)
update_clock(&time_mono.tv_sec);

last_time = the_time;
last_time = time_mono;

if (show_win != NULL)
update_show_win();
Expand Down
10 changes: 5 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct node_names_info node_names;

struct config conf;

struct timespec the_time;
struct timespec time_mono;

int mon; /* monitoring socket */

Expand Down Expand Up @@ -214,11 +214,11 @@ static void write_to_file(struct packet_info* p)
{
char buf[40];
int i;
struct tm* ltm = localtime(&the_time.tv_sec);
struct tm* ltm = localtime(&time_mono.tv_sec);

//timestamp, e.g. 2015-05-16 15:05:44.338806 +0300
i = strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ltm);
i += snprintf(buf + i, sizeof(buf) - i, ".%06ld", (long)(the_time.tv_nsec / 1000));
i += snprintf(buf + i, sizeof(buf) - i, ".%06ld", (long)(time_mono.tv_nsec / 1000));
i += strftime(buf + i, sizeof(buf) - i, " %z", ltm);
fprintf(DF, "%s, ", buf);

Expand Down Expand Up @@ -639,7 +639,7 @@ int main(int argc, char** argv)
atexit(exit_handler);

clock_gettime(CLOCK_MONOTONIC, &stats.stats_time);
clock_gettime(CLOCK_MONOTONIC, &the_time);
clock_gettime(CLOCK_MONOTONIC, &time_mono);

conf.channel_idx = -1;

Expand Down Expand Up @@ -724,7 +724,7 @@ int main(int argc, char** argv)
if (is_sigint_caught)
exit(1);

clock_gettime(CLOCK_MONOTONIC, &the_time);
clock_gettime(CLOCK_MONOTONIC, &time_mono);
node_timeout();

if (conf.serveraddr[0] == '\0') { /* server */
Expand Down
2 changes: 1 addition & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ struct config {

extern struct config conf;

extern struct timespec the_time;
extern struct timespec time_mono;

void free_lists(void);
void init_spectrum(void);
Expand Down
8 changes: 4 additions & 4 deletions node.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void copy_nodeinfo(struct node_info* n, struct packet_info* p)

memcpy(&(n->last_pkt), p, sizeof(struct packet_info));
// update timestamp
n->last_seen = the_time.tv_sec;
n->last_seen = time_mono.tv_sec;
n->pkt_count++;
n->pkt_types |= p->pkt_types;
if (p->ip_src)
Expand Down Expand Up @@ -167,11 +167,11 @@ void node_timeout(void)
struct node_info *n, *m, *n2, *m2;
struct chan_node *cn, *cn2;

if ((the_time.tv_sec - last_nodetimeout.tv_sec) < conf.node_timeout )
if ((time_mono.tv_sec - last_nodetimeout.tv_sec) < conf.node_timeout )
return;

list_for_each_safe(&nodes, n, m, list) {
if (n->last_seen < (the_time.tv_sec - conf.node_timeout)) {
if (n->last_seen < (time_mono.tv_sec - conf.node_timeout)) {
list_del(&n->list);
if (n->essid != NULL)
remove_node_from_essid(n);
Expand All @@ -191,5 +191,5 @@ void node_timeout(void)
free(n);
}
}
last_nodetimeout = the_time;
last_nodetimeout = time_mono;
}

0 comments on commit 874929e

Please sign in to comment.