Skip to content

Commit

Permalink
Update rvc app integrate service area (#34887)
Browse files Browse the repository at this point in the history
* Updated the golabl data type's XMLs, removing the cluster entries.

* Zap generated after XML update.

* Fixed namespaces used of global structs.

* Restyled by clang-format

* Renamed LocationInfoStruct to AreaInfoStruct.

* Zap generated after XML update.

* Renamed LocationStruct to AreaStruct and its LocationID and LocationDesc fields.

* Zap generated after XML update.

* Updated SDK and example code to match the new naming.

* Updated the ProgressStruct's LocationID name to AreaID.

* Zap generated after XML update.

* Updated the SDK code following name changes.

* Updated the SelectLocationsStatus and SkipLocationStatus enum names and some of their enums.

* Zap generated after XML update.

* Updated the SelectLocationsStatus and SkipCurrentLocationStatus names and their enum names.

* Updated the names of the SupportedLocations, SelectedLocations and CurrentLocation attributes.

* Zap generated after XML update.

* Updated the changed names in the SDK.

* Updated the service area command names in XML.

* Zap generated after XML update.

* Updated the service area command names in the SDK.

* Updated the rvc-example zap file.

* Refactored LocationStructureWrapper to AreaStructureWrapper.

* Restyled by clang-format

* Regenerated zap files due to changes upsteram.

* Removed unused generated file.

* Updated the Service Area XML marking previously nullabel attributes as not-nullable.

* Zap generated after XML update.

* Updated the attribute encoding and some server logic following the romoval of the nullable quality for some attributes.

* Explicitly set the Service Area version.

* Zap generated after XML update.

* Updated the service area features in the XML to match the current spec.

* Zap generated after XML update.

* Updated the SupportedArea validation logic as if the MAPS feature is not supported, the Delegate may choose not to implement map related methods.

* Change the type of the MapID to uint32 to match the spec.

* Added the SkippedArea arg to the SkipArea command.

* Zap generated after XML update.

* Updated the Service Area server code to handle the new SkippedArea command arg.

* Updated the service area XML to match the current spec. This includes the addition of the LandmarkInfoStruct and updates of AreaInfoStruct, SelectAreasStatus.

* Zap generated after XML update.

* Updated SDK server code and rvc-example after changes to the XML.

* Restyled by whitespace

* added vector include.

* spacing changes form zap regen.

* Fixed minor mistake during merge.

* Restyled by clang-format

* Applied suggestions from review.

* Restyled by whitespace

* Updated the LondmarkInfoSturct PositionTag type.

* Zap generated after XML update.

* Fixed SDK following update to the position type.

* Restyled by clang-format

* Updated the AeraStructWrapper to not contain methods with a large number of params. Updated some relate Instance and Delegate methods.

* Restyled by whitespace

* Restyled by clang-format

* Missed a submudule update.

* Made the setters reture a ref to the sturct to allow chaining.

* simplified the = oporator and add the == operator.

* Restyled by clang-format

* Added methods to set the SupportedMaps and SupproctedAreas.

* Updated the RVC app to provide a way to defined service area methods that interacte with other clusters in the RvcDevice class.

* Fixed typo.

* minor change to get restyler going.

* Restyled by clang-format

* Fixed status text referance issue.

* Fixed issue casued by a change in the way that registrations are made.

* Fixed styling and minor bug in IsValidSupportedArea.

* Implemented the IsValidSelectAreasSet method.

* implemented SaHandleSkipCurrentArea.

* Restyled by clang-format

* Added methods to updated the service area current area and progress attributes when the device starts operating.

* Updated the handle skip area method to use the GoToNextArea method.

* Added the AreaComplete out-of-band message.

* updated the reset evet handler to reset the service area attributes.

* minor shifing of responsibilites.

* Restyled by clang-format

* reverted to adding the PID to the fifo name.

* Updated readme and pics files.

* Restyled by prettier-markdown

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 5, 2024
1 parent ac8eabd commit 23f5ba3
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 41 deletions.
17 changes: 13 additions & 4 deletions examples/rvc-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ must have a `"Name"` key that contains the command name. This name is shown in
the state machine diagram above. Example
`echo '{"Name": "Charged"}' > /tmp/chip_rvc_fifo_42`.

### `AreaComplete` message

This indicates that the area currently being serviced as indicated by the
service area cluster is now complete.

### `ErrorEvent` message

The error event message requires the additional key `"Error"` which specifies
Expand All @@ -37,10 +42,14 @@ and setting up the testing environment, python tests can be executed with
`./scripts/tests/run_python_test.py --script src/python_testing/<script_name>.py --script-args "--storage-path admin_storage.json --PICS examples/rvc-app/rvc-common/pics/RVC_App_Test_Plan.txt --int-arg <PIXIT_Definitions:1>"`

**Note:** If the testing environment has not been commissioned with the RVC app,
use chip-tool to switch on the commissioning window
`chip-tool pairing open-commissioning-window`, and add the following flags to
the `--script-args` above.
`--commissioning-method on-network --discriminator XXXX --passcode XXXX`.

1. use chip-tool to switch on the commissioning window
`out/debug/chip-tool pairing open-commissioning-window 0x1230 1 180 1000 42`
2. Get the manual pairing code. This will look something like
`Manual pairing code: [01073112097]`.
3. Run any one of the tests with the `--commission-only` and `--manual-code`
flags:
`./scripts/tests/run_python_test.py --script src/python_testing/TC_RVCCLEANM_1_2.py --script-args "--commissioning-method on-network --manual-code 01073112097 --commission-only"`

Below are the PIXIT definitions required for the different python tests.

Expand Down
9 changes: 9 additions & 0 deletions examples/rvc-app/linux/RvcAppCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ void RvcAppCommandHandler::HandleCommand(intptr_t context)
{
self->OnActivityCompleteHandler();
}
else if (name == "AreaComplete")
{
self->OnAreaCompleteHandler();
}
else if (name == "ErrorEvent")
{
std::string error = self->mJsonValue["Error"].asString();
Expand Down Expand Up @@ -140,6 +144,11 @@ void RvcAppCommandHandler::OnActivityCompleteHandler()
mRvcDevice->HandleActivityCompleteEvent();
}

void RvcAppCommandHandler::OnAreaCompleteHandler()
{
mRvcDevice->HandleAreaCompletedEvent();
}

void RvcAppCommandHandler::OnErrorEventHandler(const std::string & error)
{
mRvcDevice->HandleErrorEvent(error);
Expand Down
2 changes: 2 additions & 0 deletions examples/rvc-app/linux/RvcAppCommandDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class RvcAppCommandHandler

void OnActivityCompleteHandler();

void OnAreaCompleteHandler();

void OnErrorEventHandler(const std::string & error);

void OnClearErrorHandler();
Expand Down
15 changes: 15 additions & 0 deletions examples/rvc-app/rvc-common/include/rvc-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class RvcDevice
mOperationalStateDelegate.SetPauseCallback(&RvcDevice::HandleOpStatePauseCallback, this);
mOperationalStateDelegate.SetResumeCallback(&RvcDevice::HandleOpStateResumeCallback, this);
mOperationalStateDelegate.SetGoHomeCallback(&RvcDevice::HandleOpStateGoHomeCallback, this);

mServiceAreaDelegate.SetIsSetSelectedAreasAllowedCallback(&RvcDevice::SaIsSetSelectedAreasAllowed, this);
mServiceAreaDelegate.SetHandleSkipCurrentAreaCallback(&RvcDevice::SaHandleSkipCurrentArea, this);
mServiceAreaDelegate.SetIsSupportedAreasChangeAllowedCallback(&RvcDevice::SaIsSupportedAreasChangeAllowed, this);
mServiceAreaDelegate.SetIsSupportedMapChangeAllowedCallback(&RvcDevice::SaIsSupportedMapChangeAllowed, this);
}

/**
Expand Down Expand Up @@ -97,6 +102,14 @@ class RvcDevice
*/
void HandleOpStateGoHomeCallback(Clusters::OperationalState::GenericOperationalError & err);

bool SaIsSetSelectedAreasAllowed(MutableCharSpan & statusText);

bool SaHandleSkipCurrentArea(uint32_t skippedArea, MutableCharSpan & skipStatusText);

bool SaIsSupportedAreasChangeAllowed();

bool SaIsSupportedMapChangeAllowed();

/**
* Updates the state machine when the device becomes fully-charged.
*/
Expand All @@ -112,6 +125,8 @@ class RvcDevice

void HandleActivityCompleteEvent();

void HandleAreaCompletedEvent();

/**
* Sets the device to an error state with the error state ID matching the error name given.
* @param error The error name. Could be one of UnableToStartOrResume, UnableToCompleteOperation, CommandInvalidInState,
Expand Down
77 changes: 77 additions & 0 deletions examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ namespace Clusters {

class RvcDevice;

typedef bool (RvcDevice::*IsSetSelectedAreasAllowedCallback)(MutableCharSpan & statusText);
typedef bool (RvcDevice::*HandleSkipCurrentAreaCallback)(uint32_t skippedArea, MutableCharSpan & skipStatusText);
typedef bool (RvcDevice::*IsChangeAllowedSimpleCallback)();

namespace ServiceArea {

class RvcServiceAreaDelegate : public Delegate
Expand All @@ -40,6 +44,35 @@ class RvcServiceAreaDelegate : public Delegate
std::vector<uint32_t> mSelectedAreas;
std::vector<ServiceArea::Structs::ProgressStruct::Type> mProgressList;

RvcDevice * mIsSetSelectedAreasAllowedDeviceInstance;
IsSetSelectedAreasAllowedCallback mIsSetSelectedAreasAllowedCallback;
RvcDevice * mHandleSkipCurrentAreaDeviceInstance;
HandleSkipCurrentAreaCallback mHandleSkipCurrentAreaCallback;
RvcDevice * mIsSupportedAreasChangeAllowedDeviceInstance;
IsChangeAllowedSimpleCallback mIsSupportedAreasChangeAllowedCallback;
RvcDevice * mIsSupportedMapChangeAllowedDeviceInstance;
IsChangeAllowedSimpleCallback mIsSupportedMapChangeAllowedCallback;

// hardcoded values for SUPPORTED MAPS.
const uint32_t supportedMapId_XX = 3;
const uint32_t supportedMapId_YY = 245;

// hardcoded values for SUPPORTED AREAS.
const uint32_t supportedAreaID_A = 7;
const uint32_t supportedAreaID_B = 1234567;
const uint32_t supportedAreaID_C = 10050;
const uint32_t supportedAreaID_D = 0x88888888;

/**
* Set the SupportedMaps and SupportedAreas where the SupportedMaps is not null.
*/
void SetMapTopology();

/**
* Set the SupportedMaps and SupportedAreas where the SupportedMaps is null.
*/
void SetNoMapTopology();

public:
CHIP_ERROR Init() override;

Expand Down Expand Up @@ -112,6 +145,50 @@ class RvcServiceAreaDelegate : public Delegate
const ServiceArea::Structs::ProgressStruct::Type & modifiedProgressElement) override;

