[go: nahoru, domu]

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

Add support for DC gensets #1435

Merged
merged 2 commits into from
Sep 16, 2024
Merged

Conversation

DanielMcInnes
Copy link
Contributor

Fixes #1377

@DanielMcInnes DanielMcInnes linked an issue Sep 3, 2024 that may be closed by this pull request
@DanielMcInnes DanielMcInnes marked this pull request as draft September 3, 2024 06:40
@DanielMcInnes DanielMcInnes force-pushed the 1377-add-support-for-dc-gensets branch 2 times, most recently from ae56c39 to b5ecad9 Compare September 4, 2024 01:13
@DanielMcInnes DanielMcInnes marked this pull request as ready for review September 4, 2024 01:14
@DanielMcInnes
Copy link
Contributor Author

I haven't been able to test the dc-generator-specific changes with mqtt / wasm, only with dbus via the latest venus-docker simulations 'gdf' and 'gdh'.

@@ -32,7 +33,9 @@ ObjectModel {
}
}

readonly property var nrOfPhases: VeQuickItem {
readonly property bool dcGenset: serviceType === "dcgenset"
readonly property int nrOfPhases: phases.valid ? phases.value : dcGenset ? 0 : 3
Copy link
Contributor

Choose a reason for hiding this comment

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

style nit: would prefer this to be broken over 3 lines, e.g.:

readonly property int nrOfPhases: phases.valid ? phases.value
                                : dcGenset ? 0
                                : 3

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be phases.isValid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it should be, thanks Bea.
Style nit fixed also

} else {
summary = [ gensetPowerText ]
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

style nit: for consistency, put an empty whitespace line after the break

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,59 @@
/*
** Copyright (C) 2023 Victron Energy B.V.
Copy link
Contributor

Choose a reason for hiding this comment

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

2024

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

text: qsTrId("genset_bms_control")
secondaryText: CommonWords.press_to_reset
visible: defaultAllowed && bmsControlled.dataItem.value === 1
// TODO: gui-v1 has "cornerMark: true" for this button. What does this mean? Does gui-v2 support this?
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like it's just an icon in the bottom-right hand corner of the button, which will change colour if the list item to which it belongs is the currently selected list item. It looks like it's mostly set to true for items which are editable, or activatable (e.g. slider). I suspect it's just to visualise the fact that the item is interactable in some way.

I don't think we need it, as in gui-v2 we have blue borders for interactable things, generally, and we (hopefully) visualize disabled items with grey instead.

}

ListSpinBox {
text: CommonWords.charge_current
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I would have assumed the string to be "Charge current limit" rather than "Charge current" (i.e. the maximum current which should be generated by the genset when charging the battery) but perhaps I am misunderstanding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated as suggested. It is "Charge current" in gui-v1, but I think you are right

Copy link
Contributor
@blammit blammit left a comment

Choose a reason for hiding this comment

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

Have made some initial comments; I'll try to test against the gui-v1 version to check that as well.

@@ -32,7 +33,9 @@ ObjectModel {
}
}

readonly property var nrOfPhases: VeQuickItem {
readonly property bool dcGenset: serviceType === "dcgenset"
readonly property int nrOfPhases: phases.valid ? phases.value : dcGenset ? 0 : 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be phases.isValid?

readonly property var nrOfPhases: VeQuickItem {
readonly property bool dcGenset: serviceType === "dcgenset"
readonly property int nrOfPhases: phases.valid ? phases.value : dcGenset ? 0 : 3
readonly property var phases: VeQuickItem {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be a property or can it just be a child item?

If it needs to be a property then it can be strongly typed as a VeQuickItem type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be a property, changed type to VeQuickItem for strong typing

//% "BMS Controlled"
text: qsTrId("genset_bms_controlled")
dataItem.uid: root.bindPrefix + "/Settings/BmsPresent"
enabled: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Can just make this a ListTextItem if it's not actually clickable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

allowed: defaultAllowed && dataItem.isValid
}

ListTextItem {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could be a ListLabel instead, and placed as a caption within the bmsControlled component (using bottomContent) since it's only visible when that is enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. looks like this:

Screenshot from 2024-09-11 14-04-21

dataItem.uid: root.bindPrefix + "/Settings/ChargeVoltage"
decimals: 1
stepSize: 0.1
suffix: "V"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can fetch from units.cpp instead of hardcoding, e.g. Units.defaultUnitString(VenusOS.Units_Volt)

Similarly for other suffix values elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -91,7 +94,7 @@ ObjectModel {
text: qsTrId("ac-in-genset_error")
dataItem.uid: root.bindPrefix + "/ErrorCode"
allowed: defaultAllowed && dataItem.isValid
nrOfPhases: root.nrOfPhases.value || 3
nrOfPhases: root.nrOfPhases
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this part of #1377 hasn't been done yet: port "Refactored MbItemFpGensetError to MbItemGensetError" to gui-v2

The main thing there is to rewrite ListFpGensetErrorItem so that it fetches the error description from GensetError instead of having a massive switch statement for the secondaryText. Note that GensetError will need to be registered as a QML type, similar to what's done for ChargerError and WakespeedError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ListFpGensetErrorItem has been deleted in main, so I guess this goes away until we need to translate a generator error code

@blammit
Copy link
Contributor
blammit commented Sep 9, 2024

Have made some initial comments; I'll try to test against the gui-v1 version to check that as well.

Did some more checking via venus-docker instead. The pages all seem fine, I noticed various warnings like these:

UID "AutoStartEnabled" contains invalid part: "AutoStartEnabled"
UID "NextTestRun" contains invalid part: "NextTestRun"
UID "TestRunIntervalRuntime" contains invalid part: "TestRunIntervalRuntime"

Which I think is just due to a lack of checks on whether root.startStopBindPrefix is empty, when assigning dataItem.uid values in PageGenerator.qml.

@DanielMcInnes DanielMcInnes force-pushed the 1377-add-support-for-dc-gensets branch 3 times, most recently from 1ead03b to f4eb315 Compare September 13, 2024 05:30
@DanielMcInnes
Copy link
Contributor Author

Have made some initial comments; I'll try to test against the gui-v1 version to check that as well.

Did some more checking via venus-docker instead. The pages all seem fine, I noticed various warnings like these:

UID "AutoStartEnabled" contains invalid part: "AutoStartEnabled"
UID "NextTestRun" contains invalid part: "NextTestRun"
UID "TestRunIntervalRuntime" contains invalid part: "TestRunIntervalRuntime"

Which I think is just due to a lack of checks on whether root.startStopBindPrefix is empty, when assigning dataItem.uid values in PageGenerator.qml.

I can't reproduce this, I think it may have been fixed. Would you mind checking again?

@DanielMcInnes DanielMcInnes marked this pull request as ready for review September 13, 2024 05:35
Copy link
Contributor
@chriadam chriadam left a comment

Choose a reason for hiding this comment

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

LGTM, modulo those invalid uid part warnings which Bea mentioned - @blammit could you double check whether those are fixed?

readonly property bool dcGenset: serviceType === "dcgenset"
readonly property int nrOfPhases: phases.valid ? phases.value
: dcGenset ? 0
: 3
Copy link
Contributor
@blammit blammit Sep 16, 2024

Choose a reason for hiding this comment

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

valid -> isValid

Also could we just have readonly property int nrOfPhases: phases.isValid ? phases.value : (dcGenset ? 0 : 3) to avoid the odd indentation?

[Edit: I see that @chriadam suggested this change to go over multiple lines ... hm. I wish this could be done without such massive indentation]

Copy link
Contributor

Choose a reason for hiding this comment

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

After changing this to isValid, I get this error:

<Unknown File>: Can't create role for unsupported data type

Any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a ListModel involved somewhere? I think it can serve ListElement entries or JS objects which have only QML basic type properties, and not more complex JavaScript types (including arrays).

Copy link
Contributor

Choose a reason for hiding this comment

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

Long shot, but does explicitly qualifying to root.phases make any difference? It shouldn't, of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's something to do with GensetErrorModel, I'll figure it out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, ListModel was complaining about setting an element's value to undefined

@blammit
Copy link
Contributor
blammit commented Sep 16, 2024

I can't reproduce this, I think it may have been fixed. Would you mind checking again?

LGTM, modulo those invalid uid part warnings which Bea mentioned - @blammit could you double check whether those are fixed?

@DanielMcInnes I can't reproduce those anymore, but when running with the 'gdh' simulation, if I click "Hatz Genset" in the Device List and then "Settings", there is a warning:

UID "Capabilities" contains invalid part: "Capabilities"

... hang on, this is only when running via MQTT. Let me see, I think this is related to the GensetService check in PageGensetModel.

[Edit: I will add a comment to PageGensetModel.qml regarding a fix for setting root.generatorWithGensetService to resolve this.]

@@ -12,6 +12,7 @@ ObjectModel {
property string bindPrefix
property string settingsBindPrefix: Global.systemSettings.serviceUid + "/Settings/Generator1"
property string startStopBindPrefix: startStop1Uid
readonly property string serviceType: BackendConnection.serviceTypeFromUid(bindPrefix)

// On D-Bus, the startstop1 generator is at com.victronenergy.generator.startstop1.
// On MQTT, the startstop1 generator is the one with GensetService=com.victronenergy.genset.*
Copy link
Contributor

Choose a reason for hiding this comment

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

This part needs to be updated to check for the "dcgenset" service as well, for MQTT backends. Basically, on MQTT we need to find a generator with a matching GensetService, because we don't have a straightforward way to find the startstop1 service there, unlike on a D-Bus backend. Here is a patch that seems to fix this, from testing via MQTT with the gdh simulation:

diff --git a/components/PageGensetModel.qml b/components/PageGensetModel.qml
index b386ae1e..66aeb72e 100644
--- a/components/PageGensetModel.qml
+++ b/components/PageGensetModel.qml
@@ -16,6 +16,7 @@ ObjectModel {
 
        // On D-Bus, the startstop1 generator is at com.victronenergy.generator.startstop1.
        // On MQTT, the startstop1 generator is the one with GensetService=com.victronenergy.genset.*
+       // (or GensetService=com.victronenergy.dcgenset.* if this is a dcgenset)
        readonly property string startStop1Uid: BackendConnection.type === BackendConnection.MqttSource
                        ? generatorWithGensetService
                        : BackendConnection.uidPrefix() + "/com.victronenergy.generator.startstop1"
@@ -26,7 +27,8 @@ ObjectModel {
                delegate: VeQuickItem {
                        uid: model.device.serviceUid + "/GensetService"
                        onValueChanged: {
-                               if (value !== undefined && value.startsWith("com.victronenergy.genset.")) {
+                               if ( (isValid && root.dcGenset && value.startsWith("com.victronenergy.dcgenset."))
+                                               || (isValid && !root.dcGenset && value.startsWith("com.victronenergy.genset.")) ) {
                                        root.generatorWithGensetService = model.device.serviceUid
                                }
                        }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks Bea, updated as suggested.

@DanielMcInnes DanielMcInnes force-pushed the 1377-add-support-for-dc-gensets branch 2 times, most recently from 53576e7 to ba4194f Compare September 16, 2024 05:17
As per gui-v1 commit b20574be6c3be329e5452928ee03e521c1c0e94d
Copy link
Contributor
@blammit blammit left a comment

Choose a reason for hiding this comment

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

Great, lgtm :)

@DanielMcInnes DanielMcInnes merged commit 2c69461 into main Sep 16, 2024
2 checks passed
@DanielMcInnes DanielMcInnes deleted the 1377-add-support-for-dc-gensets branch September 16, 2024 06:28
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

Successfully merging this pull request may close these issues.

Add support for DC gensets
3 participants