GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — rigsync/sync.c at master · daveriesz/rigsync

Expand file tree

/

sync.c

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
135 lines (113 loc) · 3.7 KB
/

sync.c

Copy path

File metadata and controls

135 lines (113 loc) · 3.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* sync.c - (C) David Riesz 2022
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "rigsync.h"
void rig_read_state(struct rs_rig *rig);
void rig_write_state(struct rs_rig *rig, struct rs_rig_state *state);
void rig_sync_state(struct rs_rig *rig_dest, struct rs_rig *rig_src);
void rig_sync()
{
int ii, nn, update_rig_no;
struct rs_rig *dirty_rig, *cur_rig;
nn = rig_count();
// read initial states and clear dirty flags
for(ii=0 ; ii<nn ; ii++)
{
cur_rig = get_rig(ii);
gprintf(1, "rig %d: reading initial state\n", ii);
rig_read_state(cur_rig);
gprintf(2, " clearing dirty flag\n");
cur_rig->dirty = 0;
}
gprintf(1, "reading states again\n");
for(ii=0 ; ii<nn ; ii++) { rig_read_state(get_rig(ii)); }
// set dirty flag on startup sync rig
update_rig_no = get_rig_sync_init();
cur_rig = get_rig(update_rig_no);
rig_read_state(cur_rig);
cur_rig->dirty = 1;
// When this loop starts, it will find that
// only the startup rig has the dirty flag set.
// The other rigs will be synced to it in the
// first cycle.
for( ; ; )
{
// first, find the first updated (dirty) rig
for(dirty_rig=NULL, ii=0 ; ii<nn ; ii++)
{
cur_rig = get_rig(ii);
if(cur_rig->dirty)
{
dirty_rig = cur_rig;
gprintf(1, "dirty rig: %d\n", dirty_rig?dirty_rig->number:-1);
break;
}
}
// second, sync other rigs to dirty rig
for(ii=0 ; dirty_rig!=NULL && ii<nn ; ii++)
{
cur_rig = get_rig(ii);
if(cur_rig != dirty_rig)
{
rig_sync_state(cur_rig, dirty_rig);
}
}
if(dirty_rig != NULL) { dirty_rig->dirty = 0; }
// third, find new dirty rigs
for(ii=0 ; ii<nn ; ii++) { rig_read_state(get_rig(ii)); }
usleep(10000); /* 10 milliseconds */
// return;
}
}
void rig_read_state(struct rs_rig *rig)
{
freq_t ff;
rmode_t mm;
pbwidth_t ww;
rig_get_freq(rig->rig, RIG_VFO_CURR, &ff);
rig_get_mode(rig->rig, RIG_VFO_CURR, &mm, &ww);
if((ff != rig->state.freq) || (mm != rig->state.mode))
{
rig->dirty = 1;
gprintf(2, "rig %d is dirty: old=%'15.2fHz/%3s new=%'15.2fHz/%3s\n",
rig->number,
rig->state.freq, rig_strrmode(rig->state.mode), ff, rig_strrmode(mm));
}
rig->state.freq = ff;
rig->state.mode = mm;
rig->state.width = ww;
}
void rig_write_state(struct rs_rig *rig, struct rs_rig_state *new_state)
{
struct rs_rig_state *cur_state = &(rig->state);
rig_set_freq(rig->rig, RIG_VFO_CURR, (new_state->freq));
rig_set_mode(rig->rig, RIG_VFO_CURR, (new_state->mode), (cur_state->width));
rig_read_state(rig);
cur_state = &(rig->state);
gprintf(1, "rig_write_state() req=%'15.2fHz/%3s act=%'15.2fHz/%3s\n",
new_state->freq, rig_strrmode(new_state->mode),
cur_state->freq, rig_strrmode(cur_state->mode));
rig->dirty = 0;
}
void rig_sync_state(struct rs_rig *rig_dest, struct rs_rig *rig_src)
{
rig_write_state(rig_dest, &(rig_src->state));
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.