Coder Social home page Coder Social logo

CPDLC encoding build failure about libacars HOT 3 CLOSED

szpajder avatar szpajder commented on July 22, 2024
CPDLC encoding build failure

from libacars.

Comments (3)

szpajder avatar szpajder commented on July 22, 2024

Binaries in examples directory get linked with libacars-2.so.2, but this library does not contain the routines that perform encoding. Only decoders are included. Hence, you can't use uper_encode_to_buffer() because it's simply not there - neither in libacars headers nor in the resulting library.

You may ask then, why is that, given that this function exists in asn1/per_encoder.c. Indeed, it does, because all code in the asn1 subdirectory is generated automatically and the generator kindly provides routines for decoding as well as encoding. However libacars by design only does decoding, so the encoding code could safely be removed from the tree and the library would still do everything it does now. Removal of redundant code requires manual work and I would need to do this every time I regenerate the ASN.1 code - so I don't because I'm lazy :-) But it's on my TODO list and I'll probably do this one day. Meanwhile you can use it to achieve your goal, but in a little different way - you need to put your program directly into libacars source tree and build it together with libacars, but link it directly to the asn1 library, which has the uper_encode_to_buffer() function that you need. Do the following:

  • put your program into the libacars/libacars directory
  • add the following to CMakeLists.txt in this directory:
add_executable(cpdlc_maintain_speed cpdlc_maintain_speed.c)
target_link_libraries(cpdlc_maintain_speed asn1 acars)
  • the program should look like this:
#include <stdio.h>
#include "asn1/FANSATCUplinkMessage.h"
#include "asn1/FANSTimestamp.h"
#include "asn1/asn_application.h"

void build() {
        FANSATCUplinkMessage_t um = {0};
        um.aTCMessageheader.msgIdentificationNumber = 15;
        um.aTCMessageheader.msgReferenceNumber = NULL;
        FANSTimestamp_t t = {0};
        t.hours = 9;
        t.minutes = 25;
        t.seconds = 35;
        um.aTCMessageheader.timestamp = &t;
        um.aTCuplinkmsgelementId.present = FANSATCUplinkMsgElementId_PR_uM106Speed,
        um.aTCuplinkmsgelementId.choice.uM106Speed.present = FANSSpeed_PR_speedIndicated;
        um.aTCuplinkmsgelementId.choice.uM106Speed.choice.speedIndicated = 20;
        um.aTCuplinkmsgelementid_seqOf = NULL;

        unsigned char output[50] = {0};
        asn_enc_rval_t rval = uper_encode_to_buffer(&asn_DEF_FANSATCUplinkMessage, &um, output, 50);
        if(rval.encoded == -1) {
                printf("Encoding failed at type %s\n", rval.failed_type->name);
        } else {
                printf("Encoding successful, %zd bits produced\n", rval.encoded);
                for(int i = 0; i < rval.encoded / 8 + (rval.encoded % 8 > 0); i++) {
                        printf("%02x ", output[i]);
                }
                printf("\n");
        }
}

int main() {
        build();
}
  • Build libacars as usual. Your program will be built as well.

Also note that FANSSpeedIndicated is expressed in tens of knots, so in order to express 200, you have to put a value of 20.

from libacars.

hvastani avatar hvastani commented on July 22, 2024

Thanks for your quick reply. I realized that those encode functions were not available in the libacars library so I added a few to support cpdlc encoding like a 'la_cpdlc_build' function to cpdlc.c which calls 'la_asn1_encode_as' function which calls 'uper_encode_to_buffer' and its working great. If you like, I can make a patch for it for your review.

It would be great if the libacars library supported both encoding and decoding including the json serialize/deserialize.
Good catch on the indicated speed value.

Thanks for your help

from libacars.

szpajder avatar szpajder commented on July 22, 2024

Thank you for suggestion, however I prefer to keep libacars to be a decoding library. Complete implementation of all encoders would require writing a significant amount of code, which use would be extremely limited, but it would still need to be maintained by someone (guess who). I therefore prefer to spend time on projects that might be interesting to a bit broader audience.

from libacars.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.