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

Checks for pgn that is no longer active #438

Open
mar0997 opened this issue Dec 12, 2024 · 2 comments
Open

Checks for pgn that is no longer active #438

mar0997 opened this issue Dec 12, 2024 · 2 comments

Comments

@mar0997
Copy link

mar0997 commented Dec 12, 2024

Hi Timo -

I continue to appreciate your work on the library and I have expanded my code significantly. One thing that I have done is to create a new library based on your work that adds AC parameters 127744 - 127748 that I read from my Victron equipment. I also added AC parameter 127503 that I then output to be read by my Czone equipment. In addition to being able to now read the AC data by Czone I also add my 2 AC lines to get a total AC input to my boat.

This works great under normal situations when I am plugged into shore power or running my generator. The issue that I have not been able to solve is that the AC data continues to show the last value when AC power is removed. I have tried a variety of things to attempt to resolve this. I assume it is something simple and it may or may not be related to the new library that I created.

Using DataDisplay2 as an example I have tried this approach:

void ACVoltFreqB(const tN2kMsg &N2kMsg) {
unsigned char SID;
unsigned char ConnectionNumber;
double ACRMSvoltageLtoN;
double ACRMSvoltageLtoL;
double ACFrequency;

if (ParseN2kACVoltFreqB(N2kMsg, SID, ConnectionNumber, ACRMSvoltageLtoN, ACRMSvoltageLtoL, ACFrequency) ) {
Line2Voltage = ACRMSvoltageLtoN;
Line2Frequency = ACFrequency;
}
else {
Line2Voltage = 0;
Line2Frequency = 0;
}
}

I have also tried the approach of comparing the SID to the previous SID and if has not changed for a period of time to set the parameters to 0:

ParseN2kACVoltFreqB(N2kMsg, SID, ConnectionNumber, ACRMSvoltageLtoN, ACRMSvoltageLtoL, ACFrequency); {
CurrentSID = SID;
Line2Voltage = ACRMSvoltageLtoN;
Line2Frequency = ACFrequency;

  if (CurrentSIDLastState != CurrentSID)
  {
    startAC2timer = millis();
    CurrentSIDLastState = CurrentSID;
  }

  if (millis() - startAC2timer >= 500 )
  {
    Line2Voltage = 0;
    Line2Frequency = 0;
  }

}

Both of these work fine when AC power is active. But when AC power is removed I expect that the voltage and frequency go to 0, but instead both stay at the last values prior to removing power. I have verified with my analyzer that the Victron equipment stops transmitting the pgn when I remove AC power so I'm stumped as to why neither of these work. Can you offer me some advice?

@ttlappalainen
Copy link
Owner

It is because your ACVoltFreqB will be never called after generator has been stopped and message will not be sent anymore. You have to do it like this:

static uint32_t AC2timer = 0;
static double Line2Voltage = 0;
static double Line2Frequency = 0;
#define ACTimeout 5000

void CheckTimeouts() {
  if ( millis()-AC2Timer > ACTimeout  ) {
    double Line2Voltage = 0;
    double Line2Frequency = 0;
  }
}

void ACVoltFreqB(const tN2kMsg &N2kMsg) {
  if ( ParseN2kACVoltFreqB(...) ) {
    ...
     AC2timer = millis();
  }
}

void loop() {
  NMEA2000.ParseMessages();
  CheckTimeouts();
  ...
}

@mar0997
Copy link
Author

mar0997 commented Dec 13, 2024

Thank you Timo! This makes sense to me. I got tripped up on DataDisplay2. With a small adjustment this works. I really appreciate your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants