Hamlib  3.0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 marcos 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  * to_bcd converts a long long int to a little endian BCD array,
48  * and return a pointer to this array.
49  * from_bcd converts a little endian BCD array to long long int
50  * reprensentation, and return it.
51  * bcd_len is the number of digits in the BCD array.
52  */
53 extern HAMLIB_EXPORT(unsigned char *) to_bcd(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len);
54 extern HAMLIB_EXPORT(unsigned long long) from_bcd(const unsigned char bcd_data[], unsigned bcd_len);
55 
56 /*
57  * same as to_bcd and from_bcd, but in Big Endian mode
58  */
59 extern HAMLIB_EXPORT(unsigned char *) to_bcd_be(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len);
60 extern HAMLIB_EXPORT(unsigned long long) from_bcd_be(const unsigned char bcd_data[], unsigned bcd_len);
61 
62 extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t);
63 
64 /* check if it's any of CR or LF */
65 #define isreturn(c) ((c) == 10 || (c) == 13)
66 
67 
68 /* needs config.h included beforehand in .c file */
69 #ifdef HAVE_INTTYPES_H
70 #include <inttypes.h>
71 #endif
72 #ifdef HAVE_SYS_TIME_H
73 #include <sys/time.h>
74 #endif
75 
76 extern HAMLIB_EXPORT(int) rig_check_cache_timeout(const struct timeval *tv, int timeout);
77 extern HAMLIB_EXPORT(void) rig_force_cache_timeout(struct timeval *tv);
78 
79 
80 #ifdef PRId64
81 
82 #define PRIll PRId64
83 #else
84 #ifdef FBSD4
85 #define PRIll "qd"
86 #else
87 #define PRIll "lld"
88 #endif
89 #endif
90 
91 #ifdef SCNd64
92 
93 #define SCNll SCNd64
94 #else
95 #ifdef FBSD4
96 #define SCNll "qd"
97 #else
98 #define SCNll "lld"
99 #endif
100 #endif
101 
102 
103 
104 __END_DECLS
105 
106 #endif /* _MISC_H */
double freq_t
Frequency type, Frequency type unit in Hz, able to hold SHF frequencies.
Definition: rig.h:276
void rig_force_cache_timeout(struct timeval *tv)
Helper for forcing cache timeout next call.
Definition: misc.c:838
unsigned char * 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:74
unsigned long long from_bcd_be(const unsigned char bcd_data[], unsigned bcd_len)
Convert 4-bit BCD digits to binary, big-endian.
Definition: misc.c:179
unsigned char * 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:144
unsigned long long 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:114
Hamlib rig data structures.
void dump_hex(const unsigned char ptr[], size_t size)
Do a hex dump of the unsigned char array.
Definition: debug.c:66
int rig_check_cache_timeout(const struct timeval *tv, int timeout)
Helper for checking cache timeout.
Definition: misc.c:798
int sprintf_freq(char *str, freq_t)
Pretty print a frequency.
Definition: misc.c:212

Generated by doxygen 1.8.8

Hamlib documentation for version 3.0.1 -- Wed Jan 13 2016 15:05:23
Project page: http://www.hamlib.org