diff --git a/src/locator.c b/src/locator.c index 91ebb261f..80f82e701 100644 --- a/src/locator.c +++ b/src/locator.c @@ -14,7 +14,7 @@ * Copyright (c) 2003 by Nate Bargmann * Copyright (c) 2003 by Dave Hines * - * $Id: locator.c,v 1.16 2004-10-02 10:32:08 fillods Exp $ + * $Id: locator.c,v 1.17 2005-01-18 23:06:34 n0nb Exp $ * * Code to determine bearing and range was taken from the Great Circle, * by S. R. Sampson, N5OWK. @@ -72,7 +72,7 @@ /* arc length for 1 degree, 60 Nautical Miles */ #define ARC_IN_KM 111.2 -/* The following is contributed by Dave Hines +/* The following is contributed by Dave Hines M1CXW * * begin dph */ @@ -80,25 +80,34 @@ * These are the constants used when converting between Maidenhead grid * locators and longitude/latitude values. MAX_LOCATOR_PAIRS is the maximum * number of locator character pairs to convert. This number MUST NOT exceed - * the number of pairs of values in range[] & weight[]. + * the number of pairs of values in loc_char_range[]. * Setting MAX_LOCATOR_PAIRS to 3 will convert the currently defined 6 * character locators. A value of 4 will convert the extended 8 character * locators described in section 3L of "The IARU region 1 VHF managers * handbook". Values of 5 and 6 will extent the format even more, to the - * longest definition I have seen for locators. Beware that there seems to be - * no universally accepted standard for 10 & 12 character locators. - * Note that the loc_char_weight values are in minutes of arc, to avoid - * constants which can't be represented precisely in either binary or decimal. + * longest definition I have seen for locators, see + * http://www.btinternet.com/~g8yoa/geog/non-ra.html + * Beware that there seems to be no universally accepted standard for 10 & 12 + * character locators. + * + * The ranges of characters which will be accepted by locator2longlat, and + * generated by longlat2locator, are specified by the loc_char_range[] array. + * This array may be changed without requiring any other code changes. + * + * For the fifth pair to range from aa to xx use: + * const static int loc_char_range[] = { 18, 10, 24, 10, 24, 10 }; + * + * For the fifth pair to range from aa to yy use: + * const static int loc_char_range[] = { 18, 10, 24, 10, 25, 10 }; * * MAX_LOCATOR_PAIRS now sets the limit locator2longlat() will convert and * sets the maximum length longlat2locator() will generate. Each function * properly handles any value from 1 to 6 so MAX_LOCATOR_PAIRS should be * left at 6. MIN_LOCATOR_PAIRS sets a floor on the shortest locator that * should be handled. -N0NB - * */ -const static double loc_char_weight[] = { 600.0, 60.0, 2.5, 0.25, 0.01, 0.001 }; -const static int loc_char_range[] = { 18, 10, 24, 10, 25, 10 }; +const static int loc_char_range[] = { 18, 10, 24, 10, 24, 10 }; + #define MAX_LOCATOR_PAIRS 6 #define MIN_LOCATOR_PAIRS 1 @@ -319,12 +328,12 @@ int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw) { * EM19 will return coordinates equivalent to the southwest corner * of EM19mm. * - * \retval -RIG_EINVAL if locator exceeds RR99xx99yy99 or exceeds length + * \retval -RIG_EINVAL if locator exceeds RR99xx99xx99 or exceeds length * limit--currently 1 to 6 lon/lat pairs. * \retval RIG_OK if conversion went OK. * - * \bug The fifth pair ranges from aa to yy, there is another convention - * that ranges from aa to xx. At some point both conventions should be + * \bug The fifth pair ranges from aa to xx, there is another convention + * that ranges from aa to yy. At some point both conventions should be * supported. * * \sa longlat2locator() @@ -335,7 +344,8 @@ int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw) { int HAMLIB_API locator2longlat(double *longitude, double *latitude, const char *locator) { int x_or_y, paircount; int locvalue, pair; - double xy[2], minutes; + int divisions; + double xy[2], ordinate; /* bail if NULL pointers passed */ if (!longitude || !latitude) @@ -349,9 +359,10 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude, const char * else if (paircount < MIN_LOCATOR_PAIRS) return -RIG_EINVAL; - /* For x(=lon) and y(=lat) */ + /* For x(=longitude) and y(=latitude) */ for (x_or_y = 0; x_or_y < 2; ++x_or_y) { - minutes = 0.0; + ordinate = -90.0; + divisions = 1; for (pair = 0; pair < paircount; ++pair) { locvalue = locator[pair*2 + x_or_y]; @@ -361,18 +372,19 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude, const char * (isupper(locvalue)) ? 'A' : 'a'; /* Check range for non-letter/digit or out of range */ - if (((unsigned) locvalue) >= loc_char_range[pair]) + if ((locvalue < 0) || (locvalue >= loc_char_range[pair])) return -RIG_EINVAL; - minutes += locvalue * loc_char_weight[pair]; + divisions *= loc_char_range[pair]; + ordinate += locvalue * 180.0 / divisions; } - /* Center coordinate */ - minutes += loc_char_weight[paircount - 1] / 2.0; + /* Center ordinate in the Maidenhead "square" or "subsquare" */ + ordinate += 90.0 / divisions; - xy[x_or_y] = minutes / 60.0 - 90.0; + xy[x_or_y] = ordinate; } - *longitude = xy[0] * 2; + *longitude = xy[0] * 2.0; *latitude = xy[1]; return RIG_OK; @@ -404,8 +416,8 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude, const char * /* begin dph */ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator, int pair_count) { - int x_or_y, pair, locvalue; - double tmp; + int x_or_y, pair, locvalue, divisions; + double square_size, ordinate; if (!locator) return -RIG_EINVAL; @@ -414,15 +426,17 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator, return -RIG_EINVAL; for (x_or_y = 0; x_or_y < 2; ++x_or_y) { - tmp = ((x_or_y == 0) ? longitude / 2. : latitude); + ordinate = (x_or_y == 0) ? longitude / 2.0 : latitude; + divisions = 1; /* The 1e-6 here guards against floating point rounding errors */ - tmp = fmod(tmp + 270., 180.) * 60. + 1e-6; + ordinate = fmod(ordinate + 270.000001, 180.0); for (pair = 0; pair < pair_count; ++pair) { - locvalue = (int) (tmp / loc_char_weight[pair]); + divisions *= loc_char_range[pair]; + square_size = 180.0 / divisions; - /* assert(locvalue < loc_char_range[pair]); */ - tmp -= loc_char_weight[pair] * locvalue; + locvalue = (int) (ordinate / square_size); + ordinate -= square_size * locvalue; locvalue += (loc_char_range[pair] == 10) ? '0':'A'; locator[pair * 2 + x_or_y] = locvalue; } diff --git a/yaesu/ft920.c b/yaesu/ft920.c index fe68218c8..bc287286a 100644 --- a/yaesu/ft920.c +++ b/yaesu/ft920.c @@ -2,7 +2,7 @@ * hamlib - (C) Frank Singleton 2000 (javabear at users.sourceforge.net) * * ft920.c - (C) Frank Singleton 2000 (javabear at users.sourceforge.net) - * (C) Nate Bargmann 2002, 2003 (n0nb at arrl.net) + * (C) Nate Bargmann 2002-2005 (n0nb at arrl.net) * (C) Stephane Fillod 2002 (fillods at users.sourceforge.net) * * This shared library provides an API for communicating @@ -12,7 +12,7 @@ * pages 86 to 90 * * - * $Id: ft920.c,v 1.16 2003-04-07 22:42:07 fillods Exp $ + * $Id: ft920.c,v 1.17 2005-01-18 23:06:48 n0nb Exp $ * * * This library is free software; you can redistribute it and/or @@ -36,8 +36,8 @@ #endif #include -#include /* String function definitions */ -#include /* UNIX standard function definitions */ +#include /* String function definitions */ +#include /* UNIX standard function definitions */ #include "hamlib/rig.h" #include "bandplan.h" @@ -70,19 +70,16 @@ * */ + /* Private helper function prototypes */ static int ft920_get_update_data(RIG *rig, unsigned char ci, unsigned char rl); - static int ft920_send_static_cmd(RIG *rig, unsigned char ci); - -static int ft920_send_dynamic_cmd(RIG *rig, unsigned char ci, - unsigned char p1, unsigned char p2, - unsigned char p3, unsigned char p4); - +static int ft920_send_dynamic_cmd(RIG *rig, unsigned char ci, unsigned char p1, unsigned char p2, unsigned char p3, unsigned char p4); static int ft920_send_dial_freq(RIG *rig, unsigned char ci, freq_t freq); - static int ft920_send_rit_freq(RIG *rig, unsigned char ci, shortfreq_t rit); + + /* * Native ft920 cmd set prototypes. These are READ ONLY as each * rig instance will copy from these and modify if required. @@ -95,31 +92,31 @@ static int ft920_send_rit_freq(RIG *rig, unsigned char ci, shortfreq_t rit); */ static const yaesu_cmd_set_t ncmd[] = { - { 1, { 0x00, 0x00, 0x00, 0x00, 0x01 } }, /* split = off */ - { 1, { 0x00, 0x00, 0x00, 0x01, 0x01 } }, /* split = on */ - { 0, { 0x00, 0x00, 0x00, 0x00, 0x02 } }, /* recall memory */ - { 0, { 0x00, 0x00, 0x00, 0x00, 0x03 } }, /* memory operations */ - { 1, { 0x00, 0x00, 0x00, 0x00, 0x05 } }, /* select vfo A */ - { 1, { 0x00, 0x00, 0x00, 0x01, 0x05 } }, /* select vfo B */ - { 0, { 0x00, 0x00, 0x00, 0x00, 0x06 } }, /* copy memory data to vfo A */ - { 0, { 0x00, 0x00, 0x00, 0x00, 0x09 } }, /* clarifier operations */ - { 0, { 0x00, 0x00, 0x00, 0x00, 0x0a } }, /* set vfo A freq */ - { 0, { 0x00, 0x00, 0x00, 0x00, 0x0c } }, /* mode set */ - { 0, { 0x00, 0x00, 0x00, 0x00, 0x0e } }, /* update interval/pacing */ - { 1, { 0x00, 0x00, 0x00, 0x01, 0x10 } }, /* Status Update Data--Memory Channel Number (1 byte) */ - { 1, { 0x00, 0x00, 0x00, 0x02, 0x10 } }, /* Status Update Data--Current operating data for VFO/Memory (28 bytes) */ - { 1, { 0x00, 0x00, 0x00, 0x03, 0x10 } }, /* Status Update DATA--VFO A and B Data (28 bytes) */ - { 0, { 0x00, 0x00, 0x00, 0x04, 0x10 } }, /* Status Update Data--Memory Channel Data (14 bytes) P4 = 0x00-0x89 Memory Channel Number */ - { 0, { 0x00, 0x00, 0x00, 0x00, 0x8a } }, /* set vfo B frequency */ - { 1, { 0x00, 0x00, 0x00, 0x00, 0x8c } }, /* VFO A wide filter */ - { 1, { 0x00, 0x00, 0x00, 0x02, 0x8c } }, /* VFO A narrow filter */ - { 1, { 0x00, 0x00, 0x00, 0x80, 0x8c } }, /* VFO B wide filter */ - { 1, { 0x00, 0x00, 0x00, 0x82, 0x8c } }, /* VFO B narrow filter */ - { 1, { 0x00, 0x00, 0x00, 0x01, 0xFA } }, /* Read status flags */ -/* { 0, { 0x00, 0x00, 0x00, 0x00, 0x70 } }, */ /* keyer commands */ -/* { 1, { 0x00, 0x00, 0x00, 0x00, 0x81 } }, */ /* tuner off */ -/* { 1, { 0x00, 0x00, 0x00, 0x01, 0x81 } }, */ /* tuner on */ -/* { 1, { 0x00, 0x00, 0x00, 0x00, 0x82 } }, */ /* tuner start*/ + { 1, { 0x00, 0x00, 0x00, 0x00, 0x01 } }, /* split = off */ + { 1, { 0x00, 0x00, 0x00, 0x01, 0x01 } }, /* split = on */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x02 } }, /* recall memory */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x03 } }, /* memory operations */ + { 1, { 0x00, 0x00, 0x00, 0x00, 0x05 } }, /* select vfo A */ + { 1, { 0x00, 0x00, 0x00, 0x01, 0x05 } }, /* select vfo B */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x06 } }, /* copy memory data to vfo A */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x09 } }, /* clarifier operations */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x0a } }, /* set vfo A freq */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x0c } }, /* mode set */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x0e } }, /* update interval/pacing */ + { 1, { 0x00, 0x00, 0x00, 0x01, 0x10 } }, /* Status Update Data--Memory Channel Number (1 byte) */ + { 1, { 0x00, 0x00, 0x00, 0x02, 0x10 } }, /* Status Update Data--Current operating data for VFO/Memory (28 bytes) */ + { 1, { 0x00, 0x00, 0x00, 0x03, 0x10 } }, /* Status Update DATA--VFO A and B Data (28 bytes) */ + { 0, { 0x00, 0x00, 0x00, 0x04, 0x10 } }, /* Status Update Data--Memory Channel Data (14 bytes) P4 = 0x00-0x89 Memory Channel Number */ + { 0, { 0x00, 0x00, 0x00, 0x00, 0x8a } }, /* set vfo B frequency */ + { 1, { 0x00, 0x00, 0x00, 0x00, 0x8c } }, /* VFO A wide filter */ + { 1, { 0x00, 0x00, 0x00, 0x02, 0x8c } }, /* VFO A narrow filter */ + { 1, { 0x00, 0x00, 0x00, 0x80, 0x8c } }, /* VFO B wide filter */ + { 1, { 0x00, 0x00, 0x00, 0x82, 0x8c } }, /* VFO B narrow filter */ + { 1, { 0x00, 0x00, 0x00, 0x01, 0xFA } }, /* Read status flags */ +/* { 0, { 0x00, 0x00, 0x00, 0x00, 0x70 } }, */ /* keyer commands */ +/* { 1, { 0x00, 0x00, 0x00, 0x00, 0x81 } }, */ /* tuner off */ +/* { 1, { 0x00, 0x00, 0x00, 0x01, 0x81 } }, */ /* tuner on */ +/* { 1, { 0x00, 0x00, 0x00, 0x00, 0x82 } }, */ /* tuner start*/ }; @@ -132,12 +129,12 @@ static const yaesu_cmd_set_t ncmd[] = { */ struct ft920_priv_data { - unsigned char pacing; /* pacing value */ - unsigned int read_update_delay; /* depends on pacing value */ - vfo_t current_vfo; /* active VFO from last cmd */ - unsigned char p_cmd[YAESU_CMD_LENGTH]; /* private copy of 1 constructed CAT cmd */ - yaesu_cmd_set_t pcs[FT920_NATIVE_SIZE]; /* private cmd set */ - unsigned char update_data[FT920_VFO_DATA_LENGTH]; /* returned data--max value, some are less */ + unsigned char pacing; /* pacing value */ + unsigned int read_update_delay; /* depends on pacing value */ + vfo_t current_vfo; /* active VFO from last cmd */ + unsigned char p_cmd[YAESU_CMD_LENGTH]; /* private copy of 1 constructed CAT cmd */ + yaesu_cmd_set_t pcs[FT920_NATIVE_SIZE]; /* private cmd set */ + unsigned char update_data[FT920_VFO_DATA_LENGTH]; /* returned data--max value, some are less */ }; /* @@ -147,134 +144,134 @@ struct ft920_priv_data { */ const struct rig_caps ft920_caps = { - .rig_model = RIG_MODEL_FT920, - .model_name = "FT-920", - .mfg_name = "Yaesu", - .version = "0.2.1", - .copyright = "LGPL", - .status = RIG_STATUS_ALPHA, - .rig_type = RIG_TYPE_TRANSCEIVER, - .ptt_type = RIG_PTT_NONE, - .dcd_type = RIG_DCD_NONE, - .port_type = RIG_PORT_SERIAL, - .serial_rate_min = 4800, - .serial_rate_max = 4800, - .serial_data_bits = 8, - .serial_stop_bits = 2, - .serial_parity = RIG_PARITY_NONE, - .serial_handshake = RIG_HANDSHAKE_NONE, - .write_delay = FT920_WRITE_DELAY, - .post_write_delay = FT920_POST_WRITE_DELAY, - .timeout = 2000, - .retry = 0, - .has_get_func = RIG_FUNC_NONE, - .has_set_func = RIG_FUNC_NONE, - .has_get_level = RIG_LEVEL_NONE, - .has_set_level = RIG_LEVEL_NONE, - .has_get_parm = RIG_PARM_NONE, - .has_set_parm = RIG_PARM_NONE, - .ctcss_list = NULL, - .dcs_list = NULL, - .preamp = { RIG_DBLST_END, }, - .attenuator = { RIG_DBLST_END, }, - .max_rit = Hz(9999), - .max_xit = Hz(9999), - .max_ifshift = Hz(0), - .targetable_vfo = RIG_TARGETABLE_ALL, - .transceive = RIG_TRN_OFF, /* Yaesus have to be polled, sigh */ - .bank_qty = 0, - .chan_desc_sz = 0, - .chan_list = { RIG_CHAN_END, }, /* FIXME: memory channel list: 122 (!) */ + .rig_model = RIG_MODEL_FT920, + .model_name = "FT-920", + .mfg_name = "Yaesu", + .version = "0.2.1", + .copyright = "LGPL", + .status = RIG_STATUS_ALPHA, + .rig_type = RIG_TYPE_TRANSCEIVER, + .ptt_type = RIG_PTT_NONE, + .dcd_type = RIG_DCD_NONE, + .port_type = RIG_PORT_SERIAL, + .serial_rate_min = 4800, + .serial_rate_max = 4800, + .serial_data_bits = 8, + .serial_stop_bits = 2, + .serial_parity = RIG_PARITY_NONE, + .serial_handshake = RIG_HANDSHAKE_NONE, + .write_delay = FT920_WRITE_DELAY, + .post_write_delay = FT920_POST_WRITE_DELAY, + .timeout = 2000, + .retry = 0, + .has_get_func = RIG_FUNC_NONE, + .has_set_func = RIG_FUNC_NONE, + .has_get_level = RIG_LEVEL_NONE, + .has_set_level = RIG_LEVEL_NONE, + .has_get_parm = RIG_PARM_NONE, + .has_set_parm = RIG_PARM_NONE, + .ctcss_list = NULL, + .dcs_list = NULL, + .preamp = { RIG_DBLST_END, }, + .attenuator = { RIG_DBLST_END, }, + .max_rit = Hz(9999), + .max_xit = Hz(9999), + .max_ifshift = Hz(0), + .targetable_vfo = RIG_TARGETABLE_ALL, + .transceive = RIG_TRN_OFF, /* Yaesus have to be polled, sigh */ + .bank_qty = 0, + .chan_desc_sz = 0, + .chan_list = { RIG_CHAN_END, }, /* FIXME: memory channel list: 122 (!) */ - .rx_range_list1 = { - {kHz(100), MHz(30), FT920_ALL_RX_MODES, -1, -1, FT920_VFO_ALL, FT920_ANTS}, /* General coverage + ham */ - {MHz(48), MHz(56), FT920_ALL_RX_MODES, -1, -1, FT920_VFO_ALL, FT920_ANTS}, /* 6m! */ - RIG_FRNG_END, - }, /* FIXME: Are these the correct Region 1 values? */ + .rx_range_list1 = { + {kHz(100), MHz(30), FT920_ALL_RX_MODES, -1, -1, FT920_VFO_ALL, FT920_ANTS}, /* General coverage + ham */ + {MHz(48), MHz(56), FT920_ALL_RX_MODES, -1, -1, FT920_VFO_ALL, FT920_ANTS}, /* 6m! */ + RIG_FRNG_END, + }, /* FIXME: Are these the correct Region 1 values? */ - .tx_range_list1 = { - FRQ_RNG_HF(1, FT920_OTHER_TX_MODES, W(5), W(100), FT920_VFO_ALL, FT920_ANTS), - FRQ_RNG_HF(1, FT920_AM_TX_MODES, W(2), W(25), FT920_VFO_ALL, FT920_ANTS), /* AM class */ + .tx_range_list1 = { + FRQ_RNG_HF(1, FT920_OTHER_TX_MODES, W(5), W(100), FT920_VFO_ALL, FT920_ANTS), + FRQ_RNG_HF(1, FT920_AM_TX_MODES, W(2), W(25), FT920_VFO_ALL, FT920_ANTS), /* AM class */ - FRQ_RNG_6m(1, FT920_OTHER_TX_MODES, W(5), W(100), FT920_VFO_ALL, FT920_ANTS), - FRQ_RNG_6m(1, FT920_AM_TX_MODES, W(2), W(25), FT920_VFO_ALL, FT920_ANTS), /* AM class */ - RIG_FRNG_END, - }, + FRQ_RNG_6m(1, FT920_OTHER_TX_MODES, W(5), W(100), FT920_VFO_ALL, FT920_ANTS), + FRQ_RNG_6m(1, FT920_AM_TX_MODES, W(2), W(25), FT920_VFO_ALL, FT920_ANTS), /* AM class */ + RIG_FRNG_END, + }, - .rx_range_list2 = { - {kHz(100), MHz(30), FT920_ALL_RX_MODES, -1, -1, FT920_VFO_ALL, FT920_ANTS}, - {MHz(48), MHz(56), FT920_ALL_RX_MODES, -1, -1, FT920_VFO_ALL, FT920_ANTS}, - RIG_FRNG_END, - }, + .rx_range_list2 = { + {kHz(100), MHz(30), FT920_ALL_RX_MODES, -1, -1, FT920_VFO_ALL, FT920_ANTS}, + {MHz(48), MHz(56), FT920_ALL_RX_MODES, -1, -1, FT920_VFO_ALL, FT920_ANTS}, + RIG_FRNG_END, + }, - .tx_range_list2 = { - FRQ_RNG_HF(2, FT920_OTHER_TX_MODES, W(5), W(100), FT920_VFO_ALL, FT920_ANTS), - FRQ_RNG_HF(2, FT920_AM_TX_MODES, W(2), W(25), FT920_VFO_ALL, FT920_ANTS), /* AM class */ + .tx_range_list2 = { + FRQ_RNG_HF(2, FT920_OTHER_TX_MODES, W(5), W(100), FT920_VFO_ALL, FT920_ANTS), + FRQ_RNG_HF(2, FT920_AM_TX_MODES, W(2), W(25), FT920_VFO_ALL, FT920_ANTS), /* AM class */ - FRQ_RNG_6m(2, FT920_OTHER_TX_MODES, W(5), W(100), FT920_VFO_ALL, FT920_ANTS), - FRQ_RNG_6m(2, FT920_AM_TX_MODES, W(2), W(25), FT920_VFO_ALL, FT920_ANTS), /* AM class */ - RIG_FRNG_END, - }, + FRQ_RNG_6m(2, FT920_OTHER_TX_MODES, W(5), W(100), FT920_VFO_ALL, FT920_ANTS), + FRQ_RNG_6m(2, FT920_AM_TX_MODES, W(2), W(25), FT920_VFO_ALL, FT920_ANTS), /* AM class */ + RIG_FRNG_END, + }, - .tuning_steps = { - {FT920_SSB_CW_RX_MODES, Hz(10)}, /* Normal */ - {FT920_SSB_CW_RX_MODES, Hz(100)}, /* Fast */ + .tuning_steps = { + {FT920_SSB_CW_RX_MODES, Hz(10)}, /* Normal */ + {FT920_SSB_CW_RX_MODES, Hz(100)}, /* Fast */ - {FT920_AM_RX_MODES, Hz(100)}, /* Normal */ - {FT920_AM_RX_MODES, kHz(1)}, /* Fast */ + {FT920_AM_RX_MODES, Hz(100)}, /* Normal */ + {FT920_AM_RX_MODES, kHz(1)}, /* Fast */ - {FT920_FM_RX_MODES, Hz(100)}, /* Normal */ - {FT920_FM_RX_MODES, kHz(1)}, /* Fast */ + {FT920_FM_RX_MODES, Hz(100)}, /* Normal */ + {FT920_FM_RX_MODES, kHz(1)}, /* Fast */ - RIG_TS_END, + RIG_TS_END, - /* - * The FT-920 has a Fine tuning step which increments in 1 Hz steps - * for SSB_CW_RX_MODES, and 10 Hz steps for AM_RX_MODES and - * FM_RX_MODES. It doesn't appear that anything finer than 10 Hz - * is available through the CAT interface, however. -N0NB - * - */ - }, + /* + * The FT-920 has a Fine tuning step which increments in 1 Hz steps + * for SSB_CW_RX_MODES, and 10 Hz steps for AM_RX_MODES and + * FM_RX_MODES. It doesn't appear that anything finer than 10 Hz + * is available through the CAT interface, however. -N0NB + * + */ + }, - /* mode/filter list, .remember = order matters! */ - .filters = { - {RIG_MODE_SSB, kHz(2.4)}, /* standard SSB filter bandwidth */ - {RIG_MODE_CW, kHz(2.4)}, /* normal CW filter */ - {RIG_MODE_CW, kHz(0.5)}, /* CW filter with narrow selection (must be installed!) */ - {RIG_MODE_AM, kHz(15)}, /* normal AM filter (stock radio has no AM filter!) */ - {RIG_MODE_AM, kHz(2.4)}, /* AM filter with narrow selection (SSB filter switched in) */ - {RIG_MODE_FM, kHz(12)}, /* FM with optional FM unit */ - {RIG_MODE_WFM, kHz(12)}, /* WideFM, with optional FM unit. */ - {RIG_MODE_RTTY, kHz(1.8)}, /* Alias of MODE_DATA_L */ - {RIG_MODE_RTTY, kHz(0.5)}, /* Alias of MODE_DATA_LN */ + /* mode/filter list, .remember = order matters! */ + .filters = { + {RIG_MODE_SSB, kHz(2.4)}, /* standard SSB filter bandwidth */ + {RIG_MODE_CW, kHz(2.4)}, /* normal CW filter */ + {RIG_MODE_CW, kHz(0.5)}, /* CW filter with narrow selection (must be installed!) */ + {RIG_MODE_AM, kHz(15)}, /* normal AM filter (stock radio has no AM filter!) */ + {RIG_MODE_AM, kHz(2.4)}, /* AM filter with narrow selection (SSB filter switched in) */ + {RIG_MODE_FM, kHz(12)}, /* FM with optional FM unit */ + {RIG_MODE_WFM, kHz(12)}, /* WideFM, with optional FM unit. */ + {RIG_MODE_RTTY, kHz(1.8)}, /* Alias of MODE_DATA_L */ + {RIG_MODE_RTTY, kHz(0.5)}, /* Alias of MODE_DATA_LN */ - RIG_FLT_END, - }, + RIG_FLT_END, + }, - .priv = NULL, /* private data FIXME: */ + .priv = NULL, /* private data FIXME: */ - .rig_init = ft920_init, - .rig_cleanup = ft920_cleanup, - .rig_open = ft920_open, /* port opened */ - .rig_close = ft920_close, /* port closed */ + .rig_init = ft920_init, + .rig_cleanup = ft920_cleanup, + .rig_open = ft920_open, /* port opened */ + .rig_close = ft920_close, /* port closed */ - .set_freq = ft920_set_freq, /* set freq */ - .get_freq = ft920_get_freq, /* get freq */ - .set_mode = ft920_set_mode, /* set mode */ - .get_mode = ft920_get_mode, /* get mode */ - .set_vfo = ft920_set_vfo, /* set vfo */ - .get_vfo = ft920_get_vfo, /* get vfo */ - .set_split_vfo = ft920_set_split_vfo, - .get_split_vfo = ft920_get_split_vfo, - .set_split_freq = ft920_set_split_freq, - .get_split_freq = ft920_get_split_freq, - .set_split_mode = ft920_set_split_mode, - .get_split_mode = ft920_get_split_mode, - .set_rit = ft920_set_rit, - .get_rit = ft920_get_rit, - .set_xit = ft920_set_xit, - .get_xit = ft920_get_xit, + .set_freq = ft920_set_freq, /* set freq */ + .get_freq = ft920_get_freq, /* get freq */ + .set_mode = ft920_set_mode, /* set mode */ + .get_mode = ft920_get_mode, /* get mode */ + .set_vfo = ft920_set_vfo, /* set vfo */ + .get_vfo = ft920_get_vfo, /* get vfo */ + .set_split_vfo = ft920_set_split_vfo, + .get_split_vfo = ft920_get_split_vfo, + .set_split_freq = ft920_set_split_freq, + .get_split_freq = ft920_get_split_freq, + .set_split_mode = ft920_set_split_mode, + .get_split_mode = ft920_get_split_mode, + .set_rit = ft920_set_rit, + .get_rit = ft920_get_rit, + .set_xit = ft920_set_xit, + .get_xit = ft920_get_xit, }; @@ -293,29 +290,29 @@ const struct rig_caps ft920_caps = { */ static int ft920_init(RIG *rig) { - struct ft920_priv_data *priv; - - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + struct ft920_priv_data *priv; - if (!rig) - return -RIG_EINVAL; - - priv = (struct ft920_priv_data *)malloc(sizeof(struct ft920_priv_data)); - if (!priv) /* whoops! memory shortage! */ - return -RIG_ENOMEM; - - /* - * Copy native cmd set to private cmd storage area - */ - memcpy(priv->pcs, ncmd, sizeof(ncmd)); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - /* TODO: read pacing from preferences */ - priv->pacing = FT920_PACING_DEFAULT_VALUE; /* set pacing to minimum for now */ - priv->read_update_delay = FT920_DEFAULT_READ_TIMEOUT; /* set update timeout to safe value */ - priv->current_vfo = RIG_VFO_A; /* default to VFO_A */ - rig->state.priv = (void *)priv; - - return RIG_OK; + if (!rig) + return -RIG_EINVAL; + + priv = (struct ft920_priv_data *)malloc(sizeof(struct ft920_priv_data)); + if (!priv) /* whoops! memory shortage! */ + return -RIG_ENOMEM; + + /* + * Copy native cmd set to private cmd storage area + */ + memcpy(priv->pcs, ncmd, sizeof(ncmd)); + + /* TODO: read pacing from preferences */ + priv->pacing = FT920_PACING_DEFAULT_VALUE; /* set pacing to minimum for now */ + priv->read_update_delay = FT920_DEFAULT_READ_TIMEOUT; /* set update timeout to safe value */ + priv->current_vfo = RIG_VFO_A; /* default to VFO_A */ + rig->state.priv = (void *)priv; + + return RIG_OK; } @@ -326,17 +323,16 @@ static int ft920_init(RIG *rig) { */ static int ft920_cleanup(RIG *rig) { + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!rig) + return -RIG_EINVAL; - if (!rig) - return -RIG_EINVAL; - - if (rig->state.priv) - free(rig->state.priv); - rig->state.priv = NULL; - - return RIG_OK; + if (rig->state.priv) + free(rig->state.priv); + rig->state.priv = NULL; + + return RIG_OK; } @@ -346,23 +342,23 @@ static int ft920_cleanup(RIG *rig) { */ static int ft920_open(RIG *rig) { - struct rig_state *rig_s; - - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + struct rig_state *rig_s; - if (!rig) - return -RIG_EINVAL; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_s = &rig->state; + if (!rig) + return -RIG_EINVAL; - rig_debug(RIG_DEBUG_TRACE, "%s: write_delay = %i msec\n", - __func__, rig_s->rigport.write_delay); - rig_debug(RIG_DEBUG_TRACE, "%s: post_write_delay = %i msec\n", - __func__, rig_s->rigport.post_write_delay); + rig_s = &rig->state; - /* TODO */ + rig_debug(RIG_DEBUG_TRACE, "%s: write_delay = %i msec\n", + __func__, rig_s->rigport.write_delay); + rig_debug(RIG_DEBUG_TRACE, "%s: post_write_delay = %i msec\n", + __func__, rig_s->rigport.post_write_delay); - return RIG_OK; + /* TODO: more initialization as necessary */ + + return RIG_OK; } @@ -372,13 +368,12 @@ static int ft920_open(RIG *rig) { */ static int ft920_close(RIG *rig) { + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!rig) + return -RIG_EINVAL; - if (!rig) - return -RIG_EINVAL; - - return RIG_OK; + return RIG_OK; } @@ -390,50 +385,48 @@ static int ft920_close(RIG *rig) { */ static int ft920_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - struct ft920_priv_data *priv; - int err, cmd_index; + struct ft920_priv_data *priv; + int err, cmd_index; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - priv = (struct ft920_priv_data *)rig->state.priv; + priv = (struct ft920_priv_data *)rig->state.priv; - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - rig_debug(RIG_DEBUG_TRACE, "%s: passed freq = %lli Hz\n", __func__, freq); + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); + rig_debug(RIG_DEBUG_TRACE, "%s: passed freq = %lli Hz\n", __func__, freq); - if (vfo == RIG_VFO_CURR) { - vfo = priv->current_vfo; /* from previous vfo cmd */ - rig_debug(RIG_DEBUG_TRACE, "%s: priv->current_vfo = 0x%02x\n", - __func__, vfo); - } + if (vfo == RIG_VFO_CURR) { + vfo = priv->current_vfo; /* from previous vfo cmd */ + rig_debug(RIG_DEBUG_TRACE, "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); + } - switch(vfo) { - case RIG_VFO_A: /* force main display to VFO */ - case RIG_VFO_VFO: - err = ft920_set_vfo(rig, RIG_VFO_A); - if (err != RIG_OK) - return err; - case RIG_VFO_MEM: /* MEM TUNE or user doesn't care */ - case RIG_VFO_MAIN: - cmd_index = FT920_NATIVE_VFO_A_FREQ_SET; - break; - case RIG_VFO_B: - case RIG_VFO_SUB: - cmd_index = FT920_NATIVE_VFO_B_FREQ_SET; - break; - default: - return -RIG_EINVAL; /* sorry, unsupported VFO */ - } - rig_debug(RIG_DEBUG_TRACE, "%s: set cmd_index = 0x%02x\n", - __func__, cmd_index); + switch(vfo) { + case RIG_VFO_A: /* force main display to VFO */ + case RIG_VFO_VFO: + err = ft920_set_vfo(rig, RIG_VFO_A); + if (err != RIG_OK) + return err; + case RIG_VFO_MEM: /* MEM TUNE or user doesn't care */ + case RIG_VFO_MAIN: + cmd_index = FT920_NATIVE_VFO_A_FREQ_SET; + break; + case RIG_VFO_B: + case RIG_VFO_SUB: + cmd_index = FT920_NATIVE_VFO_B_FREQ_SET; + break; + default: + return -RIG_EINVAL; /* sorry, unsupported VFO */ + } + rig_debug(RIG_DEBUG_TRACE, "%s: set cmd_index = 0x%02x\n", __func__, cmd_index); - err = ft920_send_dial_freq(rig, cmd_index, freq); - if (err != RIG_OK) - return err; + err = ft920_send_dial_freq(rig, cmd_index, freq); + if (err != RIG_OK) + return err; - return RIG_OK; + return RIG_OK; } @@ -443,59 +436,57 @@ static int ft920_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { */ static int ft920_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - struct ft920_priv_data *priv; - unsigned char *p; - unsigned char offset; - freq_t f; - int err, cmd_index; + struct ft920_priv_data *priv; + unsigned char *p; + unsigned char offset; + freq_t f; + int err, cmd_index; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - if (!rig) - return -RIG_EINVAL; - - priv = (struct ft920_priv_data *)rig->state.priv; + if (!rig) + return -RIG_EINVAL; - if (vfo == RIG_VFO_CURR) { - vfo = priv->current_vfo; /* from previous vfo cmd */ - rig_debug(RIG_DEBUG_TRACE, - "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); - } + priv = (struct ft920_priv_data *)rig->state.priv; - switch(vfo) { - case RIG_VFO_A: - case RIG_VFO_VFO: - cmd_index = FT920_NATIVE_VFO_DATA; - offset = FT920_SUMO_VFO_A_FREQ; - break; - case RIG_VFO_B: - case RIG_VFO_SUB: - cmd_index = FT920_NATIVE_OP_DATA; - offset = FT920_SUMO_VFO_B_FREQ; - break; - case RIG_VFO_MEM: - case RIG_VFO_MAIN: - cmd_index = FT920_NATIVE_OP_DATA; - offset = FT920_SUMO_DISPLAYED_FREQ; - break; - default: - return -RIG_EINVAL; /* sorry, wrong VFO */ - } - err = ft920_get_update_data(rig, cmd_index, FT920_VFO_DATA_LENGTH); - if (err != RIG_OK) - return err; - p = &priv->update_data[offset]; + if (vfo == RIG_VFO_CURR) { + vfo = priv->current_vfo; /* from previous vfo cmd */ + rig_debug(RIG_DEBUG_TRACE, "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); + } - /* big endian integer */ - f = (((((p[0]<<8) + p[1])<<8) + p[2])<<8) + p[3]; + switch(vfo) { + case RIG_VFO_A: + case RIG_VFO_VFO: + cmd_index = FT920_NATIVE_VFO_DATA; + offset = FT920_SUMO_VFO_A_FREQ; + break; + case RIG_VFO_B: + case RIG_VFO_SUB: + cmd_index = FT920_NATIVE_OP_DATA; + offset = FT920_SUMO_VFO_B_FREQ; + break; + case RIG_VFO_MEM: + case RIG_VFO_MAIN: + cmd_index = FT920_NATIVE_OP_DATA; + offset = FT920_SUMO_DISPLAYED_FREQ; + break; + default: + return -RIG_EINVAL; /* sorry, wrong VFO */ + } + err = ft920_get_update_data(rig, cmd_index, FT920_VFO_DATA_LENGTH); + if (err != RIG_OK) + return err; + p = &priv->update_data[offset]; - rig_debug(RIG_DEBUG_TRACE, - "%s: freq = %lli Hz for vfo 0x%02x\n", __func__, f, vfo); + /* big endian integer */ + f = (((((p[0]<<8) + p[1])<<8) + p[2])<<8) + p[3]; - *freq = f; /* return displayed frequency */ + rig_debug(RIG_DEBUG_TRACE, "%s: freq = %lli Hz for vfo 0x%02x\n", __func__, f, vfo); - return RIG_OK; + *freq = f; /* return displayed frequency */ + + return RIG_OK; } @@ -506,160 +497,154 @@ static int ft920_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { * */ -static int ft920_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, - pbwidth_t width ) { - struct ft920_priv_data *priv; - unsigned char cmd_index; /* index of sequence to send */ - unsigned char mode_parm; /* mode parameter */ - int err; +static int ft920_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width ) { + struct ft920_priv_data *priv; + unsigned char cmd_index; /* index of sequence to send */ + unsigned char mode_parm; /* mode parameter */ + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - rig_debug(RIG_DEBUG_TRACE, "%s: passed mode = %i\n", __func__, mode); - rig_debug(RIG_DEBUG_TRACE, "%s: passed width = %li Hz\n", - __func__, width); + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); + rig_debug(RIG_DEBUG_TRACE, "%s: passed mode = %i\n", __func__, mode); + rig_debug(RIG_DEBUG_TRACE, "%s: passed width = %li Hz\n", __func__, width); - priv = (struct ft920_priv_data *)rig->state.priv; + priv = (struct ft920_priv_data *)rig->state.priv; - if (vfo == RIG_VFO_CURR) { - vfo = priv->current_vfo; /* from previous vfo cmd */ - rig_debug(RIG_DEBUG_TRACE, - "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); - } + if (vfo == RIG_VFO_CURR) { + vfo = priv->current_vfo; /* from previous vfo cmd */ + rig_debug(RIG_DEBUG_TRACE, + "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); + } - /* translate mode from generic to ft920 specific */ - switch(vfo) { - case RIG_VFO_A: /* force to VFO */ - case RIG_VFO_VFO: - err = ft920_set_vfo(rig, RIG_VFO_A); - if (err != RIG_OK) - return err; - case RIG_VFO_MEM: /* MEM TUNE or user doesn't care */ - case RIG_VFO_MAIN: - switch(mode) { - case RIG_MODE_AM: - mode_parm = MODE_SET_A_AM_W; - break; - case RIG_MODE_CW: - mode_parm = MODE_SET_A_CW_U; - break; - case RIG_MODE_USB: - mode_parm = MODE_SET_A_USB; - break; - case RIG_MODE_LSB: - mode_parm = MODE_SET_A_LSB; - break; - case RIG_MODE_FM: - mode_parm = MODE_SET_A_FM_W; - break; - case RIG_MODE_RTTY: - mode_parm = MODE_SET_A_DATA_L; - break; - default: - return -RIG_EINVAL; /* sorry, wrong MODE */ - } - break; + /* translate mode from generic to ft920 specific */ + switch(vfo) { + case RIG_VFO_A: /* force to VFO */ + case RIG_VFO_VFO: + err = ft920_set_vfo(rig, RIG_VFO_A); + if (err != RIG_OK) + return err; + case RIG_VFO_MEM: /* MEM TUNE or user doesn't care */ + case RIG_VFO_MAIN: + switch(mode) { + case RIG_MODE_AM: + mode_parm = MODE_SET_A_AM_W; + break; + case RIG_MODE_CW: + mode_parm = MODE_SET_A_CW_U; + break; + case RIG_MODE_USB: + mode_parm = MODE_SET_A_USB; + break; + case RIG_MODE_LSB: + mode_parm = MODE_SET_A_LSB; + break; + case RIG_MODE_FM: + mode_parm = MODE_SET_A_FM_W; + break; + case RIG_MODE_RTTY: + mode_parm = MODE_SET_A_DATA_L; + break; + default: + return -RIG_EINVAL; /* sorry, wrong MODE */ + } + break; - /* Now VFO B */ - case RIG_VFO_B: - case RIG_VFO_SUB: - switch(mode) { - case RIG_MODE_AM: - mode_parm = MODE_SET_B_AM_W; - break; - case RIG_MODE_CW: - mode_parm = MODE_SET_B_CW_U; - break; - case RIG_MODE_USB: - mode_parm = MODE_SET_B_USB; - break; - case RIG_MODE_LSB: - mode_parm = MODE_SET_B_LSB; - break; - case RIG_MODE_FM: - mode_parm = MODE_SET_B_FM_W; - break; - case RIG_MODE_RTTY: - mode_parm = MODE_SET_B_DATA_L; - break; - default: - return -RIG_EINVAL; - } - break; - default: - return -RIG_EINVAL; /* sorry, wrong VFO */ - } + /* Now VFO B */ + case RIG_VFO_B: + case RIG_VFO_SUB: + switch(mode) { + case RIG_MODE_AM: + mode_parm = MODE_SET_B_AM_W; + break; + case RIG_MODE_CW: + mode_parm = MODE_SET_B_CW_U; + break; + case RIG_MODE_USB: + mode_parm = MODE_SET_B_USB; + break; + case RIG_MODE_LSB: + mode_parm = MODE_SET_B_LSB; + break; + case RIG_MODE_FM: + mode_parm = MODE_SET_B_FM_W; + break; + case RIG_MODE_RTTY: + mode_parm = MODE_SET_B_DATA_L; + break; + default: + return -RIG_EINVAL; + } + break; + default: + return -RIG_EINVAL; /* sorry, wrong VFO */ + } - /* - * Now set width (shamelessly stolen from ft847.c and then butchered :) - * The FT-920 doesn't appear to support narrow width in USB or LSB modes - * - * Yeah, it's ugly... -N0NB - * - */ - if (width == RIG_PASSBAND_NORMAL || - width == rig_passband_normal(rig, mode)) { - switch(vfo) { - case RIG_VFO_A: - case RIG_VFO_VFO: - case RIG_VFO_MEM: - case RIG_VFO_MAIN: - cmd_index = FT920_NATIVE_VFO_A_PASSBAND_WIDE; - break; - case RIG_VFO_B: - case RIG_VFO_SUB: - cmd_index = FT920_NATIVE_VFO_B_PASSBAND_WIDE; - break; - } - } else { - if (width == rig_passband_narrow(rig, mode)) { - switch(mode) { - case RIG_MODE_CW: - case RIG_MODE_AM: - case RIG_MODE_FM: - case RIG_MODE_RTTY: - switch(vfo) { - case RIG_VFO_A: - case RIG_VFO_VFO: - case RIG_VFO_MEM: - case RIG_VFO_MAIN: - cmd_index = FT920_NATIVE_VFO_A_PASSBAND_NAR; - break; - case RIG_VFO_B: - case RIG_VFO_SUB: - cmd_index = FT920_NATIVE_VFO_B_PASSBAND_NAR; - break; - } - break; - default: - return -RIG_EINVAL; /* Invalid mode, how can caller know? */ - } - } else { - if (width != RIG_PASSBAND_NORMAL && - width != rig_passband_normal(rig, mode)) { - return -RIG_EINVAL; /* Invalid width, how can caller know? */ - } - } - } + /* + * Now set width (shamelessly stolen from ft847.c and then butchered :) + * The FT-920 doesn't appear to support narrow width in USB or LSB modes + * + * Yeah, it's ugly... -N0NB + * + */ + if (width == RIG_PASSBAND_NORMAL || width == rig_passband_normal(rig, mode)) { + switch(vfo) { + case RIG_VFO_A: + case RIG_VFO_VFO: + case RIG_VFO_MEM: + case RIG_VFO_MAIN: + cmd_index = FT920_NATIVE_VFO_A_PASSBAND_WIDE; + break; + case RIG_VFO_B: + case RIG_VFO_SUB: + cmd_index = FT920_NATIVE_VFO_B_PASSBAND_WIDE; + break; + } + } else { + if (width == rig_passband_narrow(rig, mode)) { + switch(mode) { + case RIG_MODE_CW: + case RIG_MODE_AM: + case RIG_MODE_FM: + case RIG_MODE_RTTY: + switch(vfo) { + case RIG_VFO_A: + case RIG_VFO_VFO: + case RIG_VFO_MEM: + case RIG_VFO_MAIN: + cmd_index = FT920_NATIVE_VFO_A_PASSBAND_NAR; + break; + case RIG_VFO_B: + case RIG_VFO_SUB: + cmd_index = FT920_NATIVE_VFO_B_PASSBAND_NAR; + break; + } + break; + default: + return -RIG_EINVAL; /* Invalid mode; how can caller know? */ + } + } else { + if (width != RIG_PASSBAND_NORMAL && width != rig_passband_normal(rig, mode)) { + return -RIG_EINVAL; /* Invalid width; how can caller know? */ + } + } + } - rig_debug(RIG_DEBUG_TRACE, "%s: set mode_parm = 0x%02x\n", __func__, mode_parm); - rig_debug(RIG_DEBUG_TRACE, "%s: set cmd_index = %i\n", - __func__, cmd_index); + rig_debug(RIG_DEBUG_TRACE, "%s: set mode_parm = 0x%02x\n", __func__, mode_parm); + rig_debug(RIG_DEBUG_TRACE, "%s: set cmd_index = %i\n", __func__, cmd_index); - err = ft920_send_dynamic_cmd(rig, FT920_NATIVE_MODE_SET, - mode_parm, 0, 0, 0); - if (err != RIG_OK) - return err; + err = ft920_send_dynamic_cmd(rig, FT920_NATIVE_MODE_SET, mode_parm, 0, 0, 0); + if (err != RIG_OK) + return err; - err = ft920_send_static_cmd(rig, cmd_index); - if (err != RIG_OK) - return err; + err = ft920_send_static_cmd(rig, cmd_index); + if (err != RIG_OK) + return err; - return RIG_OK; /* good */ + return RIG_OK; /* Whew! */ } @@ -669,126 +654,125 @@ static int ft920_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, */ static int ft920_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - struct ft920_priv_data *priv; - unsigned char mymode, offset; /* ft920 mode, flag offset */ - int err, cmd_index, norm; + struct ft920_priv_data *priv; + unsigned char mymode, offset; /* ft920 mode, flag offset */ + int err, cmd_index, norm; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - priv = (struct ft920_priv_data *)rig->state.priv; + priv = (struct ft920_priv_data *)rig->state.priv; - if (vfo == RIG_VFO_CURR) { - vfo = priv->current_vfo; /* from previous vfo cmd */ - rig_debug(RIG_DEBUG_TRACE, - "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); - } + if (vfo == RIG_VFO_CURR) { + vfo = priv->current_vfo; /* from previous vfo cmd */ + rig_debug(RIG_DEBUG_TRACE, "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); + } - switch(vfo) { - case RIG_VFO_A: - case RIG_VFO_VFO: - cmd_index = FT920_NATIVE_VFO_DATA; - offset = FT920_SUMO_DISPLAYED_MODE; - break; - case RIG_VFO_B: - case RIG_VFO_SUB: - cmd_index = FT920_NATIVE_VFO_DATA; - offset = FT920_SUMO_VFO_B_MODE; - break; - case RIG_VFO_MEM: - case RIG_VFO_MAIN: - cmd_index = FT920_NATIVE_OP_DATA; - offset = FT920_SUMO_DISPLAYED_MODE; - break; - default: - return -RIG_EINVAL; - } + switch(vfo) { + case RIG_VFO_A: + case RIG_VFO_VFO: + cmd_index = FT920_NATIVE_VFO_DATA; + offset = FT920_SUMO_DISPLAYED_MODE; + break; + case RIG_VFO_B: + case RIG_VFO_SUB: + cmd_index = FT920_NATIVE_VFO_DATA; + offset = FT920_SUMO_VFO_B_MODE; + break; + case RIG_VFO_MEM: + case RIG_VFO_MAIN: + cmd_index = FT920_NATIVE_OP_DATA; + offset = FT920_SUMO_DISPLAYED_MODE; + break; + default: + return -RIG_EINVAL; + } - err = ft920_get_update_data(rig, cmd_index, FT920_VFO_DATA_LENGTH); - if (err != RIG_OK) - return err; + err = ft920_get_update_data(rig, cmd_index, FT920_VFO_DATA_LENGTH); + if (err != RIG_OK) + return err; - mymode = priv->update_data[offset]; - mymode &= MODE_MASK; + mymode = priv->update_data[offset]; + mymode &= MODE_MASK; - rig_debug(RIG_DEBUG_TRACE, "%s: mymode = 0x%02x\n", __func__, mymode); + rig_debug(RIG_DEBUG_TRACE, "%s: mymode = 0x%02x\n", __func__, mymode); - /* - * translate mode from ft920 to generic. - * - * FIXME: FT-920 has 3 DATA modes, LSB, USB, and FM - * do we need more bit fields in rmode_t? -N0NB - * - */ - switch(mymode) { - case MODE_USBN: /* not sure this even exists */ - *mode = RIG_MODE_USB; - norm = FALSE; - break; - case MODE_USB: - *mode = RIG_MODE_USB; - norm = TRUE; - break; - case MODE_LSBN: /* not sure this even exists */ - *mode = RIG_MODE_LSB; - norm = FALSE; - break; - case MODE_LSB: - *mode = RIG_MODE_LSB; - norm = TRUE; - break; - case MODE_CW_UN: - case MODE_CW_LN: - *mode = RIG_MODE_CW; - norm = FALSE; - break; - case MODE_CW_U: - case MODE_CW_L: - *mode = RIG_MODE_CW; - norm = TRUE; - break; - case MODE_AMN: - *mode = RIG_MODE_AM; - norm = FALSE; - break; - case MODE_AM: - *mode = RIG_MODE_AM; - norm = TRUE; - break; - case MODE_FMN: - *mode = RIG_MODE_FM; - norm = FALSE; - break; - case MODE_FM: - *mode = RIG_MODE_FM; - norm = TRUE; - break; - case MODE_DATA_LN: - *mode = RIG_MODE_RTTY; - norm = FALSE; - break; - case MODE_DATA_L: - *mode = RIG_MODE_RTTY; - norm = TRUE; - break; - default: - return -RIG_EINVAL; /* Oops! file bug report */ - } + /* + * translate mode from ft920 to generic. + * + * FIXME: FT-920 has 3 DATA modes, LSB, USB, and FM + * do we need more bit fields in rmode_t? -N0NB + * + */ + switch(mymode) { + case MODE_USBN: /* not sure this even exists */ + *mode = RIG_MODE_USB; + norm = FALSE; + break; + case MODE_USB: + *mode = RIG_MODE_USB; + norm = TRUE; + break; + case MODE_LSBN: /* not sure this even exists */ + *mode = RIG_MODE_LSB; + norm = FALSE; + break; + case MODE_LSB: + *mode = RIG_MODE_LSB; + norm = TRUE; + break; + case MODE_CW_UN: + case MODE_CW_LN: + *mode = RIG_MODE_CW; + norm = FALSE; + break; + case MODE_CW_U: + case MODE_CW_L: + *mode = RIG_MODE_CW; + norm = TRUE; + break; + case MODE_AMN: + *mode = RIG_MODE_AM; + norm = FALSE; + break; + case MODE_AM: + *mode = RIG_MODE_AM; + norm = TRUE; + break; + case MODE_FMN: + *mode = RIG_MODE_FM; + norm = FALSE; + break; + case MODE_FM: + *mode = RIG_MODE_FM; + norm = TRUE; + break; + case MODE_DATA_LN: + *mode = RIG_MODE_RTTY; + norm = FALSE; + break; + case MODE_DATA_L: + *mode = RIG_MODE_RTTY; + norm = TRUE; + break; + default: + return -RIG_EINVAL; /* Oops! file bug report */ + } - if (norm) { - *width = rig_passband_normal(rig, *mode); - } else { - *width = rig_passband_narrow(rig, *mode); - } + if (norm) { + *width = rig_passband_normal(rig, *mode); + } else { + *width = rig_passband_narrow(rig, *mode); + } - rig_debug(RIG_DEBUG_TRACE, "%s: set mode = %i\n", __func__, *mode); - rig_debug(RIG_DEBUG_TRACE, "%s: set width = %li Hz\n", __func__, *width); + rig_debug(RIG_DEBUG_TRACE, "%s: set mode = %i\n", __func__, *mode); + rig_debug(RIG_DEBUG_TRACE, "%s: set width = %li Hz\n", __func__, *width); - return RIG_OK; + return RIG_OK; } @@ -799,45 +783,45 @@ static int ft920_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) */ static int ft920_set_vfo(RIG *rig, vfo_t vfo) { - struct ft920_priv_data *priv; - unsigned char cmd_index; /* index of sequence to send */ - int err; + struct ft920_priv_data *priv; + unsigned char cmd_index; /* index of sequence to send */ + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - - priv = (struct ft920_priv_data *)rig->state.priv; + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - if (vfo == RIG_VFO_CURR) { - vfo = priv->current_vfo; /* from previous vfo cmd */ - rig_debug(RIG_DEBUG_TRACE, - "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); - } + priv = (struct ft920_priv_data *)rig->state.priv; - switch(vfo) { - case RIG_VFO_A: - case RIG_VFO_VFO: - cmd_index = FT920_NATIVE_VFO_A; - priv->current_vfo = vfo; /* update active VFO */ - break; - case RIG_VFO_B: - cmd_index = FT920_NATIVE_VFO_B; - priv->current_vfo = vfo; - break; - default: - return -RIG_EINVAL; /* sorry, wrong VFO */ - } - rig_debug(RIG_DEBUG_TRACE, "%s: set cmd_index = %i\n", __func__, cmd_index); - - err = ft920_send_static_cmd(rig, cmd_index); - if (err != RIG_OK) - return err; + if (vfo == RIG_VFO_CURR) { + vfo = priv->current_vfo; /* from previous vfo cmd */ + rig_debug(RIG_DEBUG_TRACE, "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); + } - return RIG_OK; + switch(vfo) { + case RIG_VFO_A: + case RIG_VFO_VFO: + cmd_index = FT920_NATIVE_VFO_A; + priv->current_vfo = vfo; /* update active VFO */ + break; + case RIG_VFO_B: + cmd_index = FT920_NATIVE_VFO_B; + priv->current_vfo = vfo; + break; + default: + return -RIG_EINVAL; /* sorry, wrong VFO */ + } + + rig_debug(RIG_DEBUG_TRACE, "%s: set cmd_index = %i\n", __func__, cmd_index); + + err = ft920_send_static_cmd(rig, cmd_index); + if (err != RIG_OK) + return err; + + return RIG_OK; } @@ -849,82 +833,80 @@ static int ft920_set_vfo(RIG *rig, vfo_t vfo) { */ static int ft920_get_vfo(RIG *rig, vfo_t *vfo) { - struct ft920_priv_data *priv; - unsigned char status_0; /* ft920 status flag 0 */ - unsigned char status_1; /* ft920 status flag 1 */ - int err; + struct ft920_priv_data *priv; + unsigned char status_0; /* ft920 status flag 0 */ + unsigned char status_1; /* ft920 status flag 1 */ + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; - - priv = (struct ft920_priv_data *)rig->state.priv; + if (!rig) + return -RIG_EINVAL; - /* Get flags for VFO status */ - err = ft920_get_update_data(rig, FT920_NATIVE_STATUS_FLAGS, - FT920_STATUS_FLAGS_LENGTH); - if (err != RIG_OK) - return err; - - status_0 = priv->update_data[FT920_SUMO_DISPLAYED_STATUS_0]; - status_0 &= SF_VFOB; /* get VFO B (sub display) active bits */ + priv = (struct ft920_priv_data *)rig->state.priv; - status_1 = priv->update_data[FT920_SUMO_DISPLAYED_STATUS_1]; - status_1 &= SF_VFO_MASK; /* get VFO/MEM (main display) active bits */ - - rig_debug(RIG_DEBUG_TRACE, - "%s: vfo status_0 = 0x%02x\n", __func__, status_0); - rig_debug(RIG_DEBUG_TRACE, - "%s: vfo status_1 = 0x%02x\n", __func__, status_1); + /* Get flags for VFO status */ + err = ft920_get_update_data(rig, FT920_NATIVE_STATUS_FLAGS, FT920_STATUS_FLAGS_LENGTH); + if (err != RIG_OK) + return err; - /* - * translate vfo status from ft920 to generic. - * - * Figuring out whether VFO B is the active RX vfo is tough as - * Status Flag 0 bits 0 & 1 contain this information. Testing - * Status Flag 1 only gives us the state of the main display. - * - */ - switch (status_0) { - case SF_VFOB: - *vfo = RIG_VFO_B; - priv->current_vfo = RIG_VFO_B; - break; - case SF_SPLITB: /* Split operation, RX on VFO B */ - *vfo = RIG_VFO_B; - priv->current_vfo = RIG_VFO_B; - break; - } - /* - * Okay now test for the active MEM/VFO status of the main display - * - */ - switch (status_1) { - case SF_QMB: - case SF_MT: - case SF_MR: - *vfo = RIG_VFO_MEM; - priv->current_vfo = RIG_VFO_MEM; - break; - case SF_VFO: - switch (status_0){ - case SF_SPLITA: /* Split operation, RX on VFO A */ - *vfo = RIG_VFO_A; - priv->current_vfo = RIG_VFO_A; - break; - case SF_VFOA: - *vfo = RIG_VFO_A; - priv->current_vfo = RIG_VFO_A; - break; - } - break; - default: /* Oops! */ - return -RIG_EINVAL; /* sorry, wrong current VFO */ - } - rig_debug(RIG_DEBUG_TRACE, "%s: set vfo = 0x%02x\n", __func__, *vfo); + status_0 = priv->update_data[FT920_SUMO_DISPLAYED_STATUS_0]; + status_0 &= SF_VFOB; /* get VFO B (sub display) active bits */ - return RIG_OK; + status_1 = priv->update_data[FT920_SUMO_DISPLAYED_STATUS_1]; + status_1 &= SF_VFO_MASK; /* get VFO/MEM (main display) active bits */ + + rig_debug(RIG_DEBUG_TRACE, "%s: vfo status_0 = 0x%02x\n", __func__, status_0); + rig_debug(RIG_DEBUG_TRACE, "%s: vfo status_1 = 0x%02x\n", __func__, status_1); + + /* + * translate vfo status from ft920 to generic. + * + * Figuring out whether VFO B is the active RX vfo is tough as + * Status Flag 0 bits 0 & 1 contain this information. Testing + * Status Flag 1 only gives us the state of the main display. + * + */ + switch (status_0) { + case SF_VFOB: + *vfo = RIG_VFO_B; + priv->current_vfo = RIG_VFO_B; + break; + case SF_SPLITB: /* Split operation, RX on VFO B */ + *vfo = RIG_VFO_B; + priv->current_vfo = RIG_VFO_B; + break; + } + /* + * Okay now test for the active MEM/VFO status of the main display + * + */ + switch (status_1) { + case SF_QMB: + case SF_MT: + case SF_MR: + *vfo = RIG_VFO_MEM; + priv->current_vfo = RIG_VFO_MEM; + break; + case SF_VFO: + switch (status_0){ + case SF_SPLITA: /* Split operation, RX on VFO A */ + *vfo = RIG_VFO_A; + priv->current_vfo = RIG_VFO_A; + break; + case SF_VFOA: + *vfo = RIG_VFO_A; + priv->current_vfo = RIG_VFO_A; + break; + } + break; + default: /* Oops! */ + return -RIG_EINVAL; /* sorry, wrong current VFO */ + } + + rig_debug(RIG_DEBUG_TRACE, "%s: set vfo = 0x%02x\n", __func__, *vfo); + + return RIG_OK; } @@ -939,33 +921,33 @@ static int ft920_get_vfo(RIG *rig, vfo_t *vfo) { */ static int ft920_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) { - unsigned char cmd_index; - int err; + unsigned char cmd_index; + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - rig_debug(RIG_DEBUG_TRACE, "%s: passed split = 0x%02x\n", __func__, split); - - switch(split) { - case RIG_SPLIT_OFF: - cmd_index = FT920_NATIVE_SPLIT_OFF; - break; - case RIG_SPLIT_ON: - cmd_index = FT920_NATIVE_SPLIT_ON; - break; - default: - return -RIG_EINVAL; - } + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); + rig_debug(RIG_DEBUG_TRACE, "%s: passed split = 0x%02x\n", __func__, split); - err = ft920_send_static_cmd(rig, cmd_index); - if (err != RIG_OK) - return err; + switch(split) { + case RIG_SPLIT_OFF: + cmd_index = FT920_NATIVE_SPLIT_OFF; + break; + case RIG_SPLIT_ON: + cmd_index = FT920_NATIVE_SPLIT_ON; + break; + default: + return -RIG_EINVAL; + } - return RIG_OK; + err = ft920_send_static_cmd(rig, cmd_index); + if (err != RIG_OK) + return err; + + return RIG_OK; } @@ -977,45 +959,43 @@ static int ft920_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) */ static int ft920_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) { - struct ft920_priv_data *priv; - unsigned char status_0; - int err; + struct ft920_priv_data *priv; + unsigned char status_0; + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - priv = (struct ft920_priv_data *)rig->state.priv; + priv = (struct ft920_priv_data *)rig->state.priv; - /* Get flags for VFO split status */ - err = ft920_get_update_data(rig, FT920_NATIVE_STATUS_FLAGS, - FT920_STATUS_FLAGS_LENGTH); - if (err != RIG_OK) - return err; + /* Get flags for VFO split status */ + err = ft920_get_update_data(rig, FT920_NATIVE_STATUS_FLAGS, FT920_STATUS_FLAGS_LENGTH); + if (err != RIG_OK) + return err; - status_0 = priv->update_data[FT920_SUMO_DISPLAYED_STATUS_0]; - status_0 &= SF_VFOB; /* get VFO B (sub display) active bits */ + status_0 = priv->update_data[FT920_SUMO_DISPLAYED_STATUS_0]; + status_0 &= SF_VFOB; /* get VFO B (sub display) active bits */ - rig_debug(RIG_DEBUG_TRACE, - "%s: split status_0 = 0x%02x\n", __func__, status_0); + rig_debug(RIG_DEBUG_TRACE, "%s: split status_0 = 0x%02x\n", __func__, status_0); - switch (status_0) { - case SF_SPLITA: - case SF_SPLITB: - *split = RIG_SPLIT_ON; - break; - case SF_VFOA: - case SF_VFOB: - *split = RIG_SPLIT_OFF; - break; - default: - return RIG_EINVAL; - } + switch (status_0) { + case SF_SPLITA: + case SF_SPLITB: + *split = RIG_SPLIT_ON; + break; + case SF_VFOA: + case SF_VFOB: + *split = RIG_SPLIT_OFF; + break; + default: + return RIG_EINVAL; + } - return RIG_OK; + return RIG_OK; } @@ -1028,18 +1008,18 @@ static int ft920_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vf */ static int ft920_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) { - int err; + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - err = ft920_set_freq(rig, vfo, tx_freq); - if (err != RIG_OK) - return err; + err = ft920_set_freq(rig, vfo, tx_freq); + if (err != RIG_OK) + return err; - return RIG_OK; + return RIG_OK; } @@ -1052,18 +1032,18 @@ static int ft920_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) { */ static int ft920_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) { - int err; + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - err = ft920_get_freq(rig, vfo, tx_freq); - if (err != RIG_OK) - return err; + err = ft920_get_freq(rig, vfo, tx_freq); + if (err != RIG_OK) + return err; - return RIG_OK; + return RIG_OK; } @@ -1075,20 +1055,19 @@ static int ft920_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) { * the split direction and set accordingly? */ -static int ft920_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, - pbwidth_t tx_width) { - int err; +static int ft920_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) { + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - err = ft920_set_mode(rig, vfo, tx_mode, tx_width); - if (err != RIG_OK) - return err; + err = ft920_set_mode(rig, vfo, tx_mode, tx_width); + if (err != RIG_OK) + return err; - return RIG_OK; + return RIG_OK; } @@ -1100,20 +1079,19 @@ static int ft920_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, * the split direction and set accordingly? */ -static int ft920_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, - pbwidth_t *tx_width) { - int err; +static int ft920_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, pbwidth_t *tx_width) { + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - err = ft920_get_mode(rig, vfo, tx_mode, tx_width); - if (err != RIG_OK) - return err; + err = ft920_get_mode(rig, vfo, tx_mode, tx_width); + if (err != RIG_OK) + return err; - return RIG_OK; + return RIG_OK; } @@ -1131,37 +1109,36 @@ static int ft920_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, */ static int ft920_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) { - unsigned char offset; - int err; + unsigned char offset; + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - if (rit < -9999 || rit > 9999) - return -RIG_EINVAL; + if (rit < -9999 || rit > 9999) + return -RIG_EINVAL; - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - rig_debug(RIG_DEBUG_TRACE, "%s: passed rit = %li\n", __func__, rit); + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); + rig_debug(RIG_DEBUG_TRACE, "%s: passed rit = %li\n", __func__, rit); - if (rit == 0) { - offset = CLAR_RX_OFF; - } else { - offset = CLAR_RX_ON; - } - rig_debug(RIG_DEBUG_TRACE, "%s: set offset = 0x%02x\n", __func__, offset); + if (rit == 0) { + offset = CLAR_RX_OFF; + } else { + offset = CLAR_RX_ON; + } + rig_debug(RIG_DEBUG_TRACE, "%s: set offset = 0x%02x\n", __func__, offset); - err = ft920_send_dynamic_cmd(rig, FT920_NATIVE_CLARIFIER_OPS, - offset, 0, 0, 0); - if (err != RIG_OK) - return err; + err = ft920_send_dynamic_cmd(rig, FT920_NATIVE_CLARIFIER_OPS, offset, 0, 0, 0); + if (err != RIG_OK) + return err; - err = ft920_send_rit_freq(rig, FT920_NATIVE_CLARIFIER_OPS, rit); - if (err != RIG_OK) - return err; + err = ft920_send_rit_freq(rig, FT920_NATIVE_CLARIFIER_OPS, rit); + if (err != RIG_OK) + return err; - return RIG_OK; + return RIG_OK; } @@ -1177,65 +1154,64 @@ static int ft920_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) { */ static int ft920_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { - struct ft920_priv_data *priv; - unsigned char *p; - unsigned char offset; - shortfreq_t f; - int err, cmd_index; + struct ft920_priv_data *priv; + unsigned char *p; + unsigned char offset; + shortfreq_t f; + int err, cmd_index; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - priv = (struct ft920_priv_data *)rig->state.priv; + priv = (struct ft920_priv_data *)rig->state.priv; - if (vfo == RIG_VFO_CURR) { - vfo = priv->current_vfo; /* from previous vfo cmd */ - rig_debug(RIG_DEBUG_TRACE, - "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); - } + if (vfo == RIG_VFO_CURR) { + vfo = priv->current_vfo; /* from previous vfo cmd */ + rig_debug(RIG_DEBUG_TRACE, "%s: priv->current_vfo = 0x%02x\n", __func__, vfo); + } - switch(vfo) { - case RIG_VFO_MEM: - case RIG_VFO_MAIN: - cmd_index = FT920_NATIVE_OP_DATA; - offset = FT920_SUMO_DISPLAYED_CLAR; - break; - case RIG_VFO_A: - case RIG_VFO_VFO: - cmd_index = FT920_NATIVE_VFO_DATA; - offset = FT920_SUMO_VFO_A_CLAR; - break; - case RIG_VFO_B: - case RIG_VFO_SUB: - cmd_index = FT920_NATIVE_VFO_DATA; - offset = FT920_SUMO_VFO_B_CLAR; - break; - default: - return RIG_EINVAL; - } - rig_debug(RIG_DEBUG_TRACE, "%s: set cmd_index = %i\n", __func__, cmd_index); - rig_debug(RIG_DEBUG_TRACE, "%s: set offset = 0x%02x\n", __func__, offset); + switch(vfo) { + case RIG_VFO_MEM: + case RIG_VFO_MAIN: + cmd_index = FT920_NATIVE_OP_DATA; + offset = FT920_SUMO_DISPLAYED_CLAR; + break; + case RIG_VFO_A: + case RIG_VFO_VFO: + cmd_index = FT920_NATIVE_VFO_DATA; + offset = FT920_SUMO_VFO_A_CLAR; + break; + case RIG_VFO_B: + case RIG_VFO_SUB: + cmd_index = FT920_NATIVE_VFO_DATA; + offset = FT920_SUMO_VFO_B_CLAR; + break; + default: + return RIG_EINVAL; + } + rig_debug(RIG_DEBUG_TRACE, "%s: set cmd_index = %i\n", __func__, cmd_index); + rig_debug(RIG_DEBUG_TRACE, "%s: set offset = 0x%02x\n", __func__, offset); - err = ft920_get_update_data(rig, cmd_index, FT920_VFO_DATA_LENGTH); - if (err != RIG_OK) - return err; + err = ft920_get_update_data(rig, cmd_index, FT920_VFO_DATA_LENGTH); + if (err != RIG_OK) + return err; - p = &priv->update_data[offset]; + p = &priv->update_data[offset]; - /* big endian integer */ - f = (p[0]<<8) + p[1]; - if (f > 0xd8f0) /* 0xd8f1 to 0xffff is negative offset */ - f = ~(0xffff - f); + /* big endian integer */ + f = (p[0]<<8) + p[1]; + if (f > 0xd8f0) /* 0xd8f1 to 0xffff is negative offset */ + f = ~(0xffff - f); - rig_debug(RIG_DEBUG_TRACE, "%s: read freq = %li Hz\n", __func__, f); + rig_debug(RIG_DEBUG_TRACE, "%s: read freq = %li Hz\n", __func__, f); - *rit = f; /* store clarifier frequency */ + *rit = f; /* store clarifier frequency */ - return RIG_OK; + return RIG_OK; } @@ -1249,37 +1225,36 @@ static int ft920_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { */ static int ft920_set_xit(RIG *rig, vfo_t vfo, shortfreq_t xit) { - unsigned char offset; - int err; + unsigned char offset; + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - if (xit < -9999 || xit > 9999) - return -RIG_EINVAL; + if (xit < -9999 || xit > 9999) + return -RIG_EINVAL; - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); - rig_debug(RIG_DEBUG_TRACE, "%s: passed xit = %li\n", __func__, xit); + rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); + rig_debug(RIG_DEBUG_TRACE, "%s: passed xit = %li\n", __func__, xit); - if (xit == 0) { - offset = CLAR_TX_OFF; - } else { - offset = CLAR_TX_ON; - } - rig_debug(RIG_DEBUG_TRACE, "%s: set offset = 0x%02x\n", __func__, offset); + if (xit == 0) { + offset = CLAR_TX_OFF; + } else { + offset = CLAR_TX_ON; + } + rig_debug(RIG_DEBUG_TRACE, "%s: set offset = 0x%02x\n", __func__, offset); - err = ft920_send_dynamic_cmd(rig, FT920_NATIVE_CLARIFIER_OPS, - offset, 0, 0, 0); - if (err != RIG_OK) - return err; + err = ft920_send_dynamic_cmd(rig, FT920_NATIVE_CLARIFIER_OPS, offset, 0, 0, 0); + if (err != RIG_OK) + return err; - err = ft920_send_rit_freq(rig, FT920_NATIVE_CLARIFIER_OPS, xit); - if (err != RIG_OK) - return err; + err = ft920_send_rit_freq(rig, FT920_NATIVE_CLARIFIER_OPS, xit); + if (err != RIG_OK) + return err; - return RIG_OK; + return RIG_OK; } @@ -1291,18 +1266,18 @@ static int ft920_set_xit(RIG *rig, vfo_t vfo, shortfreq_t xit) { */ static int ft920_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) { - int err; + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; + if (!rig) + return -RIG_EINVAL; - err = ft920_get_rit(rig, vfo, xit); /* abuse get_rit and store in *xit */ - if (err != RIG_OK) - return err; + err = ft920_get_rit(rig, vfo, xit); /* abuse get_rit and store in *xit */ + if (err != RIG_OK) + return err; - return RIG_OK; + return RIG_OK; } @@ -1316,7 +1291,7 @@ static int ft920_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) { /* - * Private helper function. Retrieves update data from rig. + * Private helper function to retrieve update data from rig. * using pacing value and buffer indicated in *priv struct. * Extended to be command agnostic as 920 has several ways to * get data and several ways to return it. @@ -1332,44 +1307,42 @@ static int ft920_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) { */ static int ft920_get_update_data(RIG *rig, unsigned char ci, unsigned char rl) { - struct rig_state *rig_s; - struct ft920_priv_data *priv; - int n; /* for read_ */ - int err; + struct rig_state *rig_s; + struct ft920_priv_data *priv; + int n; /* for read_ */ + int err; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - return -RIG_EINVAL; - - priv = (struct ft920_priv_data *)rig->state.priv; - rig_s = &rig->state; + if (!rig) + return -RIG_EINVAL; - /* Copy native cmd PACING to private cmd storage area */ - memcpy(&priv->p_cmd, &ncmd[FT920_NATIVE_PACING].nseq, YAESU_CMD_LENGTH); + priv = (struct ft920_priv_data *)rig->state.priv; + rig_s = &rig->state; - /* get pacing value, and store in private cmd */ - priv->p_cmd[P1] = priv->pacing; + /* Copy native cmd PACING to private cmd storage area */ + memcpy(&priv->p_cmd, &ncmd[FT920_NATIVE_PACING].nseq, YAESU_CMD_LENGTH); - rig_debug(RIG_DEBUG_TRACE, - "%s: read pacing = %i\n", __func__, priv->pacing); + /* get pacing value, and store in private cmd */ + priv->p_cmd[P1] = priv->pacing; - err = write_block(&rig_s->rigport, (unsigned char *) priv->p_cmd, - YAESU_CMD_LENGTH); - if (err != RIG_OK) - return err; + rig_debug(RIG_DEBUG_TRACE, "%s: read pacing = %i\n", __func__, priv->pacing); - err = ft920_send_static_cmd(rig, ci); - if (err != RIG_OK) - return err; + err = write_block(&rig_s->rigport, (unsigned char *) priv->p_cmd, YAESU_CMD_LENGTH); + if (err != RIG_OK) + return err; - n = read_block(&rig_s->rigport, priv->update_data, rl); - if (n < 0) - return n; /* die returning read_block error */ + err = ft920_send_static_cmd(rig, ci); + if (err != RIG_OK) + return err; - rig_debug(RIG_DEBUG_TRACE, "%s: read %i bytes\n", __func__, n); + n = read_block(&rig_s->rigport, priv->update_data, rl); + if (n < 0) + return n; /* die returning read_block error */ - return RIG_OK; + rig_debug(RIG_DEBUG_TRACE, "%s: read %i bytes\n", __func__, n); + + return RIG_OK; } @@ -1386,30 +1359,32 @@ static int ft920_get_update_data(RIG *rig, unsigned char ci, unsigned char rl) { */ static int ft920_send_static_cmd(RIG *rig, unsigned char ci) { - struct rig_state *rig_s; - struct ft920_priv_data *priv; - int err; - - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + struct rig_state *rig_s; + struct ft920_priv_data *priv; + int err; - if (!rig) - return -RIG_EINVAL; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - priv = (struct ft920_priv_data *)rig->state.priv; - rig_s = &rig->state; - - if (!priv->pcs[ci].ncomp) { - rig_debug(RIG_DEBUG_TRACE, - "%s: Attempt to send incomplete sequence\n", __func__); - return -RIG_EINVAL; - } + if (!rig) + return -RIG_EINVAL; - err = write_block(&rig_s->rigport, (unsigned char *) priv->pcs[ci].nseq, - YAESU_CMD_LENGTH); - if (err != RIG_OK) - return err; + priv = (struct ft920_priv_data *)rig->state.priv; + rig_s = &rig->state; - return RIG_OK; + /* + * If we've been passed a command index (ci) that is marked + * as dynamic (0), then bail out. + */ + if (!priv->pcs[ci].ncomp) { + rig_debug(RIG_DEBUG_TRACE, "%s: Attempt to send incomplete sequence\n", __func__); + return -RIG_EINVAL; + } + + err = write_block(&rig_s->rigport, (unsigned char *) priv->pcs[ci].nseq, YAESU_CMD_LENGTH); + if (err != RIG_OK) + return err; + + return RIG_OK; } @@ -1428,43 +1403,46 @@ static int ft920_send_static_cmd(RIG *rig, unsigned char ci) { */ static int ft920_send_dynamic_cmd(RIG *rig, unsigned char ci, - unsigned char p1, unsigned char p2, - unsigned char p3, unsigned char p4) { - struct rig_state *rig_s; - struct ft920_priv_data *priv; - int err; - - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + unsigned char p1, unsigned char p2, + unsigned char p3, unsigned char p4) { + struct rig_state *rig_s; + struct ft920_priv_data *priv; + int err; - if (!rig) - return -RIG_EINVAL; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_debug(RIG_DEBUG_TRACE, "%s: passed ci = %i\n", __func__, ci); - rig_debug(RIG_DEBUG_TRACE, - "%s: passed p1 = 0x%02x, p2 = 0x%02x, p3 = 0x%02x, p4 = 0x%02x,\n", - __func__, p1, p2, p3, p4); + if (!rig) + return -RIG_EINVAL; - priv = (struct ft920_priv_data *)rig->state.priv; - if (priv->pcs[ci].ncomp) { - rig_debug(RIG_DEBUG_TRACE, - "%s: Attempt to modify complete sequence\n", __func__); - return -RIG_EINVAL; - } + rig_debug(RIG_DEBUG_TRACE, "%s: passed ci = %i\n", __func__, ci); + rig_debug(RIG_DEBUG_TRACE, + "%s: passed p1 = 0x%02x, p2 = 0x%02x, p3 = 0x%02x, p4 = 0x%02x,\n", + __func__, p1, p2, p3, p4); - rig_s = &rig->state; - memcpy(&priv->p_cmd, &ncmd[ci].nseq, YAESU_CMD_LENGTH); + priv = (struct ft920_priv_data *)rig->state.priv; - priv->p_cmd[P1] = p1; /* ick */ - priv->p_cmd[P2] = p2; - priv->p_cmd[P3] = p3; - priv->p_cmd[P4] = p4; + /* + * If we've been passed a command index (ci) that is marked + * as static (1), then bail out. + */ + if (priv->pcs[ci].ncomp) { + rig_debug(RIG_DEBUG_TRACE, "%s: Attempt to modify complete sequence\n", __func__); + return -RIG_EINVAL; + } - err = write_block(&rig_s->rigport, (unsigned char *) &priv->p_cmd, - YAESU_CMD_LENGTH); - if (err != RIG_OK) - return err; + rig_s = &rig->state; + memcpy(&priv->p_cmd, &ncmd[ci].nseq, YAESU_CMD_LENGTH); - return RIG_OK; + priv->p_cmd[P1] = p1; /* ick */ + priv->p_cmd[P2] = p2; + priv->p_cmd[P3] = p3; + priv->p_cmd[P4] = p4; + + err = write_block(&rig_s->rigport, (unsigned char *) &priv->p_cmd, YAESU_CMD_LENGTH); + if (err != RIG_OK) + return err; + + return RIG_OK; } @@ -1483,49 +1461,52 @@ static int ft920_send_dynamic_cmd(RIG *rig, unsigned char ci, */ static int ft920_send_dial_freq(RIG *rig, unsigned char ci, freq_t freq) { - struct rig_state *rig_s; - struct ft920_priv_data *priv; - int err; - - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + struct rig_state *rig_s; + struct ft920_priv_data *priv; + int err; - if (!rig) - return -RIG_EINVAL; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_debug(RIG_DEBUG_TRACE, "%s: passed ci = %i\n", __func__, ci); - rig_debug(RIG_DEBUG_TRACE, "%s: passed freq = %lli Hz\n", __func__, freq); + if (!rig) + return -RIG_EINVAL; - priv = (struct ft920_priv_data *)rig->state.priv; - if (priv->pcs[ci].ncomp) { - rig_debug(RIG_DEBUG_TRACE, - "%s: Attempt to modify complete sequence\n", __func__); - return -RIG_EINVAL; - } + rig_debug(RIG_DEBUG_TRACE, "%s: passed ci = %i\n", __func__, ci); + rig_debug(RIG_DEBUG_TRACE, "%s: passed freq = %lli Hz\n", __func__, freq); - rig_s = &rig->state; + priv = (struct ft920_priv_data *)rig->state.priv; - /* Copy native cmd freq_set to private cmd storage area */ - memcpy(&priv->p_cmd, &ncmd[ci].nseq, YAESU_CMD_LENGTH); + /* + * If we've been passed a command index (ci) that is marked + * as static (1), then bail out. + */ + if (priv->pcs[ci].ncomp) { + rig_debug(RIG_DEBUG_TRACE, "%s: Attempt to modify complete sequence\n", __func__); + return -RIG_EINVAL; + } - /* store bcd format in in p_cmd */ - to_bcd(priv->p_cmd, freq/10, FT920_BCD_DIAL); + rig_s = &rig->state; - rig_debug(RIG_DEBUG_TRACE, - "%s: requested freq after conversion = %lli Hz\n", - __func__, from_bcd(priv->p_cmd, FT920_BCD_DIAL)* 10); + /* Copy native cmd freq_set to private cmd storage area */ + memcpy(&priv->p_cmd, &ncmd[ci].nseq, YAESU_CMD_LENGTH); - err = write_block(&rig_s->rigport, (unsigned char *) &priv->p_cmd, - YAESU_CMD_LENGTH); - if (err != RIG_OK) - return err; + /* store bcd format in in p_cmd */ + to_bcd(priv->p_cmd, freq/10, FT920_BCD_DIAL); - return RIG_OK; + rig_debug(RIG_DEBUG_TRACE, + "%s: requested freq after conversion = %lli Hz\n", + __func__, from_bcd(priv->p_cmd, FT920_BCD_DIAL)* 10); + + err = write_block(&rig_s->rigport, (unsigned char *) &priv->p_cmd, YAESU_CMD_LENGTH); + if (err != RIG_OK) + return err; + + return RIG_OK; } /* * Private helper function to build and send a complete command to - * change the Main or Sub display frequency. + * change the RIT/XIT frequency. * * TODO: place variant of this in yaesu.c * @@ -1542,57 +1523,59 @@ static int ft920_send_dial_freq(RIG *rig, unsigned char ci, freq_t freq) { */ static int ft920_send_rit_freq(RIG *rig, unsigned char ci, shortfreq_t rit) { - struct rig_state *rig_s; - struct ft920_priv_data *priv; - unsigned char p1; - unsigned char p2; - int err; - - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + struct rig_state *rig_s; + struct ft920_priv_data *priv; + unsigned char p1; + unsigned char p2; + int err; - if (!rig) - return -RIG_EINVAL; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_debug(RIG_DEBUG_TRACE, "%s: passed ci = %i\n", __func__, ci); - rig_debug(RIG_DEBUG_TRACE, "%s: passed rit = %li Hz\n", __func__, rit); + if (!rig) + return -RIG_EINVAL; - priv = (struct ft920_priv_data *)rig->state.priv; - if (priv->pcs[ci].ncomp) { - rig_debug(RIG_DEBUG_TRACE, - "%s: Attempt to modify complete sequence\n", __func__); - return -RIG_EINVAL; - } + rig_debug(RIG_DEBUG_TRACE, "%s: passed ci = %i\n", __func__, ci); + rig_debug(RIG_DEBUG_TRACE, "%s: passed rit = %li Hz\n", __func__, rit); - rig_s = &rig->state; + priv = (struct ft920_priv_data *)rig->state.priv; - p1 = CLAR_SET_FREQ; + /* + * If we've been passed a command index (ci) that is marked + * as static (1), then bail out. + */ + if (priv->pcs[ci].ncomp) { + rig_debug(RIG_DEBUG_TRACE, "%s: Attempt to modify complete sequence\n", __func__); + return -RIG_EINVAL; + } - if (rit < 0) { - rit = labs(rit); /* get absolute value of rit */ - p2 = CLAR_OFFSET_MINUS; - } else { - p2 = CLAR_OFFSET_PLUS; - } + rig_s = &rig->state; - /* Copy native cmd clarifier ops to private cmd storage area */ - memcpy(&priv->p_cmd, &ncmd[ci].nseq, YAESU_CMD_LENGTH); + p1 = CLAR_SET_FREQ; - /* store bcd format in in p_cmd */ - to_bcd(priv->p_cmd, rit/10, FT920_BCD_RIT); + if (rit < 0) { + rit = labs(rit); /* get absolute value of rit */ + p2 = CLAR_OFFSET_MINUS; + } else { + p2 = CLAR_OFFSET_PLUS; + } - rig_debug(RIG_DEBUG_TRACE, - "%s: requested rit after conversion = %li Hz\n", - __func__, from_bcd(priv->p_cmd, FT920_BCD_RIT)* 10); + /* Copy native cmd clarifier ops to private cmd storage area */ + memcpy(&priv->p_cmd, &ncmd[ci].nseq, YAESU_CMD_LENGTH); - priv->p_cmd[P1] = p1; /* ick */ - priv->p_cmd[P2] = p2; + /* store bcd format in in p_cmd */ + to_bcd(priv->p_cmd, rit/10, FT920_BCD_RIT); - err = write_block(&rig_s->rigport, (unsigned char *) &priv->p_cmd, - YAESU_CMD_LENGTH); - if (err != RIG_OK) - return err; + rig_debug(RIG_DEBUG_TRACE, "%s: requested rit after conversion = %li Hz\n", + __func__, from_bcd(priv->p_cmd, FT920_BCD_RIT)* 10); - return RIG_OK; + priv->p_cmd[P1] = p1; /* ick */ + priv->p_cmd[P2] = p2; + + err = write_block(&rig_s->rigport, (unsigned char *) &priv->p_cmd, YAESU_CMD_LENGTH); + if (err != RIG_OK) + return err; + + return RIG_OK; } diff --git a/yaesu/ft920.h b/yaesu/ft920.h index 11ccf07a2..03e590ce3 100644 --- a/yaesu/ft920.h +++ b/yaesu/ft920.h @@ -2,14 +2,14 @@ * hamlib - (C) Frank Singleton 2000 (javabear at users.sourceforge.net) * * ft920.h - (C) Frank Singleton 2000 (javabear at users.sourceforge.net) - * (C) Nate Bargmann 2002, 2003 (n0nb at arrl.net) + * (C) Nate Bargmann 2002-2005 (n0nb at arrl.net) * (C) Stephane Fillod 2002 (fillods at users.sourceforge.net) * * This shared library provides an API for communicating * via serial interface to an FT-920 using the "CAT" interface * * - * $Id: ft920.h,v 1.12 2003-04-06 18:40:36 fillods Exp $ + * $Id: ft920.h,v 1.13 2005-01-18 23:06:51 n0nb Exp $ * * * This library is free software; you can redistribute it and/or @@ -30,50 +30,50 @@ #ifndef _FT920_H -#define _FT920_H 1 +#define _FT920_H 1 -#define TRUE 1 -#define FALSE 0 +#define TRUE 1 +#define FALSE 0 -#define FT920_VFO_ALL (RIG_VFO_A|RIG_VFO_B) +#define FT920_VFO_ALL (RIG_VFO_A|RIG_VFO_B) /* Receiver caps */ -#define FT920_ALL_RX_MODES (RIG_MODE_AM|RIG_MODE_CW|RIG_MODE_USB|RIG_MODE_LSB) -#define FT920_SSB_CW_RX_MODES (RIG_MODE_CW|RIG_MODE_USB|RIG_MODE_LSB) -#define FT920_AM_RX_MODES (RIG_MODE_AM) -#define FT920_FM_RX_MODES (RIG_MODE_FM) +#define FT920_ALL_RX_MODES (RIG_MODE_AM|RIG_MODE_CW|RIG_MODE_USB|RIG_MODE_LSB) +#define FT920_SSB_CW_RX_MODES (RIG_MODE_CW|RIG_MODE_USB|RIG_MODE_LSB) +#define FT920_AM_RX_MODES (RIG_MODE_AM) +#define FT920_FM_RX_MODES (RIG_MODE_FM) /* TX caps */ -#define FT920_OTHER_TX_MODES (RIG_MODE_CW| RIG_MODE_USB| RIG_MODE_LSB ) /* 100 W class */ -#define FT920_AM_TX_MODES (RIG_MODE_AM ) /* set 25W max */ -#define FT920_FUNC_ALL (RIG_FUNC_FAGC|RIG_FUNC_NB|RIG_FUNC_COMP|RIG_FUNC_VOX|RIG_FUNC_TONE|RIG_FUNC_TSQL|RIG_FUNC_SBKIN|RIG_FUNC_FBKIN) /* fix */ +#define FT920_OTHER_TX_MODES (RIG_MODE_CW| RIG_MODE_USB| RIG_MODE_LSB ) /* 100 W class */ +#define FT920_AM_TX_MODES (RIG_MODE_AM ) /* set 25W max */ +#define FT920_FUNC_ALL (RIG_FUNC_FAGC|RIG_FUNC_NB|RIG_FUNC_COMP|RIG_FUNC_VOX|RIG_FUNC_TONE|RIG_FUNC_TSQL|RIG_FUNC_SBKIN|RIG_FUNC_FBKIN) /* fix */ /* Other features */ -#define FT920_ANTS 0 /* FIXME: declare Ant A & B and RX input */ +#define FT920_ANTS 0 /* FIXME: declare Ant A & B and RX input */ /* Returned data length in bytes */ -#define FT920_MEM_CHNL_LENGTH 1 /* 0x10 P1 = 01 return size */ -#define FT920_STATUS_FLAGS_LENGTH 8 /* 0xfa return size */ -#define FT920_VFO_DATA_LENGTH 28 /* 0x10 P1 = 02, 03 return size */ -#define FT920_MEM_CHNL_DATA_LENGTH 14 /* 0x10 P1 = 04, P4 = 0x00-0x89 return size */ +#define FT920_MEM_CHNL_LENGTH 1 /* 0x10 P1 = 01 return size */ +#define FT920_STATUS_FLAGS_LENGTH 8 /* 0xfa return size */ +#define FT920_VFO_DATA_LENGTH 28 /* 0x10 P1 = 02, 03 return size */ +#define FT920_MEM_CHNL_DATA_LENGTH 14 /* 0x10 P1 = 04, P4 = 0x00-0x89 return size */ /* Timing values in mS */ -#define FT920_PACING_INTERVAL 5 -#define FT920_PACING_DEFAULT_VALUE 1 -#define FT920_WRITE_DELAY 50 +#define FT920_PACING_INTERVAL 5 +#define FT920_PACING_DEFAULT_VALUE 1 +#define FT920_WRITE_DELAY 50 /* Delay sequential fast writes */ -#define FT920_POST_WRITE_DELAY 5 +#define FT920_POST_WRITE_DELAY 5 /* Rough safe value for default timeout */ @@ -81,8 +81,8 @@ #define FT920_DEFAULT_READ_TIMEOUT 28 * ( 5 + (FT920_PACING_INTERVAL * FT920_PACING_DEFAULT_VALUE)) /* BCD coded frequency length */ -#define FT920_BCD_DIAL 8 -#define FT920_BCD_RIT 3 +#define FT920_BCD_DIAL 8 +#define FT920_BCD_RIT 3 /* @@ -91,14 +91,14 @@ * * delay for 28 bytes = (2.2917 + pace_interval) * 28 * - * pace_interval time to read 28 bytes - * ------------ ---------------------- + * pace_interval time to read 28 bytes + * ------------- --------------------- * - * 0 64 msec - * 1 92 msec - * 2 120 msec - * 5 204 msec - * 255 7.2 sec + * 0 64 msec + * 1 92 msec + * 2 120 msec + * 5 204 msec + * 255 7.2 sec * */ @@ -109,29 +109,29 @@ */ enum ft920_native_cmd_e { - FT920_NATIVE_SPLIT_OFF = 0, - FT920_NATIVE_SPLIT_ON, - FT920_NATIVE_RECALL_MEM, - FT920_NATIVE_VFO_TO_MEM, - FT920_NATIVE_VFO_A, - FT920_NATIVE_VFO_B, - FT920_NATIVE_MEM_TO_VFO, - FT920_NATIVE_CLARIFIER_OPS, - FT920_NATIVE_VFO_A_FREQ_SET, - FT920_NATIVE_MODE_SET, - FT920_NATIVE_PACING, - FT920_NATIVE_MEM_CHNL, - FT920_NATIVE_OP_DATA, - FT920_NATIVE_VFO_DATA, - FT920_NATIVE_MEM_CHNL_DATA, - FT920_NATIVE_VFO_B_FREQ_SET, - FT920_NATIVE_VFO_A_PASSBAND_WIDE, - FT920_NATIVE_VFO_A_PASSBAND_NAR, - FT920_NATIVE_VFO_B_PASSBAND_WIDE, - FT920_NATIVE_VFO_B_PASSBAND_NAR, - FT920_NATIVE_STATUS_FLAGS, - FT920_NATIVE_SIZE /* end marker, value indicates number of */ - /* native cmd entries */ + FT920_NATIVE_SPLIT_OFF = 0, + FT920_NATIVE_SPLIT_ON, + FT920_NATIVE_RECALL_MEM, + FT920_NATIVE_VFO_TO_MEM, + FT920_NATIVE_VFO_A, + FT920_NATIVE_VFO_B, + FT920_NATIVE_MEM_TO_VFO, + FT920_NATIVE_CLARIFIER_OPS, + FT920_NATIVE_VFO_A_FREQ_SET, + FT920_NATIVE_MODE_SET, + FT920_NATIVE_PACING, + FT920_NATIVE_MEM_CHNL, + FT920_NATIVE_OP_DATA, + FT920_NATIVE_VFO_DATA, + FT920_NATIVE_MEM_CHNL_DATA, + FT920_NATIVE_VFO_B_FREQ_SET, + FT920_NATIVE_VFO_A_PASSBAND_WIDE, + FT920_NATIVE_VFO_A_PASSBAND_NAR, + FT920_NATIVE_VFO_B_PASSBAND_WIDE, + FT920_NATIVE_VFO_B_PASSBAND_NAR, + FT920_NATIVE_STATUS_FLAGS, + FT920_NATIVE_SIZE /* end marker, value indicates number of */ + /* native cmd entries */ }; typedef enum ft920_native_cmd_e ft920_native_cmd_t; @@ -143,30 +143,30 @@ typedef enum ft920_native_cmd_e ft920_native_cmd_t; */ /* VFO A */ -#define MODE_SET_A_LSB 0x00 -#define MODE_SET_A_USB 0x01 -#define MODE_SET_A_CW_U 0x02 -#define MODE_SET_A_CW_L 0x03 -#define MODE_SET_A_AM_W 0x04 -#define MODE_SET_A_AM_N 0x05 -#define MODE_SET_A_FM_W 0x06 -#define MODE_SET_A_FM_N 0x07 -#define MODE_SET_A_DATA_L 0x08 -#define MODE_SET_A_DATA_U 0x0a -#define MODE_SET_A_DATA_F 0x0b +#define MODE_SET_A_LSB 0x00 +#define MODE_SET_A_USB 0x01 +#define MODE_SET_A_CW_U 0x02 +#define MODE_SET_A_CW_L 0x03 +#define MODE_SET_A_AM_W 0x04 +#define MODE_SET_A_AM_N 0x05 +#define MODE_SET_A_FM_W 0x06 +#define MODE_SET_A_FM_N 0x07 +#define MODE_SET_A_DATA_L 0x08 +#define MODE_SET_A_DATA_U 0x0a +#define MODE_SET_A_DATA_F 0x0b /* VFO B */ -#define MODE_SET_B_LSB 0x80 -#define MODE_SET_B_USB 0x81 -#define MODE_SET_B_CW_U 0x82 -#define MODE_SET_B_CW_L 0x83 -#define MODE_SET_B_AM_W 0x84 -#define MODE_SET_B_AM_N 0x85 -#define MODE_SET_B_FM_W 0x86 -#define MODE_SET_B_FM_N 0x87 -#define MODE_SET_B_DATA_L 0x88 -#define MODE_SET_B_DATA_U 0x8a -#define MODE_SET_B_DATA_F 0x8b +#define MODE_SET_B_LSB 0x80 +#define MODE_SET_B_USB 0x81 +#define MODE_SET_B_CW_U 0x82 +#define MODE_SET_B_CW_L 0x83 +#define MODE_SET_B_AM_W 0x84 +#define MODE_SET_B_AM_N 0x85 +#define MODE_SET_B_FM_W 0x86 +#define MODE_SET_B_FM_N 0x87 +#define MODE_SET_B_DATA_L 0x88 +#define MODE_SET_B_DATA_U 0x8a +#define MODE_SET_B_DATA_F 0x8b /* @@ -176,15 +176,15 @@ typedef enum ft920_native_cmd_e ft920_native_cmd_t; */ /* P1 values */ -#define CLAR_RX_OFF 0x00 -#define CLAR_RX_ON 0x01 -#define CLAR_TX_OFF 0x80 -#define CLAR_TX_ON 0x81 -#define CLAR_SET_FREQ 0xff +#define CLAR_RX_OFF 0x00 +#define CLAR_RX_ON 0x01 +#define CLAR_TX_OFF 0x80 +#define CLAR_TX_ON 0x81 +#define CLAR_SET_FREQ 0xff /* P2 values */ -#define CLAR_OFFSET_PLUS 0x00 -#define CLAR_OFFSET_MINUS 0xff +#define CLAR_OFFSET_PLUS 0x00 +#define CLAR_OFFSET_MINUS 0xff /* @@ -192,8 +192,8 @@ typedef enum ft920_native_cmd_e ft920_native_cmd_t; * */ -//#define FT920_VFO_A 0x00 -//#define FT920_VFO_B 0x01 +//#define FT920_VFO_A 0x00 +//#define FT920_VFO_B 0x01 /* @@ -210,19 +210,19 @@ typedef enum ft920_native_cmd_e ft920_native_cmd_t; * */ -#define FT920_SUMO_DISPLAYED_STATUS_0 0x00 /* Status flag byte 0 */ -#define SF_VFOA 0x00 /* bits 0 & 1, VFO A TX/RX == 0 */ -#define SF_SPLITA (1<<0) /* Split operation with VFO-B on TX */ -#define SF_SPLITB (1<<1) /* Split operation with VFO-B on RX */ -#define SF_VFOB (SF_SPLITA|SF_SPLITB) /* bits 0 & 1, VFO B TX/RX == 3 */ +#define FT920_SUMO_DISPLAYED_STATUS_0 0x00 /* Status flag byte 0 */ +#define SF_VFOA 0x00 /* bits 0 & 1, VFO A TX/RX == 0 */ +#define SF_SPLITA (1<<0) /* Split operation with VFO-B on TX */ +#define SF_SPLITB (1<<1) /* Split operation with VFO-B on RX */ +#define SF_VFOB (SF_SPLITA|SF_SPLITB) /* bits 0 & 1, VFO B TX/RX == 3 */ -#define FT920_SUMO_DISPLAYED_STATUS_1 0x01 /* Status flag byte 1 */ -#define SF_QMB (1<<3) /* Quick Memory Bank (QMB) selected */ -#define SF_MT (1<<4) /* Memory Tuning in progress */ -#define SF_VFO (1<<5) /* VFO operation selected */ -#define SF_MR (1<<6) /* Memory Mode selected */ -#define SF_GC (1<<7) /* General Coverage Reception selected */ -#define SF_VFO_MASK (SF_QMB|SF_MT|SF_VFO|SF_MR) +#define FT920_SUMO_DISPLAYED_STATUS_1 0x01 /* Status flag byte 1 */ +#define SF_QMB (1<<3) /* Quick Memory Bank (QMB) selected */ +#define SF_MT (1<<4) /* Memory Tuning in progress */ +#define SF_VFO (1<<5) /* VFO operation selected */ +#define SF_MR (1<<6) /* Memory Mode selected */ +#define SF_GC (1<<7) /* General Coverage Reception selected */ +#define SF_VFO_MASK (SF_QMB|SF_MT|SF_VFO|SF_MR) /* * Offsets for VFO record retrieved via 0x10 P1 = 02, 03 @@ -233,17 +233,17 @@ typedef enum ft920_native_cmd_e ft920_native_cmd_t; * CAT command 0x10, P1 = 04, P4 = 0x00-0x89 returns memory channel data (14 bytes) * In all cases the format is (from the FT-920 manual page 90): * - * Offset Value - * 0x00 Band Selection (not documented!) - * 0x01 Operating Frequency (Hex value of display--Not BCD!) - * 0x05 Clarifier Offset (Hex value) - * 0x07 Mode Data - * 0x08 Flag - * 0x09 Filter Data 1 - * 0x0a Filter Data 2 - * 0x0b CTCSS Encoder Data - * 0x0c CTCSS Decoder Data - * 0x0d Memory recall Flag + * Offset Value + * 0x00 Band Selection (not documented!) + * 0x01 Operating Frequency (Hex value of display--Not BCD!) + * 0x05 Clarifier Offset (Hex value) + * 0x07 Mode Data + * 0x08 Flag + * 0x09 Filter Data 1 + * 0x0a Filter Data 2 + * 0x0b CTCSS Encoder Data + * 0x0c CTCSS Decoder Data + * 0x0d Memory recall Flag * * Memory Channel data has the same layout and offsets * VFO B data has the same layout, but the offset starts at 0x0e and @@ -251,15 +251,15 @@ typedef enum ft920_native_cmd_e ft920_native_cmd_t; * */ -#define FT920_SUMO_DISPLAYED_FREQ 0x01 /* Current main display, can be VFO A, Memory data, Memory tune */ -#define FT920_SUMO_VFO_A_FREQ 0x01 /* VFO A frequency, not necessarily currently displayed! */ -#define FT920_SUMO_DISPLAYED_CLAR 0x05 /* RIT/XIT offset -- current display */ -#define FT920_SUMO_VFO_A_CLAR 0x05 /* RIT/XIT offset -- VFO A */ -#define FT920_SUMO_DISPLAYED_MODE 0x07 /* Current main display mode */ -#define FT920_SUMO_VFO_A_MODE 0x07 /* VFO A mode, not necessarily currently displayed! */ -#define FT920_SUMO_VFO_B_FREQ 0x0f /* Current sub display && VFO B */ -#define FT920_SUMO_VFO_B_CLAR 0x13 /* RIT/XIT offset -- VFO B */ -#define FT920_SUMO_VFO_B_MODE 0x15 /* Current sub display && VFO B */ +#define FT920_SUMO_DISPLAYED_FREQ 0x01 /* Current main display, can be VFO A, Memory data, Memory tune */ +#define FT920_SUMO_VFO_A_FREQ 0x01 /* VFO A frequency, not necessarily currently displayed! */ +#define FT920_SUMO_DISPLAYED_CLAR 0x05 /* RIT/XIT offset -- current display */ +#define FT920_SUMO_VFO_A_CLAR 0x05 /* RIT/XIT offset -- VFO A */ +#define FT920_SUMO_DISPLAYED_MODE 0x07 /* Current main display mode */ +#define FT920_SUMO_VFO_A_MODE 0x07 /* VFO A mode, not necessarily currently displayed! */ +#define FT920_SUMO_VFO_B_FREQ 0x0f /* Current sub display && VFO B */ +#define FT920_SUMO_VFO_B_CLAR 0x13 /* RIT/XIT offset -- VFO B */ +#define FT920_SUMO_VFO_B_MODE 0x15 /* Current sub display && VFO B */ /* * Mode Bitmap from offset 0x07 or 0x16 in VFO Record. @@ -268,38 +268,38 @@ typedef enum ft920_native_cmd_e ft920_native_cmd_t; * */ -#define MODE_LSB 0x00 -#define MODE_CW_L 0x01 /* CW listening on LSB */ -#define MODE_AM 0x02 -#define MODE_FM 0x03 -#define MODE_DATA_L 0x04 /* DATA on LSB */ -#define MODE_DATA_U 0x05 /* DATA on USB (who does that? :) */ -#define MODE_DATA_F 0x06 /* DATA on FM */ -#define MODE_USB 0x40 -#define MODE_CW_U 0x41 /* CW listening on USB */ +#define MODE_LSB 0x00 +#define MODE_CW_L 0x01 /* CW listening on LSB */ +#define MODE_AM 0x02 +#define MODE_FM 0x03 +#define MODE_DATA_L 0x04 /* DATA on LSB */ +#define MODE_DATA_U 0x05 /* DATA on USB (who does that? :) */ +#define MODE_DATA_F 0x06 /* DATA on FM */ +#define MODE_USB 0x40 +#define MODE_CW_U 0x41 /* CW listening on USB */ /* Narrow filter selected */ -#define MODE_LSBN 0x80 /* Not sure this actually exists */ -#define MODE_CW_LN 0x81 -#define MODE_AMN 0x82 -#define MODE_FMN 0x83 -#define MODE_DATA_LN 0x84 -#define MODE_DATA_UN 0x85 -#define MODE_DATA_FN 0x86 -#define MODE_USBN 0xc0 /* Not sure this actually exists */ -#define MODE_CW_UN 0xc1 +#define MODE_LSBN 0x80 /* Not sure this actually exists */ +#define MODE_CW_LN 0x81 +#define MODE_AMN 0x82 +#define MODE_FMN 0x83 +#define MODE_DATA_LN 0x84 +#define MODE_DATA_UN 0x85 +#define MODE_DATA_FN 0x86 +#define MODE_USBN 0xc0 /* Not sure this actually exists */ +#define MODE_CW_UN 0xc1 /* All relevent bits */ -#define MODE_MASK 0xc7 +#define MODE_MASK 0xc7 /* * Command string parameter offsets */ -#define P1 3 -#define P2 2 -#define P3 1 -#define P4 0 +#define P1 3 +#define P2 2 +#define P3 1 +#define P4 0 /*