B4R Question Wrapping Radiohead RH_Serial

Discussion in 'B4R Questions' started by janderkan, Nov 1, 2018.

  1. janderkan

    janderkan Active Member Licensed User

    Hi
    I have succesfully wrapped RH_ASK class in Radiohead library by cut and paste Erels RFM95 class :)

    Now I need the RH_Serial class, but it needs a Hardware serial in the constructor.
    I managed to compile it using a Esp8266 but get a hardware reset when I try to send data.

    This is my addition to rRadiohead.h

    Code:
    class B4RRHSERIAL {

            
    private:     
                uint8_t backend[sizeof(RH_Serial)];
                RH_Serial* rhserial;
                PollerNode pnode;
                SubVoidByteArray DataAvailableSub;
                Byte buffer[RH_SERIAL_MAX_PAYLOAD_LEN];
                static void looper(void* b);
            
            
    public:                 
                bool Initialize(SubVoidByteArray DataAvailableSub, byte ThisAddress);
                bool Send(ArrayByte* Data);
        
    };
    and this is a new rRHSerial.cpp

    Code:
    #include "B4RDefines.h"

    namespace B4R {
        bool B4RRHSERIAL::Initialize(SubVoidByteArray DataAvailableSub, byte ThisAddress) {
            this->DataAvailableSub = DataAvailableSub;
            FunctionUnion fu;
            fu.PollerFunction = looper;
            pnode.functionUnion = fu;
            pnode.tag = this;

            HardwareSerial MySerial(
    0);
            MySerial.begin(
    115200);
            rhserial = new (backend) RH_Serial(MySerial);

            bool r = rhserial->init();
            
    if (r) {
            
    if (pnode.next == NULL)
                    pollers.add(&pnode);
            
    }
            return r;
        }

        void B4RRHSERIAL::looper(void* b) {
            B4RRHSERIAL* me = (B4RRHSERIAL*)b;
            
            if (me->rhserial->available()) {
                const UInt cp = B4R::StackMemory::cp;
                ArrayByte* arrPayload = CreateStackMemoryObject(ArrayByte);
                arrPayload->data = me->buffer;
                Byte len = RH_SERIAL_MAX_PAYLOAD_LEN;
                me->rhserial->recv(me->buffer, &len);
                arrPayload->length = len;
                me->DataAvailableSub(arrPayload);
                B4R::StackMemory::cp = cp;
            }
        }

        bool B4RRHSERIAL::Send(Array* Data) {
            return rhserial->send((Byte*)Data->data, Data->length);
        }
    }
    Please help me......
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Are you sure that HardwareSerial(0) is available? It is probably the same as Serial1.

    The way to debug such issues is by adding log outputs:
    Code:
    ::Serial.println("111");
    Use these messages to find the error point.

    You might also need to add delay(100) after each call.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice