[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Patch to M2 rotor



Hello,

I worked to try to solve some problems I found with the M2 rotor when upgrading to Debian 11.6 (hamlib 4.0-7).

Here in annex my patch.

I hope you can take it into consideration. I am checking the status of latest hamlib as well, but I have to run Debian 11.6 to use with Satnogs (that's the reason of this patch).

73

Alberto - iw1fnw

Description: Implemented echo solution and corrected few bugs in M2 rotor
 Upgraded the M2 RC2800 code to manage the optional echo from controller, as implemented
 in the hamlib 4.1.
 Handle properly replies from control box terminating with either CR, LF, or CR+LF
 Corrected set position command with no decimal points in azimuth for 'RC2800' model
 Corrected set position commands for RC2800_EARLY_AZEL model
Author: Alberto Busso
Origin: other
Bug: 
Bug-<Vendor>: 
Forwarded: no
Applied-Upstream: 
Reviewed-by: 
Last-Update: 2023-01-26
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/rotators/m2/rc2800.c
+++ b/rotators/m2/rc2800.c
@@ -202,26 +202,24 @@
         data_len = BUFSZ;
     }
 
-#if 0 // manual says no echos
-    /* first reply is an echo */
+    /* then comes the answer */
     memset(data, 0, data_len);
-    retval = read_string(&rs->rotport, data, data_len, CR, strlen(CR));
+    retval = read_string(&rs->rotport, data, data_len, CR LF, strlen(CR LF));
 
-    if (retval < 0)
+    // some models seem to echo -- so we'll check and read again if echoed
+    // skip last char in case the reply is terminated with LF instead of CR
+    if (strncmp(data, cmdstr, strlen(data)-1) == 0)
     {
-        if (retry_read++ < rot->state.rotport.retry)
-        {
-            goto transaction_write;
-        }
-
-        goto transaction_quit;
+        memset(data, 0, data_len);
+        retval = read_string(&rs->rotport, data, data_len, CR LF, strlen(CR LF));
     }
 
-#endif
-
-    /* then comes the answer */
-    memset(data, 0, data_len);
-    retval = read_string(&rs->rotport, data, data_len, CR, strlen(CR));
+    // some models uses both CR + LF -- so we'll check and discard the additional one
+    if (strlen(data) == 1)
+    {
+        memset(data, 0, data_len);
+        retval = read_string(&rs->rotport, data, data_len, CR LF, strlen(CR LF));
+    }
 
     if (retval < 0)
     {
@@ -247,19 +245,18 @@
 
     rig_debug(RIG_DEBUG_TRACE, "%s called: %f %f\n", __func__, az, el);
 
-    if (rot->caps->rot_model == ROT_MODEL_RC2800_EARLY_AZ)
+    if (rot->caps->rot_model == ROT_MODEL_RC2800)       // new protocol
+    {
+        // does the new protocol use decimal points?
+        // we'll assume no for now
+        num_sprintf(cmdstr, "A%.0f"CR, az);
+    }
+    else        // old protocol (both AZ and AZEL)
     {
-        // we only do azimuth and this is the old protocol
         // we have to switch modes and then send azimuth
         // an extra CR gives us a response to expect
         num_sprintf(cmdstr, "A\r%.0f\r\r", az);
     }
-    else
-    {
-        // does the new protocol use decimal points?
-        // we'll assume no for now
-        num_sprintf(cmdstr, "A%0f"CR, az);
-    }
 
     retval1 = rc2800_transaction(rot, cmdstr, NULL, 0);
 
@@ -271,17 +268,16 @@
     /* do not overwhelm the MCU? */
     hl_usleep(200 * 1000);
 
-    if (rot->caps->rot_model == ROT_MODEL_RC2800_EARLY_AZEL)
+    if (rot->caps->rot_model == ROT_MODEL_RC2800)       // new protocol
+    {
+        num_sprintf(cmdstr, "E%.0f"CR, el);
+    }
+    else        // old protocol (both AZ and AZEL)
     {
-        // this is the old protocol
         // we have to switch modes and then send azimuth
         // an extra CR gives us a response to expect
         num_sprintf(cmdstr, "E\r%.0f\r\r", el);
     }
-    else
-    {
-        num_sprintf(cmdstr, "E%.0f"CR, el);
-    }
 
     retval2 = rc2800_transaction(rot, cmdstr, NULL, 0);
 
@@ -324,36 +320,37 @@
         }
     }
 
-    if (rot->caps->rot_model == ROT_MODEL_RC2800)
+    if (rot->caps->rot_type == ROT_TYPE_AZIMUTH)
     {
-        retval = rc2800_transaction(rot, "E" CR, posbuf, sizeof(posbuf));
+        rig_debug(RIG_DEBUG_TRACE, "%s: (az) = (%.1f)\n",
+                  __func__, *az);
+        return RIG_OK;
+    }
 
-        if (retval != RIG_OK || strlen(posbuf) < 5)
-        {
-            return retval < 0 ? retval : -RIG_EPROTO;
-        }
+    /* do not overwhelm the MCU? */
+    hl_usleep(200 * 1000);
 
-        if (rc2800_parse(posbuf, &device, &value) == RIG_OK)
-        {
-            if (device == 'E')
-            {
-                *el = (elevation_t) value;
-            }
-            else
-            {
-                return -RIG_EPROTO;
-            }
-        }
+    retval = rc2800_transaction(rot, "E" CR, posbuf, sizeof(posbuf));
 
-        rig_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.1f, %.1f)\n",
-                  __func__, *az, *el);
+    if (retval != RIG_OK || strlen(posbuf) < 5)
+    {
+        return retval < 0 ? retval : -RIG_EPROTO;
     }
-    else
+
+    if (rc2800_parse(posbuf, &device, &value) == RIG_OK)
     {
-        rig_debug(RIG_DEBUG_TRACE, "%s: (az) = (%.1f)\n",
-                  __func__, *az);
+        if (device == 'E')
+        {
+            *el = (elevation_t) value;
+        }
+        else
+        {
+            return -RIG_EPROTO;
+        }
     }
 
+    rig_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.1f, %.1f)\n",
+              __func__, *az, *el);
 
     return RIG_OK;
 }
@@ -413,7 +410,7 @@
     ROT_MODEL(ROT_MODEL_RC2800),
     .model_name =     "RC2800",
     .mfg_name =       "M2",
-    .version =        "20201130",
+    .version =        "20230123",
     .copyright =      "LGPL",
     .status =         RIG_STATUS_BETA,
     .rot_type =       ROT_TYPE_AZEL,
@@ -445,7 +442,7 @@
     ROT_MODEL(ROT_MODEL_RC2800_EARLY_AZ),
     .model_name =     "RC2800_EARLY_AZ",
     .mfg_name =       "M2",
-    .version =        "20201130",
+    .version =        "20230123",
     .copyright =      "LGPL",
     .status =         RIG_STATUS_STABLE,
     .rot_type =       ROT_TYPE_AZIMUTH,
@@ -476,7 +473,7 @@
     ROT_MODEL(ROT_MODEL_RC2800_EARLY_AZEL),
     .model_name =     "RC2800_EARLY_AZEL",
     .mfg_name =       "M2",
-    .version =        "20201130",
+    .version =        "20230123",
     .copyright =      "LGPL",
     .status =         RIG_STATUS_STABLE,
     .rot_type =       ROT_TYPE_AZEL,

Reply to: