Add RFPOWER_METER_WATTS to TS890

https://github.com/Hamlib/Hamlib/issues/1497
pull/1498/head
Mike Black W9MDB 2024-01-31 10:29:46 -06:00
rodzic b4ec8a427c
commit fff1bbc8cd
3 zmienionych plików z 540 dodań i 36 usunięć

Wyświetl plik

@ -36,7 +36,7 @@
#define TS890_AM_TX_MODES RIG_MODE_AM
#define TS890_LEVEL_SET (RIG_LEVEL_RFPOWER|RIG_LEVEL_AF|RIG_LEVEL_RF|RIG_LEVEL_SQL|RIG_LEVEL_AGC|RIG_LEVEL_KEYSPD|RIG_LEVEL_CWPITCH|RIG_LEVEL_ATT|RIG_LEVEL_USB_AF|RIG_LEVEL_USB_AF_INPUT)
#define TS890_LEVEL_GET (RIG_LEVEL_RFPOWER|RIG_LEVEL_AF|RIG_LEVEL_RF|RIG_LEVEL_SQL|RIG_LEVEL_AGC|RIG_LEVEL_KEYSPD|RIG_LEVEL_ALC|RIG_LEVEL_SWR|RIG_LEVEL_COMP_METER|RIG_LEVEL_ID_METER|RIG_LEVEL_VD_METER|RIG_LEVEL_TEMP_METER|RIG_LEVEL_CWPITCH|RIG_LEVEL_RAWSTR|RIG_LEVEL_STRENGTH|RIG_LEVEL_ATT|RIG_LEVEL_USB_AF|RIG_LEVEL_USB_AF_INPUT)
#define TS890_LEVEL_GET (RIG_LEVEL_RFPOWER|RIG_LEVEL_AF|RIG_LEVEL_RF|RIG_LEVEL_SQL|RIG_LEVEL_AGC|RIG_LEVEL_KEYSPD|RIG_LEVEL_ALC|RIG_LEVEL_SWR|RIG_LEVEL_COMP_METER|RIG_LEVEL_ID_METER|RIG_LEVEL_VD_METER|RIG_LEVEL_TEMP_METER|RIG_LEVEL_CWPITCH|RIG_LEVEL_RAWSTR|RIG_LEVEL_STRENGTH|RIG_LEVEL_ATT|RIG_LEVEL_USB_AF|RIG_LEVEL_USB_AF_INPUT|RIG_LEVEL_RFPOWER_METER_WATTS)
#define TS890_FUNC_ALL (RIG_FUNC_NB|RIG_FUNC_NB2|RIG_FUNC_COMP|RIG_FUNC_VOX|RIG_FUNC_NR|RIG_FUNC_BC|RIG_FUNC_BC2|RIG_FUNC_RIT|RIG_FUNC_XIT|RIG_FUNC_TUNER|RIG_FUNC_SEND_MORSE|RIG_FUNC_TONE|RIG_FUNC_TSQL)
#define TS890_VFO_OPS (RIG_OP_UP|RIG_OP_DOWN|RIG_OP_BAND_UP|RIG_OP_BAND_DOWN|RIG_OP_CPY|RIG_OP_TUNE)
@ -289,6 +289,7 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
return -RIG_ENIMPL;
case RIG_LEVEL_STRENGTH:
case RIG_LEVEL_RFPOWER_METER_WATTS:
{
cal_table_float_t *table;
/* Values taken from the TS-890S In-Depth Manual (IDM), p. 8
@ -311,18 +312,18 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
}
};
/* Find out which meter type is in use */
retval = kenwood_safe_transaction(rig, "EX00011", ackbuf, sizeof(ackbuf), 11);
retval = kenwood_safe_transaction(rig, "EX00011", ackbuf, sizeof(ackbuf), 10);
if (retval != RIG_OK)
{
return retval;
}
if (strncmp(ackbuf + 8, "000", 3) == 0)
if (strncmp(ackbuf + 7, "000", 3) == 0)
{
table = &meter_type1;
}
else if (strncmp(ackbuf + 8, "001", 3) == 0)
else if (strncmp(ackbuf + 7, "001", 3) == 0)
{
table = &meter_type2;
}
@ -341,8 +342,17 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
}
sscanf(ackbuf + 2, "%d", &val->i);
/* Convert reading back to dB (rounded) */
val->i = (int)floorf(rig_raw2val_float(val->i, table) + 0.5f);
if (level == RIG_LEVEL_RFPOWER_METER_WATTS)
{
val->f = round(val->i / 70.0 * 150);
}
else
{
/* Convert reading back to dB (rounded) */
val->i = (int)floorf(rig_raw2val_float(val->i, table) + 0.5f);
}
return RIG_OK;
}
@ -376,22 +386,26 @@ int ts890_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
char current[4];
switch (func)
{
case RIG_FUNC_TONE:
mask = 1;
break;
case RIG_FUNC_TSQL:
mask = 2;
break;
default:
return (kenwood_set_func(rig, vfo, func, status));
}
{
case RIG_FUNC_TONE:
mask = 1;
break;
case RIG_FUNC_TSQL:
mask = 2;
break;
default:
return (kenwood_set_func(rig, vfo, func, status));
}
retval = kenwood_safe_transaction(rig, "TO", current, sizeof(current), 3);
if (retval != RIG_OK)
{
return (retval);
}
{
return (retval);
}
current[2] &= ~mask;
current[2] |= status == 0 ? 0 : mask;
return kenwood_transaction(rig, current, NULL, 0);
@ -401,24 +415,28 @@ int ts890_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
{
int mask, retval;
char current[4];
switch (func)
{
case RIG_FUNC_TONE:
mask = 1;
break;
case RIG_FUNC_TSQL:
mask = 2;
break;
default:
return (kenwood_get_func(rig, vfo, func, status));
}
{
case RIG_FUNC_TONE:
mask = 1;
break;
case RIG_FUNC_TSQL:
mask = 2;
break;
default:
return (kenwood_get_func(rig, vfo, func, status));
}
retval = kenwood_safe_transaction(rig, "TO", current, sizeof(current), 3);
if (retval != RIG_OK)
{
return retval;
}
{
return retval;
}
*status = current[2] & mask ? 1 : 0;
return RIG_OK;
}
@ -451,7 +469,7 @@ struct rig_caps ts890s_caps =
RIG_MODEL(RIG_MODEL_TS890S),
.model_name = "TS-890S",
.mfg_name = "Kenwood",
.version = BACKEND_VER ".12",
.version = BACKEND_VER ".13",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rig_type = RIG_TYPE_TRANSCEIVER,
@ -477,7 +495,7 @@ struct rig_caps ts890s_caps =
.transceive = RIG_TRN_RIG,
.agc_level_count = 5,
.agc_levels = { RIG_AGC_OFF, RIG_AGC_SLOW, RIG_AGC_MEDIUM, RIG_AGC_FAST, RIG_AGC_ON },
.chan_list = {
.chan_list = {
{ 1, 6, RIG_MTYPE_VOICE },
{ 1, 8, RIG_MTYPE_MORSE },
RIG_CHAN_END,

Wyświetl plik

@ -8,7 +8,7 @@ DISTCLEANFILES =
bin_PROGRAMS =
check_PROGRAMS = simelecraft simicgeneric simkenwood simyaesu simic9100 simic9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simic7300 simic7000 simic7100 simic7200 simatd578 simic905 simts450 simic7600 simic7610 simic705 simts950 simts990 simic7851 simftdx101 simxiegug90 simqrplabs simft818 simic275 simtrusdx simft1000 simtmd710
check_PROGRAMS = simelecraft simicgeneric simkenwood simyaesu simic9100 simic9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simic7300 simic7000 simic7100 simic7200 simatd578 simic905 simts450 simic7600 simic7610 simic705 simts950 simts990 simic7851 simftdx101 simxiegug90 simqrplabs simft818 simic275 simtrusdx simft1000 simtmd710 simts890
simelecraft_SOURCES = simelecraft.c
simkenwood_SOURCES = simkenwood.c

Wyświetl plik

@ -0,0 +1,486 @@
// can run this using rigctl/rigctld and socat pty devices
// gcc -o simyaesu simyaesu.c
#define _XOPEN_SOURCE 700
// since we are POSIX here we need this
#if 0
struct ip_mreq
{
int dummy;
};
#endif
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <hamlib/rig.h>
#define BUFSIZE 256
int mysleep = 20;
float freqA = 14074000;
float freqB = 14074500;
int filternum1 = 7;
int filternum2 = 8;
int datamode = 0;
int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune;
int operatingband;
int split;
int modeMain = 2;
int modeSub = 2;
int keyspd = 20;
#if defined(WIN32) || defined(_WIN32)
int openPort(char *comport) // doesn't matter for using pts devices
{
int fd;
fd = open(comport, O_RDWR);
if (fd < 0)
{
perror(comport);
}
return fd;
}
#else
int openPort(char *comport) // doesn't matter for using pts devices
{
int fd = posix_openpt(O_RDWR);
char *name = ptsname(fd);
if (name == NULL)
{
perror("pstname");
return -1;
}
printf("name=%s\n", name);
if (fd == -1 || grantpt(fd) == -1 || unlockpt(fd) == -1)
{
perror("posix_openpt");
return -1;
}
return fd;
}
#endif
int
getmyline(int fd, char *buf)
{
char c;
int i = 0;
memset(buf, 0, BUFSIZE);
int retval;
while ((retval = read(fd, &c, 1)) > 0)
{
buf[i++] = c;
if (c == ';') { return strlen(buf); }
}
if (retval != 0)
{
perror("read failed:");
close(fd);
fd = openPort("");
}
if (strlen(buf) == 0) { hl_usleep(10 * 1000); }
return strlen(buf);
}
int main(int argc, char *argv[])
{
char buf[256];
char *pbuf;
int fd = openPort(argv[1]);
int freqa = 14074000, freqb = 140735000;
int modeA = 1, modeB = 2;
while (1)
{
hl_usleep(10);
buf[0] = 0;
if (getmyline(fd, buf) > 0) { printf("Cmd:%s\n", buf); }
// else { return 0; }
if (strncmp(buf, "RM2", 3) == 0)
{
pbuf = "RM20020;";
write(fd, pbuf, strlen(pbuf));
}
else if (strcmp(buf, "RM5;") == 0)
{
printf("%s\n", buf);
hl_usleep(mysleep * 1000);
pbuf = "RM5100000;";
write(fd, pbuf, strlen(pbuf));
}
else if (strcmp(buf, "AN0;") == 0)
{
printf("%s\n", buf);
hl_usleep(mysleep * 1000);
pbuf = "AN030;";
write(fd, pbuf, strlen(pbuf));
}
else if (strcmp(buf, "IF;") == 0)
{
char ifbuf[256];
printf("%s\n", buf);
hl_usleep(mysleep * 1000);
// pbuf = "IF000503130001000+0000000000030000000;"
sprintf(ifbuf, "IF%011d1000+0000002000000000000;", freqa);
//pbuf = "IF00010138698 +00000000002000000 ;
write(fd, ifbuf, strlen(ifbuf));
continue;
}
else if (strcmp(buf, "NB;") == 0)
{
hl_usleep(mysleep * 1000);
pbuf = "NB0;";
write(fd, pbuf, strlen(pbuf));
continue;
}
else if (strcmp(buf, "RA;") == 0)
{
hl_usleep(mysleep * 1000);
pbuf = "RA01;";
write(fd, pbuf, strlen(pbuf));
continue;
}
else if (strcmp(buf, "RG;") == 0)
{
hl_usleep(mysleep * 1000);
pbuf = "RG055;";
write(fd, pbuf, strlen(pbuf));
continue;
}
else if (strcmp(buf, "MG;") == 0)
{
hl_usleep(mysleep * 1000);
pbuf = "MG050;";
write(fd, pbuf, strlen(pbuf));
continue;
}
else if (strcmp(buf, "AG;") == 0)
{
hl_usleep(mysleep * 1000);
pbuf = "AG100;";
write(fd, pbuf, strlen(pbuf));
continue;
}
else if (strcmp(buf, "FV;") == 0)
{
hl_usleep(mysleep * 1000);
pbuf = "FV1.2;";
write(fd, pbuf, strlen(pbuf));
continue;
}
else if (strncmp(buf, "IS;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "IS+0000;");
write(fd, buf, strlen(buf));
printf("%s\n", buf);
continue;
}
else if (strncmp(buf, "IS", 2) == 0)
{
continue;
}
else if (strncmp(buf, "SM;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "SM0035;");
write(fd, buf, strlen(buf));
printf("%s\n", buf);
continue;
}
else if (strncmp(buf, "PC;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "PC100;");
write(fd, buf, strlen(buf));
printf("%s\n", buf);
continue;
}
else if (strcmp(buf, "FW;") == 0)
{
//usleep(mysleep * 1000);
pbuf = "FW240";
write(fd, pbuf, strlen(pbuf));
hl_usleep(20 * 1000);
pbuf = "0;";
write(fd, pbuf, strlen(pbuf));
continue;
}
else if (strncmp(buf, "FW", 2) == 0)
{
continue;
}
else if (strcmp(buf, "ID;") == 0)
{
printf("%s\n", buf);
hl_usleep(mysleep * 1000);
int id = 24;
SNPRINTF(buf, sizeof(buf), "ID%03d;", id);
write(fd, buf, strlen(buf));
continue;
}
#if 0
else if (strncmp(buf, "AI", 2) == 0)
{
if (strcmp(buf, "AI;"))
{
printf("%s\n", buf);
hl_usleep(mysleep * 1000);
n = fprintf(fp, "%s", "AI0;");
}
}
#endif
else if (strcmp(buf, "VS;") == 0)
{
printf("%s\n", buf);
hl_usleep(mysleep * 1000);
pbuf = "VS0;";
write(fd, pbuf, strlen(pbuf));
continue;
}
else if (strcmp(buf, "EX00011;") == 0)
{
pbuf = "EX00011001;";
write(fd, pbuf, strlen(pbuf));
continue;
}
else if (strcmp(buf, "EX032;") == 0)
{
static int ant = 0;
ant = (ant + 1) % 3;
printf("%s\n", buf);
hl_usleep(mysleep * 1000);
SNPRINTF(buf, sizeof(buf), "EX032%1d;", ant);
write(fd, buf, strlen(buf));
continue;
}
else if (strncmp(buf, "EX", 2) == 0)
{
continue;
}
else if (strcmp(buf, "FA;") == 0)
{
SNPRINTF(buf, sizeof(buf), "FA%011d;", freqa);
write(fd, buf, strlen(buf));
continue;
}
else if (strcmp(buf, "FB;") == 0)
{
SNPRINTF(buf, sizeof(buf), "FB%011d;", freqb);
write(fd, buf, strlen(buf));
continue;
}
else if (strncmp(buf, "FA", 2) == 0)
{
sscanf(buf, "FA%d", &freqa);
continue;
}
else if (strncmp(buf, "FB", 2) == 0)
{
sscanf(buf, "FB%d", &freqb);
continue;
}
else if (strncmp(buf, "AI;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "AI0;");
write(fd, buf, strlen(buf));
continue;
}
else if (strncmp(buf, "PS;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "PS1;");
write(fd, buf, strlen(buf));
continue;
}
else if (strncmp(buf, "SA;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "SA0;");
write(fd, buf, strlen(buf));
}
else if (buf[3] == ';' && strncmp(buf, "SF", 2) == 0)
{
SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2],
buf[2] == '0' ? freqA : freqB,
buf[2] == '0' ? modeA + '0' : modeB + '0');
write(fd, buf, strlen(buf));
continue;
}
else if (strncmp(buf, "SF", 2) == 0)
{
mode_t tmpmode = buf[14];
if (buf[2] == '0') { modeA = tmpmode - '0'; }
else { modeB = tmpmode - '0'; }
printf("modeA=%c, modeB=%c\n", modeA, modeB);
continue;
}
else if (strncmp(buf, "MD;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "MD%d;",
modeA); // not worried about modeB yet for simulator
write(fd, buf, strlen(buf));
continue;
}
else if (strncmp(buf, "MD", 2) == 0)
{
sscanf(buf, "MD%d", &modeA); // not worried about modeB yet for simulator
continue;
}
else if (strncmp(buf, "FL;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "FL%03d%03d;", filternum1, filternum2);
write(fd, buf, strlen(buf));
continue;
}
else if (strncmp(buf, "FL", 2) == 0)
{
sscanf(buf, "FL%3d%3d", &filternum1, &filternum2);
continue;
}
else if (strcmp(buf, "FR;") == 0)
{
SNPRINTF(buf, sizeof(buf), "FR%d;", vfo);
write(fd, buf, strlen(buf));
continue;
}
else if (strncmp(buf, "FR", 2) == 0)
{
sscanf(buf, "FR%d", &vfo);
}
else if (strcmp(buf, "FT;") == 0)
{
SNPRINTF(buf, sizeof(buf), "FR%d;", vfo_tx);
write(fd, buf, strlen(buf));
continue;
}
else if (strncmp(buf, "FT", 2) == 0)
{
sscanf(buf, "FT%d", &vfo_tx);
}
else if (strncmp(buf, "DA;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "DA%d;", datamode);
write(fd, buf, strlen(buf));
printf("%s\n", buf);
continue;
}
else if (strncmp(buf, "DA", 2) == 0)
{
sscanf(buf, "DA%d", &datamode);
printf("%s\n", buf);
continue;
}
else if (strncmp(buf, "BD;", 3) == 0)
{
continue;
}
else if (strncmp(buf, "BU;", 3) == 0)
{
continue;
}
else if (strcmp(buf, "RX;") == 0)
{
ptt = ptt_mic = ptt_data = ptt_tune = 0;
}
else if (strncmp(buf, "TX", 2) == 0)
{
ptt = ptt_mic = ptt_data = ptt_tune = 0;
switch (buf[2])
{
case ';': ptt = 1;
case '0': ptt_mic = 1;
case '1': ptt_data = 1;
case '2': ptt_tune = 1;
}
continue;
}
else if (strncmp(buf, "CB;", 3) == 0)
{
sprintf(buf, "CB%d;", operatingband);
write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "CB", 2) == 0)
{
sscanf(buf, "CB%d", &operatingband);
}
else if (strncmp(buf, "TB;", 3) == 0)
{
sprintf(buf, "TB%d;", split);
write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "TB", 2) == 0)
{
sscanf(buf, "TB%d", &split);
}
else if (strncmp(buf, "KS;", 3) == 0)
{
sprintf(buf, "KS%03d;", keyspd);
write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "KS", 2) == 0)
{
sscanf(buf, "KS%03d", &keyspd);
}
else if (strncmp(buf, "OM0;", 4) == 0)
{
sprintf(buf, "OM0%d;", modeMain);
write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "OM0", 3) == 0)
{
sscanf(buf, "OM0%d", &modeMain);
}
else if (strncmp(buf, "OM1;", 4) == 0)
{
sprintf(buf, "OM1%d;", modeSub);
write(fd, buf, strlen(buf));
}
else if (strncmp(buf, "OM1", 3) == 0)
{
sscanf(buf, "OM1%d", &modeSub);
}
else if (strcmp(buf, "RM;") == 0)
{
sprintf(buf, "RM2%04d;", 10);
write(fd, buf, strlen(buf));
}
else if (strlen(buf) > 0)
{
fprintf(stderr, "Unknown command: %s\n", buf);
}
}
return 0;
}