Lawo / ember-plus

Ember+ control protocol - Slick and free for all!
https://github.com/Lawo/ember-plus/wiki
Boost Software License 1.0
109 stars 41 forks source link

Misunderstanding #70

Closed moritzmoritz closed 6 years ago

moritzmoritz commented 6 years ago

Hey everyone! I requested access to the google developer group but since now there's no response .. but I need some input what exactly I'm doing wrong.

First of all: I have little c++ experiences. I normally develop in languages like swift, python and so. I'm using the latest libember.

All what I want to do is to send a normal geDirectory-Request:

auto root = glow::GlowRootElementCollection::create();
    auto command = new glow::GlowCommand(root, glow::CommandType::GetDirectory);
    auto appTag = root->applicationTag();

    int const intValue = command->number().value();
    std::size_t const frameLength = ber::encodedFrameLength(intValue);

    util::OctetStream stream;
    ber::encode(stream, appTag);
    ber::encode(stream, ber::make_length(frameLength));
    ber::encodeFrame(stream, intValue);

In my understanding this is a ASN.1 encoded stream I can use to send over via tcp/ip.

Next I package it up with the s101lib.

libs101::StreamEncoder<unsigned char> encoder;

    encoder.encode(0x00);                       // Slot
    encoder.encode(libs101::MessageType::EmBER);// Message type
    encoder.encode(libs101::CommandType::EmBER);// Ember Command
    encoder.encode(0x01);                       // Version
    encoder.encode(0xc0); // Flags
    encoder.encode(libs101::Dtd::Glow);         // Glow Dtd
    encoder.encode(0x02);                       // App bytes low
    encoder.encode((version >> 0) & 0xFF);      // App specific, minor revision
    encoder.encode((version >> 8) & 0xFF);      // App specific, major revision
    encoder.encode(stream.begin(), stream.end());

    encoder.finish();

And send it via tcp / ip:

vector<unsigned char> bytes;
copy(encoder.begin(), encoder.end(), std::back_inserter(bytes));
send(sockfd, bytes.data(), bytes.size(), 0);

What is my misunderstanding of the ember+ protocol ?

benoitquiniou commented 6 years ago

Hi, By looking back at some existing implementation, I would say you should better use the encode method of the GlowRootElementCollection:

auto root = glow::GlowRootElementCollection::create();
auto command = new glow::GlowCommand(root, glow::CommandType::GetDirectory);
util::OctetStream stream;
root.encode(stream);

and then pass the stream to the libs101 stream encoder like you did. On remark about the version thing: you could use

encoder.encode(LIBEMBER_GLOWDTD_VERSION_MINOR);                                        
encoder.encode(LIBEMBER_GLOWDTD_VERSION_MAJOR);