2003-12-04 23:15:02 +00:00
|
|
|
/*
|
|
|
|
* memload.c - Copyright (C) 2003 Thierry Leconte
|
|
|
|
*
|
|
|
|
*
|
2011-08-22 01:51:06 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2003-12-04 23:15:02 +00:00
|
|
|
*
|
2011-08-22 01:51:06 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-12-04 23:15:02 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <hamlib/rig.h>
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_XML2
|
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
|
|
|
|
static int set_chan(RIG *rig, channel_t *chan ,xmlNodePtr node);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
int xml_load (RIG *my_rig, const char *infilename)
|
2011-08-22 01:51:06 +00:00
|
|
|
{
|
2003-12-04 23:15:02 +00:00
|
|
|
#ifdef HAVE_XML2
|
|
|
|
xmlDocPtr Doc;
|
|
|
|
xmlNodePtr node;
|
|
|
|
|
|
|
|
/* load xlm Doc */
|
|
|
|
Doc=xmlParseFile(infilename);
|
|
|
|
if(Doc==NULL) {
|
|
|
|
fprintf(stderr,"xmlParse failed\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
node=xmlDocGetRootElement(Doc);
|
|
|
|
if (node == NULL) {
|
|
|
|
fprintf(stderr,"get root failed\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
2006-10-07 19:56:57 +00:00
|
|
|
if(strcmp((char *) node->name, "hamlib")) {
|
2003-12-04 23:15:02 +00:00
|
|
|
fprintf(stderr,"no hamlib tag found\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
for(node=node->xmlChildrenNode;node!=NULL;node=node->next) {
|
|
|
|
if(xmlNodeIsText(node)) continue;
|
2006-10-07 19:56:57 +00:00
|
|
|
if(strcmp((char *) node->name, "channels")==0)
|
2003-12-04 23:15:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(node==NULL) {
|
|
|
|
fprintf(stderr,"no channels\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
for(node=node->xmlChildrenNode;node!=NULL;node=node->next) {
|
|
|
|
channel_t chan;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if(xmlNodeIsText(node)) continue;
|
|
|
|
|
|
|
|
set_chan(my_rig,&chan,node);
|
|
|
|
|
|
|
|
status=rig_set_channel(my_rig, &chan);
|
|
|
|
|
|
|
|
if (status != RIG_OK ) {
|
|
|
|
printf("rig_get_channel: error = %s \n", rigerror(status));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlFreeDoc(Doc);
|
|
|
|
xmlCleanupParser();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
return -RIG_ENAVAIL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int xml_parm_load (RIG *my_rig, const char *infilename)
|
2011-08-22 01:51:06 +00:00
|
|
|
{
|
2003-12-04 23:15:02 +00:00
|
|
|
return -RIG_ENIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_XML2
|
|
|
|
int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node)
|
|
|
|
{
|
|
|
|
xmlChar *prop;
|
|
|
|
int i,n;
|
|
|
|
|
|
|
|
memset(chan,0,sizeof(channel_t));
|
|
|
|
chan->vfo = RIG_VFO_MEM;
|
|
|
|
|
|
|
|
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node,(unsigned char *) "num");
|
2003-12-04 23:15:02 +00:00
|
|
|
if(prop==NULL) {
|
|
|
|
fprintf(stderr,"no num\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2006-10-07 19:56:57 +00:00
|
|
|
n=chan->channel_num = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
|
|
|
|
/* find chanel caps */
|
|
|
|
for(i=0;i<CHANLSTSIZ ;i++)
|
2011-08-22 01:51:06 +00:00
|
|
|
if (rig->state.chan_list[i].start<=n && rig->state.chan_list[i].end>=n)
|
2003-12-04 23:15:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
fprintf(stderr,"node %d %d\n",n,i);
|
|
|
|
|
|
|
|
if (rig->state.chan_list[i].mem_caps.bank_num) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *) "bank_num");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->bank_num = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rig->state.chan_list[i].mem_caps.channel_desc) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *) "channel_desc");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
strncpy(chan->channel_desc, (char *) prop, 7);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rig->state.chan_list[i].mem_caps.ant) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *) "ant");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->ant = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.freq) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *) "freq");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
sscanf((char *) prop,"%"SCNfreq,&chan->freq);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.mode) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *) "mode");
|
2003-12-04 23:15:02 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->mode = rig_parse_mode((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.width) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *) "width");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->width = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.tx_freq) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *) "tx_freq");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
sscanf((char *) prop,"%"SCNfreq,&chan->tx_freq);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.tx_mode) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"tx_mode");
|
2003-12-04 23:15:02 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->tx_mode = rig_parse_mode((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.tx_width) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"tx_width");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->tx_width = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.split) {
|
2004-01-21 19:48:12 +00:00
|
|
|
chan->split=RIG_SPLIT_OFF;
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"split");
|
2004-01-21 19:48:12 +00:00
|
|
|
if(prop!=NULL) {
|
2006-10-07 19:56:57 +00:00
|
|
|
if(strcmp((char *) prop,"on")==0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
chan->split=RIG_SPLIT_ON;
|
|
|
|
if (rig->state.chan_list[i].mem_caps.tx_vfo) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"tx_vfo");
|
2003-12-04 23:15:02 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
sscanf((char *) prop,"%x",&chan->tx_vfo);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2004-01-21 19:48:12 +00:00
|
|
|
}
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.rptr_shift) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"rptr_shift");
|
2003-12-04 23:15:02 +00:00
|
|
|
if(prop)
|
|
|
|
switch(prop[0]) {
|
|
|
|
case '=': chan->rptr_shift=RIG_RPT_SHIFT_NONE;
|
|
|
|
break;
|
|
|
|
case '+': chan->rptr_shift=RIG_RPT_SHIFT_PLUS;
|
|
|
|
break;
|
|
|
|
case '-': chan->rptr_shift=RIG_RPT_SHIFT_MINUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.rptr_offs && chan->rptr_shift!=RIG_RPT_SHIFT_NONE) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"rptr_offs");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->rptr_offs = atoi((char *) prop);
|
2011-08-22 01:51:06 +00:00
|
|
|
}
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.tuning_step) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"tuning_step");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->tuning_step = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.rit) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"rit");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->rit = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.xit) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"xit");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->xit = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.funcs) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"funcs");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
sscanf((char *) prop,"%lx",&chan->funcs);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.ctcss_tone) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"ctcss_tone");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->ctcss_tone = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.ctcss_sql) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"ctcss_sql");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->ctcss_sql = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.dcs_code) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"dcs_code");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->dcs_code = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.dcs_sql) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"dcs_sql");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->dcs_sql = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.scan_group) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"scan_group");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
chan->scan_group = atoi((char *) prop);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
if (rig->state.chan_list[i].mem_caps.flags) {
|
2006-10-07 19:56:57 +00:00
|
|
|
prop=xmlGetProp(node, (unsigned char *)"flags");
|
2011-08-22 01:51:06 +00:00
|
|
|
if(prop!=NULL)
|
2006-10-07 19:56:57 +00:00
|
|
|
sscanf((char *) prop,"%x",&chan->flags);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
|
2011-08-22 01:51:06 +00:00
|
|
|
|
2003-12-04 23:15:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|