bool ClearProgress() override;

//*************************************************************************
// RVC device callback setters

void SetIsSetSelectedAreasAllowedCallback(IsSetSelectedAreasAllowedCallback callback, RvcDevice * instance)
{
mIsSetSelectedAreasAllowedCallback = callback;
mIsSetSelectedAreasAllowedDeviceInstance = instance;
}

void SetHandleSkipCurrentAreaCallback(HandleSkipCurrentAreaCallback callback, RvcDevice * instance)
{
mHandleSkipCurrentAreaCallback = callback;
mHandleSkipCurrentAreaDeviceInstance = instance;
}

void SetIsSupportedAreasChangeAllowedCallback(IsChangeAllowedSimpleCallback callback, RvcDevice * instance)
{
mIsSupportedAreasChangeAllowedCallback = callback;
mIsSupportedAreasChangeAllowedDeviceInstance = instance;
}

void SetIsSupportedMapChangeAllowedCallback(IsChangeAllowedSimpleCallback callback, RvcDevice * instance)
{
mIsSupportedMapChangeAllowedCallback = callback;
mIsSupportedMapChangeAllowedDeviceInstance = instance;
}

//*************************************************************************
// Helper methods for setting service area attributes.

/**
* Sets the service area attributes at the start of a clean.
* This includes the current area an progress attributes.
*/
void SetAttributesAtCleanStart();

/**
* Go to the next area in the list of selected areas.
* @param currentAreaOpState The operational state to be set in the Status field of the Progress attribute for the current area.
* This can only be Completed or Skipped.
* @param finished true if there are no more areas to clean an we should end the clean.
*/
void GoToNextArea(OperationalStatusEnum currentAreaOpState, bool & finished);
};

} // namespace ServiceArea
Expand Down
28 changes: 28 additions & 0 deletions examples/rvc-app/rvc-common/pics/rvc-app-pics-values
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,31 @@ RVCRUNM.S.C01.Tx=1
RVCRUNM.S.F00=0
RVCRUNM.S.M.CAN_TEST_MODE_FAILURE=1
RVCRUNM.S.M.CAN_MANUALLY_CONTROLLED=1

SEAR.S=1
SEAR.S.F00=0
SEAR.S.F01=1
SEAR.S.F02=1
SEAR.S.A0000=1
SEAR.S.A0001=1
SEAR.S.A0002=1
SEAR.S.A0003=1
SEAR.S.A0004=1
SEAR.S.A0005=1
SEAR.S.C00.Rsp=1
SEAR.S.C02.Rsp=1
SEAR.S.C01.Tx=1
SEAR.S.C03.Tx=1
SEAR.S.M.REMOVE_AREA=0
SEAR.S.M.ADD_AREA=0
SEAR.S.M.REMOVE_MAP=0
SEAR.S.M.ADD_MAP=0
SEAR.S.M.INVALID_STATE_FOR_SELECT_AREAS=1
SEAR.S.M.VALID_STATE_FOR_SELECT_AREAS=1
SEAR.S.M.SELECT_AREAS_WHILE_NON_IDLE=1
SEAR.S.M.HAS_MANUAL_SELAREA_STATE_CONTROL=1
SEAR.S.M.HAS_MANUAL_SKIP_STATE_CONTROL=1
SEAR.S.M.INVALID_STATE_FOR_SKIP=1
SEAR.S.M.NO_SELAREA_FOR_SKIP=1
SEAR.S.M.VALID_STATE_FOR_SKIP=1
SEAR.S.M.HAS_MANUAL_OPERATING_STATE_CONTROL=1
69 changes: 69 additions & 0 deletions examples/rvc-app/rvc-common/src/rvc-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void RvcDevice::HandleRvcRunChangeToMode(uint8_t newMode, ModeBase::Commands::Ch
mDocked = false;
mRunModeInstance.UpdateCurrentMode(newMode);
mOperationalStateInstance.SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
mServiceAreaDelegate.SetAttributesAtCleanStart();
response.status = to_underlying(ModeBase::StatusCode::kSuccess);
return;
}
Expand Down Expand Up @@ -161,6 +162,55 @@ void RvcDevice::HandleOpStateGoHomeCallback(Clusters::OperationalState::GenericO
}
}

