thomasonw / NMEA2000_socketCAN

A driver for the NMEA2000 library and standard linux socketCAN devices
30 stars 20 forks source link

Compiling issue with candump example #5

Open brd904 opened 1 year ago

brd904 commented 1 year ago

Hello,

I am getting the below error when trying to compile the example code.

'serStream' was not declared in this scope; did you mean 'N2kStream'

Please help!

thomasonw commented 1 year ago

Hello!

It has been so long sense I have looked at that, I am not sure the answer! I do think Timo forked a branch, and it might have some changes… Might look there?

https://github.com/ttlappalainen/NMEA2000_socketCAN

-al-

From: brd904 @.*** Sent: Sunday, February 19, 2023 7:52 PM To: thomasonw/NMEA2000_socketCAN Cc: Subscribed Subject: [thomasonw/NMEA2000_socketCAN] Compiling issue with candump example (Issue #5)

Hello,

I am getting the below error when trying to compile the example code.

'serStream' was not declared in this scope; did you mean 'N2kStream'

Please help!

— Reply to this email directly, view it on GitHub https://github.com/thomasonw/NMEA2000_socketCAN/issues/5 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ACC5NDS523NW33LW4RJEDW3WYLS6VANCNFSM6AAAAAAVBMCIKY . You are receiving this because you are subscribed to this thread. https://github.com/notifications/beacon/ACC5NDTY2IE4LSFXM2S6CPDWYLS6VA5CNFSM6AAAAAAVBMCIK2WGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHF5VQDOU.gif Message ID: @.***>

duichan commented 1 year ago

I have the same problem which seems to be due to changes in Timo's NMEA2000 library, not to NMEA2000_SocketCAN itself. An earlier version works just fine. I am investigating and will report back.

ttlappalainen commented 1 year ago

What example do you mean? serStream is only on NMEA2000_CAN.h for mbed. It will be automatically selected if compiler option MBED is defined or you have definition #define USE_N2K_CAN 6 before including NMEA2000_CAN.h

duichan commented 1 year ago

Sorry for the omission. I am refering to the test example in https://github.com/thomasonw/NMEA2000_socketCAN/blob/master/Raspberry-Pi-CAN.md ###3. Using the NMEA2000 library

ttlappalainen commented 1 year ago

There was probably in some time serStream definition inside NMEA2000_socketCAN.cpp. That was not good idea, since it is not needed by library itself and definition belongs to user, if one needs it. So you should add to main.cpp somewhere after including NMEA2000_CAN.h e.g.,

tSocketStream serStream("/dev/tnt2");

or what ever you like to have as forward stream.

But I think there may be issue with missing peak on tSocketStream

duichan commented 1 year ago

Actually the test example with serStream isn't really my main concern.

I have my own program which compiled and linked just fine with your library in January 2021, but now fails with the latest version (everything else is unchanged): Undefined references to tNMEA2000::

Just to confirm, main.cpp contains the headers:

include

include

ttlappalainen commented 1 year ago

What reference?

duichan commented 1 year ago

Sorry, red herring due to a minor typo on my part.

However the original problem with the test program remains, despite your suggested change: cannot declare variable ‘serStream’ to be of abstract type ‘tSocketStream’

brd904 commented 1 year ago

Hey guys, I was able to get a version of the display example code in the NEMA2000 library running. I think maybe just changing the example to something that doesn't stream data via serial on the raspberry pi would be fine. I don't really need to stream data over serial for my application.

ttlappalainen commented 1 year ago

The problem is that tN2kStream has abstract peek function, which is not implemented to tSocketStream. There is some old issue of that and I am not sure has it been solved. If it is not possible to implement peek to linux, I have to add compiler definition to remove that and usage for it.

peek function is needed for multiprotocol handling for stream reading. I may be the only one using it.

brd904 commented 1 year ago

That makes sense. I am not using peek function.

An easy solution probably would be to add a compiler definition and remove it.

Thanks for your help.

ttlappalainen commented 1 year ago

Not that easy. Then parsing will not work, since it uses peek. Also parser requires definition, which is a bit more complex.

Doesn't linux allow peek?

nisalj commented 1 year ago

I've added a peek function. I believe this is now working in the pull request I created here

https://github.com/ttlappalainen/NMEA2000_socketCAN

wjquigs11 commented 1 year ago

@nisalj can you describe in more detail what you did to fix the issue? I have your version of the library but I'm still getting this error: identifier "serStream" is undefined I would like to forward messages to serial.

thomasonw commented 1 year ago

@nisalj serStream is something that has to be defined as part of the 'bridge' between Timo's and the underlying hardware. It is defined as part of Timo's NMEA2000_CAN.H file, example (in part):

#elif USE_N2K_CAN == USE_N2K_SOCKET_CAN
// Use socketCAN devices
#include <NMEA2000_SocketCAN.h>       // https://github.com/thomasonw/NMEA2000_socketCAN
tNMEA2000 &NMEA2000=*(new tNMEA2000_SocketCAN());
tSocketStream serStream;

The methods are then coded in: NMEA2000_SocketCAN.cpp Ala:


size_t tSocketStream::write(const uint8_t* data, size_t size) {                // Serial Stream bridge -- Write data to stream.
  if ( port!=-1 ) {
    return ::write(port,data,size);
  } else {
    size_t i;

    for (i=0; (i<size) && data[i];  i++)                                        // send chars to stdout for "size" or until null is found.
        putc(data[i],stdout);

    return(i);
  }
}

I hope I got this right, and this helps. Perhaps the #include paths need to be reviewed for that sample? Or something is not defined to ID the 'SocketCAN' variant should be used in Timo's lib? (It has been so long, I do not remember if some type of #define is needed to have Timo's tree select the socketCAN option....)

wjquigs11 commented 1 year ago

I think the issue is that serStream is defined for MBED devices, which makes sense...I believe it's an Arduino concept. I can just set it to NULL, but I am still wondering how to get the parser output to the console on RPI.

ttlappalainen commented 1 year ago

You can find on example NMEA2000ToNMEA0183 have used tSocketStream ForwardStream("/dev/tnt2"); to forward N2k data.