Mike Black W9MDB 2023-08-19 08:43:06 -05:00
rodzic 3492be2562
commit 1ad43a44ba
2 zmienionych plików z 223 dodań i 194 usunięć

Wyświetl plik

@ -49,6 +49,7 @@ int satmode = 0;
int agc_time = 1; int agc_time = 1;
int ovf_status = 0; int ovf_status = 0;
int powerstat = 1; int powerstat = 1;
int keyertype = 0;
void dumphex(unsigned char *buf, int n) void dumphex(unsigned char *buf, int n)
{ {
@ -412,160 +413,182 @@ void frameParse(int fd, unsigned char *frame, int len)
break; break;
case 0x07: // satmode case 0x05:
frame[4] = 0; {
int item = frame[6] * 256 + frame[7];
printf("0x05 *************************** item=%04x\n", item);
if (frame[8] != 0xfd) // then we're setting it
{
switch (item)
{
case 164:
keyertype = frame[8];
break;
}
frame[4] = 0xfb;
frame[5] = 0xfd;
n = write(fd, frame, 6);
}
else // we're reading it
{
switch (item)
case 164:
frame[8] = keyertype;
frame[9] = 0xfb;
break;
}
n = write(fd, frame, 10);
}
break;
}
case 0x1c:
switch (frame[5])
{
case 0:
if (frame[6] == 0xfd)
{
frame[6] = ptt;
frame[7] = 0xfd; frame[7] = 0xfd;
n = write(fd, frame, 8); n = write(fd, frame, 8);
break;
} }
else
break;
case 0x1c:
switch (frame[5])
{ {
case 0: ptt = frame[6];
if (frame[6] == 0xfd) frame[7] = 0xfb;
{ frame[8] = 0xfd;
frame[6] = ptt; n = write(fd, frame, 9);
frame[7] = 0xfd;
n = write(fd, frame, 8);
}
else
{
ptt = frame[6];
frame[7] = 0xfb;
frame[8] = 0xfd;
n = write(fd, frame, 9);
}
break;
} }
break; break;
}
break;
#ifdef X25 #ifdef X25
case 0x25: case 0x25:
if (frame[6] == 0xfd) if (frame[6] == 0xfd)
{
if (frame[5] == 0x00)
{ {
if (frame[5] == 0x00) to_bcd(&frame[6], (long long)freqA, (civ_731_mode ? 4 : 5) * 2);
{ printf("X25 get_freqA=%.0f\n", freqA);
to_bcd(&frame[6], (long long)freqA, (civ_731_mode ? 4 : 5) * 2);
printf("X25 get_freqA=%.0f\n", freqA);
}
else
{
to_bcd(&frame[6], (long long)freqB, (civ_731_mode ? 4 : 5) * 2);
printf("X25 get_freqB=%.0f\n", freqB);
}
frame[11] = 0xfd;
#if 0
unsigned char frame2[11];
frame2[0] = 0xfe;
frame2[1] = 0xfe;
frame2[2] = 0x00; // send transceive frame
frame2[3] = frame[3]; // send transceive frame
frame2[4] = 0x00;
frame2[5] = 0x70;
frame2[6] = 0x28;
frame2[7] = 0x57;
frame2[8] = 0x03;
frame2[9] = 0x00;
frame2[10] = 0xfd;
n = write(fd, frame2, 11);
#endif
n = write(fd, frame, 12);
} }
else else
{ {
freq = from_bcd(&frame[6], (civ_731_mode ? 4 : 5) * 2); to_bcd(&frame[6], (long long)freqB, (civ_731_mode ? 4 : 5) * 2);
printf("set_freq to %.0f\n", freq); printf("X25 get_freqB=%.0f\n", freqB);
}
if (frame[5] == 0x00) { freqA = freq; } frame[11] = 0xfd;
else { freqB = freq; }
frame[4] = 0xfb;
frame[5] = 0xfd;
n = write(fd, frame, 6);
#if 0 #if 0
// send async frame unsigned char frame2[11];
frame[2] = 0x00; // async freq
frame[3] = 0xa2; frame2[0] = 0xfe;
frame[4] = 0x00; frame2[1] = 0xfe;
frame[5] = 0x00; frame2[2] = 0x00; // send transceive frame
frame[6] = 0x10; frame2[3] = frame[3]; // send transceive frame
frame[7] = 0x01; frame2[4] = 0x00;
frame[8] = 0x96; frame2[5] = 0x70;
frame[9] = 0x12; frame2[6] = 0x28;
frame[10] = 0xfd; frame2[7] = 0x57;
n = write(fd, frame, 11); frame2[8] = 0x03;
frame2[9] = 0x00;
frame2[10] = 0xfd;
n = write(fd, frame2, 11);
#endif #endif
} n = write(fd, frame, 12);
}
else
{
freq = from_bcd(&frame[6], (civ_731_mode ? 4 : 5) * 2);
printf("set_freq to %.0f\n", freq);
break; if (frame[5] == 0x00) { freqA = freq; }
else { freqB = freq; }
case 0x26: frame[4] = 0xfb;
for (int i = 0; i < 6; ++i) { printf("%02x:", frame[i]); }
if (frame[6] == 0xfd) // then a query
{
for (int i = 0; i < 6; ++i) { printf("%02x:", frame[i]); }
frame[6] = frame[5] == 0 ? modeA : modeB;
frame[7] = frame[5] == 0 ? datamodeA : datamodeB;
frame[8] = 0xfb;
frame[9] = 0xfd;
n = write(fd, frame, 10);
}
else
{
for (int i = 0; i < 12; ++i) { printf("%02x:", frame[i]); }
if (frame[6] == 0)
{
modeA = frame[7];
datamodeA = frame[8];
}
else
{
modeB = frame[7];
datamodeB = frame[8];
}
frame[4] = 0xfb;
frame[5] = 0xfd;
n = write(fd, frame, 6);
}
printf("\n");
break;
#else
case 0x25:
printf("x25 send nak\n");
frame[4] = 0xfa;
frame[5] = 0xfd; frame[5] = 0xfd;
n = write(fd, frame, 6); n = write(fd, frame, 6);
break; #if 0
// send async frame
case 0x26: frame[2] = 0x00; // async freq
printf("x26 send nak\n"); frame[3] = 0xa2;
frame[4] = 0xfa; frame[4] = 0x00;
frame[5] = 0xfd; frame[5] = 0x00;
n = write(fd, frame, 6); frame[6] = 0x10;
break; frame[7] = 0x01;
frame[8] = 0x96;
frame[9] = 0x12;
frame[10] = 0xfd;
n = write(fd, frame, 11);
#endif #endif
default: printf("cmd 0x%02x unknown\n", frame[4]);
} }
if (n == 0) { printf("Write failed=%s\n", strerror(errno)); } break;
case 0x26:
for (int i = 0; i < 6; ++i) { printf("%02x:", frame[i]); }
if (frame[6] == 0xfd) // then a query
{
for (int i = 0; i < 6; ++i) { printf("%02x:", frame[i]); }
frame[6] = frame[5] == 0 ? modeA : modeB;
frame[7] = frame[5] == 0 ? datamodeA : datamodeB;
frame[8] = 0xfb;
frame[9] = 0xfd;
n = write(fd, frame, 10);
}
else
{
for (int i = 0; i < 12; ++i) { printf("%02x:", frame[i]); }
if (frame[6] == 0)
{
modeA = frame[7];
datamodeA = frame[8];
}
else
{
modeB = frame[7];
datamodeB = frame[8];
}
frame[4] = 0xfb;
frame[5] = 0xfd;
n = write(fd, frame, 6);
}
printf("\n");
break;
#else
case 0x25:
printf("x25 send nak\n");
frame[4] = 0xfa;
frame[5] = 0xfd;
n = write(fd, frame, 6);
break;
case 0x26:
printf("x26 send nak\n");
frame[4] = 0xfa;
frame[5] = 0xfd;
n = write(fd, frame, 6);
break;
#endif
default: printf("cmd 0x%02x unknown\n", frame[4]);
}
if (n == 0) { printf("Write failed=%s\n", strerror(errno)); }
// don't care about the rig type yet // don't care about the rig type yet
@ -574,98 +597,98 @@ void frameParse(int fd, unsigned char *frame, int len)
#if defined(WIN32) || defined(_WIN32) #if defined(WIN32) || defined(_WIN32)
int openPort(char *comport) // doesn't matter for using pts devices int openPort(char *comport) // doesn't matter for using pts devices
{ {
int fd; int fd;
fd = open(comport, O_RDWR); fd = open(comport, O_RDWR);
if (fd < 0) if (fd < 0)
{ {
perror(comport); perror(comport);
} }
return fd; return fd;
} }
#else #else
int openPort(char *comport) // doesn't matter for using pts devices int openPort(char *comport) // doesn't matter for using pts devices
{ {
int fd = posix_openpt(O_RDWR); int fd = posix_openpt(O_RDWR);
char *name = ptsname(fd); char *name = ptsname(fd);
if (name == NULL) if (name == NULL)
{ {
perror("pstname"); perror("pstname");
return -1; return -1;
} }
printf("name=%s\n", name); printf("name=%s\n", name);
if (fd == -1 || grantpt(fd) == -1 || unlockpt(fd) == -1) if (fd == -1 || grantpt(fd) == -1 || unlockpt(fd) == -1)
{ {
perror("posix_openpt"); perror("posix_openpt");
return -1; return -1;
} }
return fd; return fd;
} }
#endif #endif
void rigStatus() void rigStatus()
{ {
char vfoa = current_vfo == RIG_VFO_A ? '*' : ' '; char vfoa = current_vfo == RIG_VFO_A ? '*' : ' ';
char vfob = current_vfo == RIG_VFO_B ? '*' : ' '; char vfob = current_vfo == RIG_VFO_B ? '*' : ' ';
printf("%cVFOA: mode=%d datamode=%d width=%ld freq=%.0f\n", vfoa, modeA, printf("%cVFOA: mode=%d datamode=%d width=%ld freq=%.0f\n", vfoa, modeA,
datamodeA, datamodeA,
widthA, widthA,
freqA); freqA);
printf("%cVFOB: mode=%d datamode=%d width=%ld freq=%.0f\n", vfob, modeB, printf("%cVFOB: mode=%d datamode=%d width=%ld freq=%.0f\n", vfob, modeB,
datamodeB, datamodeB,
widthB, widthB,
freqB); freqB);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
unsigned char buf[256]; unsigned char buf[256];
int fd = openPort(argv[1]); int fd = openPort(argv[1]);
printf("%s: %s\n", argv[0], rig_version()); printf("%s: %s\n", argv[0], rig_version());
#ifdef X25 #ifdef X25
printf("x25/x26 command recognized\n"); printf("x25/x26 command recognized\n");
#else #else
printf("x25/x26 command rejected\n"); printf("x25/x26 command rejected\n");
#endif #endif
#if defined(WIN32) || defined(_WIN32) #if defined(WIN32) || defined(_WIN32)
if (argc != 2) if (argc != 2)
{ {
printf("Missing comport argument\n"); printf("Missing comport argument\n");
printf("%s [comport]\n", argv[0]); printf("%s [comport]\n", argv[0]);
exit(1); exit(1);
} }
#endif #endif
while (1) while (1)
{
int len = frameGet(fd, buf);
if (len <= 0)
{ {
int len = frameGet(fd, buf); close(fd);
fd = openPort(argv[1]);
if (len <= 0)
{
close(fd);
fd = openPort(argv[1]);
}
if (powerstat)
{
frameParse(fd, buf, len);
}
else
{
hl_usleep(1000 * 1000);
}
rigStatus();
} }
return 0; if (powerstat)
{
frameParse(fd, buf, len);
}
else
{
hl_usleep(1000 * 1000);
}
rigStatus();
}
return 0;
} }

