Skip to content

Commit

Permalink
Merge branch 'master' into TC-CNET-4.13-correct-command-step2
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-marquez-csa authored Sep 3, 2024
2 parents c69fb90 + 91ac7b3 commit 3f9b728
Show file tree
Hide file tree
Showing 21 changed files with 768 additions and 268 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,6 @@ jobs:
mkdir -p out/trace_data
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/controller/python/test/test_scripts/mobile-device-test.py'
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/execute_python_tests.py --env-file /tmp/test_env.yaml --search-directory src/python_testing'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TestMatterTestingSupport.py" --script-args "--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TestSpecParsingSupport.py" --script-args "--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
scripts/run_in_python_env.sh out/venv './scripts/tests/TestTimeSyncTrustedTimeSourceRunner.py'
scripts/run_in_python_env.sh out/venv './src/python_testing/test_testing/test_TC_ICDM_2_1.py'
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestIdChecks.py'
Expand All @@ -528,6 +526,8 @@ jobs:
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_IDM_10_4.py'
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_TC_SC_7_1.py'
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/TestDecorators.py'
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestMatterTestingSupport.py'
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestSpecParsingSupport.py'
- name: Uploading core files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ endpoint 0 {
ram attribute clusterRevision default = 1;
}
}
endpoint 1 {
endpoint 13 {
device type ma_onofflight = 256, version 1;

binding cluster Binding;
Expand Down
4 changes: 2 additions & 2 deletions examples/chef/devices/rootnode_onofflight_bbs1b7IaOV.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3473,9 +3473,9 @@
"endpointTypeName": "Anonymous Endpoint Type",
"endpointTypeIndex": 1,
"profileId": 259,
"endpointId": 1,
"endpointId": 13,
"networkId": 0,
"parentEndpointIdentifier": null
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,47 @@ enum EVSEStateMachineEvent
class EvseSession
{
public:
EvseSession(EndpointId aEndpoint) { mEndpointId = aEndpoint; }
EvseSession() {}
/**
* @brief This function records the start time and provided energy meter values as part of the new session.
*
* @param endpointId - The endpoint to report the update on
* @param chargingMeterValue - The current value of the energy meter (charging) in mWh
* @param dischargingMeterValue - The current value of the energy meter (discharging) in mWh
*/
void StartSession(int64_t chargingMeterValue, int64_t dischargingMeterValue);
void StartSession(EndpointId endpointId, int64_t chargingMeterValue, int64_t dischargingMeterValue);

/**
* @brief This function updates the session information at the unplugged event
*
* @param endpointId - The endpoint to report the update on
* @param chargingMeterValue - The current value of the energy meter (charging) in mWh
* @param dischargingMeterValue - The current value of the energy meter (discharging) in mWh
*/
void StopSession(EndpointId endpointId, int64_t chargingMeterValue, int64_t dischargingMeterValue);

/**
* @brief This function updates the session Duration to allow read attributes to return latest values
*
* @param endpointId - The endpoint to report the update on
*/
void RecalculateSessionDuration();
void RecalculateSessionDuration(EndpointId endpointId);

/**
* @brief This function updates the EnergyCharged meter value
*
* @param endpointId - The endpoint to report the update on
* @param chargingMeterValue - The value of the energy meter (charging) in mWh
*/
void UpdateEnergyCharged(int64_t chargingMeterValue);
void UpdateEnergyCharged(EndpointId endpointId, int64_t chargingMeterValue);

/**
* @brief This function updates the EnergyDischarged meter value
*
* @param endpointId - The endpoint to report the update on
* @param dischargingMeterValue - The value of the energy meter (discharging) in mWh
*/
void UpdateEnergyDischarged(int64_t dischargingMeterValue);
void UpdateEnergyDischarged(EndpointId endpointId, int64_t dischargingMeterValue);

/* Public members - represent attributes in the cluster */
DataModel::Nullable<uint32_t> mSessionID;
Expand All @@ -91,8 +105,6 @@ class EvseSession
DataModel::Nullable<int64_t> mSessionEnergyDischarged;

private:
EndpointId mEndpointId = 0;

uint32_t mStartTime = 0; // Epoch_s - 0 means it hasn't started yet
int64_t mSessionEnergyChargedAtStart = 0; // in mWh - 0 means it hasn't been set yet
int64_t mSessionEnergyDischargedAtStart = 0; // in mWh - 0 means it hasn't been set yet
Expand Down Expand Up @@ -358,7 +370,7 @@ class EnergyEvseDelegate : public EnergyEvse::Delegate
DataModel::Nullable<CharSpan> mVehicleID;

/* Session Object */
EvseSession mSession = EvseSession(mEndpointId);
EvseSession mSession = EvseSession();

/* Helper variable to hold meter val since last EnergyTransferStarted event */
int64_t mMeterValueAtEnergyTransferStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ Status EnergyEvseDelegate::HandleEVPluggedInEvent()
if (mState == StateEnum::kNotPluggedIn)
{
/* EV was not plugged in - start a new session */
// TODO get energy meter readings
mSession.StartSession(0, 0);
// TODO get energy meter readings - #35370
mSession.StartSession(mEndpointId, 0, 0);
SendEVConnectedEvent();

/* Set the state to either PluggedInNoDemand or PluggedInDemand as indicated by mHwState */
Expand All @@ -694,6 +694,8 @@ Status EnergyEvseDelegate::HandleEVNotDetectedEvent()
SendEnergyTransferStoppedEvent(EnergyTransferStoppedReasonEnum::kOther);
}

// TODO get energy meter readings - #35370
mSession.StopSession(mEndpointId, 0, 0);
SendEVNotDetectedEvent();
SetState(StateEnum::kNotPluggedIn);
return Status::Success;
Expand All @@ -706,7 +708,7 @@ Status EnergyEvseDelegate::HandleEVNoDemandEvent()
/*
* EV was transferring current - EV decided to stop
*/
mSession.RecalculateSessionDuration();
mSession.RecalculateSessionDuration(mEndpointId);
SendEnergyTransferStoppedEvent(EnergyTransferStoppedReasonEnum::kEVStopped);
}
/* We must still be plugged in to get here - so no need to check if we are plugged in! */
Expand Down Expand Up @@ -1601,7 +1603,6 @@ DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetSessionID()
}
DataModel::Nullable<uint32_t> EnergyEvseDelegate::GetSessionDuration()
{
mSession.RecalculateSessionDuration();
return mSession.mSessionDuration;
}
DataModel::Nullable<int64_t> EnergyEvseDelegate::GetSessionEnergyCharged()
Expand All @@ -1626,10 +1627,11 @@ bool EnergyEvseDelegate::IsEvsePluggedIn()
/**
* @brief This function samples the start-time, and energy meter to hold the session info
*
* @param endpointId - The endpoint to report the update on
* @param chargingMeterValue - The current value of the energy meter (charging) in mWh
* @param dischargingMeterValue - The current value of the energy meter (discharging) in mWh
*/
void EvseSession::StartSession(int64_t chargingMeterValue, int64_t dischargingMeterValue)
void EvseSession::StartSession(EndpointId endpointId, int64_t chargingMeterValue, int64_t dischargingMeterValue)
{
/* Get Timestamp */
uint32_t chipEpoch = 0;
Expand Down Expand Up @@ -1661,26 +1663,42 @@ void EvseSession::StartSession(int64_t chargingMeterValue, int64_t dischargingMe
mSessionEnergyCharged = MakeNullable(static_cast<int64_t>(0));
mSessionEnergyDischarged = MakeNullable(static_cast<int64_t>(0));

MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, SessionID::Id);
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, SessionDuration::Id);
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, SessionEnergyCharged::Id);
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, SessionEnergyDischarged::Id);
MatterReportingAttributeChangeCallback(endpointId, EnergyEvse::Id, SessionID::Id);
MatterReportingAttributeChangeCallback(endpointId, EnergyEvse::Id, SessionDuration::Id);
MatterReportingAttributeChangeCallback(endpointId, EnergyEvse::Id, SessionEnergyCharged::Id);
MatterReportingAttributeChangeCallback(endpointId, EnergyEvse::Id, SessionEnergyDischarged::Id);

