简体   繁体   中英

ESP32 function from library is not called

I'm importing aa lib in my ESP32 project, this was originally designed for eclipse and imported into my code, using PlatformIO, putting it under lib:

Strange behaviour, if I activate the line:

errn =  decode_dinExiDocument(&stream1, &exiDin1);

Code is compiled and executed but, no output from the function call is made, even the line:

Serial.println("dintest1");

At beginning of the function call to verify the method has been called.
If I remove call to decode_dinExiDocument everything is printed out correctly.
I'm little lost as I don't see any way to debug this. Any ideas?

#include <Arduino.h>

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "EXITypes.h"
#include "dinEXIDatatypes.h"
#include "dinEXIDatatypesEncoder.h"
#include "dinEXIDatatypesDecoder.h"
#define BUFFER_SIZE 256
uint8_t buffer1[BUFFER_SIZE];
uint8_t buffer2[BUFFER_SIZE];

static int din_test1(){

    Serial.println("dintest1");
    int errn = 0;

    struct dinEXIDocument exiDin1;
    struct dinEXIDocument exiDin2;

    bitstream_t stream1;
    bitstream_t stream2;
    size_t pos1 = 0;
    size_t pos2 = 0;

    stream1.size = BUFFER_SIZE;
    stream1.data = buffer1;
    stream1.pos = &pos1;

    stream2.size = BUFFER_SIZE;
    stream2.data = buffer2;
    stream2.pos = &pos2;

    /* SetupSessionReq  */
    /* BMW: 80 9A 00 11 D0 20 00 03 C1 FC 30 00 43 F8 00 */
    buffer1[0] = 0x80;
    buffer1[1] = 0x9A;
    buffer1[2] = 0x00;
    buffer1[3] = 0x11;
    buffer1[4] = 0xD0;
    buffer1[5] = 0x20;
    buffer1[6] = 0x00;
    buffer1[7] = 0x03;
    buffer1[8] = 0xC1;
    buffer1[9] = 0xFC;
    buffer1[10] = 0x30;
    buffer1[11] = 0x00;
    buffer1[12] = 0x43;
    buffer1[13] = 0xF8;
    buffer1[14] = 0x00;

    //if i make this call method is not called and i get no output
    errn =  decode_dinExiDocument(&stream1, &exiDin1);

    Serial.println(errn);
    return errn;

}

void setup() {
  // put your setup code here, to run once:

  Serial.begin(115200);
  
}

void loop() {
  // put your main code here, to run repeatedly:

    printf("+++ Start simple DIN test +++\n");
    int errn = din_test1();
    printf("+++ Terminate simple DIN test with errn = %d +++\n\n", errn);
    if(errn != 0) {
        printf("\nDIN test error %d!\n", errn);
        
    }

    Serial.println("new loop");
    delay(2000);
}

Also line that print "new loop" is not called but the delay is respected.

It is kind of impossible to answer to you without knowing what the function decode_dinExiDocument(&stream1, &exiDin1) does. I see that the function comes from https://github.com/mhei/OpenV2G and that the library is in alpha release at the moment. I also noticed how the developers do not really like to put comments in their code.

First of all, I strongly advise you to have a look at this link: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/error-handling.html

In particular, there are function calls to get a string out of an error code and redirect it to the serial port.

What is happening is a fatal error that resets your microcontroller. Is it possible that your function generates a memory leak, a stack overflow or that it tries to access a non initialized pointer?

It is also possible that the library internally uses some OS specific functions that try to allocate too much memory or that try to access some OS specific code which cannot be present on the ESP32?

Where did you call the "init" code for your structures? If you look at this header: https://github.com/mhei/OpenV2G/blob/master/src/din/dinEXIDatatypes.h you can easily see that there is a init_dinEXIDocument(struct dinEXIDocument* exiDoc); function to be called to initialize your structs before using them.

As a side note/personal opinion, I would never willingly use a function made of a giant switch statement with 81 uncommented and undocumented cases.

I solved problem. code was right. unfortunately memory heap allocation for thread was low so code hangs.

I leave the answer here if someone has similar problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM