MHz macro problem, was Re: [Hamlib-developer] RE: [Hamlib-cvs-digest] CVS: hamlib/include/hamlib rig
Library to control radio transceivers and receivers
Brought to you by:
n0nb
|
From: Stephane F. <f4...@fr...> - 2002-03-04 08:15:46
|
On Sat, Mar 02, 2002, Chuck Hemker wrote:
> Am I supposed to be using the MHz macro? This change broke my code:
Yes, MHz is for use by applications. Obviously, my change broke something.
> On 27-Feb-02 Stephane Fillod wrote:
> > diff -C2 -r1.59 -r1.60
> > *** rig.h 27 Jan 2002 23:46:01 -0000 1.59
> > --- rig.h 27 Feb 2002 23:22:31 -0000 1.60
> > ***************
> > *** 211,217 ****
> >
> > #define Hz(f) ((freq_t)(f))
> > ! #define kHz(f) ((freq_t)((f)*1000))
> > ! #define MHz(f) ((freq_t)((f)*1000000L))
> > ! #define GHz(f) ((freq_t)((f)*1000000000LL))
> >
> > #define RIG_FREQ_NONE Hz(0)
> > --- 211,217 ----
> >
> > #define Hz(f) ((freq_t)(f))
> > ! #define kHz(f) (((freq_t)(f))*1000UL)
> > ! #define MHz(f) (((freq_t)(f))*1000000UL)
> > ! #define GHz(f) (((freq_t)(f))*1000000000UL)
> >
> > #define RIG_FREQ_NONE Hz(0)
>
> It forces the frequency to a freq_t before it does the muliplication. Because
> I was calling it with a double, I lost the digits after the decimal point.
Oops, a lot of backend must have been broken by the change (anything like
MHz(10.150) etc.). Actually, I've made the change because the macro GHz
would not work with freq > 2GHz (problem with 31bit representation).
Here is a possible fix:
#define Hz(f) ((freq_t)(f))
#define kHz(f) ((freq_t)((f)*1000UL))
#define MHz(f) ((freq_t)((f)*1000000UL))
#define GHz(f) ((freq_t)((f)*1000000000UL))
Now, thanks to the UL (unsigned), this would push the new limit to 4GHz
(2^32). Or maybe the following is even better:
#define Hz(f) ((freq_t)(f))
#define kHz(f) ((freq_t)(1000ULL*(f)))
#define MHz(f) ((freq_t)(1000000ULL*(f)))
#define GHz(f) ((freq_t)(1000000000ULL*(f)))
Chuck, can you give it a try? tests/testfreq looks okay.
> If I'm not supposed be using it let me know. I just figured it was handy.
And it *was* meant to handy, not flawed. hi.
> Relevent parts of my code:
>
> void command_set_freq(int xkey,struct socket_list_struct *psocket_list,struct
> socket_line_struct *psockline,struct radio_connection_struct
> *pradio_connection,char *prest)
> {
> int x;
> double freq;
>
> ...
>
> freq = atof(prest);
>
> x = rig_set_freq(pradio_connection->rig,RIG_VFO_CURR,MHz(freq));
Just curious, I see socket args in your function. What the socket is used
for? Is it some specific stuff in your application, or have you
reimplemented the RPCrig ?
Cheers,
Stephane F8CFE
|