Start of rig menuing functions.

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1073 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.1.4
Dale E. Edmons, KD7ENI 2002-06-29 08:38:21 +00:00
rodzic 00d4985890
commit 3457f7a62b
2 zmienionych plików z 491 dodań i 0 usunięć

251
kenwood/ts2k_menu.c 100644
Wyświetl plik

@ -0,0 +1,251 @@
/*
* ts2k_menu.c (C) Copyright 2002 by Dale E. Edmons. All rights reserved.
*/
/*
* License: GNU
*/
/*
* Functions to initialize, read, set, and list menus
* for the TS-2000. These functions will be added to
* src/rig.c as rig_*menu_*() as time permits.
*
* This is likely a can of worms nobody has wanted to
* deal with--until now. The ts2k is especially a
* pain as you'll soon seen (but cool nonetheless.)
*/
#include <rig.h>
#include "ts2k.h"
#include "ts2k_menu.h"
#include <ctype.h>
/*
* Set the menu number(s) and terminate with ";" (not ';')
*/
int ts2k_set_menu_no(RIG *rig, ts2k_menu_t *menu, int main, int sub)
{
int i;
menu->menu_no[0] = main;
menu->menu_no[1] = sub;
menu->menu_no[2] = menu->menu_no[3] = 0;
i = sprintf( &menu->cmd[0], "ex%03u%02u%01u%01u;", main, sub, 0, 0);
if(i != 10)
return -RIG_EINVAL;
return RIG_OK;
}
/*
* Get the menu number(s) from cmd[]
*/
int ts2k_get_menu_no(RIG *rig, ts2k_menu_t *menu, int *main, int *sub)
{
char tmp[30];
int m, s;
if(menu==NULL)
return -RIG_EINVAL;
m = int_n(tmp, &menu->cmd[2], 3);
s = int_n(tmp, &menu->cmd[7], 2);
menu->menu_no[0] = m;
menu->menu_no[1] = s;
menu->menu_no[2] = menu->menu_no[3] = 0;
if(main != NULL)
*main = m;
if(sub != NULL)
*sub = s;
return RIG_OK;
}
/*
* When called by ts2k_pm_init we read all of
* the rig's current menu options and set them
* in the current menu array. We don't do the
* memory allocation so you can init as many
* as you want. The reason for this is huge.
* First, after full reset the rig can access
* menuA or menuB and different values retained.
* Second, by sending "pm...;" we can select
* Programmable Memory 0-5, with 0 being the
* the default. Amazingly, each PM seems to
* have its own menuA and menuB. Thus, all
* told, we have up to twelve distinct menus
* each with (potentially) unique values. We
* do the allocation in the PM routines and
* leave this one much simpler and just call
* it up to twelve times with uniq ts2k_menu_t
* pointers. Third, the user may wish to use
* this to obtain a private copy for local use
* and only has to call this routine to make
* sure its current. (A ts2k_pm_t should be
* allocated as well!)
*/
int ts2k_menu_init(RIG *rig, ts2k_menu_t *menu[])
{
int retval, i;
ts2k_menu_t *m, *mref;
if(menu == NULL || menu == ts2k_menus) {
rig_debug(rig, __FUNCTION__": invalid menu pointer\n");
return -RIG_EINVAL;
}
// One set of defaults has been globally defined (mref)
for(i=0, i<(sizeof(menu)/sizeof(ts2k_menu_t)); i++) {
m = menu[i];
mref = ts2k_menus[i];
retval = ts2k_set_menu_no(rig, m, mref->menu[0], mref->menu[1]);
if(retval != RIG_OK)
return retval;
retval = ts2k_get_menu(rig, m);
if(retval != RIG_OK)
return retval;
// FIXME: set some debug traces here?
}
return RIG_OK;
}
/*
* read the rig and get the parameters for menu[n].
* convert them to a ts2k_menu_t, and eventually to
* a rig_menu_t. I do a lot of checking to ensure
* nothing breaks (hi!).
*/
int ts2k_get_menu(RIG *rig, ts2k_menu_t *menu, )
{
int retval, i, j, k, acklen;
char ack[30];
if(menu == NULL)
return -RIG_EINVAL;
else if( (toupper(menu->cmd[0]) != 'E')
|| (toupper(menu->cmd[1]) != 'X') )
return -RIG_EINVAL;
else if(menu->cmd[9] != ';')
retval = -RIG_EINVAL;
retval = ts2k_transaction(rig, menu->cmd, 10, ack, &acklen);
if(retval != RIG_OK)
return retval;
strncpy(menu->cmd, ack, 30);
retval = ts2k_menu_parse(rig, menu);
if(retval != RIG_OK)
return retval;
return retval;
}
/*
* Here, I expect everything to be setup for me.
* All we do is determe the value and param_txt
* for the menu item we are given.
*
* status: real ugly!
*/
int ts2k_menu_parse(RIG *rig, ts2k_menu_t *menu)
{
ts2k_menu_t *mref, *m;
char *vptr;
int on_off[] = { 01, 03, 04, 05, 07, 09, 17, 18, 23, 25, 26,
27, 30, 34, 35, 36, 37, 43, 44, 52, 53, 63, 54, 55,
-1},
zero2nine = {
m = menu; // to lazy to spell menu-> all the time
if(m->cmd[0] == '\0' || m->cmd[1] == '\0')
return -RIG_EINVAL; // Caller has blown it!
// find matching refence menu
i=0;
do {
mref = ts2k_menus[i];
if(mref == NULL) // Either Caller or I blew it!
return -RIG_EINTERNAL;
if(mref->menu_no[i] == NULL)
return -RIG_EINVAL; // It has to match one!
if(menu == ts2k_menus[i]) // Nobody changes our REF!
return -RIG_EINTERNAL;
if(mref->menu[0] == m->menu[0])
&& mref->menu[1] == m->menu[1]
&& mref->menu[2] == m->menu[2]
/*&& mref->menu[3] == m->menu[3]*/) {
break;
}
} while (++i)
/* Match the main menu and only look for sub-menus later */
// check for menus that are simple on/off first
// FIXME: this isn't fast, it just eliminates alot of cases!
for(i=0; on_off == -1; i++) {
if(m->menu[0] == m->menu[0]) {
m->val = m->cmd[9] - '0';
m->param_txt = (m->val == 1)? m_on : m_off;
return RIG_OK;
}
}
// Use mref to do all we can
retval = -RIG_EINTERNAL;
for(i=0; mref->param_txt != NULL; i++) {
if(retval == RIG_OK) {
return retval;
}
switch( mref->param_txt[i] ) {
case m_tbd: // menu item under development!
m->param_txt = m_tbd;
vptr = malloc( 17 );
if(vptr == NULL)
return -RIG_NOMEM;
for(j=0; vptr[i] != ';' && i<17; i++) {
vptr[i] == m->cmd[i];
}
vptr[i] = '\0';
return -RIG_NIMPL;
case m_off:
if(m->cmd[9] == '0') {
m->param_txt = mref->param_txt[i];
m->val = 0;
retval = RIG_OK;
}
break;
case m_num:
default:
return -RIG_NIMPL;
}
}
switch( m->menu[0] ) {
case 00:
case 00:
case 00:
case 00:
case 00:
case 00:
case 00:
case 00:
default:
return -RIG_EINTERNAL; // I'm requiring 100% match
}
return RIG_OK;
}
// End of ts2k_menu.c

