Thread: [Gpredict-svn] SF.net SVN: gpredict:[655] branches/continuous_network/src
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
|
From: <aa...@us...> - 2010-09-25 13:58:53
|
Revision: 655
http://gpredict.svn.sourceforge.net/gpredict/?rev=655&view=rev
Author: aa1vs
Date: 2010-09-25 13:58:47 +0000 (Sat, 25 Sep 2010)
Log Message:
-----------
Move socket Out of radio-conf.h
Modified Paths:
--------------
branches/continuous_network/src/gtk-rig-ctrl.c
branches/continuous_network/src/gtk-rig-ctrl.h
branches/continuous_network/src/radio-conf.h
Modified: branches/continuous_network/src/gtk-rig-ctrl.c
===================================================================
--- branches/continuous_network/src/gtk-rig-ctrl.c 2010-09-25 11:46:00 UTC (rev 654)
+++ branches/continuous_network/src/gtk-rig-ctrl.c 2010-09-25 13:58:47 UTC (rev 655)
@@ -109,18 +109,18 @@
static void exec_toggle_tx_cycle (GtkRigCtrl *ctrl);
static void exec_duplex_cycle (GtkRigCtrl *ctrl);
static void exec_dual_rig_cycle (GtkRigCtrl *ctrl);
-static gboolean set_freq_simplex (GtkRigCtrl *ctrl, radio_conf_t *conf, gdouble freq);
-static gboolean get_freq_simplex (GtkRigCtrl *ctrl, radio_conf_t *conf, gdouble *freq);
-static gboolean set_freq_toggle (GtkRigCtrl *ctrl, radio_conf_t *conf, gdouble freq);
-static gboolean set_toggle (GtkRigCtrl *ctrl, radio_conf_t *conf);
-static gboolean unset_toggle (GtkRigCtrl *ctrl, radio_conf_t *conf);
-static gboolean get_freq_toggle (GtkRigCtrl *ctrl, radio_conf_t *conf, gdouble *freq);
-static gboolean get_ptt (GtkRigCtrl *ctrl, radio_conf_t *conf);
-static gboolean set_ptt (GtkRigCtrl *ctrl, radio_conf_t *conf, gboolean ptt);
+static gboolean set_freq_simplex (GtkRigCtrl *ctrl, gint sock, gdouble freq);
+static gboolean get_freq_simplex (GtkRigCtrl *ctrl, gint sock, gdouble *freq);
+static gboolean set_freq_toggle (GtkRigCtrl *ctrl, gint sock, gdouble freq);
+static gboolean set_toggle (GtkRigCtrl *ctrl, gint sock);
+static gboolean unset_toggle (GtkRigCtrl *ctrl, gint sock);
+static gboolean get_freq_toggle (GtkRigCtrl *ctrl, gint sock, gdouble *freq);
+static gboolean get_ptt (GtkRigCtrl *ctrl, gint sock);
+static gboolean set_ptt (GtkRigCtrl *ctrl, gint sock, gboolean ptt);
static gboolean set_vfo (GtkRigCtrl *ctrl, vfo_t vfo);
static void update_count_down (GtkRigCtrl *ctrl, gdouble t);
-static gboolean open_rigctld_socket(radio_conf_t *conf);
-static gboolean close_rigctld_socket(radio_conf_t *conf);
+static gboolean open_rigctld_socket(radio_conf_t *conf, gint *sock);
+static gboolean close_rigctld_socket(gint sock);
/* misc utility functions */
static void load_trsp_list (GtkRigCtrl *ctrl);
@@ -129,7 +129,7 @@
static void track_downlink (GtkRigCtrl *ctrl);
static void track_uplink (GtkRigCtrl *ctrl);
static gboolean is_rig_tx_capable (const gchar *confname);
-static gboolean send_rigctld_command(GtkRigCtrl *ctrl, radio_conf_t *conf, gchar *buff, gint size, gchar *buffout, gint sizeout);
+static gboolean send_rigctld_command(GtkRigCtrl *ctrl, gint sock, gchar *buff, gint size, gchar *buffout, gint sizeout);
static GtkVBoxClass *parent_class = NULL;
@@ -1173,15 +1173,15 @@
switch (ctrl->conf->type) {
case RIG_TYPE_TOGGLE_AUTO:
case RIG_TYPE_TOGGLE_MAN:
- unset_toggle (ctrl,ctrl->conf);
+ unset_toggle (ctrl,ctrl->sock);
break;
default:
break;
}
if (ctrl->conf2 != NULL) {
- close_rigctld_socket(ctrl->conf2);
+ close_rigctld_socket(ctrl->sock2);
}
- close_rigctld_socket(ctrl->conf);
+ close_rigctld_socket(ctrl->sock);
}
else {
@@ -1198,11 +1198,11 @@
ctrl->engaged = TRUE;
ctrl->wrops = 0;
- open_rigctld_socket(ctrl->conf);
+ open_rigctld_socket(ctrl->conf,&(ctrl->sock));
/* set initial frequency */
if (ctrl->conf2 != NULL) {
- open_rigctld_socket(ctrl->conf2);
+ open_rigctld_socket(ctrl->conf2,&(ctrl->sock2));
/* set initial dual mode */
exec_dual_rig_cycle (ctrl);
}
@@ -1227,7 +1227,7 @@
case RIG_TYPE_TOGGLE_AUTO:
case RIG_TYPE_TOGGLE_MAN:
- set_toggle (ctrl,ctrl->conf);
+ set_toggle (ctrl,ctrl->sock);
ctrl->last_toggle_tx = -1;
exec_toggle_cycle (ctrl);
break;
@@ -1363,7 +1363,7 @@
/* get PTT status */
if (ctrl->engaged && ctrl->conf->ptt)
- ptt = get_ptt (ctrl, ctrl->conf);
+ ptt = get_ptt (ctrl, ctrl->sock);
/* Dial feedback:
@@ -1377,7 +1377,7 @@
if ((ctrl->engaged) && (ctrl->lastrxf > 0.0)) {
if (ptt == FALSE) {
- if (!get_freq_simplex (ctrl, ctrl->conf, &readfreq)) {
+ if (!get_freq_simplex (ctrl, ctrl->sock, &readfreq)) {
/* error => use a passive value */
readfreq = ctrl->lastrxf;
ctrl->errcnt++;
@@ -1442,7 +1442,7 @@
/* if device is engaged, send freq command to radio */
if ((ctrl->engaged) && (ptt == FALSE) && (fabs(ctrl->lastrxf - tmpfreq) >= 1.0)) {
- if (set_freq_simplex (ctrl, ctrl->conf, tmpfreq)) {
+ if (set_freq_simplex (ctrl, ctrl->sock, tmpfreq)) {
/* reset error counter */
ctrl->errcnt = 0;
@@ -1453,7 +1453,7 @@
the tuning step is larger than what we work with (e.g. FT-817 has a
smallest tuning step of 10 Hz). Therefore we read back the actual
frequency from the rig. */
- get_freq_simplex (ctrl, ctrl->conf, &tmpfreq);
+ get_freq_simplex (ctrl, ctrl->sock, &tmpfreq);
ctrl->lastrxf = tmpfreq;
}
else {
@@ -1478,7 +1478,7 @@
/* get PTT status */
if (ctrl->engaged && ctrl->conf->ptt) {
- ptt = get_ptt (ctrl, ctrl->conf);
+ ptt = get_ptt (ctrl, ctrl->sock);
}
/* Dial feedback:
@@ -1492,7 +1492,7 @@
if ((ctrl->engaged) && (ctrl->lasttxf > 0.0)) {
if (ptt == TRUE) {
- if (!get_freq_simplex (ctrl, ctrl->conf, &readfreq)) {
+ if (!get_freq_simplex (ctrl, ctrl->sock, &readfreq)) {
/* error => use a passive value */
readfreq = ctrl->lasttxf;
ctrl->errcnt++;
@@ -1555,7 +1555,7 @@
/* if device is engaged, send freq command to radio */
if ((ctrl->engaged) && (ptt == TRUE) && (fabs(ctrl->lasttxf - tmpfreq) >= 1.0)) {
- if (set_freq_simplex (ctrl, ctrl->conf, tmpfreq)) {
+ if (set_freq_simplex (ctrl, ctrl->sock, tmpfreq)) {
/* reset error counter */
ctrl->errcnt = 0;
@@ -1566,7 +1566,7 @@
the tuning step is larger than what we work with (e.g. FT-817 has a
smallest tuning step of 10 Hz). Therefore we read back the actual
frequency from the rig. */
- get_freq_simplex (ctrl, ctrl->conf, &tmpfreq);
+ get_freq_simplex (ctrl, ctrl->sock, &tmpfreq);
ctrl->lasttxf = tmpfreq;
}
else {
@@ -1643,7 +1643,7 @@
if (ctrl->engaged && ctrl->conf->ptt) {
- ptt = get_ptt (ctrl, ctrl->conf);
+ ptt = get_ptt (ctrl, ctrl->sock);
}
/* if we are in TX mode do nothing */
@@ -1656,7 +1656,7 @@
/* if device is engaged, send freq command to radio */
if ((ctrl->engaged) && (fabs(ctrl->lasttxf - tmpfreq) >= 10.0)) {
- if (set_freq_toggle (ctrl, ctrl->conf, tmpfreq)) {
+ if (set_freq_toggle (ctrl, ctrl->sock, tmpfreq)) {
/* reset error counter */
ctrl->errcnt = 0;
}
@@ -1710,7 +1710,7 @@
if (ctrl->engaged && (ctrl->lastrxf > 0.0)) {
/* get frequency from receiver */
- if (!get_freq_simplex (ctrl, ctrl->conf, &readfreq)) {
+ if (!get_freq_simplex (ctrl, ctrl->sock, &readfreq)) {
/* error => use a passive value */
readfreq = ctrl->lastrxf;
ctrl->errcnt++;
@@ -1755,7 +1755,7 @@
/* if device is engaged, send freq command to radio */
if ((ctrl->engaged) && (fabs(ctrl->lasttxf - tmpfreq) >= 1.0)) {
- if (set_freq_simplex (ctrl, ctrl->conf2, tmpfreq)) {
+ if (set_freq_simplex (ctrl, ctrl->sock2, tmpfreq)) {
/* reset error counter */
ctrl->errcnt = 0;
@@ -1763,7 +1763,7 @@
g_usleep (WR_DEL);
/* The actual frequency migh be different from what we have set */
- get_freq_simplex (ctrl, ctrl->conf2, &tmpfreq);
+ get_freq_simplex (ctrl, ctrl->sock2, &tmpfreq);
ctrl->lasttxf = tmpfreq;
}
else {
@@ -1792,7 +1792,7 @@
/* if device is engaged, send freq command to radio */
if ((ctrl->engaged) && (fabs(ctrl->lastrxf - tmpfreq) >= 1.0)) {
- if (set_freq_simplex (ctrl, ctrl->conf, tmpfreq)) {
+ if (set_freq_simplex (ctrl, ctrl->sock, tmpfreq)) {
/* reset error counter */
ctrl->errcnt = 0;
@@ -1800,7 +1800,7 @@
g_usleep (WR_DEL);
/* The actual frequency migh be different from what we have set */
- get_freq_simplex (ctrl, ctrl->conf, &tmpfreq);
+ get_freq_simplex (ctrl, ctrl->sock, &tmpfreq);
ctrl->lastrxf = tmpfreq;
}
else {
@@ -1813,7 +1813,7 @@
/* check if uplink dial has changed */
if ((ctrl->engaged) && (ctrl->lasttxf > 0.0)) {
- if (!get_freq_simplex (ctrl, ctrl->conf2, &readfreq)) {
+ if (!get_freq_simplex (ctrl, ctrl->sock2, &readfreq)) {
/* error => use a passive value */
readfreq = ctrl->lasttxf;
ctrl->errcnt++;
@@ -1857,7 +1857,7 @@
/* if device is engaged, send freq command to radio */
if ((ctrl->engaged) && (fabs(ctrl->lastrxf - tmpfreq) >= 1.0)) {
- if (set_freq_simplex (ctrl, ctrl->conf, tmpfreq)) {
+ if (set_freq_simplex (ctrl, ctrl->sock, tmpfreq)) {
/* reset error counter */
ctrl->errcnt = 0;
@@ -1865,7 +1865,7 @@
g_usleep (WR_DEL);
/* The actual frequency migh be different from what we have set */
- get_freq_simplex (ctrl, ctrl->conf, &tmpfreq);
+ get_freq_simplex (ctrl, ctrl->sock, &tmpfreq);
ctrl->lastrxf = tmpfreq;
}
else {
@@ -1889,15 +1889,15 @@
/* if device is engaged, send freq command to radio */
if ((ctrl->engaged) && (fabs(ctrl->lasttxf - tmpfreq) >= 1.0)) {
- if (set_freq_simplex (ctrl, ctrl->conf2, tmpfreq)) {
+ if (set_freq_simplex (ctrl, ctrl->sock2, tmpfreq)) {
/* reset error counter */
ctrl->errcnt = 0;
/* give radio a chance to set frequency */
g_usleep (WR_DEL);
- /* The actual frequency migh be different from what we have set. */
- get_freq_simplex (ctrl, ctrl->conf2, &tmpfreq);
+ /* The actual frequency might be different from what we have set. */
+ get_freq_simplex (ctrl, ctrl->sock2, &tmpfreq);
ctrl->lasttxf = tmpfreq;
}
else {
@@ -1917,7 +1917,7 @@
* \return TRUE if PTT is ON, FALSE if PTT is OFF or an error occurred.
*
*/
-static gboolean get_ptt (GtkRigCtrl *ctrl, radio_conf_t *conf)
+static gboolean get_ptt (GtkRigCtrl *ctrl, gint sock)
{
gchar *buff,**vbuff;
gchar buffback[128];
@@ -1926,7 +1926,7 @@
guint64 pttstat = 0;
- if (conf->ptt == PTT_TYPE_CAT) {
+ if (ctrl->conf->ptt == PTT_TYPE_CAT) {
/* send command get_ptt (t) */
buff = g_strdup_printf ("t\x0a");
size = 2;
@@ -1937,7 +1937,7 @@
size = 2;
}
- retcode=send_rigctld_command(ctrl,conf,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
if (retcode) {
vbuff = g_strsplit (buffback, "\n", 3);
pttstat = g_ascii_strtoull (vbuff[0], NULL, 0); //FIXME base = 0 ok?
@@ -1955,7 +1955,7 @@
* \param ptt The new PTT value (TRUE=ON, FALSE=OFF)
* \return TRUE if the operation was successful, FALSE if an error has occurred
*/
-static gboolean set_ptt (GtkRigCtrl *ctrl, radio_conf_t *conf, gboolean ptt)
+static gboolean set_ptt (GtkRigCtrl *ctrl, gint sock, gboolean ptt)
{
gchar *buff;
gchar buffback[128];
@@ -1971,7 +1971,7 @@
}
size = 4;
- retcode=send_rigctld_command(ctrl,conf,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
g_free (buff);
@@ -1991,7 +1991,7 @@
* gotten the current frequency from the ctrl; however, the param
* might become useful in the future.
*/
-static gboolean set_freq_simplex (GtkRigCtrl *ctrl, radio_conf_t *conf, gdouble freq)
+static gboolean set_freq_simplex (GtkRigCtrl *ctrl, gint sock, gdouble freq)
{
gchar *buff;
gchar buffback[128];
@@ -2002,7 +2002,7 @@
size = 13;
- retcode=send_rigctld_command(ctrl,conf,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
g_free(buff);
return retcode;
@@ -2020,7 +2020,7 @@
* might become useful in the future.
*/
-static gboolean set_freq_toggle (GtkRigCtrl *ctrl, radio_conf_t *conf, gdouble freq)
+static gboolean set_freq_toggle (GtkRigCtrl *ctrl, gint sock, gdouble freq)
{
gchar *buff;
gchar buffback[128];
@@ -2029,7 +2029,7 @@
/* send command */
buff = g_strdup_printf ("I %10.0f\x0a", freq);
size = 12;
- retcode=send_rigctld_command(ctrl,conf,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
g_free(buff);
return retcode;
@@ -2042,7 +2042,7 @@
* occurred.
*
*/
-static gboolean set_toggle (GtkRigCtrl *ctrl, radio_conf_t *conf)
+static gboolean set_toggle (GtkRigCtrl *ctrl, gint sock)
{
gchar *buff;
gchar buffback[128];
@@ -2053,7 +2053,7 @@
buff = g_strdup_printf ("S 1 %d\x0a",ctrl->conf->vfoDown);
size = 13;
- retcode=send_rigctld_command(ctrl,conf,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
g_free(buff);
return retcode;
@@ -2066,7 +2066,7 @@
*
*/
-static gboolean unset_toggle (GtkRigCtrl *ctrl, radio_conf_t *conf)
+static gboolean unset_toggle (GtkRigCtrl *ctrl, gint sock)
{
gchar *buff;
gchar buffback[128];
@@ -2076,7 +2076,7 @@
buff = g_strdup_printf ("S 0 %d\x0a",ctrl->conf->vfoDown);
size = 13;
- retcode=send_rigctld_command(ctrl,conf,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
g_free(buff);
return retcode;
@@ -2089,7 +2089,7 @@
* \return TRUE if the operation was successful, FALSE if a connection error
* occurred.
*/
-static gboolean get_freq_simplex (GtkRigCtrl *ctrl, radio_conf_t *conf, gdouble *freq)
+static gboolean get_freq_simplex (GtkRigCtrl *ctrl, gint sock, gdouble *freq)
{
gchar *buff,**vbuff;
gchar buffback[128];
@@ -2106,7 +2106,7 @@
/* send command */
buff = g_strdup_printf ("f\x0a");
size = 2;
- retcode=send_rigctld_command(ctrl,conf,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
if (retcode) {
vbuff = g_strsplit (buffback, "\n", 3);
*freq = g_ascii_strtod (vbuff[0], NULL);
@@ -2124,7 +2124,7 @@
* occurred.
*/
-static gboolean get_freq_toggle (GtkRigCtrl *ctrl, radio_conf_t *conf, gdouble *freq)
+static gboolean get_freq_toggle (GtkRigCtrl *ctrl, gint sock, gdouble *freq)
{
gchar *buff,**vbuff;
gchar buffback[128];
@@ -2142,7 +2142,7 @@
/* send command */
buff = g_strdup_printf ("i\x0a");
size = 2;
- retcode=send_rigctld_command(ctrl,conf,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
if (retcode) {
vbuff = g_strsplit (buffback, "\n", 3);
*freq = g_ascii_strtod (vbuff[0], NULL);
@@ -2198,7 +2198,7 @@
size = 7;
break;
}
- retcode=send_rigctld_command(ctrl,ctrl->conf,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,ctrl->sock,buff,size,buffback,128);
g_free(buff);
return retcode;
@@ -2488,60 +2488,19 @@
-gboolean send_rigctld_command(GtkRigCtrl *ctrl, radio_conf_t *conf, gchar *buff, gint size, gchar *buffout, gint sizeout)
+gboolean send_rigctld_command(GtkRigCtrl *ctrl, gint sock, gchar *buff, gint size, gchar *buffout, gint sizeout)
{
gint written;
-#if 0
- gint status;
- struct hostent *h;
- struct sockaddr_in ServAddr;
- gint sock; /*!< Network socket */
-
-
- /* create socket */
- sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (sock < 0) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s: Failed to create socket"),
- __FUNCTION__);
- return FALSE;
- }
- else {
- sat_log_log (SAT_LOG_LEVEL_DEBUG,
- _("%s: Network socket created successfully"),
- __FUNCTION__);
- }
-
- memset(&ServAddr, 0, sizeof(ServAddr)); /* Zero out structure */
- ServAddr.sin_family = AF_INET; /* Internet address family */
- h = gethostbyname(conf->host);
- memcpy((char *) &ServAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
- ServAddr.sin_port = htons(conf->port); /* Server port */
-
- /* establish connection */
- status = connect(sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr));
- if (status < 0) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s: Failed to connect to %s:%d"),
- __FUNCTION__, conf->host, conf->port);
- return FALSE;
- }
- else {
- sat_log_log (SAT_LOG_LEVEL_DEBUG,
- _("%s: Connection opened to %s:%d"),
- __FUNCTION__, conf->host, conf->port);
- }
-#endif
/* send command */
- written = send(conf->sock, buff, size, 0);
+ written = send(sock, buff, size, 0);
if (written != size) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s: SIZE ERROR %d / %d"),
__FUNCTION__, written, size);
}
/* try to read answer */
- size = read (conf->sock, buffout, 127);
+ size = read (sock, buffout, 127);
if (size == 0) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s:%s: Got 0 bytes from rigctld"),
@@ -2554,17 +2513,6 @@
}
-#if 0
- /*shutdown the rigctld connect*/
- written = send(sock, "q\x0a", 2, 0);
-#ifndef WIN32
- shutdown (sock, SHUT_RDWR);
-#else
-
- shutdown (sock, SD_BOTH);
-#endif
- close (sock);
-#endif
ctrl->wrops++;
return TRUE;
@@ -2661,7 +2609,7 @@
}
else {
- ptt = get_ptt (ctrl, ctrl->conf);
+ ptt = get_ptt (ctrl, ctrl->sock);
if (ptt == FALSE) {
/* PTT is OFF => set TX freq then set PTT to ON */
@@ -2670,7 +2618,7 @@
__FUNCTION__);
exec_toggle_tx_cycle (ctrl);
- set_ptt(ctrl, ctrl->conf, TRUE);
+ set_ptt(ctrl, ctrl->sock, TRUE);
}
else {
/* PTT is ON => set to OFF */
@@ -2678,7 +2626,7 @@
_("%s: PTT is ON = Set PTT=OFF"),
__FUNCTION__);
- set_ptt(ctrl, ctrl->conf, FALSE);
+ set_ptt(ctrl, ctrl->sock, FALSE);
}
}
@@ -2693,13 +2641,13 @@
}
-static gboolean open_rigctld_socket (radio_conf_t *conf) {
+static gboolean open_rigctld_socket (radio_conf_t *conf, gint *sock) {
struct sockaddr_in ServAddr;
struct hostent *h;
gint status;
- conf->sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
- if (conf->sock < 0) {
+ *sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
+ if (sock < 0) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s: Failed to create socket"),
__FUNCTION__);
@@ -2718,7 +2666,7 @@
ServAddr.sin_port = htons(conf->port); /* Server port */
/* establish connection */
- status = connect(conf->sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr));
+ status = connect(*sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr));
if (status < 0) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s: Failed to connect to %s:%d"),
@@ -2734,18 +2682,18 @@
return TRUE;
}
-static gboolean close_rigctld_socket (radio_conf_t *conf) {
+static gboolean close_rigctld_socket (gint sock) {
gint written;
/*shutdown the rigctld connect*/
- written = send(conf->sock, "q\x0a", 2, 0);
+ written = send(sock, "q\x0a", 2, 0);
#ifndef WIN32
- shutdown (conf->sock, SHUT_RDWR);
+ shutdown (sock, SHUT_RDWR);
#else
- shutdown (conf->sock, SD_BOTH);
+ shutdown (sock, SD_BOTH);
#endif
- close (conf->sock);
+ close (sock);
return TRUE;
}
Modified: branches/continuous_network/src/gtk-rig-ctrl.h
===================================================================
--- branches/continuous_network/src/gtk-rig-ctrl.h 2010-09-25 11:46:00 UTC (rev 654)
+++ branches/continuous_network/src/gtk-rig-ctrl.h 2010-09-25 13:58:47 UTC (rev 655)
@@ -108,7 +108,9 @@
glong last_toggle_tx; /*!< Last time when exec_toggle_tx_cycle() was executed (seconds)
-1 indicates that an update should be performed ASAP */
-
+
+ gint sock, sock2; /*!< Sockets for controlling the radio(s). */
+
/* debug related */
guint wrops;
guint rdops;
Modified: branches/continuous_network/src/radio-conf.h
===================================================================
--- branches/continuous_network/src/radio-conf.h 2010-09-25 11:46:00 UTC (rev 654)
+++ branches/continuous_network/src/radio-conf.h 2010-09-25 13:58:47 UTC (rev 655)
@@ -69,7 +69,6 @@
ptt_type_t ptt; /*!< PTT type (needed for RX, TX, and TRX) */
vfo_t vfoDown; /*!< Downlink VFO for full-duplex radios */
vfo_t vfoUp; /*!< Uplink VFO for full-duplex radios */
- gint sock; /*!< Socket for communications with rigctld */
} radio_conf_t;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aa...@us...> - 2010-09-25 16:45:36
|
Revision: 656
http://gpredict.svn.sourceforge.net/gpredict/?rev=656&view=rev
Author: aa1vs
Date: 2010-09-25 16:45:30 +0000 (Sat, 25 Sep 2010)
Log Message:
-----------
Added persistent connection for rotator and fixed bugs in ric control
Modified Paths:
--------------
branches/continuous_network/src/gtk-rig-ctrl.c
branches/continuous_network/src/gtk-rot-ctrl.c
branches/continuous_network/src/gtk-rot-ctrl.h
Modified: branches/continuous_network/src/gtk-rig-ctrl.c
===================================================================
--- branches/continuous_network/src/gtk-rig-ctrl.c 2010-09-25 13:58:47 UTC (rev 655)
+++ branches/continuous_network/src/gtk-rig-ctrl.c 2010-09-25 16:45:30 UTC (rev 656)
@@ -2501,6 +2501,7 @@
}
/* try to read answer */
size = read (sock, buffout, 127);
+ buffout[size]='\0';
if (size == 0) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s:%s: Got 0 bytes from rigctld"),
@@ -2647,7 +2648,7 @@
gint status;
*sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
- if (sock < 0) {
+ if (*sock < 0) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s: Failed to create socket"),
__FUNCTION__);
Modified: branches/continuous_network/src/gtk-rot-ctrl.c
===================================================================
--- branches/continuous_network/src/gtk-rot-ctrl.c 2010-09-25 13:58:47 UTC (rev 655)
+++ branches/continuous_network/src/gtk-rot-ctrl.c 2010-09-25 16:45:30 UTC (rev 656)
@@ -89,6 +89,10 @@
static gboolean get_pos (GtkRotCtrl *ctrl, gdouble *az, gdouble *el);
static gboolean set_pos (GtkRotCtrl *ctrl, gdouble az, gdouble el);
+static gboolean send_rotctld_command(GtkRotCtrl *ctrl, gchar *buff, gint size, gchar *buffout, gint sizeout);
+static gboolean open_rotctld_socket (GtkRotCtrl *ctrl, gint *sock);
+static gboolean close_rotctld_socket (gint sock);
+
static gboolean have_conf (void);
static GtkVBoxClass *parent_class = NULL;
@@ -771,6 +775,7 @@
if (!gtk_toggle_button_get_active (button)) {
gtk_widget_set_sensitive (ctrl->DevSel, TRUE);
ctrl->engaged = FALSE;
+ close_rotctld_socket(ctrl->sock);
gtk_label_set_text (GTK_LABEL (ctrl->AzRead), "---");
gtk_label_set_text (GTK_LABEL (ctrl->ElRead), "---");
}
@@ -784,7 +789,7 @@
}
gtk_widget_set_sensitive (ctrl->DevSel, FALSE);
ctrl->engaged = TRUE;
-
+ open_rotctld_socket(ctrl,&(ctrl->sock));
ctrl->wrops = 0;
ctrl->rdops = 0;
}
@@ -943,13 +948,10 @@
static gboolean get_pos (GtkRotCtrl *ctrl, gdouble *az, gdouble *el)
{
gchar *buff,**vbuff;
- gint written,size;
- gint status;
- struct hostent *h;
- struct sockaddr_in ServAddr;
- gint sock; /*!< Network socket */
-
-
+ gchar buffback[128];
+ gint size;
+ gboolean retcode;
+
if ((az == NULL) || (el == NULL)) {
sat_log_log (SAT_LOG_LEVEL_BUG,
_("%s:%d: NULL storage."),
@@ -957,108 +959,29 @@
return FALSE;
}
- /* create socket */
- sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (sock < 0) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%d: Failed to create socket"),
- __FILE__, __LINE__);
- return FALSE;
- }
- else {
- sat_log_log (SAT_LOG_LEVEL_DEBUG,
- _("%s:%d Network socket created successfully"),
- __FILE__, __LINE__);
- }
-
- memset(&ServAddr, 0, sizeof(ServAddr)); /* Zero out structure */
- ServAddr.sin_family = AF_INET; /* Internet address family */
- h = gethostbyname(ctrl->conf->host);
- memcpy((char *) &ServAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
- ServAddr.sin_port = htons(ctrl->conf->port); /* Server port */
-
- /* establish connection */
- status = connect(sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr));
- if (status < 0) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%d: Failed to connect to %s:%d"),
- __FILE__, __LINE__, ctrl->conf->host, ctrl->conf->port);
- return FALSE;
- }
- else {
- sat_log_log (SAT_LOG_LEVEL_DEBUG,
- _("%s:%d: Connection opened to %s:%d"),
- __FILE__, __LINE__, ctrl->conf->host, ctrl->conf->port);
- }
-
/* send command */
- buff = g_strdup_printf ("p\x0aq\x0a");
+ buff = g_strdup_printf ("p\x0a");
+ size = 2;
+ retcode=send_rotctld_command(ctrl,buff,size,buffback,128);
- size = 4;
- written = send(sock, buff, size, 0);
- if (written != size) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%d: SIZE ERROR %d / %d"),
- __FILE__, __LINE__, written, size);
- }
- g_free (buff);
-
-
+ printf(" buffback = %s\n", buffback);
/* try to read answer */
- buff = g_try_malloc (128);
- if (buff == NULL) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%s: Failed to allocate 128 bytes (yes, this means trouble)"),
- __FILE__, __FUNCTION__);
-
-#ifndef WIN32
- shutdown (sock, SHUT_RDWR);
-#else
- shutdown (sock, SD_BOTH);
-#endif
-
- close (sock);
- return FALSE;
- }
-
- size = read (sock, buff, 127);
- if (size == 0) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%s: Got 0 bytes from rotctld"),
- __FILE__, __FUNCTION__);
- }
- else {
- sat_log_log (SAT_LOG_LEVEL_DEBUG,
- _("%s:%s: Read %d bytes from rotctld"),
- __FILE__, __FUNCTION__, size);
-
- buff[size] = 0;
- vbuff = g_strsplit (buff, "\n", 3);
+ if (retcode) {
+ vbuff = g_strsplit (buffback, "\n", 3);
*az = g_strtod (vbuff[0], NULL);
*el = g_strtod (vbuff[1], NULL);
g_strfreev (vbuff);
- }
+ }
g_free (buff);
-#ifndef WIN32
- shutdown (sock, SHUT_RDWR);
-#else
- shutdown (sock, SD_BOTH);
-#endif
-
- close (sock);
-
- ctrl->wrops++;
- ctrl->rdops++;
-
- return TRUE;
+ return retcode;
}
/** \brief Send new position to rotator device
- * \param ctrl Poitner to the GtkRotCtrl widget
+ * \param ctrl Pointer to the GtkRotCtrl widget
* \param az The new Azimuth
* \param el The new Elevation
* \return TRUE if the new position has been sent successfully
@@ -1070,76 +993,22 @@
static gboolean set_pos (GtkRotCtrl *ctrl, gdouble az, gdouble el)
{
gchar *buff;
+ gchar buffback[128];
gchar azstr[8],elstr[8];
- gint written,size;
- gint status;
- struct hostent *h;
- struct sockaddr_in ServAddr;
- gint sock; /*!< Network socket */
-
+ gint size;
+ gboolean retcode;
- /* create socket */
- sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (sock < 0) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%d: Failed to create socket"),
- __FILE__, __LINE__);
- return FALSE;
- }
- else {
- sat_log_log (SAT_LOG_LEVEL_DEBUG,
- _("%s:%d Network socket created successfully"),
- __FILE__, __LINE__);
- }
-
- memset(&ServAddr, 0, sizeof(ServAddr)); /* Zero out structure */
- ServAddr.sin_family = AF_INET; /* Internet address family */
- h = gethostbyname(ctrl->conf->host);
- memcpy((char *) &ServAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
- ServAddr.sin_port = htons(ctrl->conf->port); /* Server port */
-
- /* establish connection */
- status = connect(sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr));
- if (status < 0) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%d: Failed to connect to %s:%d"),
- __FILE__, __LINE__, ctrl->conf->host, ctrl->conf->port);
- return FALSE;
- }
- else {
- sat_log_log (SAT_LOG_LEVEL_DEBUG,
- _("%s:%d: Connection opened to %s:%d"),
- __FILE__, __LINE__, ctrl->conf->host, ctrl->conf->port);
- }
-
/* send command */
g_ascii_formatd (azstr, 8, "%7.2f", az);
g_ascii_formatd (elstr, 8, "%7.2f", el);
- buff = g_strdup_printf ("P %s %s\x0aq\x0a", azstr, elstr);
+ buff = g_strdup_printf ("P %s %s\x0a", azstr, elstr);
- size = 20;
- written = send(sock, buff, size, 0);
- if (written != size) {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%d: SIZE ERROR %d / %d"),
- __FILE__, __LINE__, written, size);
- }
+ size = strlen(buff);
+ retcode=send_rotctld_command(ctrl,buff,size,buffback,128);
- //g_print ("SZ:%d WR:%d AZ:%s EL:%s STR:%s", size, written, azstr, elstr, buff);
-
g_free (buff);
-#ifndef WIN32
- shutdown (sock, SHUT_RDWR);
-#else
- shutdown (sock, SD_BOTH);
-#endif
-
- close (sock);
-
- ctrl->wrops++;
-
- return TRUE;
+ return (retcode);
}
@@ -1248,3 +1117,92 @@
return (i > 0) ? TRUE : FALSE;
}
+
+static gboolean open_rotctld_socket (GtkRotCtrl * ctrl, gint *sock) {
+ struct sockaddr_in ServAddr;
+ struct hostent *h;
+ gint status;
+
+ ctrl->sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
+ if (ctrl->sock < 0) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: Failed to create socket"),
+ __FUNCTION__);
+ return FALSE;
+ }
+ else {
+ sat_log_log (SAT_LOG_LEVEL_DEBUG,
+ _("%s: Network socket created successfully"),
+ __FUNCTION__);
+ }
+
+ memset(&ServAddr, 0, sizeof(ServAddr)); /* Zero out structure */
+ ServAddr.sin_family = AF_INET; /* Internet address family */
+ h = gethostbyname(ctrl->conf->host);
+ memcpy((char *) &ServAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
+ ServAddr.sin_port = htons(ctrl->conf->port); /* Server port */
+
+ /* establish connection */
+ status = connect(ctrl->sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr));
+ if (status < 0) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: Failed to connect to %s:%d"),
+ __FUNCTION__, ctrl->conf->host, ctrl->conf->port);
+ return FALSE;
+ }
+ else {
+ sat_log_log (SAT_LOG_LEVEL_DEBUG,
+ _("%s: Connection opened to %s:%d"),
+ __FUNCTION__, ctrl->conf->host, ctrl->conf->port);
+ }
+
+ return TRUE;
+}
+
+static gboolean close_rotctld_socket (gint sock) {
+ gint written;
+ /*shutdown the rigctld connect*/
+ written = send(sock, "q\x0a", 2, 0);
+
+#ifndef WIN32
+ shutdown (sock, SHUT_RDWR);
+#else
+ shutdown (sock, SD_BOTH);
+#endif
+
+ close (sock);
+
+ return TRUE;
+}
+gboolean send_rotctld_command(GtkRotCtrl *ctrl, gchar *buff, gint size, gchar *buffout, gint sizeout)
+{
+ gint written;
+
+ /* send command */
+ written = send(ctrl->sock, buff, size, 0);
+ if (written != size) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: SIZE ERROR %d / %d"),
+ __FUNCTION__, written, size);
+ }
+ /* try to read answer */
+ size = read (ctrl->sock, buffout, sizeout);
+ buffout[size]='\0';
+ if (size == 0) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s:%s: Got 0 bytes from rotctld"),
+ __FILE__, __FUNCTION__);
+ }
+ else {
+ sat_log_log (SAT_LOG_LEVEL_DEBUG,
+ _("%s:%s: Read %d bytes from rotctld"),
+ __FILE__, __FUNCTION__, size);
+
+ }
+
+ ctrl->wrops++;
+
+ return TRUE;
+}
+
+
Modified: branches/continuous_network/src/gtk-rot-ctrl.h
===================================================================
--- branches/continuous_network/src/gtk-rot-ctrl.h 2010-09-25 13:58:47 UTC (rev 655)
+++ branches/continuous_network/src/gtk-rot-ctrl.h 2010-09-25 16:45:30 UTC (rev 656)
@@ -93,7 +93,8 @@
gboolean engaged; /*!< Flag indicating that rotor device is engaged. */
gint errcnt; /*!< Error counter. */
-
+ gint sock; /*!< socket for connecting to rotctld. */
+
/* debug related */
guint wrops;
guint rdops;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aa...@us...> - 2010-09-26 20:23:14
|
Revision: 657
http://gpredict.svn.sourceforge.net/gpredict/?rev=657&view=rev
Author: aa1vs
Date: 2010-09-26 20:23:08 +0000 (Sun, 26 Sep 2010)
Log Message:
-----------
Added improved error handling for network errors
Modified Paths:
--------------
branches/continuous_network/src/gtk-rig-ctrl.c
branches/continuous_network/src/gtk-rot-ctrl.c
Modified: branches/continuous_network/src/gtk-rig-ctrl.c
===================================================================
--- branches/continuous_network/src/gtk-rig-ctrl.c 2010-09-25 16:45:30 UTC (rev 656)
+++ branches/continuous_network/src/gtk-rig-ctrl.c 2010-09-26 20:23:08 UTC (rev 657)
@@ -2499,9 +2499,23 @@
_("%s: SIZE ERROR %d / %d"),
__FUNCTION__, written, size);
}
+ if (written == -1) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: rigctld port closed"),
+ __FUNCTION__);
+ return FALSE;
+ }
/* try to read answer */
size = read (sock, buffout, 127);
+ if (size == -1) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: rigctld port closed"),
+ __FUNCTION__);
+ return FALSE;
+ }
+
buffout[size]='\0';
+
if (size == 0) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s:%s: Got 0 bytes from rigctld"),
Modified: branches/continuous_network/src/gtk-rot-ctrl.c
===================================================================
--- branches/continuous_network/src/gtk-rot-ctrl.c 2010-09-25 16:45:30 UTC (rev 656)
+++ branches/continuous_network/src/gtk-rot-ctrl.c 2010-09-26 20:23:08 UTC (rev 657)
@@ -964,7 +964,6 @@
size = 2;
retcode=send_rotctld_command(ctrl,buff,size,buffback,128);
- printf(" buffback = %s\n", buffback);
/* try to read answer */
if (retcode) {
vbuff = g_strsplit (buffback, "\n", 3);
@@ -1177,7 +1176,11 @@
gboolean send_rotctld_command(GtkRotCtrl *ctrl, gchar *buff, gint size, gchar *buffout, gint sizeout)
{
gint written;
+ sat_log_log (SAT_LOG_LEVEL_DEBUG,
+ _("%s:%s: Sending %d bytes as %s."),
+ __FILE__, __FUNCTION__, size, buff);
+
/* send command */
written = send(ctrl->sock, buff, size, 0);
if (written != size) {
@@ -1185,18 +1188,33 @@
_("%s: SIZE ERROR %d / %d"),
__FUNCTION__, written, size);
}
+ if (written == -1) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: rotctld Socket Down"),
+ __FUNCTION__);
+ return FALSE;
+ }
+
/* try to read answer */
size = read (ctrl->sock, buffout, sizeout);
+
+ if (size == -1) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: rotctld Socket Down"),
+ __FUNCTION__);
+ return FALSE;
+ }
+
buffout[size]='\0';
- if (size == 0) {
+ if (size == 0) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s:%s: Got 0 bytes from rotctld"),
__FILE__, __FUNCTION__);
}
else {
sat_log_log (SAT_LOG_LEVEL_DEBUG,
- _("%s:%s: Read %d bytes from rotctld"),
- __FILE__, __FUNCTION__, size);
+ _("%s:%s: Read %d bytes as %s from rotctld"),
+ __FILE__, __FUNCTION__, size, buffout);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aa...@us...> - 2010-10-02 14:39:19
|
Revision: 659
http://gpredict.svn.sourceforge.net/gpredict/?rev=659&view=rev
Author: aa1vs
Date: 2010-10-02 14:39:11 +0000 (Sat, 02 Oct 2010)
Log Message:
-----------
Updates to gtk-rit-ctrl.c and gtk-rot-ctrl.c towards a polished continuous network connection.
Modified Paths:
--------------
branches/continuous_network/src/gtk-rig-ctrl.c
branches/continuous_network/src/gtk-rot-ctrl.c
Modified: branches/continuous_network/src/gtk-rig-ctrl.c
===================================================================
--- branches/continuous_network/src/gtk-rig-ctrl.c 2010-10-02 14:23:44 UTC (rev 658)
+++ branches/continuous_network/src/gtk-rig-ctrl.c 2010-10-02 14:39:11 UTC (rev 659)
@@ -129,7 +129,11 @@
static void track_downlink (GtkRigCtrl *ctrl);
static void track_uplink (GtkRigCtrl *ctrl);
static gboolean is_rig_tx_capable (const gchar *confname);
-static gboolean send_rigctld_command(GtkRigCtrl *ctrl, gint sock, gchar *buff, gint size, gchar *buffout, gint sizeout);
+static gboolean send_rigctld_command(GtkRigCtrl *ctrl, gint sock, gchar *buff, gchar *buffout, gint sizeout);
+static gboolean check_set_response (gchar *buff,gboolean retcode,const gchar* filename);
+static gboolean check_get_response (gchar *buff,gboolean retcode,const gchar* filename);
+static gint sat_name_compare (sat_t* a,sat_t*b);
+static gint rig_name_compare (const gchar* a,const gchar *b);
static GtkVBoxClass *parent_class = NULL;
@@ -654,7 +658,7 @@
gchar *dirname; /* directory name */
gchar **vbuff;
const gchar *filename; /* file name */
-
+ gchar *rigname;
table = gtk_table_new (4, 3, FALSE);
@@ -678,15 +682,26 @@
dir = g_dir_open (dirname, 0, &error);
if (dir) {
/* read each .rig file */
+ GSList *rigs=NULL;
+ gint i;
+ gint n;
while ((filename = g_dir_read_name (dir))) {
if (g_str_has_suffix (filename, ".rig")) {
-
- vbuff = g_strsplit (filename, ".rig", 0);
- gtk_combo_box_append_text (GTK_COMBO_BOX (ctrl->DevSel), vbuff[0]);
+ vbuff = g_strsplit (filename, ".rig", 0);
+ rigs=g_slist_insert_sorted(rigs,g_strdup(vbuff[0]),(GCompareFunc)rig_name_compare);
g_strfreev (vbuff);
}
}
+ n = g_slist_length (rigs);
+ for (i = 0; i < n; i++) {
+ rigname = g_slist_nth_data (rigs, i);
+ if (rigname) {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (ctrl->DevSel), rigname);
+ g_free(rigname);
+ }
+ }
+ g_slist_free(rigs);
}
else {
sat_log_log (SAT_LOG_LEVEL_ERROR,
@@ -811,7 +826,8 @@
GtkRigCtrl *ctrl = GTK_RIG_CTRL( user_data);
sat_t *sat = SAT (value);
- ctrl->sats = g_slist_append (ctrl->sats, sat);
+ //ctrl->sats = g_slist_append (ctrl->sats, sat);
+ ctrl->sats = g_slist_insert_sorted (ctrl->sats, sat, (GCompareFunc)sat_name_compare);
}
@@ -1179,6 +1195,7 @@
break;
}
if (ctrl->conf2 != NULL) {
+
close_rigctld_socket(ctrl->sock2);
}
close_rigctld_socket(ctrl->sock);
@@ -1240,6 +1257,7 @@
}
}
}
+ printf("Returning from engage\n");
}
@@ -1922,22 +1940,19 @@
gchar *buff,**vbuff;
gchar buffback[128];
gboolean retcode;
- gint size;
guint64 pttstat = 0;
if (ctrl->conf->ptt == PTT_TYPE_CAT) {
/* send command get_ptt (t) */
buff = g_strdup_printf ("t\x0a");
- size = 2;
}
else {
/* send command \get_dcd */
buff = g_strdup_printf ("%c\x0a",0x8b);
- size = 2;
}
- retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,buffback,128);
if (retcode) {
vbuff = g_strsplit (buffback, "\n", 3);
pttstat = g_ascii_strtoull (vbuff[0], NULL, 0); //FIXME base = 0 ok?
@@ -1959,7 +1974,6 @@
{
gchar *buff;
gchar buffback[128];
- gint size;
gboolean retcode;
/* send command */
@@ -1970,13 +1984,12 @@
buff = g_strdup_printf ("T 0\x0a");
}
- size = 4;
- retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,buffback,128);
g_free (buff);
+ return(check_set_response(buffback,retcode,__FUNCTION__));
- return retcode;
}
@@ -1995,17 +2008,15 @@
{
gchar *buff;
gchar buffback[128];
- gint size;
gboolean retcode;
- buff = g_strdup_printf ("F %10.0f\x0a", freq);
-
- size = 13;
+ buff = g_strdup_printf ("F %10.0f\x0a", freq);
- retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,buffback,128);
g_free(buff);
- return retcode;
+ return(check_set_response(buffback,retcode,__FUNCTION__));
+
}
@@ -2024,15 +2035,17 @@
{
gchar *buff;
gchar buffback[128];
- gint size;
gboolean retcode;
+
/* send command */
buff = g_strdup_printf ("I %10.0f\x0a", freq);
- size = 12;
- retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
+
+ retcode=send_rigctld_command(ctrl,sock,buff,buffback,128);
g_free(buff);
- return retcode;
+
+ return(check_set_response(buffback,retcode,__FUNCTION__));
+
}
@@ -2047,16 +2060,15 @@
gchar *buff;
gchar buffback[128];
gboolean retcode;
- gint size;
/* send command */
buff = g_strdup_printf ("S 1 %d\x0a",ctrl->conf->vfoDown);
- size = 13;
- retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,buffback,128);
g_free(buff);
- return retcode;
+ return(check_set_response(buffback,retcode,__FUNCTION__));
+
}
/** \brief Turn off the radios toggle mode
@@ -2071,16 +2083,16 @@
gchar *buff;
gchar buffback[128];
gboolean retcode;
- gint size;
+
/* send command */
buff = g_strdup_printf ("S 0 %d\x0a",ctrl->conf->vfoDown);
- size = 13;
- retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
+ retcode=send_rigctld_command(ctrl,sock,buff,buffback,128);
g_free(buff);
- return retcode;
+ return(check_set_response(buffback,retcode,__FUNCTION__));
+
}
/** \brief Get frequency
@@ -2094,7 +2106,6 @@
gchar *buff,**vbuff;
gchar buffback[128];
gboolean retcode;
- gint size;
if (freq == NULL) {
sat_log_log (SAT_LOG_LEVEL_BUG,
@@ -2105,8 +2116,9 @@
/* send command */
buff = g_strdup_printf ("f\x0a");
- size = 2;
- retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
+
+ retcode=send_rigctld_command(ctrl,sock,buff,buffback,128);
+ retcode=check_get_response(buffback,retcode,__FUNCTION__);
if (retcode) {
vbuff = g_strsplit (buffback, "\n", 3);
*freq = g_ascii_strtod (vbuff[0], NULL);
@@ -2128,7 +2140,6 @@
{
gchar *buff,**vbuff;
gchar buffback[128];
- gint size;
gboolean retcode;
@@ -2141,8 +2152,9 @@
/* send command */
buff = g_strdup_printf ("i\x0a");
- size = 2;
- retcode=send_rigctld_command(ctrl,sock,buff,size,buffback,128);
+
+ retcode=send_rigctld_command(ctrl,sock,buff,buffback,128);
+ retcode=check_get_response(buffback,retcode,__FUNCTION__);
if (retcode) {
vbuff = g_strsplit (buffback, "\n", 3);
*freq = g_ascii_strtod (vbuff[0], NULL);
@@ -2164,7 +2176,6 @@
{
gchar *buff;
gchar buffback[128];
- gint size;
gboolean retcode;
@@ -2172,22 +2183,18 @@
switch (vfo) {
case VFO_A:
buff = g_strdup_printf ("V VFOA\x0a");
- size = 7;
break;
case VFO_B:
buff = g_strdup_printf ("V VFOB\x0a");
- size = 7;
break;
case VFO_MAIN:
buff = g_strdup_printf ("V Main\x0a");
- size = 7;
break;
case VFO_SUB:
buff = g_strdup_printf ("V Sub\x0a");
- size = 6;
break;
default:
@@ -2195,13 +2202,14 @@
_("%s: Invalid VFO argument. Using VFOA."),
__FUNCTION__);
buff = g_strdup_printf ("V VFOA\x0a");
- size = 7;
break;
}
- retcode=send_rigctld_command(ctrl,ctrl->sock,buff,size,buffback,128);
+
+ retcode=send_rigctld_command(ctrl,ctrl->sock,buff,buffback,128);
g_free(buff);
- return retcode;
+
+ return(check_set_response(buffback,retcode,__FUNCTION__));
}
@@ -2488,12 +2496,19 @@
-gboolean send_rigctld_command(GtkRigCtrl *ctrl, gint sock, gchar *buff, gint size, gchar *buffout, gint sizeout)
+gboolean send_rigctld_command(GtkRigCtrl *ctrl, gint sock, gchar *buff, gchar *buffout, gint sizeout)
{
gint written;
+ gint size;
+
+ size = strlen(buff);
+ sat_log_log (SAT_LOG_LEVEL_DEBUG,
+ _("%s:%s: sending %d bytes to rigctld as \"%s\""),
+ __FILE__, __FUNCTION__, size, buff);
+
/* send command */
- written = send(sock, buff, size, 0);
+ written = send(sock, buff, strlen(buff), 0);
if (written != size) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s: SIZE ERROR %d / %d"),
@@ -2712,3 +2727,36 @@
return TRUE;
}
+
+/*simple function to sort the list of satellites in the combo box.*/
+static gint sat_name_compare (sat_t* a,sat_t*b){
+ return (g_ascii_strcasecmp(a->nickname,b->nickname));
+}
+
+static gint rig_name_compare (const gchar* a,const gchar *b){
+ return (g_ascii_strcasecmp(a,b));
+}
+
+static gboolean check_set_response (gchar *buffback,gboolean retcode,const gchar *function){
+ if (retcode==TRUE)
+ if (strncmp(buffback,"RPRT 0",6)!=0) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: %s rigctld returned error (%s)"),
+ __FILE__,function,buffback);
+
+ retcode=FALSE;
+ }
+ return retcode;
+}
+
+static gboolean check_get_response (gchar *buffback,gboolean retcode,const gchar *function){
+ if (retcode==TRUE)
+ if (strncmp(buffback,"RPRT",4)==0) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: %s rigctld returned error (%s)"),
+ __FILE__,function,buffback);
+
+ retcode=FALSE;
+ }
+ return retcode;
+}
Modified: branches/continuous_network/src/gtk-rot-ctrl.c
===================================================================
--- branches/continuous_network/src/gtk-rot-ctrl.c 2010-10-02 14:23:44 UTC (rev 658)
+++ branches/continuous_network/src/gtk-rot-ctrl.c 2010-10-02 14:39:11 UTC (rev 659)
@@ -89,11 +89,13 @@
static gboolean get_pos (GtkRotCtrl *ctrl, gdouble *az, gdouble *el);
static gboolean set_pos (GtkRotCtrl *ctrl, gdouble az, gdouble el);
-static gboolean send_rotctld_command(GtkRotCtrl *ctrl, gchar *buff, gint size, gchar *buffout, gint sizeout);
+static gboolean send_rotctld_command(GtkRotCtrl *ctrl, gchar *buff, gchar *buffout, gint sizeout);
static gboolean open_rotctld_socket (GtkRotCtrl *ctrl, gint *sock);
static gboolean close_rotctld_socket (gint sock);
static gboolean have_conf (void);
+static gint sat_name_compare (sat_t* a,sat_t*b);
+static gint rot_name_compare (const gchar* a,const gchar *b);
static GtkVBoxClass *parent_class = NULL;
@@ -481,7 +483,7 @@
gchar *dirname; /* directory name */
gchar **vbuff;
const gchar *filename; /* file name */
-
+ gchar *rotname;
table = gtk_table_new (3, 3, FALSE);
@@ -503,15 +505,27 @@
dir = g_dir_open (dirname, 0, &error);
if (dir) {
/* read each .rot file */
+ GSList *rots=NULL;
+ gint i;
+ gint n;
while ((filename = g_dir_read_name (dir))) {
if (g_str_has_suffix (filename, ".rot")) {
vbuff = g_strsplit (filename, ".rot", 0);
- gtk_combo_box_append_text (GTK_COMBO_BOX (ctrl->DevSel), vbuff[0]);
+ rots=g_slist_insert_sorted(rots,g_strdup(vbuff[0]),(GCompareFunc)rot_name_compare);
g_strfreev (vbuff);
}
}
+ n = g_slist_length (rots);
+ for (i = 0; i < n; i++) {
+ rotname = g_slist_nth_data (rots, i);
+ if (rotname) {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (ctrl->DevSel), rotname);
+ g_free(rotname);
+ }
+ }
+ g_slist_free(rots);
}
else {
sat_log_log (SAT_LOG_LEVEL_ERROR,
@@ -609,7 +623,8 @@
GtkRotCtrl *ctrl = GTK_ROT_CTRL( user_data);
sat_t *sat = SAT (value);
- ctrl->sats = g_slist_append (ctrl->sats, sat);
+ //ctrl->sats = g_slist_append (ctrl->sats, sat);
+ ctrl->sats = g_slist_insert_sorted (ctrl->sats, sat, (GCompareFunc)sat_name_compare);
}
@@ -949,7 +964,6 @@
{
gchar *buff,**vbuff;
gchar buffback[128];
- gint size;
gboolean retcode;
if ((az == NULL) || (el == NULL)) {
@@ -961,16 +975,24 @@
/* send command */
buff = g_strdup_printf ("p\x0a");
- size = 2;
- retcode=send_rotctld_command(ctrl,buff,size,buffback,128);
+
+ retcode=send_rotctld_command(ctrl,buff,buffback,128);
/* try to read answer */
if (retcode) {
- vbuff = g_strsplit (buffback, "\n", 3);
- *az = g_strtod (vbuff[0], NULL);
- *el = g_strtod (vbuff[1], NULL);
+ if (strncmp(buffback,"RPRT",4)==0){
+ retcode=FALSE;
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s:%d: rotctld returned error (%s)"),
+ __FILE__, __LINE__,buffback);
- g_strfreev (vbuff);
+ } else {
+ vbuff = g_strsplit (buffback, "\n", 3);
+ *az = g_strtod (vbuff[0], NULL);
+ *el = g_strtod (vbuff[1], NULL);
+
+ g_strfreev (vbuff);
+ }
}
g_free (buff);
@@ -994,7 +1016,6 @@
gchar *buff;
gchar buffback[128];
gchar azstr[8],elstr[8];
- gint size;
gboolean retcode;
/* send command */
@@ -1002,11 +1023,19 @@
g_ascii_formatd (elstr, 8, "%7.2f", el);
buff = g_strdup_printf ("P %s %s\x0a", azstr, elstr);
- size = strlen(buff);
- retcode=send_rotctld_command(ctrl,buff,size,buffback,128);
+ retcode=send_rotctld_command(ctrl,buff,buffback,128);
g_free (buff);
+ if (retcode==TRUE)
+ if (strncmp(buffback,"RPRT 0",6)!=0) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s:%d: rotctld returned error (%s)"),
+ __FILE__, __LINE__,buffback);
+
+ retcode=FALSE;
+ }
+
return (retcode);
}
@@ -1173,9 +1202,13 @@
return TRUE;
}
-gboolean send_rotctld_command(GtkRotCtrl *ctrl, gchar *buff, gint size, gchar *buffout, gint sizeout)
+gboolean send_rotctld_command(GtkRotCtrl *ctrl, gchar *buff, gchar *buffout, gint sizeout)
{
gint written;
+ gint size;
+
+ size = strlen(buff);
+
sat_log_log (SAT_LOG_LEVEL_DEBUG,
_("%s:%s: Sending %d bytes as %s."),
__FILE__, __FUNCTION__, size, buff);
@@ -1223,4 +1256,11 @@
return TRUE;
}
+/*simple function to sort the list of satellites in the combo box.*/
+static gint sat_name_compare (sat_t* a,sat_t*b){
+ return (g_ascii_strcasecmp(a->nickname,b->nickname));
+}
+static gint rot_name_compare (const gchar* a,const gchar *b){
+ return (g_ascii_strcasecmp(a,b));
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aa...@us...> - 2010-10-02 22:29:44
|
Revision: 664
http://gpredict.svn.sourceforge.net/gpredict/?rev=664&view=rev
Author: aa1vs
Date: 2010-10-02 22:29:38 +0000 (Sat, 02 Oct 2010)
Log Message:
-----------
Added checks for null ctrl->conf
Modified Paths:
--------------
branches/continuous_network/src/gtk-rig-ctrl.c
branches/continuous_network/src/gtk-rot-ctrl.c
Modified: branches/continuous_network/src/gtk-rig-ctrl.c
===================================================================
--- branches/continuous_network/src/gtk-rig-ctrl.c 2010-10-02 21:35:09 UTC (rev 663)
+++ branches/continuous_network/src/gtk-rig-ctrl.c 2010-10-02 22:29:38 UTC (rev 664)
@@ -1178,6 +1178,16 @@
{
GtkRigCtrl *ctrl = GTK_RIG_CTRL (data);
+ if (ctrl->conf == NULL) {
+ /* we don't have a working configuration */
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: Controller does not have a valid configuration"),
+ __FUNCTION__);
+ return;
+ }
+
+
+
if (!gtk_toggle_button_get_active (button)) {
/* close socket */
@@ -1186,6 +1196,7 @@
ctrl->engaged = FALSE;
ctrl->lasttxf = 0.0;
ctrl->lastrxf = 0.0;
+
switch (ctrl->conf->type) {
case RIG_TYPE_TOGGLE_AUTO:
case RIG_TYPE_TOGGLE_MAN:
@@ -1193,7 +1204,7 @@
break;
default:
break;
- }
+ }
if (ctrl->conf2 != NULL) {
close_rigctld_socket(ctrl->sock2);
@@ -1202,14 +1213,6 @@
}
else {
- if (ctrl->conf == NULL) {
- /* we don't have a working configuration */
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s: Controller does not have a valid configuration"),
- __FUNCTION__);
- return;
- }
-
gtk_widget_set_sensitive (ctrl->DevSel, FALSE);
gtk_widget_set_sensitive (ctrl->DevSel2, FALSE);
ctrl->engaged = TRUE;
@@ -1302,6 +1305,14 @@
static gboolean rig_ctrl_timeout_cb (gpointer data)
{
GtkRigCtrl *ctrl = GTK_RIG_CTRL (data);
+
+ if (ctrl->conf == NULL) {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s: Controller does not have a valid configuration"),
+ __FUNCTION__);
+ return (TRUE);
+ }
+
if (g_static_mutex_trylock(&(ctrl->busy))==FALSE) {
sat_log_log (SAT_LOG_LEVEL_ERROR,_("%s missed the deadline"),__FUNCTION__);
@@ -2374,6 +2385,8 @@
if (g_str_has_suffix (filename, ".rig")) {
i++;
+ /*once we have one we are done*/
+ break;
}
}
}
Modified: branches/continuous_network/src/gtk-rot-ctrl.c
===================================================================
--- branches/continuous_network/src/gtk-rot-ctrl.c 2010-10-02 21:35:09 UTC (rev 663)
+++ branches/continuous_network/src/gtk-rot-ctrl.c 2010-10-02 22:29:38 UTC (rev 664)
@@ -936,19 +936,20 @@
}
/* update controller circle on polar plot */
- if ((ctrl->conf->aztype == ROT_AZ_TYPE_180) && (rotaz < 0.0)) {
- gtk_polar_plot_set_ctrl_pos (GTK_POLAR_PLOT (ctrl->plot),
- gtk_rot_knob_get_value (GTK_ROT_KNOB (ctrl->AzSet))+360.0,
- gtk_rot_knob_get_value (GTK_ROT_KNOB (ctrl->ElSet)));
- }
- else {
- gtk_polar_plot_set_ctrl_pos (GTK_POLAR_PLOT (ctrl->plot),
- gtk_rot_knob_get_value (GTK_ROT_KNOB (ctrl->AzSet)),
- gtk_rot_knob_get_value (GTK_ROT_KNOB (ctrl->ElSet)));
- }
+ if (ctrl->conf !=NULL){
+ if ((ctrl->conf->aztype == ROT_AZ_TYPE_180) && (rotaz < 0.0)) {
+ gtk_polar_plot_set_ctrl_pos (GTK_POLAR_PLOT (ctrl->plot),
+ gtk_rot_knob_get_value (GTK_ROT_KNOB (ctrl->AzSet))+360.0,
+ gtk_rot_knob_get_value (GTK_ROT_KNOB (ctrl->ElSet)));
+ }
+ else {
+ gtk_polar_plot_set_ctrl_pos (GTK_POLAR_PLOT (ctrl->plot),
+ gtk_rot_knob_get_value (GTK_ROT_KNOB (ctrl->AzSet)),
+ gtk_rot_knob_get_value (GTK_ROT_KNOB (ctrl->ElSet)));
+ }
+ }
+ g_static_mutex_unlock(&(ctrl->busy));
- g_static_mutex_unlock(&(ctrl->busy));
-
return TRUE;
}
@@ -1130,6 +1131,8 @@
if (g_str_has_suffix (filename, ".rot")) {
i++;
+ /*once we have one we need nothing else*/
+ break;
}
}
}
@@ -1146,6 +1149,8 @@
return (i > 0) ? TRUE : FALSE;
}
+/** \brief open the rotcld socket. return true if successful false otherwise.*/
+
static gboolean open_rotctld_socket (GtkRotCtrl * ctrl, gint *sock) {
struct sockaddr_in ServAddr;
struct hostent *h;
@@ -1187,6 +1192,8 @@
return TRUE;
}
+
+/*close a rotcld socket. First send a q command to cleanly shut down rotctld*/
static gboolean close_rotctld_socket (gint sock) {
gint written;
/*shutdown the rigctld connect*/
@@ -1202,6 +1209,11 @@
return TRUE;
}
+
+/** \brief Send a command to rigctld
+ * Inputs are a controller, a string command, and a buffer and length for returning the output from rigctld.
+ */
+
gboolean send_rotctld_command(GtkRotCtrl *ctrl, gchar *buff, gchar *buffout, gint sizeout)
{
gint written;
@@ -1256,11 +1268,16 @@
return TRUE;
}
-/*simple function to sort the list of satellites in the combo box.*/
+/** \brief Compare Satellite Names.
+ *simple function to sort the list of satellites in the combo box.
+ */
static gint sat_name_compare (sat_t* a,sat_t*b){
return (g_ascii_strcasecmp(a->nickname,b->nickname));
}
+
+/** \brief Compare Rotator Names.
+ */
static gint rot_name_compare (const gchar* a,const gchar *b){
return (g_ascii_strcasecmp(a,b));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|