2003-12-04 23:15:02 +00:00
|
|
|
/*
|
2005-01-25 00:22:14 +00:00
|
|
|
* memsave.c - Copyright (C) 2003-2005 Thierry Leconte
|
2008-04-27 09:56:06 +00:00
|
|
|
* Copyright (C) 2008 Stephane Fillod
|
2003-12-04 23:15:02 +00:00
|
|
|
*
|
|
|
|
*
|
2008-04-27 09:56:06 +00:00
|
|
|
* $Id: memsave.c,v 1.11 2008-04-27 09:56:06 fillods Exp $
|
2003-12-04 23:15:02 +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.
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2008-04-27 09:56:06 +00:00
|
|
|
#include <ctype.h>
|
2003-12-04 23:15:02 +00:00
|
|
|
|
|
|
|
#include <hamlib/rig.h>
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_XML2
|
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
|
2005-04-20 14:47:04 +00:00
|
|
|
static int dump_xml_chan(RIG *rig, channel_t **chan, int channel_num, const chan_t *chan_list, rig_ptr_t arg);
|
2003-12-04 23:15:02 +00:00
|
|
|
#endif
|
|
|
|
|
2005-04-20 14:47:04 +00:00
|
|
|
int xml_save (RIG *rig, const char *outfilename)
|
2003-12-04 23:15:02 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_XML2
|
2005-04-20 14:47:04 +00:00
|
|
|
int retval;
|
2003-12-04 23:15:02 +00:00
|
|
|
xmlDocPtr Doc;
|
|
|
|
xmlNodePtr root;
|
|
|
|
|
|
|
|
/* create xlm Doc */
|
2006-10-07 19:56:57 +00:00
|
|
|
Doc=xmlNewDoc((unsigned char *) "1.0");
|
|
|
|
root=xmlNewNode(NULL,(unsigned char *) "hamlib");
|
2003-12-04 23:15:02 +00:00
|
|
|
xmlDocSetRootElement(Doc, root);
|
2006-10-07 19:56:57 +00:00
|
|
|
root=xmlNewChild(root,NULL,(unsigned char *) "channels",NULL);
|
2003-12-04 23:15:02 +00:00
|
|
|
|
|
|
|
|
2005-04-20 14:47:04 +00:00
|
|
|
if (rig->caps->clone_combo_get)
|
|
|
|
printf("About to save data, enter cloning mode: %s\n",
|
|
|
|
rig->caps->clone_combo_get);
|
|
|
|
|
|
|
|
retval = rig_get_chan_all_cb (rig, dump_xml_chan, root);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2003-12-04 23:15:02 +00:00
|
|
|
|
|
|
|
/* write xml File */
|
|
|
|
|
|
|
|
xmlSaveFormatFileEnc(outfilename, Doc, "UTF-8", 1);
|
|
|
|
|
|
|
|
xmlFreeDoc(Doc);
|
|
|
|
xmlCleanupParser();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
return -RIG_ENAVAIL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-04-20 14:47:04 +00:00
|
|
|
int xml_parm_save (RIG *rig, const char *outfilename)
|
2003-12-04 23:15:02 +00:00
|
|
|
{
|
|
|
|
return -RIG_ENIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_XML2
|
2005-04-20 14:47:04 +00:00
|
|
|
int dump_xml_chan(RIG *rig, channel_t **chan_pp, int chan_num, const chan_t *chan_list, rig_ptr_t arg)
|
2003-12-04 23:15:02 +00:00
|
|
|
{
|
|
|
|
char attrbuf[20];
|
2005-04-20 14:47:04 +00:00
|
|
|
xmlNodePtr root = arg;
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNodePtr node = NULL;
|
2008-04-27 09:56:06 +00:00
|
|
|
int i;
|
|
|
|
const char *mtype;
|
2003-12-04 23:15:02 +00:00
|
|
|
|
2005-04-20 14:47:04 +00:00
|
|
|
static channel_t chan;
|
|
|
|
const channel_cap_t *mem_caps = &chan_list->mem_caps;
|
2003-12-04 23:15:02 +00:00
|
|
|
|
2004-12-27 12:53:02 +00:00
|
|
|
|
2005-04-20 14:47:04 +00:00
|
|
|
if (*chan_pp == NULL) {
|
|
|
|
/*
|
|
|
|
* Hamlib frontend demand application an allocated
|
|
|
|
* channel_t pointer for next round.
|
|
|
|
*/
|
|
|
|
*chan_pp = &chan;
|
2003-12-04 23:15:02 +00:00
|
|
|
|
2005-04-20 14:47:04 +00:00
|
|
|
return RIG_OK;
|
|
|
|
}
|
2008-04-27 09:56:06 +00:00
|
|
|
|
|
|
|
if (chan_list->type == RIG_MTYPE_NONE)
|
|
|
|
return RIG_OK;
|
|
|
|
|
|
|
|
mtype = rig_strmtype(chan_list->type);
|
|
|
|
for (i=0; i<strlen(mtype); i++)
|
|
|
|
attrbuf[i] = tolower(mtype[i]);
|
|
|
|
attrbuf[i] = '\0';
|
|
|
|
|
|
|
|
node=xmlNewChild(root,NULL,(unsigned char *)attrbuf,NULL);
|
2003-12-04 23:15:02 +00:00
|
|
|
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->bank_num) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",chan.bank_num);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "bank_num", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(attrbuf,"%d",chan.channel_num);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "num", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->channel_desc && chan.channel_desc[0]!='\0') {
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node,
|
|
|
|
(unsigned char *) "channel_desc",
|
|
|
|
(unsigned char *) chan.channel_desc);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->vfo) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",chan.vfo);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "vfo", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->ant && chan.ant != RIG_ANT_NONE) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",chan.ant);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "ant", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->freq && chan.freq != RIG_FREQ_NONE) {
|
2005-01-25 00:22:14 +00:00
|
|
|
sprintf(attrbuf,"%"PRIll,(long long)chan.freq);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "freq", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->mode && chan.mode != RIG_MODE_NONE) {
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "mode", (unsigned char *) rig_strrmode(chan.mode));
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->width && chan.width != 0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",(int)chan.width);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "width", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->tx_freq && chan.tx_freq != RIG_FREQ_NONE) {
|
2005-01-25 00:22:14 +00:00
|
|
|
sprintf(attrbuf,"%"PRIll,(long long)chan.tx_freq);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "tx_freq", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->tx_mode && chan.tx_mode != RIG_MODE_NONE) {
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node,
|
|
|
|
(unsigned char *) "tx_mode",
|
|
|
|
(unsigned char *) rig_strrmode(chan.tx_mode));
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->tx_width && chan.tx_width!=0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",(int)chan.tx_width);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "tx_width", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->split && chan.split!=RIG_SPLIT_OFF) {
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "split", (unsigned char *) "on");
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->tx_vfo) {
|
2004-01-21 19:47:15 +00:00
|
|
|
sprintf(attrbuf,"%x",chan.tx_vfo);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node,
|
|
|
|
(unsigned char *) "tx_vfo",
|
|
|
|
(unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->rptr_shift && chan.rptr_shift!=RIG_RPT_SHIFT_NONE) {
|
2008-04-27 09:56:06 +00:00
|
|
|
xmlNewProp(node,
|
|
|
|
(unsigned char *) "rptr_shift",
|
|
|
|
(unsigned char *) rig_strptrshift(chan.rptr_shift));
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->rptr_offs && (int)chan.rptr_offs!=0) {
|
2004-01-21 19:47:15 +00:00
|
|
|
sprintf(attrbuf,"%d",(int)chan.rptr_offs);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node,
|
|
|
|
(unsigned char *) "rptr_offs",
|
|
|
|
(unsigned char *) attrbuf);
|
2004-01-21 19:47:15 +00:00
|
|
|
}
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->tuning_step && chan.tuning_step !=0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",(int)chan.tuning_step);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "tuning_step", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->rit && chan.rit!=0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",(int)chan.rit);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "rit", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->xit && chan.xit !=0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",(int)chan.xit);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "xit", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->funcs) {
|
2004-01-15 22:43:59 +00:00
|
|
|
sprintf(attrbuf,"%llx",(long long)chan.funcs);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "funcs", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->ctcss_tone && chan.ctcss_tone !=0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",chan.ctcss_tone);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "ctcss_tone", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->ctcss_sql && chan.ctcss_sql !=0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",chan.ctcss_sql);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "ctcss_sql", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->dcs_code && chan.dcs_code !=0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",chan.dcs_code);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "dcs_code", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->dcs_sql && chan.dcs_sql !=0) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",chan.dcs_sql);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "dcs_sql", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->scan_group) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%d",chan.scan_group);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "scan_group", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
2005-04-20 14:47:04 +00:00
|
|
|
if (mem_caps->flags) {
|
2003-12-04 23:15:02 +00:00
|
|
|
sprintf(attrbuf,"%x",chan.flags);
|
2006-10-07 19:56:57 +00:00
|
|
|
xmlNewProp(node, (unsigned char *) "flags", (unsigned char *) attrbuf);
|
2003-12-04 23:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|