// Write values to persistent storage.
ConcreteAttributePath path = ConcreteAttributePath(mEndpointId, EnergyEvse::Id, SessionID::Id);
ConcreteAttributePath path = ConcreteAttributePath(endpointId, EnergyEvse::Id, SessionID::Id);
GetSafeAttributePersistenceProvider()->WriteScalarValue(path, mSessionID);

// TODO persist mStartTime
// TODO persist mSessionEnergyChargedAtStart
// TODO persist mSessionEnergyDischargedAtStart
}

/**
* @brief This function updates the session information at the unplugged event
*
* @param endpointId - The endpoint to report the update on
* @param chargingMeterValue - The current value of the energy meter (charging) in mWh
* @param dischargingMeterValue - The current value of the energy meter (discharging) in mWh
*/
void EvseSession::StopSession(EndpointId endpointId, int64_t chargingMeterValue, int64_t dischargingMeterValue)
{
RecalculateSessionDuration(endpointId);
UpdateEnergyCharged(endpointId, chargingMeterValue);
UpdateEnergyDischarged(endpointId, dischargingMeterValue);
}

/*---------------------- EvseSession functions --------------------------*/

/**
* @brief This function updates the session attrs to allow read attributes to return latest values
*
* @param endpointId - The endpoint to report the update on
*/
void EvseSession::RecalculateSessionDuration()
void EvseSession::RecalculateSessionDuration(EndpointId endpointId)
{
/* Get Timestamp */
uint32_t chipEpoch = 0;
Expand All @@ -1696,27 +1714,29 @@ void EvseSession::RecalculateSessionDuration()

uint32_t duration = chipEpoch - mStartTime;
mSessionDuration = MakeNullable(duration);
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, SessionDuration::Id);
MatterReportingAttributeChangeCallback(endpointId, EnergyEvse::Id, SessionDuration::Id);
}

