From: Stéphane F. <fi...@us...> - 2008-05-05 21:57:37
|
Update of /cvsroot/hamlib/hamlib/kenwood In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv30704/kenwood Modified Files: th.c Log Message: * fix remaining places not knowing that tuning step is hexadecimal * get ready for freqs higher than 31 bits * on freq higher than 470MHz, tuning step of TH-F7 must be at least 10kHz * fix flexible th_get_mode * added RIG_LEVEL_BALANCE/RIG_LEVEL_ATT * and yes, we do want to read the transaction's reply, to know if successful Index: th.c =================================================================== RCS file: /cvsroot/hamlib/hamlib/kenwood/th.c,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -r1.31 -r1.32 *** th.c 4 May 2008 21:27:26 -0000 1.31 --- th.c 5 May 2008 21:57:32 -0000 1.32 *************** *** 75,79 **** int step, shift, rev, tone, ctcss, tonefq, ctcssfq; ! retval = sscanf(asyncbuf, "BUF %d,%"SCNfreq",%d,%d,%d,%d,%d,,%d,,%d,%"SCNfreq",%d", &vfo, &freq, &step, &shift, &rev, &tone, &ctcss, &tonefq, &ctcssfq, &offset, &mode); --- 75,79 ---- int step, shift, rev, tone, ctcss, tonefq, ctcssfq; ! retval = sscanf(asyncbuf, "BUF %d,%"SCNfreq",%X,%d,%d,%d,%d,,%d,,%d,%"SCNfreq",%d", &vfo, &freq, &step, &shift, &rev, &tone, &ctcss, &tonefq, &ctcssfq, &offset, &mode); *************** *** 177,181 **** int retval, step; size_t ack_len; - long f; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __FUNCTION__); --- 177,180 ---- *************** *** 186,193 **** } ! step = 1; ! f=(long) freq; ! sprintf(freqbuf, "FQ %011ld,%1d"EOM, f, step); ! ack_len = 0; retval = kenwood_transaction(rig, freqbuf, strlen(freqbuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 185,192 ---- } ! /* Step needs to be at least 10kHz on higher band */ ! step = freq >= MHz(470) ? 4 : 1; ! sprintf(freqbuf, "FQ %011"PRIll",%X"EOM, (long long)freq, step); ! ack_len = ACKBUF_LEN; retval = kenwood_transaction(rig, freqbuf, strlen(freqbuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 222,226 **** return retval; ! retval = sscanf(ackbuf, "FQ %"SCNfreq",%d",freq,&step); if (retval != 2) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __FUNCTION__, freqbuf); --- 221,225 ---- return retval; ! retval = sscanf(ackbuf, "FQ %"SCNfreq",%x",freq,&step); if (retval != 2) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __FUNCTION__, freqbuf); *************** *** 272,276 **** sprintf(mdbuf, "MD %c" EOM, kmode); ! ack_len = 0; retval = kenwood_transaction (rig, mdbuf, strlen(mdbuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 271,275 ---- sprintf(mdbuf, "MD %c" EOM, kmode); ! ack_len = ACKBUF_LEN; retval = kenwood_transaction (rig, mdbuf, strlen(mdbuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 305,309 **** return retval; ! if (strlen(ackbuf) < 4 ) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __FUNCTION__, ackbuf); return -RIG_ERJCTED; --- 304,308 ---- return retval; ! if (strlen(ackbuf) < 4 || ackbuf[3] < '0' || ackbuf[3] > '9') { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __FUNCTION__, ackbuf); return -RIG_ERJCTED; *************** *** 312,318 **** if (priv->mode_table) { ! *mode = kenwood2rmode(ackbuf[3], priv->mode_table); if (*mode == RIG_MODE_NONE) { ! rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Mode value '%c'\n", __FUNCTION__, ackbuf[3]); return -RIG_EINVAL; --- 311,317 ---- if (priv->mode_table) { ! *mode = kenwood2rmode(ackbuf[3]-'0', priv->mode_table); if (*mode == RIG_MODE_NONE) { ! rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Mode (table)value '%c'\n", __FUNCTION__, ackbuf[3]); return -RIG_EINVAL; *************** *** 370,374 **** } ! ack_len = 0; retval = kenwood_transaction(rig, vfobuf, strlen(vfobuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 369,373 ---- } ! ack_len = ACKBUF_LEN; retval = kenwood_transaction(rig, vfobuf, strlen(vfobuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 386,390 **** } ! ack_len = 0; retval = kenwood_transaction(rig, vfobuf, strlen(vfobuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 385,389 ---- } ! ack_len = ACKBUF_LEN; retval = kenwood_transaction(rig, vfobuf, strlen(vfobuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 466,470 **** sprintf(trnbuf, "AI %c" EOM, (trn == RIG_TRN_RIG) ? '1' : '0'); ! ack_len = 0; retval = kenwood_transaction (rig, trnbuf, strlen(trnbuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 465,469 ---- sprintf(trnbuf, "AI %c" EOM, (trn == RIG_TRN_RIG) ? '1' : '0'); ! ack_len = ACKBUF_LEN; retval = kenwood_transaction (rig, trnbuf, strlen(trnbuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 570,574 **** size_t ack_len; ! ack_len = 0; if(status==1) { retval = kenwood_transaction(rig, "TT"EOM, 3, ackbuf, &ack_len); --- 569,573 ---- size_t ack_len; ! ack_len = ACKBUF_LEN; if(status==1) { retval = kenwood_transaction(rig, "TT"EOM, 3, ackbuf, &ack_len); *************** *** 599,603 **** strncat(trbuf,(status)?" 1":" 0",16); strncat(trbuf,EOM,16); ! ack_len = 0; retval = kenwood_transaction (rig, cmd, strlen(cmd), ackbuf, &ack_len); if (retval != RIG_OK) --- 598,602 ---- strncat(trbuf,(status)?" 1":" 0",16); strncat(trbuf,EOM,16); ! ack_len = ACKBUF_LEN; retval = kenwood_transaction (rig, cmd, strlen(cmd), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 768,771 **** --- 767,794 ---- val->f = (float)(l-rig->caps->level_gran[LVL_RFPOWER].min.i) / (float)(rig->caps->level_gran[LVL_RFPOWER].max.i-rig->caps->level_gran[LVL_AF].min.i); break; + + case RIG_LEVEL_BALANCE: + sprintf(lvlbuf, "BAL" EOM); + retval = kenwood_transaction (rig, lvlbuf, strlen(lvlbuf), ackbuf, &ack_len); + if (retval != RIG_OK) + return retval; + if (ackbuf[4] < '0' || ackbuf[4] > '9') + return -RIG_EPROTO; + val->f = (float)('4'-ackbuf[4])/('4'-'0'); + break; + + case RIG_LEVEL_ATT: + sprintf(lvlbuf, "ATT" EOM); + retval = kenwood_transaction (rig, lvlbuf, strlen(lvlbuf), ackbuf, &ack_len); + if (retval != RIG_OK) + return retval; + if (ackbuf[4] < '0' || ackbuf[4] > '9') + return -RIG_EPROTO; + if (ackbuf[4] == '0') + val->i = 0; + else + val->i = rig->state.attenuator[ackbuf[4]-'1']; + break; + default: rig_debug(RIG_DEBUG_ERR,"%s: Unsupported Level %d", __FUNCTION__, level); *************** *** 799,803 **** } ! ack_len = 0; switch(level) { --- 822,826 ---- } ! ack_len = ACKBUF_LEN; switch(level) { *************** *** 814,817 **** --- 837,848 ---- retval = kenwood_transaction (rig, lvlbuf, strlen(lvlbuf), ackbuf, &ack_len); return retval; + case RIG_LEVEL_ATT : + sprintf(lvlbuf, "ATT %c" EOM, val.i ? '1' : '0'); + retval = kenwood_transaction (rig, lvlbuf, strlen(lvlbuf), ackbuf, &ack_len); + return retval; + case RIG_LEVEL_BALANCE : + sprintf(lvlbuf, "BAL %c" EOM, '4' - (int) (val.f * ('4'-'0'))); + retval = kenwood_transaction (rig, lvlbuf, strlen(lvlbuf), ackbuf, &ack_len); + return retval; default: rig_debug(RIG_DEBUG_ERR,"%s: Unsupported Level %d", __FUNCTION__, level); *************** *** 850,854 **** i += (i == 0) ? 1 : 2; /* Correct for TH-7DA index anomally */ sprintf(tonebuf, "CTN %02d" EOM, i); ! ack_len = 0; retval = kenwood_transaction(rig, tonebuf, strlen(tonebuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 881,885 ---- i += (i == 0) ? 1 : 2; /* Correct for TH-7DA index anomally */ sprintf(tonebuf, "CTN %02d" EOM, i); ! ack_len = ACKBUF_LEN; retval = kenwood_transaction(rig, tonebuf, strlen(tonebuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 955,959 **** return retval; ! ack_len = 0; retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 986,990 ---- return retval; ! ack_len = ACKBUF_LEN; retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 1036,1040 **** return -RIG_EINVAL; } ! ack_len = 0; retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 1067,1071 ---- return -RIG_EINVAL; } ! ack_len = ACKBUF_LEN; retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 1064,1068 **** } ! ack_len = 0; retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 1095,1099 ---- } ! ack_len = ACKBUF_LEN; retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 1166,1170 **** } ! ack_len = 0; retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len); if (retval != RIG_OK) --- 1197,1201 ---- } ! ack_len = ACKBUF_LEN; retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len); if (retval != RIG_OK) *************** *** 1358,1362 **** if (retval == RIG_OK) { strcpy(scf,req); ! strcat(scf,",%"SCNfreq",%d"); retval = sscanf(ackbuf, scf, &freq, &step); chan->tx_freq=freq; --- 1389,1393 ---- if (retval == RIG_OK) { strcpy(scf,req); ! strcat(scf,",%"SCNfreq",%x"); retval = sscanf(ackbuf, scf, &freq, &step); chan->tx_freq=freq; *************** *** 1586,1592 **** int th_set_ant (RIG * rig, vfo_t vfo, ant_t ant) { ! char ackbuf[50]; const char *cmd; ! size_t ack_len = 0; switch (ant) { --- 1617,1623 ---- int th_set_ant (RIG * rig, vfo_t vfo, ant_t ant) { ! char ackbuf[ACKBUF_LEN]; const char *cmd; ! size_t ack_len = ACKBUF_LEN; switch (ant) { *************** *** 1610,1615 **** int th_get_ant (RIG * rig, vfo_t vfo, ant_t * ant) { ! char ackbuf[50]; ! size_t ack_len = 50; int retval; --- 1641,1646 ---- int th_get_ant (RIG * rig, vfo_t vfo, ant_t * ant) { ! char ackbuf[ACKBUF_LEN]; ! size_t ack_len = ACKBUF_LEN; int retval; |