1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
|
/*
* Hamlib ACLog backend - main file
* Copyright (c) 2023 by Michael Black W9MDB
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hamlib/rig.h>
#include <serial.h>
#include <misc.h>
#define DEBUG 1
#define DEBUG_TRACE DEBUG_VERBOSE
#define TRUE 1
#define FALSE 0
#define MAXCMDLEN 8192
#define MAXXMLLEN 8192
#define MAXARGLEN 128
#define MAXBANDWIDTHLEN 4096
#define DEFAULTPATH "127.0.0.1:1100"
#define ACLOG_VFOS (RIG_VFO_A)
#define ACLOG_MODES (RIG_MODE_AM | RIG_MODE_PKTAM | RIG_MODE_CW | RIG_MODE_CWR |\
RIG_MODE_RTTY | RIG_MODE_RTTYR |\
RIG_MODE_PKTLSB | RIG_MODE_PKTUSB |\
RIG_MODE_SSB | RIG_MODE_LSB | RIG_MODE_USB |\
RIG_MODE_FM | RIG_MODE_WFM | RIG_MODE_FMN | RIG_MODE_PKTFM |\
RIG_MODE_C4FM)
#define streq(s1,s2) (strcmp(s1,s2)==0)
struct aclog_priv_data
{
vfo_t curr_vfo;
char bandwidths[MAXBANDWIDTHLEN]; /* pipe delimited set returned from aclog */
int nbandwidths;
char info[8192];
ptt_t ptt;
split_t split;
rmode_t curr_modeA;
rmode_t curr_modeB;
freq_t curr_freqA;
freq_t curr_freqB;
pbwidth_t curr_widthA;
pbwidth_t curr_widthB;
int has_get_modeA; /* True if this function is available */
int has_get_bwA; /* True if this function is available */
int has_set_bwA; /* True if this function is available */
float powermeter_scale; /* So we can scale power meter to 0-1 */
value_t parms[RIG_SETTING_MAX];
struct ext_list *ext_parms;
};
//Structure for mapping aclog dynamic modes to hamlib modes
//aclog displays modes as the rig displays them
struct s_modeMap
{
rmode_t mode_hamlib;
char *mode_aclog;
};
//ACLog will provide us the modes for the selected rig
//We will then put them in this struct
static struct s_modeMap modeMap[] =
{
{RIG_MODE_USB, "|USB|"},
{RIG_MODE_USB, "|SSB|"},
{RIG_MODE_LSB, "|LSB|"},
{RIG_MODE_PKTUSB, NULL},
{RIG_MODE_PKTLSB, NULL},
{RIG_MODE_AM, "|AM|"},
{RIG_MODE_FM, "|FM|"},
{RIG_MODE_FMN, NULL},
{RIG_MODE_WFM, NULL},
{RIG_MODE_CW, "|CW|"},
{RIG_MODE_CWR, "|CWR|"},
{RIG_MODE_RTTY, "|RTTY|"},
{RIG_MODE_RTTYR, "|RTTYR|"},
{RIG_MODE_C4FM, "|C4FM|"},
{0, NULL}
};
/*
* check_vfo
* No assumptions
*/
static int check_vfo(vfo_t vfo)
{
switch (vfo)
{
case RIG_VFO_A:
break;
case RIG_VFO_TX:
case RIG_VFO_B:
break;
case RIG_VFO_CURR:
break; // will default to A in which_vfo
default:
return (FALSE);
}
return (TRUE);
}
/*
* read_transaction
* Assumes rig!=NULL, xml!=NULL, xml_len>=MAXXMLLEN
*/
static int read_transaction(RIG *rig, char *xml, int xml_len)
{
int retval;
int retry;
char *delims;
char *terminator = "</CMD>\r\n";
ENTERFUNC;
retry = 2;
delims = "\n";
xml[0] = 0;
do
{
char tmp_buf[MAXXMLLEN]; // plenty big for expected aclog responses hopefully
if (retry < 2)
{
rig_debug(RIG_DEBUG_WARN, "%s: retry needed? retry=%d\n", __func__, retry);
}
int len = read_string(RIGPORT(rig), (unsigned char *) tmp_buf, sizeof(tmp_buf),
delims,
strlen(delims), 0, 1);
rig_debug(RIG_DEBUG_TRACE, "%s: string='%s'\n", __func__, tmp_buf);
// if our first response we should see the HTTP header
if (strlen(xml) == 0 && strstr(tmp_buf, "<CMD>") == NULL)
{
rig_debug(RIG_DEBUG_ERR, "%s: Expected '</CMD>', got '%s'\n", __func__,
tmp_buf);
continue; // we'll try again
}
if (len > 0) { retry = 3; }
if (len <= 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: read_string error=%d\n", __func__, len);
continue;
}
if (strlen(xml) + strlen(tmp_buf) < xml_len - 1)
{
strncat(xml, tmp_buf, xml_len - 1);
}
else
{
rig_debug(RIG_DEBUG_ERR,
"%s: xml buffer overflow!!\nTrying to add len=%d\nTo len=%d\n", __func__,
(int)strlen(tmp_buf), (int)strlen(xml));
RETURNFUNC(-RIG_EPROTO);
}
}
while (retry-- > 0 && strstr(xml, terminator) == NULL);
if (retry == 0)
{
rig_debug(RIG_DEBUG_WARN, "%s: retry timeout\n", __func__);
RETURNFUNC(-RIG_ETIMEOUT);
}
if (strstr(xml, terminator))
{
rig_debug(RIG_DEBUG_TRACE, "%s: got %s\n", __func__, terminator);
retval = RIG_OK;
}
else
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: did not get %s\n", __func__, terminator);
retval = -(101 + RIG_EPROTO);
}
RETURNFUNC(retval);
}
/*
* write_transaction
* Assumes rig!=NULL, xml!=NULL, xml_len=total size of xml for response
*/
static int write_transaction(RIG *rig, char *xml, int xml_len)
{
int try = rig->caps->retry;
int retval = -RIG_EPROTO;
hamlib_port_t *rp = RIGPORT(rig);
ENTERFUNC;
// This shouldn't ever happen...but just in case
// We need to avoid an empty write as rigctld replies with blank line
if (xml_len == 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: len==0??\n", __func__);
RETURNFUNC(retval);
}
// appears we can lose sync if we don't clear things out
// shouldn't be anything for us now anyways
rig_flush(rp);
while (try-- >= 0 && retval != RIG_OK)
{
retval = write_block(rp, (unsigned char *) xml, strlen(xml));
if (retval < 0)
{
RETURNFUNC(-RIG_EIO);
}
}
RETURNFUNC(retval);
}
static int aclog_transaction(RIG *rig, char *cmd, char *value,
int value_len)
{
char xml[MAXXMLLEN];
int retry = 3;
ENTERFUNC;
ELAPSED1;
strcpy(xml, "UNKNOWN");
set_transaction_active(rig);
if (value)
{
value[0] = 0;
}
do
{
int retval;
if (retry != 3)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: cmd=%s, retry=%d\n", __func__, cmd, retry);
}
retval = write_transaction(rig, cmd, strlen(cmd));
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: write_transaction error=%d\n", __func__, retval);
// if we get RIG_EIO the socket has probably disappeared
// so bubble up the error so port can re re-opened
if (retval == -RIG_EIO) { set_transaction_inactive(rig); RETURNFUNC(retval); }
hl_usleep(50 * 1000); // 50ms sleep if error
}
if (value)
{
read_transaction(rig, xml, sizeof(xml)); // this might time out -- that's OK
}
// we get an unknown response if function does not exist
if (strstr(xml, "UNKNOWN")) { set_transaction_inactive(rig); RETURNFUNC(-RIG_ENAVAIL); }
if (value) { strncpy(value, xml, value_len); }
}
while (((value && strlen(value) == 0))
&& retry--); // we'll do retries if needed
if (value && strlen(value) == 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: no value returned\n", __func__);
set_transaction_inactive(rig); RETURNFUNC(-RIG_EPROTO);
}
ELAPSED2;
set_transaction_inactive(rig);
RETURNFUNC(RIG_OK);
}
/*
* aclog_init
* Assumes rig!=NULL
*/
static int aclog_init(RIG *rig)
{
struct aclog_priv_data *priv;
hamlib_port_t *rp = RIGPORT(rig);
ENTERFUNC;
rig_debug(RIG_DEBUG_TRACE, "%s version %s\n", __func__, rig->caps->version);
STATE(rig)->priv = (struct aclog_priv_data *)calloc(1, sizeof(
struct aclog_priv_data));
if (!STATE(rig)->priv)
{
RETURNFUNC(-RIG_ENOMEM);
}
priv = STATE(rig)->priv;
memset(priv, 0, sizeof(struct aclog_priv_data));
memset(priv->parms, 0, RIG_SETTING_MAX * sizeof(value_t));
/*
* set arbitrary initial status
*/
STATE(rig)->current_vfo = RIG_VFO_A;
priv->split = 0;
priv->ptt = 0;
priv->curr_modeA = -1;
priv->curr_modeB = -1;
priv->curr_widthA = -1;
priv->curr_widthB = -1;
if (!rig->caps)
{
RETURNFUNC(-RIG_EINVAL);
}
strncpy(rp->pathname, DEFAULTPATH, sizeof(rp->pathname));
RETURNFUNC(RIG_OK);
}
/*
* modeMapGet
* Assumes mode!=NULL
* Return the string for ACLog for the given hamlib mode
*/
static const char *modeMapGet(rmode_t modeHamlib)
{
int i;
rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__);
for (i = 0; modeMap[i].mode_hamlib != 0; ++i)
{
if (modeMap[i].mode_aclog == NULL) { continue; }
rig_debug(RIG_DEBUG_TRACE,
"%s: checking modeMap[%d]=%.0f to modeHamlib=%.0f, mode_aclog='%s'\n", __func__,
i, (double)modeMap[i].mode_hamlib, (double)modeHamlib, modeMap[i].mode_aclog);
if (modeMap[i].mode_hamlib == modeHamlib && strlen(modeMap[i].mode_aclog) > 0)
{
rig_debug(RIG_DEBUG_TRACE, "%s matched mode=%.0f, returning '%s'\n", __func__,
(double)modeHamlib, modeMap[i].mode_aclog);
return (modeMap[i].mode_aclog);
}
}
rig_debug(RIG_DEBUG_ERR, "%s: ACLog does not have mode: %s\n", __func__,
rig_strrmode(modeHamlib));
return ("ERROR");
}
/*
* modeMapGetHamlib
* Assumes mode!=NULL
* Return the hamlib mode from the given ACLog string
*/
static rmode_t modeMapGetHamlib(const char *modeACLog)
{
int i;
char modeCheck[64];
SNPRINTF(modeCheck, sizeof(modeCheck), "|%s|", modeACLog);
for (i = 0; modeMap[i].mode_hamlib != 0; ++i)
{
rig_debug(RIG_DEBUG_TRACE, "%s: find '%s' in '%s'\n", __func__,
modeCheck, modeMap[i].mode_aclog);
if (modeMap[i].mode_aclog
&& strcmp(modeMap[i].mode_aclog, modeCheck) == 0)
{
return (modeMap[i].mode_hamlib);
}
}
rig_debug(RIG_DEBUG_TRACE, "%s: mode requested: %s, not in modeMap\n", __func__,
modeACLog);
return (RIG_MODE_NONE);
}
/*
* aclog_get_freq
* Assumes rig!=NULL, STATE(rig)->priv!=NULL, freq!=NULL
*
* string='<CMD><READBMFRESPONSE><BAND>23</BAND><MODE>SSB</MODE><MODETEST>PH</MODETEST><FREQ>1,296.171100</FREQ></CMD> '
*/
static int aclog_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
{
int i, j = 0;
char f_string[32];
char value[MAXARGLEN];
struct aclog_priv_data *priv = (struct aclog_priv_data *) STATE(rig)->priv;
ENTERFUNC;
rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__,
rig_strvfo(vfo));
if (check_vfo(vfo) == FALSE)
{
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n",
__func__, rig_strvfo(vfo));
RETURNFUNC(-RIG_EINVAL);
}
if (vfo == RIG_VFO_CURR)
{
vfo = STATE(rig)->current_vfo;
rig_debug(RIG_DEBUG_TRACE, "%s: get_freq2 vfo=%s\n",
__func__, rig_strvfo(vfo));
}
char *cmd = "<CMD><READBMF></CMD>\r\n";
int retval;
retval = aclog_transaction(rig, cmd, value, sizeof(value));
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: READBMF failed retval=%s\n", __func__,
rigerror(retval));
RETURNFUNC(retval);
}
char *p = strstr(value, "<FREQ>");
*freq = 0;
if (p)
{
// Move the pointer to the first digit.
p += strlen("<FREQ>");
// Parse "1,296.171100" ignoring the comma.
for (i = 0; p[i] != '<'; i++)
{
if (isdigit(p[i]))
{
f_string[j++] = p[i];
}
else if (ispunct(p[i]) && p[i] == '.')
{
f_string[j++] = p[i];
}
}
f_string[j] = '\0';
rig_debug(RIG_DEBUG_TRACE, "%s: f_string=%s\n", __func__, f_string);
*freq = strtold(f_string, NULL);
rig_debug(RIG_DEBUG_TRACE, "%s: freq=%.0f\n", __func__, *freq);
}
*freq *= 1e6; // convert from MHz to Hz
if (*freq == 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: freq==0??\nvalue=%s\n", __func__,
value);
RETURNFUNC(-RIG_EPROTO);
}
else
{
rig_debug(RIG_DEBUG_TRACE, "%s: freq=%.0f\n", __func__, *freq);
}
if (vfo == RIG_VFO_A)
{
priv->curr_freqA = *freq;
}
else // future support in ACLOG maybe?
{
priv->curr_freqB = *freq;
}
RETURNFUNC(RIG_OK);
}
/*
* aclog_get_mode
* Assumes rig!=NULL, STATE(rig)->priv!=NULL, mode!=NULL
*/
static int aclog_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
{
int retval;
char value[MAXCMDLEN];
char *cmdp;
struct aclog_priv_data *priv = (struct aclog_priv_data *) STATE(rig)->priv;
ENTERFUNC;
rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__,
rig_strvfo(vfo));
if (check_vfo(vfo) == FALSE)
{
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n",
__func__, rig_strvfo(vfo));
RETURNFUNC(-RIG_EINVAL);
}
cmdp = "<CMD><READBMF></CMD>\r\n"; /* default to old way */
retval = aclog_transaction(rig, cmdp, value, sizeof(value));
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: %s failed: %s\n", __func__, cmdp,
rigerror(retval));
RETURNFUNC(retval);
}
char *p = strstr(value, "<MODE>");
char modetmp[32];
modetmp[0] = 0;
if (p)
{
*mode = RIG_MODE_NONE;
int n = sscanf(p, "<MODE>%31[^<]", modetmp);
if (n == 1) { *mode = modeMapGetHamlib(modetmp); }
else
{
rig_debug(RIG_DEBUG_ERR, "%s: Unable to parse <MODE> from '%s'\n", __func__,
value);
*mode = RIG_MODE_USB; // just default to USB if we fail parsing
}
}
rig_debug(RIG_DEBUG_TRACE, "%s: mode='%s'\n", __func__,
rig_strrmode(*mode));
if (vfo == RIG_VFO_A)
{
priv->curr_modeA = *mode;
}
else
{
priv->curr_modeB = *mode;
}
*width = 2400; // just default to 2400 for now
RETURNFUNC(RIG_OK);
}
/*
* aclog_open
* Assumes rig!=NULL, STATE(rig)->priv!=NULL
*/
static int aclog_open(RIG *rig)
{
int retval;
char value[MAXARGLEN];
char *p;
//;struct aclog_priv_data *priv = (struct aclog_priv_data *) STATE(rig)->priv;
ENTERFUNC;
rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __func__, rig->caps->version);
retval = aclog_transaction(rig, "<CMD><PROGRAM></CMD>\r\n", value,
sizeof(value));
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR,
"%s: PROGRAM failed: %s", __func__, rigerror(retval));
}
rig_debug(RIG_DEBUG_TRACE, "%s: returned value=%s\n", __func__, value);
char version_pgm[64];
sscanf(value,
"<CMD><PROGRAMRESPONSE><PGM>N3FJP's Amateur Contact Log</PGM><VER>%63[^<]",
version_pgm);
rig_debug(RIG_DEBUG_VERBOSE, "%s: ACLog version=%s\n", __func__, version_pgm);
double version_api = 0;
p = strstr(value, "<APIVER>");
if (p) { sscanf(strstr(value, "<APIVER>"), "<APIVER>%lf", &version_api); }
rig_debug(RIG_DEBUG_VERBOSE, "%s ACLog API version %.1lf\n", __func__,
version_api);
retval = aclog_transaction(rig, "<CMD><RIGENABLED></CMD>\r\n", value,
sizeof(value));
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: RIGENABLED failed,,,not fatal: %s\n", __func__,
rigerror(retval));
}
p = strstr(value, "<RIG>");
char transceiver[64];
strcpy(transceiver, "Unknown");
if (p) { sscanf(p, "<RIG>%63[^<]", transceiver); }
rig_debug(RIG_DEBUG_VERBOSE, "Transceiver=%s\n", transceiver);
freq_t freq;
retval = aclog_get_freq(rig, RIG_VFO_CURR, &freq);
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: aclog_get_freq not working!!\n", __func__);
RETURNFUNC(-RIG_EPROTO);
}
STATE(rig)->current_vfo = RIG_VFO_A;
rig_debug(RIG_DEBUG_TRACE, "%s: currvfo=%s value=%s\n", __func__,
rig_strvfo(STATE(rig)->current_vfo), value);
RETURNFUNC(retval);
}
/*
* aclog_close
* Assumes rig!=NULL
*/
static int aclog_close(RIG *rig)
{
ENTERFUNC;
RETURNFUNC(RIG_OK);
}
/*
* aclog_cleanup
* Assumes rig!=NULL, STATE(rig)->priv!=NULL
*/
static int aclog_cleanup(RIG *rig)
{
struct aclog_priv_data *priv;
rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__);
if (!rig)
{
RETURNFUNC2(-RIG_EINVAL);
}
priv = (struct aclog_priv_data *)STATE(rig)->priv;
free(priv->ext_parms);
free(STATE(rig)->priv);
STATE(rig)->priv = NULL;
// we really don't need to free this up as it's only done once
// was causing problem when cleanup was followed by rig_open
// model_aclog was not getting refilled
// if we can figure out that one we can re-enable this
#if 0
int i;
for (i = 0; modeMap[i].mode_hamlib != 0; ++i)
{
if (modeMap[i].mode_aclog)
{
free(modeMap[i].mode_aclog);
modeMap[i].mode_aclog = NULL;
modeMap[i].mode_hamlib = 0;
}
}
#endif
RETURNFUNC2(RIG_OK);
}
/*
* aclog_set_freq
* assumes rig!=NULL, STATE(rig)->priv!=NULL
*/
static int aclog_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
int retval;
char cmd[MAXARGLEN];
char value[1024];
//struct aclog_priv_data *priv = (struct aclog_priv_data *) STATE(rig)->priv;
rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__);
rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s freq=%.0f\n", __func__,
rig_strvfo(vfo), freq);
if (check_vfo(vfo) == FALSE)
{
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n",
__func__, rig_strvfo(vfo));
RETURNFUNC2(-RIG_EINVAL);
}
#if 0
if (vfo == RIG_VFO_CURR)
{
vfo = STATE(rig)->current_vfo;
}
#endif
SNPRINTF(cmd, sizeof(cmd),
"<CMD><CHANGEFREQ><VALUE>%lf</VALUE><SUPPRESSMODEDEFAULT>TRUE</SUPPRESSMODEDEFAULT></CMD>\r\n",
freq / 1e6);
retval = aclog_transaction(rig, cmd, value, sizeof(value));
if (retval != RIG_OK)
{
RETURNFUNC2(retval);
}
RETURNFUNC2(RIG_OK);
}
/*
* aclog_set_mode
* Assumes rig!=NULL
*/
static int aclog_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
{
int retval;
char cmd[MAXCMDLEN];
char *p;
char *pttmode;
char *ttmode = NULL;
struct aclog_priv_data *priv = (struct aclog_priv_data *) STATE(rig)->priv;
ENTERFUNC;
rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s mode=%s width=%d\n",
__func__, rig_strvfo(vfo), rig_strrmode(mode), (int)width);
// if ptt is on do not set mode
if (priv->ptt)
{
rig_debug(RIG_DEBUG_TRACE, "%s: returning because priv->ptt=%d\n", __func__,
(int)priv->ptt);
RETURNFUNC(RIG_OK);
}
if (vfo == RIG_VFO_CURR)
{
vfo = STATE(rig)->current_vfo;
}
if (check_vfo(vfo) == FALSE)
{
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n",
__func__, rig_strvfo(vfo));
RETURNFUNC(-RIG_EINVAL);
}
if (priv->ptt)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s set_mode call not made as PTT=1\n", __func__);
RETURNFUNC(RIG_OK); // just return OK and ignore this
}
// Switch to VFOB if appropriate since we can't set mode directly
// MDB
rig_debug(RIG_DEBUG_TRACE, "%s: curr_vfo = %s\n", __func__,
rig_strvfo(STATE(rig)->current_vfo));
// Set the mode
if (strstr(modeMapGet(mode), "ERROR") == NULL)
{
ttmode = strdup(modeMapGet(mode));
}
else
{
rig_debug(RIG_DEBUG_ERR, "%s: modeMapGet failed on mode=%d\n", __func__,
(int)mode);
RETURNFUNC(-RIG_EINVAL);
}
rig_debug(RIG_DEBUG_TRACE, "%s: got ttmode = %s\n", __func__,
ttmode == NULL ? "NULL" : ttmode);
if (ttmode == NULL)
{
rig_debug(RIG_DEBUG_ERR, "%s: strdup failed\n", __func__);
RETURNFUNC(-RIG_EINTERNAL);
}
pttmode = ttmode;
if (ttmode[0] == '|') { pttmode = &ttmode[1]; } // remove first pipe symbol
p = strchr(pttmode, '|');
if (p) { *p = 0; } // remove any other pipe
SNPRINTF(cmd, sizeof(cmd),
"<CMD><CHANGEMODE><VALUE>%s</VALUE></CMD>\r\n", pttmode);
free(ttmode);
retval = aclog_transaction(rig, cmd, NULL, 0);
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: failed: %s\n", __func__,
rigerror(retval));
RETURNFUNC(retval);
}
if (vfo == RIG_VFO_A)
{
priv->curr_modeA = mode;
priv->curr_widthA = width;
}
else
{
priv->curr_modeB = mode;
priv->curr_widthB = width;
}
rig_debug(RIG_DEBUG_TRACE,
"%s: Return modeA=%s, widthA=%d\n,modeB=%s, widthB=%d\n", __func__,
rig_strrmode(priv->curr_modeA), (int)priv->curr_widthA,
rig_strrmode(priv->curr_modeB), (int)priv->curr_widthB);
RETURNFUNC(RIG_OK);
}
/*
* aclog_get_vfo
* assumes rig!=NULL, vfo != NULL
*/
static int aclog_get_vfo(RIG *rig, vfo_t *vfo)
{
ENTERFUNC;
*vfo = RIG_VFO_A;
RETURNFUNC(RIG_OK);
}
/*
* aclog_get_info
* assumes rig!=NULL
*/
static const char *aclog_get_info(RIG *rig)
{
const struct aclog_priv_data *priv = (struct aclog_priv_data *) STATE(
rig)->priv;
return (priv->info);
}
static int aclog_power2mW(RIG *rig, unsigned int *mwpower, float power,
freq_t freq, rmode_t mode)
{
const struct aclog_priv_data *priv = (struct aclog_priv_data *) STATE(
rig)->priv;
ENTERFUNC;
rig_debug(RIG_DEBUG_TRACE, "%s: passed power = %f\n", __func__, power);
rig_debug(RIG_DEBUG_TRACE, "%s: passed freq = %"PRIfreq" Hz\n", __func__, freq);
rig_debug(RIG_DEBUG_TRACE, "%s: passed mode = %s\n", __func__,
rig_strrmode(mode));
power *= priv->powermeter_scale;
*mwpower = (power * 100000);
RETURNFUNC(RIG_OK);
}
static int aclog_mW2power(RIG *rig, float *power, unsigned int mwpower,
freq_t freq, rmode_t mode)
{
ENTERFUNC;
rig_debug(RIG_DEBUG_TRACE, "%s: passed mwpower = %u\n", __func__, mwpower);
rig_debug(RIG_DEBUG_TRACE, "%s: passed freq = %"PRIfreq" Hz\n", __func__, freq);
rig_debug(RIG_DEBUG_TRACE, "%s: passed mode = %s\n", __func__,
rig_strrmode(mode));
*power = ((float)mwpower / 100000);
RETURNFUNC(RIG_OK);
}
/*
* aclog_set_ptt
* Assumes rig!=NULL
*/
static int aclog_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
{
int retval;
char cmd[MAXCMDLEN];
struct aclog_priv_data *priv = (struct aclog_priv_data *) STATE(rig)->priv;
ENTERFUNC;
rig_debug(RIG_DEBUG_TRACE, "%s: ptt=%d\n", __func__, ptt);
if (check_vfo(vfo) == FALSE)
{
rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n",
__func__, rig_strvfo(vfo));
RETURNFUNC(-RIG_EINVAL);
}
snprintf(cmd, sizeof(cmd),
ptt == RIG_PTT_ON ? "<CMD><RIGTX></CMD>\r\n" : "<CMD><RIGRX></CMD>\r\n");
retval = aclog_transaction(rig, cmd, NULL, 0);
if (retval != RIG_OK)
{
RETURNFUNC(retval);
}
priv->ptt = ptt;
RETURNFUNC(RIG_OK);
}
struct rig_caps aclog_caps =
{
RIG_MODEL(RIG_MODEL_ACLOG),
.model_name = "ACLog",
.mfg_name = "N3FJP",
.version = "20230120.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rig_type = RIG_TYPE_TRANSCEIVER,
//.targetable_vfo = RIG_TARGETABLE_FREQ | RIG_TARGETABLE_MODE,
.ptt_type = RIG_PTT_RIG,
.port_type = RIG_PORT_NETWORK,
.write_delay = 0,
.post_write_delay = 0,
.timeout = 1000,
.retry = 2,
.filters = {
{RIG_MODE_ALL, RIG_FLT_ANY},
RIG_FLT_END
},
.rx_range_list1 = {{
.startf = kHz(1), .endf = GHz(10), .modes = ACLOG_MODES,
.low_power = -1, .high_power = -1, ACLOG_VFOS, RIG_ANT_1
},
RIG_FRNG_END,
},
.tx_range_list1 = {RIG_FRNG_END,},
.rx_range_list2 = {{
.startf = kHz(1), .endf = GHz(10), .modes = ACLOG_MODES,
.low_power = -1, .high_power = -1, ACLOG_VFOS, RIG_ANT_1
},
RIG_FRNG_END,
},
.tx_range_list2 = {RIG_FRNG_END,},
.tuning_steps = { {ACLOG_MODES, 1}, {ACLOG_MODES, RIG_TS_ANY}, RIG_TS_END, },
.priv = NULL, /* priv */
.rig_init = aclog_init,
.rig_open = aclog_open,
.rig_close = aclog_close,
.rig_cleanup = aclog_cleanup,
.set_freq = aclog_set_freq,
.get_freq = aclog_get_freq,
.get_vfo = aclog_get_vfo,
.set_mode = aclog_set_mode,
.get_mode = aclog_get_mode,
.get_info = aclog_get_info,
.set_ptt = aclog_set_ptt,
//.get_ptt = aclog_get_ptt,
.power2mW = aclog_power2mW,
.mW2power = aclog_mW2power,
.hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS
};
|