goToMain / libosdp

Implementation of IEC 60839-11-5 OSDP (Open Supervised Device Protocol); provides a C library with support for C++, Rust and Python3
https://libosdp.sidcha.dev
Apache License 2.0
128 stars 69 forks source link

How to use libosdp to send data after opening the 485 serial port? #138

Closed back2100 closed 9 months ago

back2100 commented 9 months ago

question

I now have a project on the rv1109 platform, based on libosdp, to interact with osdp ControlPanel。 But I am wondering, after I opened the 485 serial port and get the file descriptor(Of course, I know that through the function write, data is sent to the 485 serial port), how to use libosdp?

sample code

#include xxxx
#define UART_485          "/dev/ttyS0"   

int32_t openDevice(void) {
    int32_t fd = open(UART_485, O_RDWR | O_NOCTTY | O_NONBLOCK);
    if(fd < 2) {
        error code;
    }
    return fd;
}

osdp_pd_info_t info = {
    .name = "pd[101]",
    .baud_rate = 9600,
    .address = 101,
    .flags = 0,
    .id = {
        .version = 1,
        .model = 153,
        .vendor_code = 31337,
        .serial_number = 0x01020304,
        .firmware_version = 0x0A0B0C0D,
    },
    .cap = (struct osdp_pd_cap []) {
        {
            .function_code = OSDP_PD_CAP_READER_LED_CONTROL,
            .compliance_level = 1,
            .num_items = 1
        },
        {
            .function_code = OSDP_PD_CAP_READER_AUDIBLE_OUTPUT,
            .compliance_level = 1,
            .num_items = 1
        },
        { static_cast<uint8_t>(-1), 0, 0 } /* Sentinel */
    },
    .channel = {
        .data = nullptr,
        .id = 0,
        .recv = sample_pd_recv_func,
        .send = sample_pd_send_func,
        .flush = nullptr
    },
    .scbk = nullptr,
};

int main(int argc, char **argv) {
    int32_t fd = openDevice();
    osdp_t *_ctx = osdp_pd_setup(&info);
    //
}

question is,I don't know where to receive data(read function) and where to send it(write function)

back2100 commented 9 months ago

I have already know how to send data to port

int sample_pd_send_func(void *data, uint8_t *buf, int len)
{
    (void)(data);
    (void)(buf);

    write(fd, buf, len);
    return len;
}

int sample_pd_recv_func(void *data, uint8_t *buf, int len)
{
    (void)(data);
    (void)(buf);
    (void)(len);

    read(fd, buf, len);

    return 0;
}