240
kenwood/ts2k_menu.h 100644
Wyświetl plik

@ -0,0 +1,240 @@
/*
* ts2k_menu.h (C) Copyright 2002 by Dale E. Edmons. All rights reserved.
*/
/*
* License: GNU (same as what hamlib currently is using)
*/
/*
* status: uncompiled. Haven't finished factory defaults.
* anything with m_tbd is: to be developed
*/
/* Header to implement menus equivalent to those on the TS-2000. */
// sub-menu defines
#define MENU_A 1
#define MENU_B 2
#define MENU_C 3
#define MENU_D 4
#define MENU_E 5
#define MENU_F 6
// parameter value text. may be used in any menu.
const char m_on[]="On";
const char m_off[]="Off";
const char m_to[]="TO";
const char m_co[]="CO";
const char m_h_boost[]="High Boost";
const char m_b_boost[]="Bass Boost";
const char m_f_pass[]="F Pass";
const char m_conven[]="Conven";
const char m_user[]="User";
const char m_auto[]="Auto";
const char m_norm[]="Normal";
const char m_inv[]="Inverse";
const char m_low[]="Low";
const char m_mid[]="Mid";
const char m_hi[]="High";
const char m_burst[]="Burst";
const char m_cont[]="Cont";
const char m_slow[]="Slow";
const char m_fast[]="Fast";
const char m_main[]="Main";
const char m_sub[]="Sub";
const char m_tnc_band[]="TNC Band";
const char m_main_sub[]="Main & Sub";
const char m_man[]="Manual";
const char m_morse[]="Morse";
const char m_voice[]="Voice";
const char m_neg[]="Negative";
const char m_pos[]="Positive";
const char m_locked[]="Locked";
const char m_cross[]="Cross";
const char m_client[]="Client";
const char m_commander[]="Commander";
const char m_transporter[]="Transporter";
const char m_font1[]="font1";
const char m_font2[]="font2";
const char m_num[8+2]; // storage for numeric constants
const char m_text[8+2]; // storage for text constants
//const char m_[]="";
// array valued constants (mostly) or other undefined text
const char m_tbd[]="hamlib: t.b.d.";
// PF1 key assignments
#define KEY_MENU_MAX 62
#define KEY_KEY_MAX 90
#define KEY_UNASSIGNED 99
const char key_menu[]="Menu"; // menu # 0-62
const char key_none[]="None";
const char key_key[][KEY_KEY_MAX-KEY_MENU_MAX] = {
"Voice1", Voice2", "Voice3", "RX Moni", "DSP Moni",
"Quick Memo MR", "Quick Memo M.IN", "Split", "TF-SET",
"A/B", "VFO/M", "A=B", "Scan", "M>VFO", "M.IN", "CW TUNE",
"CH1", "CH2", "CH3", "Fine", "CLR", "Call", "CTRL",
"1MHz", "ANT1/2", "N.B.", "N.R.", "B.C.", "A.N.",
""
};
typedef struct {
const char menu_no[];
const char txt[];
const char *param_txt[];
char cmd[30];
const int menu[4];
int val; // same as P5
} ts2k_menu_t;
/*
* Defaults for menu_t.val were obtained via minicom
* on my rig after doing a full reset to factory defaults.
* (unfinished)
*/
const ts2k_menu_t ts2k_menus[] = {
{ "00", "Display Brightness", {m_off, m_num, NULL}, "", {00,0,0,0}, 3},
{ "01", "Key Illumination", {m_off, m_on, NULL}, "", {01,0,0,0}, 1},
{ "02", "Tuning Control Change Per Revolution", {m_num, NULL}, "", {02,0,0,0}, 1},
{ "03", "Tune using MULTI/CH Frequency Step", {m_off, m_on, NULL}, "", {03,0,0,0}, 1},
{ "04", "Round off VFO using MULTI/CH Control", {m_off, m_on, NULL}, "", {04,0,0,0}, 1},
{ "05", "9kHz step size for MULTI/CH in AM Broadcast Band", {m_off, m_on, NULL}, "", {05,0,0,0}, 0},
{ "06A", "Mem: Memory-VFO Split", {m_off, m_on, NULL}, "", {06,1,0,0}, 0},
{ "06B", "Mem: Temporary Frequency change after Memory Recall", {m_off, m_on, NULL}, "", {06,2,0,0}, 0},
{ "07", "Program scan partially slowed", {m_off, m_on, NULL}, "", {07,0,0,0}, 0},
{ "08", "Program Slow-Scan Range", {m_num, NULL}, "", {08,0,0,0}, 0},
{ "09", "Program scan hold", {m_off, m_on, NULL}, "", {09,0,0,0}, 0},
{ "10", "Scan Resume Method", {m_to, m_co, NULL}, "", {10,0,0,0}, 0},
{ "11", "Visual Scan Range", {m_tbd, NULL}, "", {11,0,0,0}, 0},
{ "12", "Beep Volume", {m_off, m_num, NULL}, "", {12,0,0,0}, 0},
{ "13", "Sidetone Volume", {m_off, m_num, NULL}, "", {13,0,0,0}, 0},
{ "14", "Message Playback Volume", {m_off, m_num, NULL}, "", {14,0,0,0}, 0},
{ "15", "Voice Volume", {m_off, m_num, NULL}, "", {15,0,0,0}, 0},
{ "16", "Output Configuration for sp2 or headphones", {m_tbd, NULL}, "", {16,0,0,0}, 0},
{ "17", "Reversed output configuration for sp2 or headphones", {m_off, m_on, NULL}, "", {17,0,0,0}, 0},
{ "18", "RX-Dedicated antenna", {m_off, m_on, NULL}, "", {18,0,0,0}, 0},
{ "19A", "S-Meter: SQ", {m_off, m_on, NULL}, "", {19,1,0,0}, 0},
{ "19B", "S-Meter: Hang Time", {m_off, m_tbd, NULL}, "", {19,2,0,0}, 0},
{ "20", "RX Equalizer", {m_off, m_h_boost, m_b_boost, m_conven, m_user, NULL}, "", {20,0,0,0}, 0},
{ "21", "TX Equalizer", {m_off, m_h_boost, m_b_boost, m_conven, m_user, NULL}, "", {21,0,0,0}, 0},
{ "22", "TX Filter Bandwidth for SSB or AM", {m_tbd, NULL}, "", {22,0,0,0}, 0},
{ "23", "Fine Transmit power change step", {m_off, m_on, NULL}, "", {23,0,0,0}, 0},
{ "24", "Time-out Timer", {m_off, m_tbd, NULL}, "", {24,0,0,0}, 0},
{ "25", "Transverter Frequency Display", {m_off, m_on, NULL}, "", {25,0,0,0}, 0},
{ "26", "TX Hold; Antenna tuner", {m_off, m_on, NULL}, "", {26,0,0,0}, 0},
{ "27", "Antenna tuner while receiving", {m_off, m_on, NULL}, "", {27,0,0,0}, 0},
{ "28A", "Linear Amp Control Relay: HF", {m_off, m_num, NULL}, "", {28,1,0,0}, 0},
{ "28B", "Linear Amp Control Relay: 50MHz", {m_off, m_num, NULL}, "", {28,2,0,0}, 0},
{ "28C", "Linear Amp Control Relay: 144MHz", {m_off, m_num, NULL}, "", {28,3,0,0}, 0},
{ "28D", "Linear Amp Control Relay: 430MHz", {m_off, m_num, NULL}, "", {28,4,0,0}, 0},
{ "28E", "Linear Amp Control Relay: 1.2GHz", {m_off, m_num, NULL}, "", {28,5,0,0}, 0},
{ "29A", "CW Message: Playback Repeat", {m_off, m_on, NULL}, "", {29,1,0,0}, 0},
{ "29B", "CW Message: Playback Interval", {m_num, NULL}, "", {29,2,0,0}, 0},
{ "30", "Keying Priority over playback", {m_off, m_on, NULL}, "", {30,0,0,0}, 0},
{ "31", "CW RX Pitch/TX sidetone frequency", {m_tbd, NULL}, "", {31,0,0,0}, 0},
{ "32", "CW rise time", {m_tbd, NULL}, "", {32,0,0,0}, 0},
{ "33", "CW weighting", {m_auto, m_tbd, NULL}, "", {33,0,0,0}, 0},
{ "34", "Reversed CW weighting", {m_off, m_on, NULL}, "", {34,0,0,0}, 0},
{ "35", "Bug key function", {m_off, m_on, NULL}, "", {35,0,0,0}, 0},
{ "36", "Auto CW TX when keying in SSB", {m_off, m_on, NULL}, "", {36,0,0,0}, 0},
{ "37", "Frequency correction for SSB-to-CW change", {m_off, m_on, NULL}, "", {37,0,0,0}, 0},
{ "38", "FSK shift", {m_tbd, NULL}, "", {38,0,0,0}, 0},
{ "39", "FSK key-down polarity", {m_norm, m_inv, NULL}, "", {39,0,0,0}, 0},
{ "40", "FSK tone frequency", {m_tbd, NULL}, "", {40,0,0,0}, 0},
{ "41", "FM mic gain", {m_low, m_mid, m_high, NULL}, "", {41,0,0,0}, 0},
{ "42", "FM sub-tone type", {m_burst, m_cont, NULL}, "", {42,0,0,0}, 0},
{ "43", "Auto repeater offset", {m_off, m_on, NULL}, "", {43,0,0,0}, 0},
{ "44", "TX hold; 1750Hz tone", {m_off, m_on, NULL}, "", {44,0,0,0}, 0},
{ "45A", "DTMF: Memory", {m_tbd, NULL}, "", {45,1,0,0}, 0},
{ "45B", "DTMF: TX speed", {m_fast, m_slow, NULL}, "", {45,2,0,0}, 0},
{ "45C", "DTMF: Pause duration", {m_tbd, NULL}, "", {45,3,0,0}, 0},
{ "45D", "DTMF: Mic control", {m_off, m_on, NULL}, "", {45,4,0,0}, 0},
{ "46", "TNC: Main/Sub", {m_main, m_sub, NULL}, "", {46,0,0,0}, 0},
{ "47", "Data transfer rate; Built-in TNC", {m_tbd, NULL}, "", {47,0,0,0}, 0},
{ "48", "DCD sense", {m_tnc, m_main_sub, NULL}, "", {48,0,0,0}, 0},
{ "49A", "Packet Cluster: Tune", {m_auto, m_man, NULL}, "", {49,1,0,0}, 0},
{ "49B", "Packet Cluster: RX confirmation tone", {m_off, m_morse, m_voice, NULL}, "", {49,2,0,0}, 0},
{ "50A", "TNC: filter bandwidth", {m_off, m_on, NULL}, "", {50,1,0,0}, 0},
{ "50B", "TNC: AF input level", {m_tbd, NULL}, "", {50,2,0,0}, 0},
{ "50C", "TNC: Main band AF output level", {m_tbd, NULL}, "", {50,3,0,0}, 0},
{ "50D", "TNC: Sub band AF output level", {m_tbd, NULL}, "", {50,4,0,0}, 0},
{ "50E", "TNC: External", {m_main, m_sub, NULL}, "", {50,5,0,0}, 0},
{ "50F", "TNC: Ext. Data transfer rate", {m_tbd, NULL}, "", {50,6,0,0}, 0},
{ "51A", "Front panel PF key program", {key_menu, key_key, NULL}, "", {51,1,0,0}, 0},
{ "51B", "Mic key program: PF1", {key_menu, key_key, NULL}, "", {51,2,0,0}, 0},
{ "51C", "Mic key program: PF2", {key_menu, key_key, NULL}, "", {51,3,0,0}, 0},
{ "51D", "Mic key program: PF3", {key_menu, key_key, NULL}, "", {51,4,0,0}, 0},
{ "51E", "Mic key program: PF4", {key_menu, key_key, NULL}, "", {51,5,0,0}, 0},
{ "52", "Settings copy to another transceiver", {m_off, m_on, NULL}, "", {52,0,0,0}, 0},
{ "53", "Settings Copy to VFO", {m_off, m_on, NULL}, "", {53,0,0,0}, 0},
{ "54", "TX inhibit", {m_off, m_on, NULL}, "", {54,0,0,0}, 0},
{ "55", "Packet operation", {m_off, m_on, NULL}, "", {0550,0,0}, 0},
{ "56", "COM connector parameters", {m_tbd, NULL}, "", {56,0,0,0}, 0},
{ "57", "Auto power off", {m_off, m_on, NULL}, "", {57,0,0,0}, 0},
{ "58", "Detachable-panel Display font in easy operation mode", {m_font1, m_font1, NULL}, "", {58,0,0,0}, 0},
{ "59", "Panel display contrast", {m_tbd, NULL}, "", {59,0,0,0}, 0},
{ "60", "Detachable-panel display reversal", {m_tbd, NULL}, "", {60,0,0,0}, 0},
{ "61A", "Repeater mode select", {m_off, m_locked, m_cross, NULL}, "", {61,1,0,0}, 0},
{ "61B", "TX hold; repeater", {m_off, m_on, NULL}, "", {61,2,0,0}, 0},
{ "61C", "Remote Control ID code", {m_num, NULL}, "", {61,3,0,0}, 0},
{ "61D", "Remote control acknowledge", {m_off, m_on, NULL}, "", {61,4,0,0}, 0},
{ "61E", "Remote control", {m_off, m_on, NULL}, "", {61,5,0,0}, 0},
{ "62A", "Commander callsign", {m_text, NULL}, "", {62,1,0,0}, 0},
{ "62B", "Transporter callsign", {m_text, NULL}, "", {62,2,0,0}, 0},
{ "62C", "Sky Command tone frequency", {m_tbd, NULL}, "", {62,3,0,0}, 0},
{ "62D", "Sky command communication speed", {m_tbd, NULL}, "", {62,4,0,0}, 0},
{ "62E", "Transceiver define", {m_off, m_client, m_command, m_transporter, NULL}, "", {62,5,0,0}, 0},
{ NULL, NULL, NULL, {00,0,0,0}, 0}
};
/*
* Items related to menu structure
*/
// Programmable memories
typedef struct {
int curr; // PM now in use
int orig; // what PM to restore on exit
int orig_menu; // orignal menu in effect
int menu; // menuA or menuB of current PM
// the following set which PM's are private or public
// they are set on init and enforced until exit
unsigned int pub;
unsigned int priv;
#ifdef TS2K_ENFORCE_PM
# define TS2K_PM_PUB ( (1<<2) | (1<<3) )
# define TS2K_PM_PRIV ( (1<<0) | (1<<1) | (1<<4) | (1<<5) )
#else
# define TS2K_PM_PUB ( (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) )
# define TS2K_PM_PRIV (0)
#endif
} ts2k_pm_t;
// Implemented/coded functions
int ts2k_menu_init(RIG *rig, ts2k_menu_t *menu[]);
int ts2k_menu_close(RIG *rig, ts2k_menu_t *menu[]);
int ts2k_get_menu_no(RIG *rig, ts2k_menu_t *menu, int *main, int *sub);
int ts2k_set_menu_no(RIG *rig, ts2k_menu_t *menu, int main, int sub);
// Unimplemented/uncoded functions
char * ts2k_list_menu_no(RIG *rig, ts2k_menu_t *menu, int main, int sub);
int ts2k_get_menu(RIG *rig, ts2k_menu_t *menu);
int ts2k_set_menu(RIG *rig, ts2k_menu_t *menu);
int ts2k_menu_parse(RIG *rig, ts2k_menu_t *menu);
/*
* Related functions specific to this rig
*/
// Programmable memories[0, ..., 5] + menu[A, ..., B]
int ts2k_get_menu_mode(RIG *rig, ts2k_menu_t *menu, ts2k_pm_t *pm);
int ts2k_set_menu_mode(RIG *rig, ts2k_menu_t *menu, ts2k_pm_t *pm);
int ts2k_pm_init(RIG *rig, ts2k_pm_t *pm);
int ts2k_pm_close(RIG *rig, ts2k_pm_t *pm);
// End ts2k_menu.c