/**
* @brief This function updates the EnergyCharged meter value
*
* @param endpointId - The endpoint to report the update on
* @param chargingMeterValue - The value of the energy meter (charging) in mWh
*/
void EvseSession::UpdateEnergyCharged(int64_t chargingMeterValue)
void EvseSession::UpdateEnergyCharged(EndpointId endpointId, int64_t chargingMeterValue)
{
mSessionEnergyCharged = MakeNullable(chargingMeterValue - mSessionEnergyChargedAtStart);
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, SessionEnergyCharged::Id);
MatterReportingAttributeChangeCallback(endpointId, EnergyEvse::Id, SessionEnergyCharged::Id);
}

/**
* @brief This function updates the EnergyDischarged meter value
*
* @param endpointId - The endpoint to report the update on
* @param dischargingMeterValue - The value of the energy meter (discharging) in mWh
*/
void EvseSession::UpdateEnergyDischarged(int64_t dischargingMeterValue)
void EvseSession::UpdateEnergyDischarged(EndpointId endpointId, int64_t dischargingMeterValue)
{
mSessionEnergyDischarged = MakeNullable(dischargingMeterValue - mSessionEnergyDischargedAtStart);
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, SessionEnergyDischarged::Id);
MatterReportingAttributeChangeCallback(endpointId, EnergyEvse::Id, SessionEnergyDischarged::Id);
}
31 changes: 31 additions & 0 deletions src/controller/python/ChipDeviceController-Discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
*
*/

#include <string>

#include <controller/CHIPDeviceController.h>
#include <controller/python/chip/native/PyChipError.h>
#include <json/json.h>
#include <lib/core/CHIPError.h>
#include <lib/core/TLV.h>
#include <lib/dnssd/Resolver.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

using namespace chip;

Expand Down Expand Up @@ -186,4 +190,31 @@ bool pychip_DeviceController_GetIPForDiscoveredDevice(Controller::DeviceCommissi
}
return false;
}

PyChipError pychip_CreateManualCode(uint16_t longDiscriminator, uint32_t passcode, char * manualCodeBuffer, size_t inBufSize,
size_t * outBufSize)
{
SetupPayload payload;
SetupDiscriminator discriminator;
discriminator.SetLongValue(longDiscriminator);
payload.discriminator = discriminator;
payload.setUpPINCode = passcode;
std::string setupManualCode;

*outBufSize = 0;
CHIP_ERROR err = ManualSetupPayloadGenerator(payload).payloadDecimalStringRepresentation(setupManualCode);
if (err == CHIP_NO_ERROR)
{
MutableCharSpan span(manualCodeBuffer, inBufSize);
// Plus 1 so we copy the null terminator
CopyCharSpanToMutableCharSpan(CharSpan(setupManualCode.c_str(), setupManualCode.length() + 1), span);
*outBufSize = span.size();
if (*outBufSize == 0)
{
err = CHIP_ERROR_NO_MEMORY;
}
}

return ToPyChipError(err);
}
}
16 changes: 16 additions & 0 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,19 @@ def InitGroupTestingData(self):
self.devCtrl)
).raise_on_error()

def CreateManualCode(self, discriminator: int, passcode: int) -> str:
""" Creates a standard flow manual code from the given discriminator and passcode."""
# 64 bytes is WAY more than required, but let's be safe
in_size = 64
out_size = c_size_t(0)
buf = create_string_buffer(in_size)
self._ChipStack.Call(
lambda: self._dmLib.pychip_CreateManualCode(discriminator, passcode, buf, in_size, pointer(out_size))
).raise_on_error()
if out_size.value == 0 or out_size.value > in_size:
raise MemoryError("Invalid output size for manual code")
return buf.value.decode()

# ----- Private Members -----
def _InitLib(self):
if self._dmLib is None:
Expand Down Expand Up @@ -1938,6 +1951,9 @@ def _InitLib(self):
self._dmLib.pychip_DeviceProxy_GetRemoteSessionParameters.restype = PyChipError
self._dmLib.pychip_DeviceProxy_GetRemoteSessionParameters.argtypes = [c_void_p, c_char_p]

self._dmLib.pychip_CreateManualCode.restype = PyChipError
self._dmLib.pychip_CreateManualCode.argtypes = [c_uint16, c_uint32, c_char_p, c_size_t, POINTER(c_size_t)]


class ChipDeviceController(ChipDeviceControllerBase):
''' The ChipDeviceCommissioner binding, named as ChipDeviceController
Expand Down
4 changes: 2 additions & 2 deletions src/python_testing/TC_CCTRL_2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

import chip.clusters as Clusters
from matter_testing_support import MatterBaseTest, TestStep, default_matter_test_main, has_cluster, per_endpoint_test
from matter_testing_support import MatterBaseTest, TestStep, default_matter_test_main, has_cluster, run_if_endpoint_matches
from mobly import asserts


Expand All @@ -27,7 +27,7 @@ def steps_TC_CCTRL_2_1(self) -> list[TestStep]:
TestStep(2, "Validate SupportedDeviceCategories is set accordingly based on MCORE.FS")]
return steps

@per_endpoint_test(has_cluster(Clusters.CommissionerControl))
@run_if_endpoint_matches(has_cluster(Clusters.CommissionerControl))
async def test_TC_CCTRL_2_1(self):
self.step(1)
is_fabric_sync_pics_enabled = self.check_pics("MCORE.FS")
Expand Down
4 changes: 2 additions & 2 deletions src/python_testing/TC_CCTRL_2_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from chip import ChipDeviceCtrl
from chip.interaction_model import InteractionModelError, Status
from matter_testing_support import (MatterBaseTest, TestStep, async_test_body, default_matter_test_main, has_cluster,
per_endpoint_test)
run_if_endpoint_matches)
from mobly import asserts


Expand Down Expand Up @@ -119,7 +119,7 @@ def steps_TC_CCTRL_2_2(self) -> list[TestStep]:

return steps

@per_endpoint_test(has_cluster(Clusters.CommissionerControl))
@run_if_endpoint_matches(has_cluster(Clusters.CommissionerControl))
async def test_TC_CCTRL_2_2(self):
self.is_ci = self.check_pics('PICS_SDK_CI_ONLY')

Expand Down
6 changes: 3 additions & 3 deletions src/python_testing/TC_CC_2_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# test-runner-run/run1/factoryreset: True
# test-runner-run/run1/quiet: True
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
# === END CI TEST ARGUMENTS ===

import logging
Expand All @@ -33,7 +33,7 @@
import chip.clusters as Clusters
from chip.clusters import ClusterObjects as ClusterObjects
from matter_testing_support import (ClusterAttributeChangeAccumulator, MatterBaseTest, TestStep, default_matter_test_main,
has_cluster, per_endpoint_test)
has_cluster, run_if_endpoint_matches)
from mobly import asserts
from test_plan_support import commission_if_required, if_feature_supported, read_attribute, verify_success

Expand Down Expand Up @@ -107,7 +107,7 @@ def entry_count_verification() -> str:
"The third entry in _reportedRemainingTimeValuesList_ is equal to 0")
]

@per_endpoint_test(has_cluster(Clusters.ColorControl))
@run_if_endpoint_matches(has_cluster(Clusters.ColorControl))
async def test_TC_CC_2_2(self):
gather_time = 20

Expand Down
Loading

0 comments on commit 3f9b728

Please sign in to comment.