File: sharedloop.c

package info (click to toggle)
hamlib 4.6.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,984 kB
  • sloc: ansic: 262,996; sh: 6,135; cpp: 1,578; perl: 876; makefile: 855; python: 148; awk: 58; xml: 26
file content (99 lines) | stat: -rw-r--r-- 2,299 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Apex Shared Loop Controller */

#include <math.h>
#include "hamlib/rotator.h"
#include "iofunc.h"
#include "apex.h"

int apex_shared_loop_get_position(ROT *rot, float *az, float *el)
{
    int loop = 10;

    while (--loop > 0 && apex_azimuth < 0)
    {
        hl_usleep(250 * 1000);
    };

    *az = apex_azimuth;

    *el = 0;

    return RIG_OK;
}

int apex_shared_loop_set_position(ROT *rot, float az, float dummy)
{
    char cmdstr[16];
    int retval;
    hamlib_port_t *rotp = ROTPORT(rot);
    int remainder = lround(az + 22.5) % 45;
    int apex_az = lround(az + 22.5) - remainder;

    // default to 0 degrees
    snprintf(cmdstr, sizeof(cmdstr), "[R99T4AM10]\r\n");

    switch (apex_az)
    {
    case  45: cmdstr[9] = '1'; break;

    case  90: cmdstr[9] = '2'; break;

    case 135: cmdstr[9] = '3'; break;

    case 180: cmdstr[9] = '4'; break;

    case 225: cmdstr[9] = '5'; break;

    case 270: cmdstr[9] = '6'; break;

    case 315: cmdstr[9] = '7'; break;

    default:
        rig_debug(RIG_DEBUG_ERR, "%s: unknown az=%d\n", __func__, apex_az);
        return -RIG_EINTERNAL;
    }

    rig_flush(rotp);
    apex_azimuth = -1;
    retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr));

    if (retval != RIG_OK)
    {
        rig_debug(RIG_DEBUG_ERR, "%s: write_block error - %s\n", __func__,
                  rigerror(retval));
        return retval;
    }

    return RIG_OK;
}

const struct rot_caps apex_shared_loop_rot_caps =
{
    ROT_MODEL(ROT_MODEL_APEX_SHARED_LOOP),
    .model_name =     "Shared Loop",
    .mfg_name =       "Apex",
    .version =        "20231013.0",
    .copyright =      "LGPL",
    .status =         RIG_STATUS_STABLE,
    .rot_type =       ROT_TYPE_AZIMUTH,
    .port_type =      RIG_PORT_SERIAL,
    .serial_rate_min  = 57600,
    .serial_rate_max  = 57600,
    .serial_data_bits = 8,
    .serial_stop_bits = 1,
    .serial_parity    = RIG_PARITY_NONE,
    .serial_handshake = RIG_HANDSHAKE_NONE,
    .write_delay      = 0,
    .post_write_delay = 0,
    .timeout          = 4000,
    .retry            = 2,

    .min_az =     0.0,
    .max_az =     360.0,

    .rot_open = apex_open,
    .get_info = apex_get_info,
    .get_position = apex_shared_loop_get_position,
    .set_position = apex_shared_loop_set_position,
};