Learning the code_A failure to find the function body of hal.console->available()

Hello, everyone!
I am a fresh man in the domain of UAV, with just a little experience of C++.
I am trying to learn the example code, and have some confusion now, so sincerely hope someone can help me for my question that may seems childish, thanks a lot!

My question is as follows:
I noticed the statement “hal.console->available()” in INS_generic.cpp, but I can’t find the function body of available().

Two known information:

  1. The type of console: AP_HAL::UARTDriver*
  2. The inheritance relation of class: Stream→BetterStream→UARTDriver

When I select the “available”, the context window of Source Insight displays the pure virtual function available() in the “AP:HAL::Stream:public AP::Print”.

In my opinion, the available() should be redefined in the derived class. But I didn’t find it in BetterStream Class or UARTDriver Class. Besides, I didn’t find any derived class of UARTDriver.

PS: I think UARTDriver might have derived classes, but I didn’t find them. Because I noticed there are many pure virtual functions in UARTDriver, and the definition of virtual functions should be in the derived classes.

Because the question I asked is too elementary?
Why didn’t anyone reply me ┭┮﹏┭┮

Welll… I didn’t get the original message… :slight_smile:

Perhaps you should check the various HAL implementations we have -
AP_HAL_ChibiOS, AP_HAL_SITL etc etc. They implement the methods you’re
looking for.

1 Like

If your IDE isn’t “smart” enough to automatically find all the implementations of a virtual function, you can use its text-based search of the project instead.

There’s also “git grep”…

(base) 07:54:47 (flight-test-3) ~/linux_git/kd0aij/ardupilot$ git grep "available() override"
libraries/AP_HAL/Util.cpp:    uint32_t available() override { return 0; }
libraries/AP_HAL_ChibiOS/UARTDriver.h:    uint32_t available() override;
libraries/AP_HAL_ChibiOS/stdio.cpp:    uint32_t available() override { return 0; }
libraries/AP_HAL_Empty/UARTDriver.h:    uint32_t available() override;
libraries/AP_HAL_Linux/CAN.h:    int32_t available() override;
libraries/AP_HAL_Linux/UARTDriver.h:    uint32_t available() override;
libraries/AP_HAL_SITL/UARTDriver.h:    uint32_t available() override;
libraries/AP_Logger/AP_Logger_Block.h:    uint32_t bufferspace_available() override;
libraries/AP_Logger/AP_Logger_File.h:    uint32_t bufferspace_available() override;
libraries/AP_Logger/AP_Logger_MAVLink.h:    uint32_t bufferspace_available() override; // in bytes
libraries/AP_UAVCAN/AP_UAVCAN_SLCAN.h:    int32_t available() override
1 Like

Thank you very much!:grin:

I found myself lacking a lot of necessary knowledge. I know a little about the “AP_HAL_ChibiOS” and “AP_HAL_SITL”, only know HAL is a virtual class, and the above two classes are its derived class, which represents a hardware platform.

Thanks for your suggestion~ I will try to find the implement of available() in these derived classes.

Thanks♪(・ω・)ノ

I also think the Source Insight seems not so smart.
In fact, I lack in elementary skills for reading the code.
Very grateful for the two methods you provide~
Next, I will try my best (#^.^#)