Hamlib  3.3
misc.h
1 /*
2  * Hamlib Interface - toolbox header
3  * Copyright (c) 2000-2004 by Stephane Fillod
4  *
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  */
21 
22 #ifndef _MISC_H
23 #define _MISC_H 1
24 
25 #include <hamlib/rig.h>
26 
27 
28 /*
29  * Carefull!! These macros are NOT reentrant!
30  * ie. they may not be executed atomically,
31  * thus not ensure mutual exclusion.
32  * Fix it when making Hamlib reentrant! --SF
33  */
34 #define Hold_Decode(rig) {(rig)->state.hold_decode = 1;}
35 #define Unhold_Decode(rig) {(rig)->state.hold_decode = 0;}
36 
37 __BEGIN_DECLS
38 
39 /*
40  * Do a hex dump of the unsigned char array.
41  */
42 
43 void dump_hex(const unsigned char ptr[], size_t size);
44 
45 /*
46  * BCD conversion routines.
47  *
48  * to_bcd() converts a long long int to a little endian BCD array,
49  * and return a pointer to this array.
50  *
51  * from_bcd() converts a little endian BCD array to long long int
52  * reprensentation, and return it.
53  *
54  * bcd_len is the number of digits in the BCD array.
55  */
56 extern HAMLIB_EXPORT(unsigned char *) to_bcd(unsigned char bcd_data[],
57  unsigned long long freq,
58  unsigned bcd_len);
59 
60 extern HAMLIB_EXPORT(unsigned long long) from_bcd(const unsigned char
61  bcd_data[],
62  unsigned bcd_len);
63 
64 /*
65  * same as to_bcd() and from_bcd(), but in Big Endian mode
66  */
67 extern HAMLIB_EXPORT(unsigned char *) to_bcd_be(unsigned char bcd_data[],
68  unsigned long long freq,
69  unsigned bcd_len);
70 
71 extern HAMLIB_EXPORT(unsigned long long) from_bcd_be(const unsigned char
72  bcd_data[],
73  unsigned bcd_len);
74 
75 extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t);
76 
77 /* flag that determines if AI mode should be restored on exit on
78  applicable rigs - See rig_no_restore_ai() */
79 extern int no_restore_ai;
80 
81 /* check if it's any of CR or LF */
82 #define isreturn(c) ((c) == 10 || (c) == 13)
83 
84 
85 /* needs config.h included beforehand in .c file */
86 #ifdef HAVE_INTTYPES_H
87 # include <inttypes.h>
88 #endif
89 
90 #ifdef HAVE_SYS_TIME_H
91 # include <sys/time.h>
92 #endif
93 
94 extern HAMLIB_EXPORT(int) rig_check_cache_timeout(const struct timeval *tv,
95  int timeout);
96 
97 extern HAMLIB_EXPORT(void) rig_force_cache_timeout(struct timeval *tv);
98 
99 
100 #ifdef PRId64
101 
102 # define PRIll PRId64
103 #else
104 # ifdef FBSD4
105 # define PRIll "qd"
106 # else
107 # define PRIll "lld"
108 # endif
109 #endif
110 
111 #ifdef SCNd64
112 
113 # define SCNll SCNd64
114 #else
115 # ifdef FBSD4
116 # define SCNll "qd"
117 # else
118 # define SCNll "lld"
119 # endif
120 #endif
121 
122 
123 
124 __END_DECLS
125 
126 #endif /* _MISC_H */
dump_hex
void dump_hex(const unsigned char ptr[], size_t size)
Do a hex dump of the unsigned char array.
Definition: debug.c:69
from_bcd
unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[], unsigned bcd_len)
Convert BCD digits, little-endian, to a long long (e.g. frequency in Hz)
Definition: misc.c:126
from_bcd_be
unsigned long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[], unsigned bcd_len)
Convert 4-bit BCD digits to binary, big-endian.
Definition: misc.c:207
to_bcd_be
unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len)
Convert from binary to 4-bit BCD digits, big-endian.
Definition: misc.c:163
freq_t
double freq_t
Frequency type,.
Definition: rig.h:302
rig_force_cache_timeout
void HAMLIB_API rig_force_cache_timeout(struct timeval *tv)
Helper for forcing cache timeout next call.
Definition: misc.c:1078
sprintf_freq
int HAMLIB_API sprintf_freq(char *str, freq_t)
Pretty print a frequency.
Definition: misc.c:247
rig_check_cache_timeout
int HAMLIB_API rig_check_cache_timeout(const struct timeval *tv, int timeout)
Helper for checking cache timeout.
Definition: misc.c:1024
rig.h
Hamlib rig data structures.
to_bcd
unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len)
Convert from binary to 4-bit BCD digits, little-endian.
Definition: misc.c:78

Generated by doxygen 1.8.17

Hamlib documentation for version 3.3 -- Wed Jan 29 2020 00:00:00
Project page: http://www.hamlib.org