Coder Social home page Coder Social logo

Comments (3)

softov avatar softov commented on July 25, 2024

I have beat the code to work.

Expose get_buffer_used, because is not accessible outside, then use this to see if there is something to read. Get A->B and B->A talking.

RAM_CODE static inline size_t get_buffer_used(struct queue_buffer_t *buffer_p)
{
    if (buffer_p->begin_p == NULL) {
        return (0);
    }

    if (buffer_p->write_p == buffer_p->read_p) {
        return (0);
    } else if (buffer_p->write_p > buffer_p->read_p) {
        return (buffer_p->write_p - buffer_p->read_p);
    } else {
        return ((buffer_p->end_p - buffer_p->begin_p)
                - (buffer_p->read_p - buffer_p->write_p));
    }
}
/************************************************************/
int loopExample1(struct uart_driver_t *s_hw, struct uart_soft_driver_t *s_485, struct pin_driver_t *pinT)
{
    char c = 0;
    while (1)
    {
        while (get_buffer_used(&s_hw->chin.buffer) > 0)
        {
            chan_read(&s_hw->chin, &c, sizeof(c));

            /* enable sending */
            pin_write(pinT, 1);
            chan_write(&s_485->chout, &c, sizeof(c));
            /* disable sending */
            pin_write(pinT, 0);
        }
        while (get_buffer_used(&s_485->chin.buffer) > 0)
        {
            chan_read(&s_485->chin, &c, sizeof(c));
            chan_write(&s_hw->chout, &c, sizeof(c));
        }
    }
    return 0;
}

This is wrong?
I don't known IF this is the right function to call, none if this is the right way.

PS, there is a exemple using shell and threads? I have searched in google, without success.
So, I can put rs485 inside a thread, only to receive/reply commands, and let HardwareSerial to Shell to manage the system.

from simba.

eerimoq avatar eerimoq commented on July 25, 2024

Sorry, but I don't have time to look into this i detail. But yes, a list can be used if data is expected in one or more channels. Also there is a chan_size() function to see how many betys that can be read.

from simba.

mikaelpatel avatar mikaelpatel commented on July 25, 2024

@softov Actually the delay(10); in the original Arduino sketch is really important.

from simba.

Related Issues (20)

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.