Wyświetl plik

@ -3568,9 +3568,9 @@ declare_proto_rig(set_parm)
if (strcmp(arg1,"KEYERTYPE")==0 && strcmp(arg2,"?") != 0) if (strcmp(arg1,"KEYERTYPE")==0 && strcmp(arg2,"?") != 0)
{ {
if (strcmp(arg2,"STRAIGHT")==0) arg2 = "0"; if (strcmp(arg2,"STRAIGHT")==0) {arg2 = "0";}
else if (strcmp(arg2,"BUG")==0) arg2 = "1"; else if (strcmp(arg2,"BUG")==0) {arg2 = "1";}
else if (strcmp(arg2,"PADDLE")==0) arg2 = "2"; else if (strcmp(arg2,"PADDLE")==0) {arg2 = "2";}
} }
parm = rig_parse_parm(arg1); parm = rig_parse_parm(arg1);
@ -3603,6 +3603,9 @@ declare_proto_rig(set_parm)
break; break;
case RIG_CONF_STRING: case RIG_CONF_STRING:
if (parm == RIG_PARM_KEYERTYPE)
val.i = atoi(arg2);
else
val.cs = arg2; val.cs = arg2;
break; break;
@ -3623,6 +3626,9 @@ declare_proto_rig(set_parm)
} }
else if (RIG_PARM_IS_STRING(parm)) else if (RIG_PARM_IS_STRING(parm))
{ {
if (parm == RIG_PARM_KEYERTYPE)
val.i = atoi(arg2);
else
val.cs = arg2; val.cs = arg2;
} }
else else