Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(serial receiver interface): ✨ Introduce three new callbacks #134

Merged
merged 4 commits into from
Aug 31, 2024

Conversation

ddanilchenko
Copy link

@ddanilchenko ddanilchenko commented Aug 29, 2024

  • on connection down. performs if there is no data received within last CRSF_FAILSAFE_STAGE1_MS (300 ms)
  • on connection up. performs when connection was previously in down state and new data received successfully
  • raw data received. performs when new data received. can be used in case you need to deal with the raw data
 ...
   outputSerial.begin(CRSF_BAUD_RATE, SERIAL_8N1, TX_PIN2, RX_PIN2);

    // Initialise CRSF for Arduino.
    crsfInput0 = new CRSFforArduino(&inputSerial0, RX_PIN0, TX_PIN0);
    if (!crsfInput0->begin())
    {
        crsfInput0->end();
        delete crsfInput0;
        crsfInput0 = nullptr;

        Serial.println("CRSF0 for Arduino initialisation failed!");
        while (1)
        {
            delay(10);
        }
    }
   
    rcChannelCount = rcChannelCount > crsfProtocol::RC_CHANNEL_COUNT ? crsfProtocol::RC_CHANNEL_COUNT : rcChannelCount;

    crsfInput0->setLinkStatisticsCallback(onLinkStatisticsUpdate0);

    crsfInput0->setRawDataCallback(onRawDataCallback0);
    crsfInput0->setLinkUpCallback(onLink0UpCallback);
    crsfInput0->setLinkDownCallback(onLink0DownCallback);

...

void onLinkStatisticsUpdate0(serialReceiverLayer::link_statistics_t linkStatistics)
{
    if (millis() - lastUpdateLQ0 >= LINK_QUALITY_UPDATE_INTERVAL)
    {
        lastUpdateLQ0 = millis();
        Serial.print("Link Statistics0: ");
        Serial.print("RSSI: ");
        Serial.print(linkStatistics.rssi);
        Serial.print(", Link Quality: ");
        Serial.print(linkStatistics.lqi);
        Serial.print(", Signal-to-Noise Ratio: ");
        Serial.print(linkStatistics.snr);
        Serial.print(", Transmitter Power: ");
        Serial.println(linkStatistics.tx_power);
    }
}

...

void onRawDataCallback0(int8_t byteReceived)
{
    Serial.println("primary channel passthrough");
    outputSerial.write(byteReceived);
}

...

void onLink0DownCallback()
{
  Serial.println("main link is down");
}

void onLink0UpCallback()
{
    Serial.println("main link is up");
}

 - on connection down
 - on connection up
 - raw data received

Signed-off-by: Dmytro <ddanilchenko@dataxdev.com>
@ddanilchenko ddanilchenko changed the title Introduced the following callbacks: Introducing new callbacks Aug 29, 2024
@ZZ-Cat
Copy link
Owner

ZZ-Cat commented Aug 29, 2024

Before I run my CodeQL and Quality Control workflows on this, can you change the base branch from Main-Trunk to Version-1.1.0-Development?

Also, in your Pull Request description, can you clarify what each callback does and their purpose?

@ZZ-Cat ZZ-Cat self-assigned this Aug 29, 2024
@ddanilchenko ddanilchenko changed the base branch from Main-Trunk to Version-1.1.0-Development August 30, 2024 05:25
@ddanilchenko
Copy link
Author

ddanilchenko commented Aug 30, 2024

Before I run my CodeQL and Quality Control workflows on this, can you change the base branch from Main-Trunk to Version-1.1.0-Development?

Also, in your Pull Request description, can you clarify what each callback does and their purpose?

done. modified the initial comment for the PR. please have as look. a few words about onrawdatareceived. the main purpose of it is to add possibility of handling raw data received by the instance of the SerialReceiver class. in my case i used it to implement seamless integration with fc, e.g. read data from rx, handle crsf packages and bypass raw data to fc.

@ZZ-Cat ZZ-Cat added this to the Version 1.1.0 milestone Aug 30, 2024
@ZZ-Cat ZZ-Cat added ✨️ Enhancement ✨️ New feature or request 👍 Good first-time contribution Welcome to the club. This is how we roll, around here. labels Aug 30, 2024
@ZZ-Cat ZZ-Cat self-requested a review August 30, 2024 22:01
Copy link
Owner

@ZZ-Cat ZZ-Cat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defects detected

My Defect Detector has pinged you in the copy constructor for SerialReceiver.cpp

Summary of defects

src/SerialReceiver/SerialReceiver.cpp:152: [medium:warning] Member variable 'SerialReceiver::_rawDataCallback' is not assigned a value in 'SerialReceiver::operator='. [operatorEqVarError]
src/SerialReceiver/SerialReceiver.cpp:152: [medium:warning] Member variable 'SerialReceiver::_linkUpCallback' is not assigned a value in 'SerialReceiver::operator='. [operatorEqVarError]
src/SerialReceiver/SerialReceiver.cpp:152: [medium:warning] Member variable 'SerialReceiver::_linkDownCallback' is not assigned a value in 'SerialReceiver::operator='. [operatorEqVarError]

Full error message

Screenshot from 2024-08-31 10-07-40

Possible solution

Consider assigning values to your three callbacks in SerialReceiver::operator= copy constructor.

Example:

namespace serialReceiverLayer
{
    SerialReceiver &SerialReceiver::operator=(const SerialReceiver &serialReceiver)
    {

        /* ... */

        _rawDataCallback = serialReceiver._rawDataCallback;
        _linkUpCallback = serialReceiver._linkUpCallback;
        _linkDownCallback = serialReceiver._linkDownCallback;

        /* ... */

    }
}

Copy link
Owner

@ZZ-Cat ZZ-Cat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution here, it's greatly appreciated.
Everything has passed with flying colours. =^/.^=

So, Imma go ahead and update the PR name to bring it in-line with my Conventional Commits and then merge your Pull Request.

@ZZ-Cat ZZ-Cat changed the title Introducing new callbacks feat(serial receiver interface): ✨ Introduce three new callbacks Aug 31, 2024
@ZZ-Cat ZZ-Cat merged commit 0902150 into ZZ-Cat:Version-1.1.0-Development Aug 31, 2024
5 checks passed
@ZZ-Cat ZZ-Cat mentioned this pull request Aug 31, 2024
29 tasks
ZZ-Cat added a commit that referenced this pull request Aug 31, 2024
Three new callback functions are added to the Serial Receiver Interface:

- `onLinkDownCallback`
   Runs when no CRSF data is received within `CRSF_FAILSAFE_STAGE1_MS` (default is 300 milliseconds), and this may be used to facilitate fail-safe conditions.
- `onLinkUpCallback`
   Runs when a reconnection is established, and this may be used to facilitate fail-safe recovery.
- `onRawDataCallback`
   Runs whenever individual bytes from the raw CRSF data stream is received, and this may be used to facilitate UART pass-through.

Signed-off-by: Dmytro <ddanilchenko@dataxdev.com>
Co-authored-by: Cassandra "ZZ Cat" Robinson <nicad.heli.flier@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨️ Enhancement ✨️ New feature or request 👍 Good first-time contribution Welcome to the club. This is how we roll, around here.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants