kopia lustrzana https://github.com/Hamlib/Hamlib
guohetec: fix cppcheck warnings and improve code quality
Based on cppcheck analysis and maintainer feedback: - Fix constParameterPointer warnings: declare reply parameters as const where appropriate - Fix variableScope warnings: reduce reply variable scope to minimum required - Apply IWYU (IncludeWhatYouUse) suggestions for header optimization: * 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) - Maintain backward compatibility and existing functionality - Improve code maintainability and reduce compilation warnings All changes follow maintainer recommendations and maintain WSJT-X compatibility.pull/1787/head
rodzic
c2d4fbe601
commit
6797ab7646
|
@ -189,7 +189,7 @@ int read_rig_response(RIG *rig, unsigned char *reply, int reply_size,
|
||||||
* @param func_name Function name for debug messages
|
* @param func_name Function name for debug messages
|
||||||
* @return 0 on success, -1 on error
|
* @return 0 on success, -1 on error
|
||||||
*/
|
*/
|
||||||
int validate_rig_response(RIG *rig, unsigned char *reply, int reply_size,
|
int validate_rig_response(RIG *rig, const unsigned char *reply, int reply_size,
|
||||||
const char *func_name)
|
const char *func_name)
|
||||||
{
|
{
|
||||||
// Validate packet header
|
// Validate packet header
|
||||||
|
@ -213,7 +213,7 @@ int validate_rig_response(RIG *rig, unsigned char *reply, int reply_size,
|
||||||
* @param func_name Function name for debug messages
|
* @param func_name Function name for debug messages
|
||||||
* @return 0 on success, -1 on error
|
* @return 0 on success, -1 on error
|
||||||
*/
|
*/
|
||||||
int validate_freq_response(RIG *rig, unsigned char *reply, int reply_size,
|
int validate_freq_response(RIG *rig, const unsigned char *reply, int reply_size,
|
||||||
const char *func_name)
|
const char *func_name)
|
||||||
{
|
{
|
||||||
// Basic validation
|
// Basic validation
|
||||||
|
@ -257,7 +257,7 @@ int validate_freq_response(RIG *rig, unsigned char *reply, int reply_size,
|
||||||
* @param min_length Minimum required data length
|
* @param min_length Minimum required data length
|
||||||
* @return 0 on success, -1 on error
|
* @return 0 on success, -1 on error
|
||||||
*/
|
*/
|
||||||
int validate_mode_response(RIG *rig, unsigned char *reply, int reply_size,
|
int validate_mode_response(RIG *rig, const unsigned char *reply, int reply_size,
|
||||||
const char *func_name, int min_length)
|
const char *func_name, int min_length)
|
||||||
{
|
{
|
||||||
// Basic validation
|
// Basic validation
|
||||||
|
@ -305,8 +305,6 @@ DECLARE_PROBERIG_BACKEND(guohetec) {
|
||||||
0x0B,
|
0x0B,
|
||||||
0x00, 0x00
|
0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t reply[PMR171_REPLY_LENGTH];
|
|
||||||
|
|
||||||
int orig_rate = port->parm.serial.rate;
|
int orig_rate = port->parm.serial.rate;
|
||||||
int orig_timeout = port->timeout;
|
int orig_timeout = port->timeout;
|
||||||
|
@ -314,6 +312,8 @@ DECLARE_PROBERIG_BACKEND(guohetec) {
|
||||||
const int rates[] = {9600, 19200, 38400, 57600, 115200, 0};
|
const int rates[] = {9600, 19200, 38400, 57600, 115200, 0};
|
||||||
|
|
||||||
for (int i = 0; rates[i]; i++) {
|
for (int i = 0; rates[i]; i++) {
|
||||||
|
uint8_t reply[PMR171_REPLY_LENGTH];
|
||||||
|
|
||||||
port->parm.serial.rate = rates[i];
|
port->parm.serial.rate = rates[i];
|
||||||
port->timeout = 500;
|
port->timeout = 500;
|
||||||
|
|
||||||
|
|
|
@ -61,13 +61,13 @@ unsigned char *to_be(unsigned char data[], unsigned long long freq, unsigned int
|
||||||
unsigned long long from_be(const unsigned char data[],unsigned int byte_len);
|
unsigned long long from_be(const unsigned char data[],unsigned int byte_len);
|
||||||
|
|
||||||
// Common response validation functions
|
// Common response validation functions
|
||||||
int validate_rig_response(RIG *rig, unsigned char *reply, int reply_size,
|
int validate_rig_response(RIG *rig, const unsigned char *reply, int reply_size,
|
||||||
const char *func_name);
|
const char *func_name);
|
||||||
int read_rig_response(RIG *rig, unsigned char *reply, int reply_size,
|
int read_rig_response(RIG *rig, unsigned char *reply, int reply_size,
|
||||||
const char *func_name);
|
const char *func_name);
|
||||||
int validate_freq_response(RIG *rig, unsigned char *reply, int reply_size,
|
int validate_freq_response(RIG *rig, const unsigned char *reply, int reply_size,
|
||||||
const char *func_name);
|
const char *func_name);
|
||||||
int validate_mode_response(RIG *rig, unsigned char *reply, int reply_size,
|
int validate_mode_response(RIG *rig, const unsigned char *reply, int reply_size,
|
||||||
const char *func_name, int min_length);
|
const char *func_name, int min_length);
|
||||||
|
|
||||||
#endif // _guohetec_H_
|
#endif // _guohetec_H_
|
||||||
|
|
|
@ -367,39 +367,39 @@ static int pmr171_open(RIG *rig)
|
||||||
cmd[6] = crc >> 8;
|
cmd[6] = crc >> 8;
|
||||||
cmd[7] = crc & 0xFF;
|
cmd[7] = crc & 0xFF;
|
||||||
|
|
||||||
// Receive buffer and send command
|
{
|
||||||
unsigned char reply[40];
|
unsigned char reply[40];
|
||||||
pmr171_send(rig, cmd, sizeof(cmd), reply, sizeof(reply));
|
pmr171_send(rig, cmd, sizeof(cmd), reply, sizeof(reply));
|
||||||
|
|
||||||
// Validate response using common function
|
// Validate response using common function
|
||||||
if (validate_freq_response(rig, reply, sizeof(reply), __func__) < 0) {
|
if (validate_freq_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
RETURN_CACHED_FREQ(rig, vfo, freq);
|
RETURN_CACHED_FREQ(rig, vfo, freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse frequency (big-endian)
|
||||||
|
int freq_a_offset = 9; // VFOA frequency starting position
|
||||||
|
int freq_b_offset = 13; // VFOB frequency starting position
|
||||||
|
|
||||||
|
uint32_t freq_a = (reply[freq_a_offset] << 24) |
|
||||||
|
(reply[freq_a_offset+1] << 16) |
|
||||||
|
(reply[freq_a_offset+2] << 8) |
|
||||||
|
reply[freq_a_offset+3];
|
||||||
|
|
||||||
|
uint32_t freq_b = (reply[freq_b_offset] << 24) |
|
||||||
|
(reply[freq_b_offset+1] << 16) |
|
||||||
|
(reply[freq_b_offset+2] << 8) |
|
||||||
|
reply[freq_b_offset+3];
|
||||||
|
|
||||||
|
// Update cache
|
||||||
|
CACHE(rig)->freqMainA = (freq_t)freq_a;
|
||||||
|
CACHE(rig)->freqMainB = (freq_t)freq_b;
|
||||||
|
|
||||||
|
// Return requested VFO frequency
|
||||||
|
*freq = (vfo == RIG_VFO_A) ? CACHE(rig)->freqMainA : CACHE(rig)->freqMainB;
|
||||||
|
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: Successfully got VFOA=%.0f Hz, VFOB=%.0f Hz\n",
|
||||||
|
__func__, CACHE(rig)->freqMainA, CACHE(rig)->freqMainB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse frequency (big-endian)
|
|
||||||
int freq_a_offset = 9; // VFOA frequency starting position
|
|
||||||
int freq_b_offset = 13; // VFOB frequency starting position
|
|
||||||
|
|
||||||
uint32_t freq_a = (reply[freq_a_offset] << 24) |
|
|
||||||
(reply[freq_a_offset+1] << 16) |
|
|
||||||
(reply[freq_a_offset+2] << 8) |
|
|
||||||
reply[freq_a_offset+3];
|
|
||||||
|
|
||||||
uint32_t freq_b = (reply[freq_b_offset] << 24) |
|
|
||||||
(reply[freq_b_offset+1] << 16) |
|
|
||||||
(reply[freq_b_offset+2] << 8) |
|
|
||||||
reply[freq_b_offset+3];
|
|
||||||
|
|
||||||
// Update cache
|
|
||||||
CACHE(rig)->freqMainA = (freq_t)freq_a;
|
|
||||||
CACHE(rig)->freqMainB = (freq_t)freq_b;
|
|
||||||
|
|
||||||
// Return requested VFO frequency
|
|
||||||
*freq = (vfo == RIG_VFO_A) ? CACHE(rig)->freqMainA : CACHE(rig)->freqMainB;
|
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: Successfully got VFOA=%.0f Hz, VFOB=%.0f Hz\n",
|
|
||||||
__func__, CACHE(rig)->freqMainA, CACHE(rig)->freqMainB);
|
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,28 +407,25 @@ static int pmr171_open(RIG *rig)
|
||||||
{
|
{
|
||||||
struct rig_cache *cachep = CACHE(rig);
|
struct rig_cache *cachep = CACHE(rig);
|
||||||
const pmr171_data_t *p = (pmr171_data_t *) STATE(rig)->priv;
|
const pmr171_data_t *p = (pmr171_data_t *) STATE(rig)->priv;
|
||||||
unsigned char reply[40];
|
{
|
||||||
|
unsigned char reply[40];
|
||||||
// Get latest status from hardware
|
// Get latest status from hardware
|
||||||
pmr171_send_cmd1(rig, 0x0b, 0);
|
pmr171_send_cmd1(rig, 0x0b, 0);
|
||||||
|
// Read and validate response using common function
|
||||||
// Read and validate response using common function
|
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
RETURN_CACHED_MODE(rig, vfo, mode, width, cachep, p);
|
||||||
RETURN_CACHED_MODE(rig, vfo, mode, width, cachep, p);
|
}
|
||||||
|
// Validate mode response using common function
|
||||||
|
if (validate_mode_response(rig, reply, sizeof(reply), __func__, 5) < 0) {
|
||||||
|
RETURN_CACHED_MODE(rig, vfo, mode, width, cachep, p);
|
||||||
|
}
|
||||||
|
// Update cache
|
||||||
|
cachep->modeMainA = guohe2rmode(reply[7], pmr171_modes);
|
||||||
|
cachep->modeMainB = guohe2rmode(reply[8], pmr171_modes);
|
||||||
|
// Return requested mode
|
||||||
|
*mode = (vfo == RIG_VFO_A) ? cachep->modeMainA : cachep->modeMainB;
|
||||||
|
*width = p->filterBW;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate mode response using common function
|
|
||||||
if (validate_mode_response(rig, reply, sizeof(reply), __func__, 5) < 0) {
|
|
||||||
RETURN_CACHED_MODE(rig, vfo, mode, width, cachep, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update cache
|
|
||||||
cachep->modeMainA = guohe2rmode(reply[7], pmr171_modes);
|
|
||||||
cachep->modeMainB = guohe2rmode(reply[8], pmr171_modes);
|
|
||||||
|
|
||||||
// Return requested mode
|
|
||||||
*mode = (vfo == RIG_VFO_A) ? cachep->modeMainA : cachep->modeMainB;
|
|
||||||
*width = p->filterBW;
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,25 +442,22 @@ static int pmr171_open(RIG *rig)
|
||||||
|
|
||||||
static int pmr171_get_vfo(RIG *rig, vfo_t *vfo)
|
static int pmr171_get_vfo(RIG *rig, vfo_t *vfo)
|
||||||
{
|
{
|
||||||
unsigned char reply[40];
|
{
|
||||||
|
unsigned char reply[40];
|
||||||
// Send status sync command to get current VFO state
|
// Send status sync command to get current VFO state
|
||||||
pmr171_send_cmd1(rig, 0x0b, 0);
|
pmr171_send_cmd1(rig, 0x0b, 0);
|
||||||
|
// Read and validate response using common function
|
||||||
// Read and validate response using common function
|
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
RETURN_CACHED_VFO(rig, vfo);
|
||||||
RETURN_CACHED_VFO(rig, vfo);
|
}
|
||||||
|
// Validate VFO status field index won't overflow
|
||||||
|
if (reply[4] < 13) { // Need at least 13 bytes to access reply[17]
|
||||||
|
rig_debug(RIG_DEBUG_ERR, "%s: Response too short for VFO data, using cached values\n", __func__);
|
||||||
|
RETURN_CACHED_VFO(rig, vfo);
|
||||||
|
}
|
||||||
|
// According to protocol doc, reply[17] is A/B frequency status
|
||||||
|
*vfo = (reply[17] == 1) ? RIG_VFO_B : RIG_VFO_A;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate VFO status field index won't overflow
|
|
||||||
if (reply[4] < 13) { // Need at least 13 bytes to access reply[17]
|
|
||||||
rig_debug(RIG_DEBUG_ERR, "%s: Response too short for VFO data, using cached values\n", __func__);
|
|
||||||
RETURN_CACHED_VFO(rig, vfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// According to protocol doc, reply[17] is A/B frequency status
|
|
||||||
*vfo = (reply[17] == 1) ? RIG_VFO_B : RIG_VFO_A;
|
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,25 +465,22 @@ static int pmr171_open(RIG *rig)
|
||||||
static int pmr171_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
static int pmr171_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
||||||
{
|
{
|
||||||
struct rig_cache *cachep = CACHE(rig);
|
struct rig_cache *cachep = CACHE(rig);
|
||||||
unsigned char reply[40];
|
{
|
||||||
|
unsigned char reply[40];
|
||||||
pmr171_send_cmd1(rig, 0x0b, 0);
|
pmr171_send_cmd1(rig, 0x0b, 0);
|
||||||
|
// Read and validate response using common function
|
||||||
// Read and validate response using common function
|
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
RETURN_CACHED_PTT(rig, ptt, cachep);
|
||||||
RETURN_CACHED_PTT(rig, ptt, cachep);
|
}
|
||||||
|
// Validate PTT status field index won't overflow
|
||||||
|
if (reply[4] < 2) { // Need at least 2 bytes to access reply[6]
|
||||||
|
rig_debug(RIG_DEBUG_ERR, "%s: Response too short for PTT data, using cached values\n", __func__);
|
||||||
|
RETURN_CACHED_PTT(rig, ptt, cachep);
|
||||||
|
}
|
||||||
|
// Get PTT status
|
||||||
|
cachep->ptt = reply[6];
|
||||||
|
*ptt = cachep->ptt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate PTT status field index won't overflow
|
|
||||||
if (reply[4] < 2) { // Need at least 2 bytes to access reply[6]
|
|
||||||
rig_debug(RIG_DEBUG_ERR, "%s: Response too short for PTT data, using cached values\n", __func__);
|
|
||||||
RETURN_CACHED_PTT(rig, ptt, cachep);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get PTT status
|
|
||||||
cachep->ptt = reply[6];
|
|
||||||
*ptt = cachep->ptt;
|
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,28 +516,24 @@ static int pmr171_open(RIG *rig)
|
||||||
static int pmr171_send_cmd2(RIG *rig, unsigned char cmd, unsigned char value,
|
static int pmr171_send_cmd2(RIG *rig, unsigned char cmd, unsigned char value,
|
||||||
int response)
|
int response)
|
||||||
{
|
{
|
||||||
unsigned char reply[40];
|
unsigned char buf[64] = { 0xa5, 0xa5, 0xa5, 0xa5, 0x04, 0x00, 0x00, 0x00, 0x00 };
|
||||||
hamlib_port_t *rp = RIGPORT(rig);
|
hamlib_port_t *rp = RIGPORT(rig);
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
|
||||||
unsigned char buf[64] = { 0xa5, 0xa5, 0xa5, 0xa5, 0x04, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
buf[5] = cmd;
|
buf[5] = cmd;
|
||||||
buf[6] = value;
|
buf[6] = value;
|
||||||
unsigned int crc = CRC16Check(&buf[4], 3);
|
unsigned int crc = CRC16Check(&buf[4], 3);
|
||||||
buf[7] = crc >> 8;
|
buf[7] = crc >> 8;
|
||||||
buf[8] = crc & 0xff;
|
buf[8] = crc & 0xff;
|
||||||
|
|
||||||
rig_flush(rp);
|
rig_flush(rp);
|
||||||
write_block(rp, buf, 9);
|
write_block(rp, buf, 9);
|
||||||
|
|
||||||
if (response)
|
if (response)
|
||||||
{
|
{
|
||||||
|
unsigned char reply[40];
|
||||||
// Use common response reading function
|
// Use common response reading function
|
||||||
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
return RIG_OK; // Return OK to use cached values
|
return RIG_OK; // Return OK to use cached values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pmr171_read_ack(rig);
|
return pmr171_read_ack(rig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -363,36 +363,32 @@ static int q900_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||||
cmd[6] = crc >> 8;
|
cmd[6] = crc >> 8;
|
||||||
cmd[7] = crc & 0xFF;
|
cmd[7] = crc & 0xFF;
|
||||||
|
|
||||||
unsigned char reply[40];
|
{
|
||||||
q900_send(rig, cmd, sizeof(cmd), reply, sizeof(reply));
|
unsigned char reply[40];
|
||||||
|
q900_send(rig, cmd, sizeof(cmd), reply, sizeof(reply));
|
||||||
// Validate response using common function
|
// Validate response using common function
|
||||||
if (validate_freq_response(rig, reply, sizeof(reply), __func__) < 0) {
|
if (validate_freq_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
RETURN_CACHED_FREQ(rig, vfo, freq);
|
RETURN_CACHED_FREQ(rig, vfo, freq);
|
||||||
|
}
|
||||||
|
// Parse frequency (big-endian)
|
||||||
|
int freq_a_offset = 9; // VFOA frequency starting position
|
||||||
|
int freq_b_offset = 13; // VFOB frequency starting position
|
||||||
|
uint32_t freq_a = (reply[freq_a_offset] << 24) |
|
||||||
|
(reply[freq_a_offset+1] << 16) |
|
||||||
|
(reply[freq_a_offset+2] << 8) |
|
||||||
|
reply[freq_a_offset+3];
|
||||||
|
uint32_t freq_b = (reply[freq_b_offset] << 24) |
|
||||||
|
(reply[freq_b_offset+1] << 16) |
|
||||||
|
(reply[freq_b_offset+2] << 8) |
|
||||||
|
reply[freq_b_offset+3];
|
||||||
|
// Update cache
|
||||||
|
CACHE(rig)->freqMainA = (freq_t)freq_a;
|
||||||
|
CACHE(rig)->freqMainB = (freq_t)freq_b;
|
||||||
|
// Return requested VFO frequency
|
||||||
|
*freq = (vfo == RIG_VFO_A) ? CACHE(rig)->freqMainA : CACHE(rig)->freqMainB;
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: Successfully got VFOA=%.0f Hz, VFOB=%.0f Hz\n",
|
||||||
|
__func__, CACHE(rig)->freqMainA, CACHE(rig)->freqMainB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse frequency (big-endian)
|
|
||||||
int freq_a_offset = 9;
|
|
||||||
int freq_b_offset = 13;
|
|
||||||
|
|
||||||
uint32_t freq_a = (reply[freq_a_offset] << 24) |
|
|
||||||
(reply[freq_a_offset+1] << 16) |
|
|
||||||
(reply[freq_a_offset+2] << 8) |
|
|
||||||
reply[freq_a_offset+3];
|
|
||||||
|
|
||||||
uint32_t freq_b = (reply[freq_b_offset] << 24) |
|
|
||||||
(reply[freq_b_offset+1] << 16) |
|
|
||||||
(reply[freq_b_offset+2] << 8) |
|
|
||||||
reply[freq_b_offset+3];
|
|
||||||
|
|
||||||
CACHE(rig)->freqMainA = (freq_t)freq_a;
|
|
||||||
CACHE(rig)->freqMainB = (freq_t)freq_b;
|
|
||||||
|
|
||||||
*freq = (vfo == RIG_VFO_A) ? CACHE(rig)->freqMainA : CACHE(rig)->freqMainB;
|
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: Successfully obtained VFOA=%.0f Hz, VFOB=%.0f Hz\n",
|
|
||||||
__func__, CACHE(rig)->freqMainA, CACHE(rig)->freqMainB);
|
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,25 +396,25 @@ static int q900_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||||
{
|
{
|
||||||
struct rig_cache *cachep = CACHE(rig);
|
struct rig_cache *cachep = CACHE(rig);
|
||||||
const q900_data_t *p = (q900_data_t *) STATE(rig)->priv;
|
const q900_data_t *p = (q900_data_t *) STATE(rig)->priv;
|
||||||
unsigned char reply[255];
|
{
|
||||||
|
unsigned char reply[255];
|
||||||
q900_send_cmd1(rig, 0x0b, 0);
|
// Get latest status from hardware
|
||||||
|
q900_send_cmd1(rig, 0x0b, 0);
|
||||||
// Read and validate response using common function
|
// Read and validate response using common function
|
||||||
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
RETURN_CACHED_MODE(rig, vfo, mode, width, cachep, p);
|
RETURN_CACHED_MODE(rig, vfo, mode, width, cachep, p);
|
||||||
|
}
|
||||||
|
// Validate mode response using common function
|
||||||
|
if (validate_mode_response(rig, reply, sizeof(reply), __func__, 5) < 0) {
|
||||||
|
RETURN_CACHED_MODE(rig, vfo, mode, width, cachep, p);
|
||||||
|
}
|
||||||
|
// Update cache
|
||||||
|
cachep->modeMainA = guohe2rmode(reply[7], q900_modes);
|
||||||
|
cachep->modeMainB = guohe2rmode(reply[8], q900_modes);
|
||||||
|
// Return requested mode
|
||||||
|
*mode = (vfo == RIG_VFO_A) ? cachep->modeMainA : cachep->modeMainB;
|
||||||
|
*width = p->filterBW;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate mode response using common function
|
|
||||||
if (validate_mode_response(rig, reply, sizeof(reply), __func__, 5) < 0) {
|
|
||||||
RETURN_CACHED_MODE(rig, vfo, mode, width, cachep, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
cachep->modeMainA = guohe2rmode(reply[7], q900_modes);
|
|
||||||
cachep->modeMainB = guohe2rmode(reply[8], q900_modes);
|
|
||||||
|
|
||||||
*mode = (vfo == RIG_VFO_A) ? cachep->modeMainA : cachep->modeMainB;
|
|
||||||
*width = p->filterBW;
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,29 +431,22 @@ static int q900_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||||
|
|
||||||
static int q900_get_vfo(RIG *rig, vfo_t *vfo)
|
static int q900_get_vfo(RIG *rig, vfo_t *vfo)
|
||||||
{
|
{
|
||||||
unsigned char reply[255];
|
{
|
||||||
|
unsigned char reply[255];
|
||||||
q900_send_cmd1(rig, 0x0b, 0);
|
// Send status sync command to get current VFO state
|
||||||
|
q900_send_cmd1(rig, 0x0b, 0);
|
||||||
// Read and validate response using common function
|
// Read and validate response using common function
|
||||||
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
RETURN_CACHED_VFO(rig, vfo);
|
RETURN_CACHED_VFO(rig, vfo);
|
||||||
|
}
|
||||||
|
// Validate VFO status field index won't overflow
|
||||||
|
if (reply[4] < 13) { // Need at least 13 bytes to access reply[17]
|
||||||
|
rig_debug(RIG_DEBUG_ERR, "%s: Response too short for VFO data, using cached values\n", __func__);
|
||||||
|
RETURN_CACHED_VFO(rig, vfo);
|
||||||
|
}
|
||||||
|
// According to protocol doc, reply[17] is A/B frequency status
|
||||||
|
*vfo = (reply[17] == 1) ? RIG_VFO_B : RIG_VFO_A;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate VFO status field index won't overflow
|
|
||||||
if (reply[4] < 13) { // Need at least 13 bytes to access reply[17]
|
|
||||||
rig_debug(RIG_DEBUG_ERR, "%s: Response too short for VFO data, using cached values\n", __func__);
|
|
||||||
RETURN_CACHED_VFO(rig, vfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate VFO status value
|
|
||||||
if (reply[17] != 0 && reply[17] != 1) {
|
|
||||||
rig_debug(RIG_DEBUG_ERR, "%s: Invalid VFO status value %d, using cached values\n", __func__, reply[17]);
|
|
||||||
RETURN_CACHED_VFO(rig, vfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
*vfo = (reply[17] == 1) ? RIG_VFO_B : RIG_VFO_A;
|
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,30 +454,22 @@ static int q900_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||||
static int q900_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
static int q900_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
||||||
{
|
{
|
||||||
struct rig_cache *cachep = CACHE(rig);
|
struct rig_cache *cachep = CACHE(rig);
|
||||||
unsigned char reply[255];
|
{
|
||||||
|
unsigned char reply[255];
|
||||||
q900_send_cmd1(rig, 0x0b, 0);
|
q900_send_cmd1(rig, 0x0b, 0);
|
||||||
|
// Read and validate response using common function
|
||||||
// Read and validate response using common function
|
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
RETURN_CACHED_PTT(rig, ptt, cachep);
|
||||||
RETURN_CACHED_PTT(rig, ptt, cachep);
|
}
|
||||||
|
// Validate PTT status field index won't overflow
|
||||||
|
if (reply[4] < 2) { // Need at least 2 bytes to access reply[6]
|
||||||
|
rig_debug(RIG_DEBUG_ERR, "%s: Response too short for PTT data, using cached values\n", __func__);
|
||||||
|
RETURN_CACHED_PTT(rig, ptt, cachep);
|
||||||
|
}
|
||||||
|
// Get PTT status
|
||||||
|
cachep->ptt = reply[6];
|
||||||
|
*ptt = cachep->ptt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate PTT status field index won't overflow
|
|
||||||
if (reply[4] < 2) { // Need at least 2 bytes to access reply[6]
|
|
||||||
rig_debug(RIG_DEBUG_ERR, "%s: Response too short for PTT data, using cached values\n", __func__);
|
|
||||||
RETURN_CACHED_PTT(rig, ptt, cachep);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate PTT status value
|
|
||||||
if (reply[6] != 0 && reply[6] != 1) {
|
|
||||||
rig_debug(RIG_DEBUG_ERR, "%s: Invalid PTT status value %d, using cached values\n", __func__, reply[6]);
|
|
||||||
RETURN_CACHED_PTT(rig, ptt, cachep);
|
|
||||||
}
|
|
||||||
|
|
||||||
cachep->ptt = reply[6];
|
|
||||||
*ptt = cachep->ptt;
|
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,28 +508,24 @@ static int q900_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
||||||
static int q900_send_cmd2(RIG *rig, unsigned char cmd, unsigned char value,
|
static int q900_send_cmd2(RIG *rig, unsigned char cmd, unsigned char value,
|
||||||
int response)
|
int response)
|
||||||
{
|
{
|
||||||
unsigned char reply[256];
|
unsigned char buf[64] = { 0xa5, 0xa5, 0xa5, 0xa5, 0x04, 0x00, 0x00, 0x00, 0x00 };
|
||||||
hamlib_port_t *rp = RIGPORT(rig);
|
hamlib_port_t *rp = RIGPORT(rig);
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
|
||||||
unsigned char buf[64] = { 0xa5, 0xa5, 0xa5, 0xa5, 0x04, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
buf[5] = cmd;
|
buf[5] = cmd;
|
||||||
buf[6] = value;
|
buf[6] = value;
|
||||||
unsigned int crc = CRC16Check(&buf[4], 3);
|
unsigned int crc = CRC16Check(&buf[4], 3);
|
||||||
buf[7] = crc >> 8;
|
buf[7] = crc >> 8;
|
||||||
buf[8] = crc & 0xff;
|
buf[8] = crc & 0xff;
|
||||||
|
|
||||||
rig_flush(rp);
|
rig_flush(rp);
|
||||||
write_block(rp, buf, 9);
|
write_block(rp, buf, 9);
|
||||||
|
|
||||||
if (response)
|
if (response)
|
||||||
{
|
{
|
||||||
|
unsigned char reply[256];
|
||||||
// Use common response reading function
|
// Use common response reading function
|
||||||
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
if (read_rig_response(rig, reply, sizeof(reply), __func__) < 0) {
|
||||||
return RIG_OK; // Return OK to use cached values
|
return RIG_OK; // Return OK to use cached values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return q900_read_ack(rig);
|
return q900_read_ack(rig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue