Skip to content

Commit 972dbda

Browse files
Update rvc app integrate service area (project-chip#34887)
* 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 <commits@restyled.io>
1 parent 1b24bf6 commit 972dbda

10 files changed

+465
-41
lines changed

examples/rvc-app/README.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ must have a `"Name"` key that contains the command name. This name is shown in
2020
the state machine diagram above. Example
2121
`echo '{"Name": "Charged"}' > /tmp/chip_rvc_fifo_42`.
2222

23+
### `AreaComplete` message
24+
25+
This indicates that the area currently being serviced as indicated by the
26+
service area cluster is now complete.
27+
2328
### `ErrorEvent` message
2429

2530
The error event message requires the additional key `"Error"` which specifies
@@ -37,10 +42,14 @@ and setting up the testing environment, python tests can be executed with
3742
`./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>"`
3843

3944
**Note:** If the testing environment has not been commissioned with the RVC app,
40-
use chip-tool to switch on the commissioning window
41-
`chip-tool pairing open-commissioning-window`, and add the following flags to
42-
the `--script-args` above.
43-
`--commissioning-method on-network --discriminator XXXX --passcode XXXX`.
45+
46+
1. use chip-tool to switch on the commissioning window
47+
`out/debug/chip-tool pairing open-commissioning-window 0x1230 1 180 1000 42`
48+
2. Get the manual pairing code. This will look something like
49+
`Manual pairing code: [01073112097]`.
50+
3. Run any one of the tests with the `--commission-only` and `--manual-code`
51+
flags:
52+
`./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"`
4453

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

examples/rvc-app/linux/RvcAppCommandDelegate.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ void RvcAppCommandHandler::HandleCommand(intptr_t context)
8383
{
8484
self->OnActivityCompleteHandler();
8585
}
86+
else if (name == "AreaComplete")
87+
{
88+
self->OnAreaCompleteHandler();
89+
}
8690
else if (name == "ErrorEvent")
8791
{
8892
std::string error = self->mJsonValue["Error"].asString();
@@ -140,6 +144,11 @@ void RvcAppCommandHandler::OnActivityCompleteHandler()
140144
mRvcDevice->HandleActivityCompleteEvent();
141145
}
142146

147+
void RvcAppCommandHandler::OnAreaCompleteHandler()
148+
{
149+
mRvcDevice->HandleAreaCompletedEvent();
150+
}
151+
143152
void RvcAppCommandHandler::OnErrorEventHandler(const std::string & error)
144153
{
145154
mRvcDevice->HandleErrorEvent(error);

examples/rvc-app/linux/RvcAppCommandDelegate.h

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class RvcAppCommandHandler
5555

5656
void OnActivityCompleteHandler();
5757

58+
void OnAreaCompleteHandler();
59+
5860
void OnErrorEventHandler(const std::string & error);
5961

6062
void OnClearErrorHandler();

examples/rvc-app/rvc-common/include/rvc-device.h

+15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class RvcDevice
5959
mOperationalStateDelegate.SetPauseCallback(&RvcDevice::HandleOpStatePauseCallback, this);
6060
mOperationalStateDelegate.SetResumeCallback(&RvcDevice::HandleOpStateResumeCallback, this);
6161
mOperationalStateDelegate.SetGoHomeCallback(&RvcDevice::HandleOpStateGoHomeCallback, this);
62+
63+
mServiceAreaDelegate.SetIsSetSelectedAreasAllowedCallback(&RvcDevice::SaIsSetSelectedAreasAllowed, this);
64+
mServiceAreaDelegate.SetHandleSkipCurrentAreaCallback(&RvcDevice::SaHandleSkipCurrentArea, this);
65+
mServiceAreaDelegate.SetIsSupportedAreasChangeAllowedCallback(&RvcDevice::SaIsSupportedAreasChangeAllowed, this);
66+
mServiceAreaDelegate.SetIsSupportedMapChangeAllowedCallback(&RvcDevice::SaIsSupportedMapChangeAllowed, this);
6267
}
6368

6469
/**
@@ -97,6 +102,14 @@ class RvcDevice
97102
*/
98103
void HandleOpStateGoHomeCallback(Clusters::OperationalState::GenericOperationalError & err);
99104

105+
bool SaIsSetSelectedAreasAllowed(MutableCharSpan & statusText);
106+
107+
bool SaHandleSkipCurrentArea(uint32_t skippedArea, MutableCharSpan & skipStatusText);
108+
109+
bool SaIsSupportedAreasChangeAllowed();
110+
111+
bool SaIsSupportedMapChangeAllowed();
112+
100113
/**
101114
* Updates the state machine when the device becomes fully-charged.
102115
*/
@@ -112,6 +125,8 @@ class RvcDevice
112125

113126
void HandleActivityCompleteEvent();
114127

128+
void HandleAreaCompletedEvent();
129+
115130
/**
116131
* Sets the device to an error state with the error state ID matching the error name given.
117132
* @param error The error name. Could be one of UnableToStartOrResume, UnableToCompleteOperation, CommandInvalidInState,

examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h

+77
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ namespace Clusters {
2929

3030
class RvcDevice;
3131

32+
typedef bool (RvcDevice::*IsSetSelectedAreasAllowedCallback)(MutableCharSpan & statusText);
33+
typedef bool (RvcDevice::*HandleSkipCurrentAreaCallback)(uint32_t skippedArea, MutableCharSpan & skipStatusText);
34+
typedef bool (RvcDevice::*IsChangeAllowedSimpleCallback)();
35+
3236
namespace ServiceArea {
3337

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

47+
RvcDevice * mIsSetSelectedAreasAllowedDeviceInstance;
48+
IsSetSelectedAreasAllowedCallback mIsSetSelectedAreasAllowedCallback;
49+
RvcDevice * mHandleSkipCurrentAreaDeviceInstance;
50+
HandleSkipCurrentAreaCallback mHandleSkipCurrentAreaCallback;
51+
RvcDevice * mIsSupportedAreasChangeAllowedDeviceInstance;
52+
IsChangeAllowedSimpleCallback mIsSupportedAreasChangeAllowedCallback;
53+
RvcDevice * mIsSupportedMapChangeAllowedDeviceInstance;
54+
IsChangeAllowedSimpleCallback mIsSupportedMapChangeAllowedCallback;
55+
56+
// hardcoded values for SUPPORTED MAPS.
57+
const uint32_t supportedMapId_XX = 3;
58+
const uint32_t supportedMapId_YY = 245;
59+
60+
// hardcoded values for SUPPORTED AREAS.
61+
const uint32_t supportedAreaID_A = 7;
62+
const uint32_t supportedAreaID_B = 1234567;
63+
const uint32_t supportedAreaID_C = 10050;
64+
const uint32_t supportedAreaID_D = 0x88888888;
65+
66+
/**
67+
* Set the SupportedMaps and SupportedAreas where the SupportedMaps is not null.
68+
*/
69+
void SetMapTopology();
70+
71+
/**
72+
* Set the SupportedMaps and SupportedAreas where the SupportedMaps is null.
73+
*/
74+
void SetNoMapTopology();
75+
4376
public:
4477
CHIP_ERROR Init() override;
4578

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

114147
bool ClearProgress() override;
148+
149+
//*************************************************************************
150+
// RVC device callback setters
151+
152+
void SetIsSetSelectedAreasAllowedCallback(IsSetSelectedAreasAllowedCallback callback, RvcDevice * instance)
153+
{
154+
mIsSetSelectedAreasAllowedCallback = callback;
155+
mIsSetSelectedAreasAllowedDeviceInstance = instance;
156+
}
157+
158+
void SetHandleSkipCurrentAreaCallback(HandleSkipCurrentAreaCallback callback, RvcDevice * instance)
159+
{
160+
mHandleSkipCurrentAreaCallback = callback;
161+
mHandleSkipCurrentAreaDeviceInstance = instance;
162+
}
163+
164+
void SetIsSupportedAreasChangeAllowedCallback(IsChangeAllowedSimpleCallback callback, RvcDevice * instance)
165+
{
166+
mIsSupportedAreasChangeAllowedCallback = callback;
167+
mIsSupportedAreasChangeAllowedDeviceInstance = instance;
168+
}
169+
170+
void SetIsSupportedMapChangeAllowedCallback(IsChangeAllowedSimpleCallback callback, RvcDevice * instance)
171+
{
172+
mIsSupportedMapChangeAllowedCallback = callback;
173+
mIsSupportedMapChangeAllowedDeviceInstance = instance;
174+
}
175+
176+
//*************************************************************************
177+
// Helper methods for setting service area attributes.
178+
179+
/**
180+
* Sets the service area attributes at the start of a clean.
181+
* This includes the current area an progress attributes.
182+
*/
183+
void SetAttributesAtCleanStart();
184+
185+
/**
186+
* Go to the next area in the list of selected areas.
187+
* @param currentAreaOpState The operational state to be set in the Status field of the Progress attribute for the current area.
188+
* This can only be Completed or Skipped.
189+
* @param finished true if there are no more areas to clean an we should end the clean.
190+
*/
191+
void GoToNextArea(OperationalStatusEnum currentAreaOpState, bool & finished);
115192
};
116193

117194
} // namespace ServiceArea

examples/rvc-app/rvc-common/pics/rvc-app-pics-values

+28
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,31 @@ RVCRUNM.S.C01.Tx=1
5050
RVCRUNM.S.F00=0
5151
RVCRUNM.S.M.CAN_TEST_MODE_FAILURE=1
5252
RVCRUNM.S.M.CAN_MANUALLY_CONTROLLED=1
53+
54+
SEAR.S=1
55+
SEAR.S.F00=0
56+
SEAR.S.F01=1
57+
SEAR.S.F02=1
58+
SEAR.S.A0000=1
59+
SEAR.S.A0001=1
60+
SEAR.S.A0002=1
61+
SEAR.S.A0003=1
62+
SEAR.S.A0004=1
63+
SEAR.S.A0005=1
64+
SEAR.S.C00.Rsp=1
65+
SEAR.S.C02.Rsp=1
66+
SEAR.S.C01.Tx=1
67+
SEAR.S.C03.Tx=1
68+
SEAR.S.M.REMOVE_AREA=0
69+
SEAR.S.M.ADD_AREA=0
70+
SEAR.S.M.REMOVE_MAP=0
71+
SEAR.S.M.ADD_MAP=0
72+
SEAR.S.M.INVALID_STATE_FOR_SELECT_AREAS=1
73+
SEAR.S.M.VALID_STATE_FOR_SELECT_AREAS=1
74+
SEAR.S.M.SELECT_AREAS_WHILE_NON_IDLE=1
75+
SEAR.S.M.HAS_MANUAL_SELAREA_STATE_CONTROL=1
76+
SEAR.S.M.HAS_MANUAL_SKIP_STATE_CONTROL=1
77+
SEAR.S.M.INVALID_STATE_FOR_SKIP=1
78+
SEAR.S.M.NO_SELAREA_FOR_SKIP=1
79+
SEAR.S.M.VALID_STATE_FOR_SKIP=1
80+
SEAR.S.M.HAS_MANUAL_OPERATING_STATE_CONTROL=1

examples/rvc-app/rvc-common/src/rvc-device.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void RvcDevice::HandleRvcRunChangeToMode(uint8_t newMode, ModeBase::Commands::Ch
5252
mDocked = false;
5353
mRunModeInstance.UpdateCurrentMode(newMode);
5454
mOperationalStateInstance.SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
55+
mServiceAreaDelegate.SetAttributesAtCleanStart();
5556
response.status = to_underlying(ModeBase::StatusCode::kSuccess);
5657
return;
5758
}
@@ -161,6 +162,55 @@ void RvcDevice::HandleOpStateGoHomeCallback(Clusters::OperationalState::GenericO
161162
}
162163
}
163164

165+
bool RvcDevice::SaIsSetSelectedAreasAllowed(MutableCharSpan & statusText)
166+
{
167+
if (mOperationalStateInstance.GetCurrentOperationalState() == to_underlying(OperationalState::OperationalStateEnum::kRunning))
168+
{
169+
CopyCharSpanToMutableCharSpan("cannot set the Selected Areas while the device is running"_span, statusText);
170+
return false;
171+
}
172+
return true;
173+
}
174+
175+
bool RvcDevice::SaHandleSkipCurrentArea(uint32_t skippedArea, MutableCharSpan & skipStatusText)
176+
{
177+
if (mServiceAreaInstance.GetCurrentArea() != skippedArea)
178+
{
179+
// This device only supports skipping the current location.
180+
CopyCharSpanToMutableCharSpan("the skipped area does not match the current area"_span, skipStatusText);
181+
return false;
182+
}
183+
184+
if (mOperationalStateInstance.GetCurrentOperationalState() != to_underlying(OperationalState::OperationalStateEnum::kRunning))
185+
{
186+
// This device only accepts the skip are command while in the running state
187+
CopyCharSpanToMutableCharSpan("skip area is only accepted when the device is running"_span, skipStatusText);
188+
return false;
189+
}
190+
191+
bool finished;
192+
mServiceAreaDelegate.GoToNextArea(ServiceArea::OperationalStatusEnum::kSkipped, finished);
193+
194+
if (finished)
195+
{
196+
HandleActivityCompleteEvent();
197+
}
198+
199+
return true;
200+
}
201+
202+
bool RvcDevice::SaIsSupportedAreasChangeAllowed()
203+
{
204+
return mOperationalStateInstance.GetCurrentOperationalState() !=
205+
to_underlying(OperationalState::OperationalStateEnum::kRunning);
206+
}
207+
208+
bool RvcDevice::SaIsSupportedMapChangeAllowed()
209+
{
210+
return mOperationalStateInstance.GetCurrentOperationalState() !=
211+
to_underlying(OperationalState::OperationalStateEnum::kRunning);
212+
}
213+
164214
void RvcDevice::HandleChargedMessage()
165215
{
166216
if (mOperationalStateInstance.GetCurrentOperationalState() !=
@@ -258,6 +308,20 @@ void RvcDevice::HandleActivityCompleteEvent()
258308
mOperationalStateInstance.OnOperationCompletionDetected(0, a, b);
259309

260310
mOperationalStateInstance.SetOperationalState(to_underlying(RvcOperationalState::OperationalStateEnum::kSeekingCharger));
311+
312+
mServiceAreaInstance.SetCurrentArea(DataModel::NullNullable);
313+
mServiceAreaInstance.SetEstimatedEndTime(DataModel::NullNullable);
314+
}
315+
316+
void RvcDevice::HandleAreaCompletedEvent()
317+
{
318+
bool finished;
319+
mServiceAreaDelegate.GoToNextArea(ServiceArea::OperationalStatusEnum::kCompleted, finished);
320+
321+
if (finished)
322+
{
323+
HandleActivityCompleteEvent();
324+
}
261325
}
262326

263327
void RvcDevice::HandleErrorEvent(const std::string & error)
@@ -334,4 +398,9 @@ void RvcDevice::HandleResetMessage()
334398
mRunModeInstance.UpdateCurrentMode(RvcRunMode::ModeIdle);
335399
mOperationalStateInstance.SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));
336400
mCleanModeInstance.UpdateCurrentMode(RvcCleanMode::ModeQuick);
401+
402+
mServiceAreaInstance.ClearSelectedAreas();
403+
mServiceAreaInstance.ClearProgress();
404+
mServiceAreaInstance.SetCurrentArea(DataModel::NullNullable);
405+
mServiceAreaInstance.SetEstimatedEndTime(DataModel::NullNullable);
337406
}

0 commit comments

Comments
 (0)