Skip to content

Commit

Permalink
Add ProductInfo to contain product id constants
Browse files Browse the repository at this point in the history
  • Loading branch information
blammit committed Jul 15, 2024
1 parent 532617e commit 09a1485
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 59 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ list(APPEND VenusQMLModule_CPP_SOURCES
src/cpuinfo.cpp
src/frameratemodel.h
src/frameratemodel.cpp
src/productinfo.h
src/quantityinfo.h
src/quantityinfo.cpp
src/qrangemodel_p.h
Expand Down
13 changes: 4 additions & 9 deletions components/settings/ListAcInError.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ ListTextItem {

property string bindPrefix

// froniusInverterProductId should always be equal to VE_PROD_ID_PV_INVERTER_FRONIUS
readonly property int froniusInverterProductId: 0xA142
// carloGavazziEmProductId should always be equal to VE_PROD_ID_CARLO_GAVAZZI_EM
readonly property int carloGavazziEmProductId: 0xB002

text: CommonWords.error_code
dataItem.uid: root.bindPrefix + "/ErrorCode"
secondaryText: {
if (productId.value === froniusInverterProductId) {
if (productId.value === ProductInfo.ProductId_PvInverter_Fronius) {
return dataItem.value
} else if (productId.value === carloGavazziEmProductId) {
} else if (productId.value === ProductInfo.ProductId_EnergyMeter_CarloGavazzi) {
if (dataItem.value === 1) {
//: %1 = the error number
//% "Front selector locked (%1)"
Expand All @@ -34,8 +29,8 @@ ListTextItem {
}
return ""
}
allowed: productId.value === froniusInverterProductId
|| productId.value === carloGavazziEmProductId
allowed: productId.value === ProductInfo.ProductId_PvInverter_Fronius
|| productId.value === ProductInfo.ProductId_EnergyMeter_CarloGavazzi


VeQuickItem {
Expand Down
2 changes: 1 addition & 1 deletion data/common/Tank.qml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Device {
}
}

name: productId === 0xA160
name: productId === ProductInfo.ProductId_TankSensor_Generic
// This must be a generic Victron tank sensor, where the product name is always "Tank
// sensor" and there is no custom name, so use the tank type to provide a meaningful name.
? Gauges.tankProperties(type).name
Expand Down
2 changes: 1 addition & 1 deletion data/mock/AcInputsImpl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ QtObject {
customName: "Genset AC input",
connected: 1,
phaseCount: 3,
productId: 0xB040, // fisher panda
productId: ProductInfo.ProductId_Genset_FischerPanda,
}
setInputs([ gridInput, generatorInput ])
}
Expand Down
4 changes: 2 additions & 2 deletions data/mock/DcInputsImpl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ QtObject {
}
if (props.serviceType === "alternator" && props.productId === undefined) {
// Set a generic product id so that PageAlternator can show a valid page.
input._productId.setValue(0xB091)
input._productId.setValue(ProductInfo.ProductId_Alternator_Generic)
}
_createdObjects.push(input)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ QtObject {
}

onProductIdChanged: {
if (productId === 0xA3F0) {
if (productId === ProductInfo.ProductId_OrionXs_Min) {
initOrionXSValues()
}
}
Expand Down
2 changes: 1 addition & 1 deletion data/mock/config/BriefAndOverviewPageConfig.qml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ QtObject {
{
name: "Multiple alternators (including Orion XS), no AC/DC inputs",
acInputs: [emptyAcInput, emptyAcInput],
dcInputs: { types: [ { serviceType: "alternator", productId: 0xA3F0 }, { serviceType: "alternator" } ] },
dcInputs: { types: [ { serviceType: "alternator", productId: ProductInfo.ProductId_OrionXs_Min }, { serviceType: "alternator" } ] },
},
{
name: "Shore and Generator, Shore active",
Expand Down
9 changes: 1 addition & 8 deletions pages/settings/devicelist/ac-in/PageAcIn.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,13 @@ Page {

property string bindPrefix

// Genset productids
readonly property int fisherPandaProductId: 0xB040
readonly property int comApProductId: 0xB044
readonly property int dseProductId: 0xB046
readonly property int creProductId: 0xB048
readonly property int deifProductId: 0xB049

VeQuickItem {
id: productIdDataItem

uid: root.bindPrefix + "/ProductId"
onValueChanged: {
if (value !== undefined && modelLoader.status === Loader.Null) {
if ([fisherPandaProductId, comApProductId, dseProductId, creProductId, deifProductId].indexOf(value) > -1) {
if (ProductInfo.isGensetProduct(value)) {
modelLoader.sourceComponent = gensetModelComponent
} else {
modelLoader.sourceComponent = defaultModelComponent
Expand Down
9 changes: 2 additions & 7 deletions pages/settings/devicelist/ac-in/PageAcInModelDefault.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ ObjectModel {
property string bindPrefix
property int productId

// froniusInverterProductId should always be equal to VE_PROD_ID_PV_INVERTER_FRONIUS
readonly property int froniusInverterProductId: 0xA142
// carloGavazziEmProductId should always be equal to VE_PROD_ID_CARLO_GAVAZZI_EM
readonly property int carloGavazziEmProductId: 0xB002

readonly property var nrOfPhases: VeQuickItem {
uid: root.bindPrefix + "/NrOfPhases"
}

ListTextItem {
text: CommonWords.status
dataItem.uid: root.productId === froniusInverterProductId
dataItem.uid: root.productId === ProductInfo.ProductId_PvInverter_Fronius
? root.bindPrefix + "/StatusCode"
: ""
allowed: root.productId === froniusInverterProductId
allowed: root.productId === ProductInfo.ProductId_PvInverter_Fronius
secondaryText: Global.pvInverters.statusCodeToText(dataItem.value)
}

Expand Down
15 changes: 6 additions & 9 deletions pages/settings/devicelist/ac-in/PageAcInSetup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Page {

property string bindPrefix

property int em24ProductId: 0xb017
property int smappeeProductId: 0xb018

/*
* This is a bit weird, when changing the role in a cgwacs service, it will
* directly disconnect, without a reply or signal that the value changed. So
Expand Down Expand Up @@ -100,7 +97,7 @@ Page {
ListRadioButtonGroup {
//% "Phase configuration"
text: qsTrId("ac-in-setup_phase_configuration")
allowed: productId.value == em24ProductId
allowed: productId.value == ProductInfo.ProductId_EnergyMeter_Em24
dataItem.uid: root.bindPrefix + "/PhaseConfig"
enabled: !em24Locked()
optionModel: [
Expand All @@ -116,22 +113,22 @@ Page {
id: em24SwitchPos
//% "Switch position"
text: qsTrId("ac-in-setup_switch_position")
allowed: productId.value == em24ProductId
allowed: productId.value == ProductInfo.ProductId_EnergyMeter_Em24
dataItem.uid: root.bindPrefix + "/SwitchPos"
secondaryText: dataItem.isValid ? em24SwitchText(dataItem.value) : "--"
}

ListLabel {
text: qsTr("Set the switch in an unlocked position to modify the settings.")
allowed: productId.value == em24ProductId && em24Locked()
allowed: productId.value == ProductInfo.ProductId_EnergyMeter_Em24 && em24Locked()
}

/* Smappee settings */

ListRadioButtonGroup {
//% "Phase configuration"
text: qsTrId("ac-in-setup_phase_configuration")
allowed: productId.value == smappeeProductId
allowed: productId.value == ProductInfo.ProductId_PowerBox_Smappee
dataItem.uid: root.bindPrefix + "/PhaseConfig"
optionModel: [
//% "Single phase"
Expand All @@ -145,7 +142,7 @@ Page {

ListNavigationItem {
text: CommonWords.current_transformers
allowed: productId.value == smappeeProductId
allowed: productId.value == ProductInfo.ProductId_PowerBox_Smappee
onClicked: {
Global.pageManager.pushPage("/pages/settings/devicelist/ac-in/PageSmappeeCTList.qml",
{ "title": text, "bindPrefix": root.bindPrefix })
Expand All @@ -155,7 +152,7 @@ Page {
ListNavigationItem {
//% "Devices"
text: qsTrId("ac-in-setup_devices")
allowed: productId.value == smappeeProductId
allowed: productId.value == ProductInfo.ProductId_PowerBox_Smappee
onClicked: {
Global.pageManager.pushPage("/pages/settings/devicelist/ac-in/PageSmappeeDeviceList.qml",
{ "bindPrefix": root.bindPrefix })
Expand Down
4 changes: 2 additions & 2 deletions pages/settings/devicelist/battery/PageBattery.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Page {

property var battery

readonly property bool isFiamm48TL: productId.value === 0xB012
readonly property bool isParallelBms: productId.value === 0xA3E3
readonly property bool isFiamm48TL: productId.value === ProductInfo.ProductId_Battery_Fiamm48TL
readonly property bool isParallelBms: productId.value === ProductInfo.ProductId_Battery_ParallelBms

title: battery.name

Expand Down
20 changes: 1 addition & 19 deletions pages/settings/devicelist/dc-in/PageAlternator.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,13 @@ Page {

property string bindPrefix

// wakespeedProductId should always be equal to VE_PROD_ID_WAKESPEED_WS500
readonly property int wakespeedProductId: 0xB080
readonly property int arcoProductId: 0xB090
readonly property int mgAfcProductId: 0xB0F0
readonly property int genericProductId: 0xB091
readonly property int integrelProductId: 0xB092
readonly property int orionXsProductIdMin: 0xA3F0
readonly property int orionXsProductIdMax: 0xA3FF

function isRealAlternator(productId) {
const alternators = [arcoProductId, wakespeedProductId, mgAfcProductId, genericProductId, integrelProductId]
return alternators.indexOf(productId) > -1
}

function isOrionXsAlternator(productId) {
return productId >= orionXsProductIdMin && productId <= orionXsProductIdMax
}

VeQuickItem {
id: productIdDataItem

uid: root.bindPrefix + "/ProductId"
onValueChanged: {
if (value !== undefined && modelLoader.status === Loader.Null) {
if (isRealAlternator(value) || isOrionXsAlternator(value)) {
if (ProductInfo.isRealAlternatorProduct(value) || ProductInfo.isOrionXsProduct(value)) {
modelLoader.sourceComponent = alternatorModelComponent
} else {
modelLoader.sourceComponent = dcMeterModelComponent
Expand Down
94 changes: 94 additions & 0 deletions src/productinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
** Copyright (C) 2024 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

#ifndef VICTRON_VENUSOS_GUI_V2_PRODUCTINFO_H
#define VICTRON_VENUSOS_GUI_V2_PRODUCTINFO_H

#include <QQmlEngine>
#include <QObject>

namespace Victron {
namespace VenusOS {

class ProductInfo : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON

public:
explicit ProductInfo(QObject * = nullptr) {}
~ProductInfo() override {}

enum ProductId_Alternator {
ProductId_Alternator_Wakespeed = 0xB080, // VE_PROD_ID_WAKESPEED_WS500
ProductId_Alternator_Arco = 0xB090,
ProductId_Alternator_Generic = 0xB091,
ProductId_Alternator_Integrel = 0xB092,
ProductId_Alternator_MgAfc = 0xB0F0,
};
Q_ENUM(ProductId_Alternator)

enum ProductId_Battery {
ProductId_Battery_ParallelBms = 0xA3E3,
ProductId_Battery_Fiamm48TL = 0xB012,
};
Q_ENUM(ProductId_Battery)

enum ProductId_Genset {
ProductId_Genset_FischerPanda = 0xB040,
ProductId_Genset_ComAp = 0xB044,
ProductId_Genset_Dse = 0xB046,
ProductId_Genset_Cre = 0xB048,
ProductId_Genset_Deif = 0xB049,
};
Q_ENUM(ProductId_Genset)

enum ProductId_Misc {
ProductId_EnergyMeter_CarloGavazzi = 0xB002, // VE_PROD_ID_CARLO_GAVAZZI_EM
ProductId_EnergyMeter_Em24 = 0xB017,
ProductId_OrionXs_Min = 0xA3F0,
ProductId_OrionXs_Max = 0xA3FF,
ProductId_PowerBox_Smappee = 0xB018,
ProductId_PvInverter_Fronius = 0xA142, // VE_PROD_ID_PV_INVERTER_FRONIUS
ProductId_TankSensor_Generic = 0xA160,
};
Q_ENUM(ProductId_Misc)

Q_INVOKABLE bool isGensetProduct(int productId) {
switch (productId) {
case ProductId_Genset_FischerPanda:
case ProductId_Genset_ComAp:
case ProductId_Genset_Dse:
case ProductId_Genset_Cre:
case ProductId_Genset_Deif:
return true;
default:
return false;
};
}

Q_INVOKABLE bool isOrionXsProduct(int productId) {
return productId >= ProductId_OrionXs_Min && productId <= ProductId_OrionXs_Max;
}

Q_INVOKABLE bool isRealAlternatorProduct(int productId) {
switch (productId) {
case ProductId_Alternator_Arco:
case ProductId_Alternator_Wakespeed:
case ProductId_Alternator_MgAfc:
case ProductId_Alternator_Generic:
case ProductId_Alternator_Integrel:
return true;
default:
return false;
};
}
};

}
}

#endif // VICTRON_VENUSOS_GUI_V2_PRODUCTINFO_H

0 comments on commit 09a1485

Please sign in to comment.