bool RvcDevice::SaIsSetSelectedAreasAllowed(MutableCharSpan & statusText)
{
if (mOperationalStateInstance.GetCurrentOperationalState() == to_underlying(OperationalState::OperationalStateEnum::kRunning))
{
CopyCharSpanToMutableCharSpan("cannot set the Selected Areas while the device is running"_span, statusText);
return false;
}
return true;
}

bool RvcDevice::SaHandleSkipCurrentArea(uint32_t skippedArea, MutableCharSpan & skipStatusText)
{
if (mServiceAreaInstance.GetCurrentArea() != skippedArea)
{
// This device only supports skipping the current location.
CopyCharSpanToMutableCharSpan("the skipped area does not match the current area"_span, skipStatusText);
return false;
}

if (mOperationalStateInstance.GetCurrentOperationalState() != to_underlying(OperationalState::OperationalStateEnum::kRunning))
{
// This device only accepts the skip are command while in the running state
CopyCharSpanToMutableCharSpan("skip area is only accepted when the device is running"_span, skipStatusText);
return false;
}

bool finished;
mServiceAreaDelegate.GoToNextArea(ServiceArea::OperationalStatusEnum::kSkipped, finished);

if (finished)
{
HandleActivityCompleteEvent();
}

return true;
}

bool RvcDevice::SaIsSupportedAreasChangeAllowed()
{
return mOperationalStateInstance.GetCurrentOperationalState() !=
to_underlying(OperationalState::OperationalStateEnum::kRunning);
}

bool RvcDevice::SaIsSupportedMapChangeAllowed()
{
return mOperationalStateInstance.GetCurrentOperationalState() !=
to_underlying(OperationalState::OperationalStateEnum::kRunning);
}

void RvcDevice::HandleChargedMessage()
{
if (mOperationalStateInstance.GetCurrentOperationalState() !=
Expand Down Expand Up @@ -258,6 +308,20 @@ void RvcDevice::HandleActivityCompleteEvent()
mOperationalStateInstance.OnOperationCompletionDetected(0, a, b);

mOperationalStateInstance.SetOperationalState(to_underlying(RvcOperationalState::OperationalStateEnum::kSeekingCharger));

mServiceAreaInstance.SetCurrentArea(DataModel::NullNullable);
mServiceAreaInstance.SetEstimatedEndTime(DataModel::NullNullable);
}

void RvcDevice::HandleAreaCompletedEvent()
{
bool finished;
mServiceAreaDelegate.GoToNextArea(ServiceArea::OperationalStatusEnum::kCompleted, finished);

if (finished)
{
HandleActivityCompleteEvent();
}
}

void RvcDevice::HandleErrorEvent(const std::string & error)
Expand Down Expand Up @@ -334,4 +398,9 @@ void RvcDevice::HandleResetMessage()
mRunModeInstance.UpdateCurrentMode(RvcRunMode::ModeIdle);
mOperationalStateInstance.SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));
mCleanModeInstance.UpdateCurrentMode(RvcCleanMode::ModeQuick);

mServiceAreaInstance.ClearSelectedAreas();
mServiceAreaInstance.ClearProgress();
mServiceAreaInstance.SetCurrentArea(DataModel::NullNullable);
mServiceAreaInstance.SetEstimatedEndTime(DataModel::NullNullable);
}
Loading

0 comments on commit 23f5ba3

Please sign in to comment.