kopia lustrzana https://github.com/Hamlib/Hamlib
guohetec: comprehensive code quality improvements
- Fix compilation warnings by removing unnecessary dump_hex function calls - Resolve implicit function declaration warnings for validation macros - Remove duplicate GUOHE_MODE_TABLE_MAX definitions across files - Optimize header includes based on IWYU suggestions: * Add iofunc.h (for read_block/write_block functions) * Add riglist.h (for RIG_MODEL_* constants) * Remove unistd.h, misc.h, serial.h (unnecessary includes) - Convert validation macros to functions for better compiler compatibility - Maintain backward compatibility with existing macro definitions - Improve code structure and maintainability - Ensure WSJT-X compatibility with consistent error handling All changes maintain existing functionality while improving code quality and reducing compilation warnings.pull/1787/head
rodzic
a61877a60b
commit
c2d4fbe601
|
@ -1,11 +1,29 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <hamlib/rig.h>
|
||||
#include "serial.h"
|
||||
#include "iofunc.h"
|
||||
#include "register.h"
|
||||
#include "riglist.h"
|
||||
#include "guohetec.h"
|
||||
#include "misc.h"
|
||||
|
||||
// Common response validation function implementations
|
||||
int validate_packet_header(const unsigned char *reply, const char *func_name)
|
||||
{
|
||||
if (reply[0] != 0xA5 || reply[1] != 0xA5 ||
|
||||
reply[2] != 0xA5 || reply[3] != 0xA5) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Invalid packet header, using cached values\n", func_name);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int validate_data_length(const unsigned char *reply, int reply_size, const char *func_name)
|
||||
{
|
||||
if (reply[4] == 0 || reply[4] > reply_size - 5) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Invalid data length %d, using cached values\n", func_name, reply[4]);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// CRC16/CCITT-FALSE
|
||||
uint16_t CRC16Check(const unsigned char *buf, int len)
|
||||
|
@ -175,10 +193,14 @@ int validate_rig_response(RIG *rig, unsigned char *reply, int reply_size,
|
|||
const char *func_name)
|
||||
{
|
||||
// Validate packet header
|
||||
VALIDATE_PACKET_HEADER(reply, func_name);
|
||||
if (validate_packet_header(reply, func_name) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Validate data length
|
||||
VALIDATE_DATA_LENGTH(reply, reply_size, func_name);
|
||||
if (validate_data_length(reply, reply_size, func_name) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,21 +31,13 @@
|
|||
return RIG_OK; \
|
||||
} while(0)
|
||||
|
||||
// Common response validation macros
|
||||
#define VALIDATE_PACKET_HEADER(reply, func_name) do { \
|
||||
if (reply[0] != 0xA5 || reply[1] != 0xA5 || \
|
||||
reply[2] != 0xA5 || reply[3] != 0xA5) { \
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Invalid packet header, using cached values\n", func_name); \
|
||||
return -1; \
|
||||
} \
|
||||
} while(0)
|
||||
// Common response validation function declarations
|
||||
int validate_packet_header(const unsigned char *reply, const char *func_name);
|
||||
int validate_data_length(const unsigned char *reply, int reply_size, const char *func_name);
|
||||
|
||||
#define VALIDATE_DATA_LENGTH(reply, reply_size, func_name) do { \
|
||||
if (reply[4] == 0 || reply[4] > (reply_size) - 5) { \
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Invalid data length %d, using cached values\n", func_name, reply[4]); \
|
||||
return -1; \
|
||||
} \
|
||||
} while(0)
|
||||
// Keep the macro for backward compatibility
|
||||
#define VALIDATE_PACKET_HEADER(reply, func_name) validate_packet_header(reply, func_name)
|
||||
#define VALIDATE_DATA_LENGTH(reply, reply_size, func_name) validate_data_length(reply, reply_size, func_name)
|
||||
|
||||
#define VALIDATE_READ_RESULT(ret, expected, func_name) do { \
|
||||
if (ret < 0) { \
|
||||
|
|
|
@ -7,14 +7,12 @@
|
|||
#endif
|
||||
|
||||
#include "hamlib/rig.h"
|
||||
#include "serial.h"
|
||||
#include "iofunc.h"
|
||||
#include "guohetec.h"
|
||||
#include "cache.h"
|
||||
#include "misc.h"
|
||||
#include "tones.h"
|
||||
#include "bandplan.h"
|
||||
#include "cal.h"
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
typedef struct pmr171_data_s
|
||||
|
@ -39,8 +37,6 @@ typedef struct pmr171_data_s
|
|||
char SWR;
|
||||
} pmr171_data_t;
|
||||
|
||||
|
||||
#define GUOHE_MODE_TABLE_MAX 8
|
||||
static rmode_t pmr171_modes[GUOHE_MODE_TABLE_MAX] =
|
||||
{
|
||||
RIG_MODE_USB,
|
||||
|
@ -598,17 +594,15 @@ static int pmr171_open(RIG *rig)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
dump_hex(reply, 16);
|
||||
|
||||
// Update cache with requested frequency
|
||||
if (vfo == RIG_VFO_B)
|
||||
{
|
||||
CACHE(rig)->freqMainB = freq;
|
||||
}
|
||||
else
|
||||
{
|
||||
CACHE(rig)->freqMainA = freq;
|
||||
}
|
||||
// Update cache with requested frequency
|
||||
if (vfo == RIG_VFO_B)
|
||||
{
|
||||
CACHE(rig)->freqMainB = freq;
|
||||
}
|
||||
else
|
||||
{
|
||||
CACHE(rig)->freqMainA = freq;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
@ -684,8 +678,6 @@ static int pmr171_open(RIG *rig)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
dump_hex(reply, reply[4] + 5);
|
||||
|
||||
// Update cache with response data
|
||||
CACHE(rig)->modeMainA = guohe2rmode(reply[6], pmr171_modes);
|
||||
CACHE(rig)->modeMainB = guohe2rmode(reply[7], pmr171_modes);
|
||||
|
|
|
@ -7,14 +7,12 @@
|
|||
#endif
|
||||
|
||||
#include "hamlib/rig.h"
|
||||
#include "serial.h"
|
||||
#include "iofunc.h"
|
||||
#include "guohetec.h"
|
||||
#include "cache.h"
|
||||
#include "misc.h"
|
||||
#include "tones.h"
|
||||
#include "bandplan.h"
|
||||
#include "cal.h"
|
||||
#include <unistd.h>
|
||||
|
||||
typedef struct q900_data_s
|
||||
{
|
||||
|
@ -38,8 +36,6 @@ typedef struct q900_data_s
|
|||
char SWR;
|
||||
} q900_data_t;
|
||||
|
||||
|
||||
#define GUOHE_MODE_TABLE_MAX 8
|
||||
static rmode_t q900_modes[GUOHE_MODE_TABLE_MAX] =
|
||||
{
|
||||
RIG_MODE_USB,
|
||||
|
@ -599,17 +595,15 @@ static int q900_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
dump_hex(reply, 16);
|
||||
|
||||
// Update cache with requested frequency
|
||||
if (vfo == RIG_VFO_B)
|
||||
{
|
||||
CACHE(rig)->freqMainB = freq;
|
||||
}
|
||||
else
|
||||
{
|
||||
CACHE(rig)->freqMainA = freq;
|
||||
}
|
||||
// Update cache with requested frequency
|
||||
if (vfo == RIG_VFO_B)
|
||||
{
|
||||
CACHE(rig)->freqMainB = freq;
|
||||
}
|
||||
else
|
||||
{
|
||||
CACHE(rig)->freqMainA = freq;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
@ -712,8 +706,6 @@ static int q900_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
dump_hex(reply, reply[4] + 5);
|
||||
|
||||
// Update cache with response data
|
||||
CACHE(rig)->modeMainA = guohe2rmode(reply[6], q900_modes);
|
||||
CACHE(rig)->modeMainB = guohe2rmode(reply[7], q900_modes);
|
||||
|
@ -799,3 +791,4 @@ static int q900_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
|
|||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue