Skip to content

Easycomm parser library for Hamlib rotator control (written in C for C and C++ projects)

License

Notifications You must be signed in to change notification settings

yapiolibs/hamlib-rotctl-easycomm-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hamlib rotctl Easycomm parser PlatformIO Registry

A PlatformIO parser library for Hamlib rotator control commands.

  • Parses the string-based protocol as described by Easycomm standards I, II or III.
    • from string to C-struct (reception)
    • from C-struct to string (response)
    • Commands reference
  • Programmed with less dependencies in C for C and C++ projects.
    • can be used without the PlatformIO framework
    • not exclusively for micro cotrollers
    • depends on scanf and printf
  • Requires float support for scanf and printf.

Integrate in project example

# platformio.ini
[env:xxx]
platform  = xxx # one of ["native", "atmelavr", "ststm32", "espressiv8266", "espressif32"]
board     = xxx
framework = arduino
lib_deps  = rubienr/HamlibRotctlEasycommParser
# some platforms require folat support for scanf/printf to be explicitely enabled
build_flags =
    # if platfrom is atmelavr:
    -Wl,-u,vfscanf,-lscanf_flt,-u,vfprintf,-lprintf_flt
    # if platform is [...]

Parse a single command example

// main.c
void setup() {}

void loop()
{
    EasycommData result;

    easycommData(&result);
    if(easycommParseCommand("AZ000.1 EL000.0 UP000000000 UUU DN000000000 DDD", &result, EasycommParserStandard1))
    {
        // standard 1 command was parsed
    }

    easycommData(&result);
    if(easycommParseCommand("AZ100", &result, EasycommParserStandard2))
    {
        // standard 2 command was parsed
    }

    easycommData(&result);
    if(easycommParseCommand("VU50", &result, EasycommParserStandard23))
    {
        // standard 3 command was parsed
    }
}

Parse with callback example

// main.c
void customCallback(const EasycommData *command, void *custom_data)
{
    *((bool *)custom_data) = true;
}

void setup() {}

void loop()
{
    // registry for possible callbacks (CB) for each command; CBs may be nullptr
    EasycommCommandsCallback cb_handler;

    // register empty SB stubs for all commands described in standard 2
    easycommCommandsCallback(&cb_handler, EasycommParserStandard2);

    // override a specific CB
    cb_handler.registry[EasycommIdAzimuth] = customCallback;

    bool some_cb_invoked = { false };
    bool custom_cb_invoked = { false };

    some_cb_invoked = easycommHandleCommand("EL100.1", &cb_handler, EasycommParserStandard2, &custom_cb_invoked);
    // custom_cb_invoked == false because customCallback(...) was regitered for AZ but not EL
    // command some_cb_invoked == true because a default empty CB was called for EL command

    some_cb_invoked = easycommHandleCommand("AZ100.1", &cb_handler, EasycommParserStandard2, &custom_cb_invoked);
    // custom_cb_invoked == true
    // some_cb_invoked == true

    some_cb_invoked = easycommHandleCommand("VU", &cb_handler, EasycommParserStandard3, &custom_cb_invoked);
    // custom_cb_invoked == false
    // some_cb_invoked == false because VU is a standard 3 command but CBs are registered only for standard 2

    // suppress unused variable warnings
    (void)custom_cb_invoked;
    (void)some_cb_invoked;
}

Parse from stream: see full example

More examples: native-integration-test-program.cpp, unit tests

Checks

pio-run.yaml
pio-check.yaml
unit-tests.yaml
integration-tests-hamlib3x.yaml
integration-tests-hamlib4x.yaml
codeql-analysis.yml