From 5b9db723d59a2d787a4ab38fedad402580ef739d Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Mon, 20 May 2024 08:01:32 -0500 Subject: [PATCH] Add missing file --- rigs/flexradio/smartsdr_caps.c | 71 +++++++++++ rigs/icom/ic7300.c | 128 +++++++++++++++++-- rigs/icom/icom.c | 4 +- rigs/icom/icom.h | 1 + rigs/icom/xiegu.c | 3 +- rigs/motorola/micom.c | 217 +++++++++++++++++++++++++++------ simulators/Makefile.am | 2 +- simulators/simmicom.c | 15 +++ 8 files changed, 387 insertions(+), 54 deletions(-) create mode 100644 rigs/flexradio/smartsdr_caps.c diff --git a/rigs/flexradio/smartsdr_caps.c b/rigs/flexradio/smartsdr_caps.c new file mode 100644 index 000000000..308f3c8a6 --- /dev/null +++ b/rigs/flexradio/smartsdr_caps.c @@ -0,0 +1,71 @@ + .mfg_name = "Flex-radio", + .version = "20240519.0", + .copyright = "LGPL", + .status = RIG_STATUS_ALPHA, + .rig_type = RIG_TYPE_TRANSCEIVER, + .targetable_vfo = 0, + .ptt_type = RIG_PTT_RIG, + .port_type = RIG_PORT_NETWORK, + + .has_get_func = SMARTSDR_FUNC, + .has_set_func = SMARTSDR_FUNC, + .has_get_level = SMARTSDR_LEVEL, + .has_set_level = RIG_LEVEL_SET(SMARTSDR_LEVEL), + .has_get_parm = SMARTSDR_PARM, + .has_set_parm = RIG_PARM_SET(SMARTSDR_PARM), + .chan_list = { + RIG_CHAN_END, + }, + .scan_ops = RIG_SCAN_NONE, + .vfo_ops = RIG_OP_NONE, + .transceive = RIG_TRN_OFF, + .attenuator = { RIG_DBLST_END, }, + .preamp = { 14, RIG_DBLST_END, }, + + .rx_range_list1 = { { + .startf = kHz(30), .endf = MHz(54), .modes = SMARTSDR_MODES, + .low_power = -1, .high_power = -1, SMARTSDR_VFO + }, + RIG_FRNG_END, + }, + .tx_range_list1 = { + /* restricted to ham band */ + FRQ_RNG_HF(1, SMARTSDR_MODES, W(1), W(100), SMARTSDR_VFO, SMARTSDR_ANTS), + FRQ_RNG_6m(1, SMARTSDR_MODES, W(1), W(100), SMARTSDR_VFO, SMARTSDR_ANTS), + RIG_FRNG_END, + }, + + .rx_range_list2 = { { + .startf = kHz(30), .endf = MHz(100), .modes = SMARTSDR_MODES, + .low_power = -1, .high_power = -1, SMARTSDR_VFO + }, + RIG_FRNG_END, + }, + .tx_range_list2 = { + /* restricted to ham band */ + FRQ_RNG_HF(2, SMARTSDR_MODES, W(1), W(100), SMARTSDR_VFO, SMARTSDR_ANTS), + FRQ_RNG_6m(2, SMARTSDR_MODES, W(1), W(100), SMARTSDR_VFO, SMARTSDR_ANTS), + RIG_FRNG_END, + }, + + .tuning_steps = { {SMARTSDR_MODES, 1}, + RIG_TS_END, + }, + .filters = { + {RIG_MODE_ALL, RIG_FLT_ANY}, + RIG_FLT_END + }, + .priv = NULL, /* priv */ + + .rig_init = smartsdr_init, + .rig_open = smartsdr_open, + .rig_close = smartsdr_close, + .rig_cleanup = smartsdr_cleanup, + + .set_freq = smartsdr_set_freq, + .get_freq = smartsdr_get_freq, + .set_ptt = smartsdr_set_ptt, +// .reset = smartsdr_reset, +// .set_level = smartsdr_set_level, +// .set_func = _set_func, + .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS diff --git a/rigs/icom/ic7300.c b/rigs/icom/ic7300.c index 1c0ac833a..5c3ba518e 100644 --- a/rigs/icom/ic7300.c +++ b/rigs/icom/ic7300.c @@ -37,17 +37,19 @@ static int ic7300_set_parm(RIG *rig, setting_t parm, value_t val); static int ic7300_get_parm(RIG *rig, setting_t parm, value_t *val); int ic7300_set_clock(RIG *rig, int year, int month, int day, int hour, - int min, int sec, double msec, int utc_offset); + int min, int sec, double msec, int utc_offset); int ic7300_get_clock(RIG *rig, int *year, int *month, int *day, - int *hour, - int *min, int *sec, double *msec, int *utc_offset); + int *hour, + int *min, int *sec, double *msec, int *utc_offset); int ic9700_set_clock(RIG *rig, int year, int month, int day, int hour, - int min, int sec, double msec, int utc_offset); + int min, int sec, double msec, int utc_offset); int ic9700_get_clock(RIG *rig, int *year, int *month, int *day, - int *hour, - int *min, int *sec, double *msec, int *utc_offset); + int *hour, + int *min, int *sec, double *msec, int *utc_offset); int ic9700_set_vfo(RIG *rig, vfo_t vfo); +int ic9700_set_freq(RIG *rig, vfo_t vfo, freq_t freq); +int ic9700_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); #define IC7300_ALL_RX_MODES (RIG_MODE_FM|RIG_MODE_PKTFM|RIG_MODE_AM|RIG_MODE_CW|RIG_MODE_CWR|RIG_MODE_SSB|RIG_MODE_RTTY|RIG_MODE_RTTYR|RIG_MODE_PKTLSB|RIG_MODE_PKTUSB|RIG_MODE_PKTFM|RIG_MODE_PKTAM) @@ -1247,8 +1249,8 @@ struct rig_caps ic9700_caps = .rig_open = icom_rig_open, .rig_close = icom_rig_close, - .set_freq = icom_set_freq, - .get_freq = icom_get_freq, + .set_freq = ic9700_set_freq, + .get_freq = ic9700_get_freq, .set_mode = icom_set_mode, .get_mode = icom_get_mode, // IC-9700 can indicate Main/Sub band selection, but not VFO A/B, so leave get_vfo not implemented @@ -2225,6 +2227,15 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) struct rig_cache *cachep = CACHE(rig); ENTERFUNC; + int satmode; + retval = rig_get_func(rig, RIG_VFO_CURR, RIG_FUNC_SATMODE, &satmode); + + if (retval != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: get satmode error: %s\n", __func__, + rigerror(retval)); + return retval; + } rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); @@ -2241,12 +2252,13 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) } else { - rig_debug(RIG_DEBUG_ERR, "%s: Invalid VFO %s in satellite mode\n", __func__, rig_strvfo(vfo)); + rig_debug(RIG_DEBUG_ERR, "%s: Invalid VFO %s in satellite mode\n", __func__, + rig_strvfo(vfo)); return -RIG_EINVAL; } } - if (vfo == RIG_VFO_A) + if (vfo == RIG_VFO_A || vfo == RIG_VFO_CURR) { retval = icom_transaction(rig, C_SET_VFO, S_VFOA, NULL, 0, ackbuf, &ack_len); } @@ -2266,6 +2278,7 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) { // First switch to Main receiver retval = icom_transaction(rig, C_SET_VFO, S_MAIN, NULL, 0, ackbuf, &ack_len); + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: %s\n", __func__, rigerror(retval)); @@ -2274,7 +2287,8 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) if (cachep->satmode && vfo == RIG_VFO_MAIN_B) { - rig_debug(RIG_DEBUG_WARN, "%s: cannot switch to VFOB when in satmode\n", __func__); + rig_debug(RIG_DEBUG_WARN, "%s: cannot switch to VFOB when in satmode\n", + __func__); // we return RIG_OK anyways as this should just be a bad request return RIG_OK; } @@ -2289,6 +2303,7 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) { // First switch to Sub receiver retval = icom_transaction(rig, C_SET_VFO, S_SUB, NULL, 0, ackbuf, &ack_len); + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: %s\n", __func__, rigerror(retval)); @@ -2297,7 +2312,8 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) if (cachep->satmode && vfo == RIG_VFO_SUB_B) { - rig_debug(RIG_DEBUG_WARN, "%s: cannot switch to VFOB when in satmode\n", __func__); + rig_debug(RIG_DEBUG_WARN, "%s: cannot switch to VFOB when in satmode\n", + __func__); // we return RIG_OK anyways as this should just be a bad request return RIG_OK; } @@ -2327,3 +2343,91 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) RETURNFUNC(retval); } + +int ic9700_set_freq(RIG *rig, vfo_t vfo, freq_t freq) +{ + ENTERFUNC; + int satmode; + int retval = icom_get_func(rig, RIG_VFO_CURR, RIG_FUNC_SATMODE, &satmode); + + if (retval != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: get satmode error: %s\n", __func__, + rigerror(retval)); + return retval; + } + + if (vfo & (RIG_VFO_A | RIG_VFO_B | RIG_VFO_MAIN_A | RIG_VFO_MAIN_B | + RIG_VFO_CURR)) + { + return icom_set_freq(rig, vfo, freq); + } + else if (vfo & (RIG_VFO_SUB | RIG_VFO_SUB_A | RIG_VFO_SUB_B)) + { + icom_set_vfo(rig, RIG_VFO_SUB_A); + return icom_set_freq(rig, vfo == RIG_VFO_SUB_B ? RIG_VFO_B : RIG_VFO_A, freq); + icom_set_vfo(rig, RIG_VFO_SUB_A); + } + + RETURNFUNC(-RIG_ENIMPL); +} + +int ic9700_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) +{ + struct rig_state *rs = &rig->state; + ENTERFUNC; + int satmode; + int retval = icom_get_func(rig, RIG_VFO_CURR, RIG_FUNC_SATMODE, &satmode); + + if (retval != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: get satmode error: %s\n", __func__, + rigerror(retval)); + RETURNFUNC(retval); + } + + if (vfo & (RIG_VFO_A | RIG_VFO_B | RIG_VFO_MAIN_A | RIG_VFO_MAIN_B | + RIG_VFO_CURR)) + { + int ack_len; + int freqbuf_offset; + unsigned char ackbuf[16]; + + if (satmode) + { + int save = rs->targetable_vfo; + rs->targetable_vfo = 0; + // retval = icom_get_freq(rig, vfo, &ack_len, ackbuf, &freqbuf_offset); + rs->targetable_vfo = save; + } + else + { + retval = icom_get_freq_x25(rig, vfo, &ack_len, ackbuf, &freqbuf_offset); + } + + if (retval == RIG_OK) + { + *freq = from_bcd(&ackbuf[freqbuf_offset], 5 * 2); + RETURNFUNC2(retval); + } + + RETURNFUNC(retval); + } + else if (vfo & (RIG_VFO_SUB | RIG_VFO_SUB_A | RIG_VFO_SUB_B)) + { + icom_set_vfo(rig, RIG_VFO_SUB_A); + int save = rs->targetable_vfo; + rs->targetable_vfo = 0; + retval = icom_get_freq(rig, vfo == RIG_VFO_SUB_B ? RIG_VFO_B : RIG_VFO_A, freq); + rs->targetable_vfo = save; + icom_set_vfo(rig, RIG_VFO_MAIN_A); + RETURNFUNC(retval); + } + else + { + rig_debug(RIG_DEBUG_ERR, "%s: unknown vfo=%s\n", __func__, rig_strvfo(vfo)); + RETURNFUNC(-RIG_EPROTO); + } + + RETURNFUNC(-RIG_ENIMPL); +} diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 7dd23c42e..0571df6d0 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -1425,7 +1425,7 @@ static int icom_set_freq_x25(RIG *rig, vfo_t vfo, freq_t freq, int freq_len, return retval; } -static int icom_get_freq_x25(RIG *rig, vfo_t vfo, int *ack_len, +int icom_get_freq_x25(RIG *rig, vfo_t vfo, int *ack_len, unsigned char *ackbuf, int *freqbuf_offset) { struct rig_state *rs = &rig->state; @@ -2254,7 +2254,7 @@ static int icom_get_mode_x26(RIG *rig, vfo_t vfo, int *mode_len, const struct icom_priv_caps *priv_caps = rig->caps->priv; int retval; - if (priv->x26cmdfails != 0 && priv_caps->x25x26_always==0) + if (priv->x26cmdfails > 0 && priv_caps->x25x26_always==0) { rig_debug(RIG_DEBUG_WARN, "%s: x26cmdfails=%d, x25x26_always=%d\n", __func__, priv->x26cmdfails, priv_caps->x25x26_always); return -RIG_ENAVAIL; diff --git a/rigs/icom/icom.h b/rigs/icom/icom.h index 131db64b9..7830c97f1 100644 --- a/rigs/icom/icom.h +++ b/rigs/icom/icom.h @@ -330,6 +330,7 @@ int icom_rig_close(RIG *rig); int icom_cleanup(RIG *rig); int icom_set_freq(RIG *rig, vfo_t vfo, freq_t freq); int icom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); +int icom_get_freq_x25(RIG *rig, vfo_t vfo, int *ack_len, unsigned char *ackbuf, int *freqbuf_offset); int icom_get_rit_new(RIG *rig, vfo_t vfo, shortfreq_t *ts); int icom_set_rit_new(RIG *rig, vfo_t vfo, shortfreq_t ts); int icom_set_xit_new(RIG *rig, vfo_t vfo, shortfreq_t ts); diff --git a/rigs/icom/xiegu.c b/rigs/icom/xiegu.c index fad83abdc..2b914d935 100644 --- a/rigs/icom/xiegu.c +++ b/rigs/icom/xiegu.c @@ -152,8 +152,7 @@ int xiegu_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s: Xiegu Radio ID=0x%04x\n", __func__, iid); switch(iid) { - case 0x0070: rig_debug(RIG_DEBUG_VERBOSE, "%s: Xiegu model %s\n", __func__, "G90");break; - case 0x0090: rig_debug(RIG_DEBUG_VERBOSE, "%s: Xiegu model %s\n", __func__, "G90S");break; + case 0x0090: rig_debug(RIG_DEBUG_VERBOSE, "%s: Xiegu model %s\n", __func__, "G90/G90S");break; case 0x0106: rig_debug(RIG_DEBUG_VERBOSE, "%s: Xiegu model %s\n", __func__, "G106/G106C");break; case 0x6100: case 0xa400: rig_debug(RIG_DEBUG_VERBOSE, "%s: Xiegu model %s\n", __func__, "X6100");break; diff --git a/rigs/motorola/micom.c b/rigs/motorola/micom.c index 7d26a30f4..4226abc6a 100644 --- a/rigs/motorola/micom.c +++ b/rigs/motorola/micom.c @@ -23,6 +23,12 @@ #include #include +#define M2_ALL_MODES (RIG_MODE_USB|RIG_MODE_LSB) + +#define M2_FUNCS (RIG_FUNC_TSQL) + +#define M2_LEVELS (RIG_LEVEL_SQL) + // char* to start of checksum for len bytes unsigned int checksum(unsigned char *buf, int len) { @@ -41,25 +47,38 @@ static int micom_open(RIG *rig) RETURNFUNC(RIG_OK); } +static int ACK(RIG *rig) +{ + unsigned char ack[6] = { 0x24, 0x01, 0x18, 0xf3, 0xff, 0x03 }; + return write_block(RIGPORT(rig), ack, sizeof(ack)); +} +#if 0 +#define ACK {\ + unsigned char ack[6] = { 0x24, 0x01, 0x18, 0xf3, 0xff, 0x03 };\ + write_block(RIGPORT(rig), ack, sizeof(ack));\ +} +#endif + // returns bytes read // format has length in byte[1] plus 5 bytes 0x24/len/cmd at start and checksum+0x03 at end -// So a data "length" of 5 is 10 bytes for example +// So a data "length" of 5 is 10 bytes for example static int micom_read_frame(RIG *rig, unsigned char *buf, int maxlen) { - hamlib_port_t *rp = RIGPORT(rig); int bytes; //const char stopset[1] = {0x03}; ENTERFUNC; - bytes = read_block(rp, buf, 3); - if (bytes+buf[1]+2 > maxlen) + bytes = read_block(RIGPORT(rig), buf, 3); + if (bytes <= 0) return -RIG_ETIMEOUT; + if (bytes + buf[1] + 2 > maxlen) { rig_debug(RIG_DEBUG_ERR, "%s: buffer overrun...expected max of %d, got %d\n", - __func__, maxlen, bytes+buf[1]+2); - dump_hex(buf,bytes); + __func__, maxlen, bytes + buf[1] + 2); + dump_hex(buf, bytes); RETURNFUNC(-RIG_EPROTO); } - bytes += read_block(rp, &buf[3], buf[1]+2); - dump_hex(buf,bytes); + + bytes += read_block(RIGPORT(rig), &buf[3], buf[1] + 2); + dump_hex(buf, bytes); RETURNFUNC(bytes); } @@ -72,14 +91,14 @@ static int micom_read_frame(RIG *rig, unsigned char *buf, int maxlen) */ static int micom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - hamlib_port_t *rp = RIGPORT(rig); - unsigned char rxcmd[12] = { 0x24, 0x06, 0x18, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x15 }; - unsigned char cmd2[11] = { 0x24, 0x05, 0x18, 0x36, 0xfe, 0x7b, 0xef, 0x01, 0xe0, 0x03, 0x15 }; - unsigned char cmd3[11] = { 0x24, 0x05, 0x18, 0x36, 0xfe, 0x7b, 0xef, 0x01, 0xe1, 0x03, 0x15 }; - unsigned char cmd4[11] = { 0x24, 0x05, 0x18, 0x36, 0xdf, 0x7b, 0xef, 0x01, 0xc1, 0x03, 0x15 }; - unsigned char cmd5[10] = { 0x24, 0x05, 0x18, 0x36, 0xff, 0x7b, 0xef, 0x01, 0xe1, 0x03 }; + unsigned char rxcmd[12] = { 0x24, 0x06, 0x18, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x15 }; + unsigned char up[11] = { 0x24, 0x05, 0x18, 0x36, 0xfe, 0x7b, 0xef, 0x01, 0xe0, 0x03, 0x15 }; // up + unsigned char release[11] = { 0x24, 0x05, 0x18, 0x36, 0xfe, 0x7b, 0xef, 0x01, 0xe1, 0x03, 0x15 }; // release + unsigned char down[11] = { 0x24, 0x05, 0x18, 0x36, 0xdf, 0x7b, 0xef, 0x01, 0xc1, 0x03, 0x15 }; // down + unsigned char release1[10] = { 0x24, 0x05, 0x18, 0x36, 0xff, 0x7b, 0xef, 0x01, 0xe1, 0x03 }; //unsigned char txcmd[11] = { 0x24, 0x05, 0x81, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 }; - unsigned int ifreq = freq; + // we substract 10 because the sequence set TX freq too and ends up 10Hz higher + unsigned int ifreq = freq - 10; unsigned char reply[11]; int retval; @@ -90,17 +109,20 @@ static int micom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) rxcmd[9] = checksum(rxcmd, 9); set_transaction_active(rig); - rig_flush(rp); - retval = write_block(rp, rxcmd, sizeof(rxcmd)); + rig_flush(RIGPORT(rig)); + retval = write_block(RIGPORT(rig), rxcmd, sizeof(rxcmd)); micom_read_frame(rig, reply, sizeof(reply)); - if (retval == RIG_OK) retval = write_block(rp, cmd2, sizeof(cmd2)); + + if (retval == RIG_OK) { retval = write_block(RIGPORT(rig), up, sizeof(up)); } micom_read_frame(rig, reply, sizeof(reply)); - if (retval == RIG_OK) retval = write_block(rp, cmd3, sizeof(cmd3)); + + if (retval == RIG_OK) { retval = write_block(RIGPORT(rig), release, sizeof(release)); } micom_read_frame(rig, reply, sizeof(reply)); - if (retval == RIG_OK) retval = write_block(rp, cmd4, sizeof(cmd4)); - micom_read_frame(rig, reply, sizeof(reply)); - if (retval == RIG_OK) retval = write_block(rp, cmd5, sizeof(cmd5)); + + if (retval == RIG_OK) { retval = write_block(RIGPORT(rig), down, sizeof(down)); } micom_read_frame(rig, reply, sizeof(reply)); + + if (retval == RIG_OK) { retval = write_block(RIGPORT(rig), release1, sizeof(release1)); } micom_read_frame(rig, reply, sizeof(reply)); if (retval != RIG_OK) @@ -111,8 +133,6 @@ static int micom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) return retval; } - micom_read_frame(rig, reply, sizeof(reply)); - #if 0 // this method doesn't work txcmd[5] = (ifreq >> 16) & 0xff; txcmd[6] = (ifreq >> 8) & 0xff; @@ -123,7 +143,7 @@ static int micom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) txcmd[7] = (ifreq >> 8) & 0xff; txcmd[8] = ifreq & 0xff; txcmd[9] = checksum(rxcmd, 9); - retval = write_block(rp, txcmd, sizeof(txcmd)); + retval = write_block(RIGPORT(rig), txcmd, sizeof(txcmd)); micom_read_frame(rig, reply, sizeof(reply)); if (retval != RIG_OK) @@ -141,16 +161,14 @@ static int micom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) static int micom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - hamlib_port_t *rp = RIGPORT(rig); unsigned char cmd[6] = { 0x24, 0x01, 0x18, 0x06, 0x06, 0x03 }; - unsigned char ack[6] = { 0x24, 0x01, 0x18, 0xf3, 0xff, 0x03 }; unsigned char reply[11]; int retval; - cmd[4] = checksum(cmd,4); + cmd[4] = checksum(cmd, 4); set_transaction_active(rig); - rig_flush(rp); - retval = write_block(rp, cmd, sizeof(cmd)); + rig_flush(RIGPORT(rig)); + retval = write_block(RIGPORT(rig), cmd, sizeof(cmd)); if (retval != RIG_OK) { @@ -162,12 +180,15 @@ static int micom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) // expecting 24 01 80 fe 98 03 -- an ack packet? micom_read_frame(rig, reply, sizeof(reply)); + if (reply[3] != 0xfe) { - rig_debug(RIG_DEBUG_ERR, "%s: unknown packet...expected byte 4 = 0xfe\n", __func__); + rig_debug(RIG_DEBUG_ERR, "%s: unknown packet...expected byte 4 = 0xfe\n", + __func__); } + micom_read_frame(rig, reply, sizeof(reply)); - write_block(rp, ack, sizeof(ack)); + ACK(rig); set_transaction_inactive(rig); *freq = (reply[4] << 24) | (reply[5] << 16) | (reply[6] << 8) | reply[7]; RETURNFUNC(RIG_OK); @@ -175,29 +196,130 @@ static int micom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) static int micom_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { - hamlib_port_t *rp = RIGPORT(rig); unsigned char on[] = { 0x24, 0x02, 0x81, 0x13, 0x01, 0xBB, 0x03 }; unsigned char off[] = { 0x24, 0x02, 0x81, 0x14, 0x01, 0xBC, 0x03 }; int retval; set_transaction_active(rig); - rig_flush(rp); + rig_flush(RIGPORT(rig)); - retval = write_block(rp, ptt ? on : off, sizeof(on)); + retval = write_block(RIGPORT(rig), ptt ? on : off, sizeof(on)); + set_transaction_inactive(rig); + return retval; +} + +static int micom_set_mode HAMLIB_PARAMS((RIG *rig, vfo_t vfo, rmode_t mode, + pbwidth_t width)) +{ + unsigned char setmode[] = { 0x24, 0x03, 0x18, 0x03, 0x01, 0xff, 0xff, 0x03 }; + int retval; + + if (mode != RIG_MODE_USB && mode != RIG_MODE_LSB) + { + rig_debug(RIG_DEBUG_ERR, "%s: USB and LSB are the only modes\n", __func__); + return -RIG_EINVAL; + } + + setmode[5] = mode == RIG_MODE_LSB ? 0 : 1; + setmode[6] = checksum(setmode, sizeof(setmode) - 2); + set_transaction_active(rig); + retval = write_block(RIGPORT(rig), setmode, sizeof(setmode)); set_transaction_inactive(rig); return retval; } +static int micom_get_mode HAMLIB_PARAMS((RIG *rig, vfo_t vfo, rmode_t *mode, + pbwidth_t *width)) +{ + unsigned char getsb[6] = { 0x24, 0x01, 0x18, 0x04, 0xff, 0x03 }; + unsigned char modecmd[6] = { 0x24, 0x01, 0x18, 0x0e, 0xff, 0x03 }; + unsigned char reply[11]; + int retval; + + getsb[4] = checksum(getsb, sizeof(getsb) - 2); + + set_transaction_active(rig); + + retval = write_block(RIGPORT(rig), getsb, sizeof(getsb)); + + if (retval == RIG_OK) { micom_read_frame(rig, reply, sizeof(reply)); } + + if (retval == RIG_OK) { retval = ACK(rig); } + + if (reply[4] == 0) { *mode = RIG_MODE_LSB; } + else { *mode = RIG_MODE_USB; } + + *width = 2700; // manual says 350 to 2700 + // test the ReportTransceiverMode + modecmd[4] = checksum(modecmd, sizeof(modecmd) - 2); + retval = write_block(RIGPORT(rig), modecmd, sizeof(modecmd)); + if (retval == RIG_OK) { micom_read_frame(rig, reply, sizeof(reply)); } + + set_transaction_inactive(rig); + return retval; +} + +int m2_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) +{ + unsigned char sql[6] = { 0x24, 0x03, 0x18, 0x09, 0xff, 0x03 }; + unsigned char reply[11]; + int retval = RIG_EPROTO; + switch (func) + { + case RIG_FUNC_TSQL: + sql[4] = status == 0 ? 0 : 1; + checksum(sql,4); + retval = write_block(RIGPORT(rig), sql, sizeof(sql)); + if (retval == RIG_OK) { micom_read_frame(rig, reply, sizeof(reply)); } + break; + default: + rig_debug(RIG_DEBUG_ERR, "%s: rig does know about func=%s\n", __func__, rig_strfunc(func)); + } + return retval; +} + +int m2_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) +{ + unsigned char sql[6] = { 0x24, 0x03, 0x18, 0x0a, 0xff, 0x03 }; + unsigned char reply[11]; + int retval = -RIG_EPROTO; + + switch (func) + { + case RIG_FUNC_TSQL: + checksum(sql,4); + retval = write_block(RIGPORT(rig), sql, sizeof(sql)); + if (retval == RIG_OK) { micom_read_frame(rig, reply, sizeof(reply)); } + micom_read_frame(rig, reply, sizeof(reply)); + ACK(rig); + break; + default: + rig_debug(RIG_DEBUG_ERR, "%s: rig does know about func=%s\n", __func__, rig_strfunc(func)); + } + return retval; +} + +int m2_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) +{ + return -RIG_ENIMPL; +} + +int m2_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) +{ + return -RIG_ENIMPL; +} + + struct rig_caps micom_caps = { RIG_MODEL(RIG_MODEL_MICOM2), .model_name = "Micom 2/3", .mfg_name = "Micom", - .version = "20240504.0", + .version = "20240505.2", .copyright = "LGPL", - .status = RIG_STATUS_ALPHA, + .status = RIG_STATUS_BETA, .rig_type = RIG_TYPE_TRANSCEIVER, .targetable_vfo = RIG_TARGETABLE_FREQ | RIG_TARGETABLE_MODE, .ptt_type = RIG_PTT_RIG, @@ -212,6 +334,27 @@ struct rig_caps micom_caps = .rig_open = micom_open, .set_freq = micom_set_freq, .get_freq = micom_get_freq, + .set_mode = micom_set_mode, + .get_mode = micom_get_mode, .set_ptt = micom_set_ptt, + .set_level = m2_set_level, + .get_level = m2_get_level, + .set_func = m2_set_func, + .get_func = m2_get_func, + + .rx_range_list1 = { + {MHz(0.1), MHz(30), M2_ALL_MODES, -1, -1, RIG_VFO_A}, RIG_FRNG_END + }, + .tx_range_list1 = { + {MHz(1.6), MHz(30), M2_ALL_MODES, W(25), W(125), RIG_VFO_A}, RIG_FRNG_END + }, + .filters = { + {M2_ALL_MODES, kHz(2.2)}, + {M2_ALL_MODES, kHz(3.7)} + }, + .tuning_steps = { + {M2_ALL_MODES, Hz(10)} + }, + .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; diff --git a/simulators/Makefile.am b/simulators/Makefile.am index 74fb40224..c2d4122cb 100644 --- a/simulators/Makefile.am +++ b/simulators/Makefile.am @@ -21,7 +21,7 @@ simid5100_SOURCES = simid5100.c # all the programs need this LDADD = $(top_builddir)/src/libhamlib.la $(top_builddir)/lib/libmisc.la $(DL_LIBS) -simelecraft_CFLAGS = $(AM_CFLAGS) $(LIBXML2_CFLAGS) -I$(top_builddir)/src +simelecraft_CFLAGS = -g $(AM_CFLAGS) $(LIBXML2_CFLAGS) -I$(top_builddir)/src simkenwood_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I$(top_builddir)/src simyaesu_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I$(top_builddir)/src simid5100_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I$(top_builddir)/src diff --git a/simulators/simmicom.c b/simulators/simmicom.c index 1cfb6a4d4..708204b03 100644 --- a/simulators/simmicom.c +++ b/simulators/simmicom.c @@ -28,6 +28,10 @@ char modeB = '1'; int width_main = 500; int width_sub = 700; +#define ACK {\ + unsigned char ack[6] = { 0x24, 0x01, 0x18, 0xf3, 0xff, 0x03 };\ + write(fd, ack, sizeof(ack));\ +} int getmyline(int fd, unsigned char *buf) @@ -117,17 +121,28 @@ again: printf("Report receiver freq\n"); unsigned char cmd[11] = { 0x24,0x06,0x18,0x05,0x01,0x00,0x38,0xea,0x50,0xba,0x03}; dump_hex(cmd, 11); + ACK; int n = write(fd, cmd, sizeof(cmd)); printf("%d bytes sent\n", n); + getmyline(fd, buf); break; case 0x13: printf("PTT On\n"); + ACK; break; case 0x14: printf("PTT Off\n"); + ACK; + break; + case 0x03: + ACK; + break; + case 0x04: + ACK; break; case 0x36: printf("Key request\n"); + ACK; break; default: printf("Unknown cmd=%02x\n", buf[3]);