Skip to content

Commit

Permalink
Add out-of-band msgs to add and remove Supported Areas and Maps (proj…
Browse files Browse the repository at this point in the history
…ect-chip#34930)

* update the status field of progress elements at the end of a clean.

* Added some style suggestions from the review of PR 34887.

* update the readme.

* Added a simple message to add a map.

* Added an out-of-band message to add a supported area.

* Added out-of-band messages to remove supported maps and supported areas.

* Updated the rvc-app PICS values. Updated TC-SEAR-1.2 to include the necessary out-of-band messages to run the test in CI.

* refactored to improve readability.

* Restyled by clang-format

* Restyled by prettier-markdown

* Removed oddly duplicated method.

* Fixed the json value conversion types.

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
hicklin and restyled-commits authored Aug 13, 2024
1 parent 8eccf68 commit ddf44dc
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 12 deletions.
37 changes: 36 additions & 1 deletion examples/rvc-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,42 @@ 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
### ServiceArea related messages

#### `AddMap` message

This message adds a map to the SupportedMaps attribute of the Service Area
cluster. This message requires the following extra keys.

- `MapId` This is an `int` setting the ID of the new map.
- `MapName` This is a `string` setting the name of the new map.

#### `AddArea` message

This message adds a new area to the SupportedAreas attribute of the Service Area
cluster. This message requires the following extra keys, most of which are
optional. Consult the `SupportedAreas` attribute spec for more information on
what are valid areas.

- `AreaId` This is an `int` setting the ID of the area.
- `MapId` This is an `int` sitting the map ID the area is associated with.
- `LocationName` This is a `string` setting the location's name.
- `FloorNumber` This is an `int` setting the floor number of the area.
- `AreaType` This is an `int` setting the area type tag.
- `LandmarkTag` This is an `int` setting the landmark tag.
- `PositianTag` This is an `int` setting the position tag.

#### `RemoveMap` message

This message removes a map with the given map ID. This message requires the
`int` key `MapId`.

#### `RemoveArea` message

This message removes an area with the given area ID. This message requires the
`int` key `AreaId`.

#### `AreaComplete` message

This indicates that the area currently being serviced as indicated by the
service area cluster is now complete.
Expand Down
88 changes: 88 additions & 0 deletions examples/rvc-app/linux/RvcAppCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
*/

#include "RvcAppCommandDelegate.h"
#include <app/data-model/Nullable.h>
#include <platform/PlatformManager.h>

#include "rvc-device.h"
#include <string>
#include <utility>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;

RvcAppCommandHandler * RvcAppCommandHandler::FromJSON(const char * json)
Expand Down Expand Up @@ -87,6 +89,25 @@ void RvcAppCommandHandler::HandleCommand(intptr_t context)
{
self->OnAreaCompleteHandler();
}
else if (name == "AddMap")
{
self->OnAddServiceAreaMap(self->mJsonValue);
}
else if (name == "AddArea")
{
VerifyOrExit(self->mJsonValue.isMember("AreaId"), ChipLogError(NotSpecified, "RVC App: AreaId key is missing"));
self->OnAddServiceAreaArea(self->mJsonValue);
}
else if (name == "RemoveMap")
{
VerifyOrExit(self->mJsonValue.isMember("MapId"), ChipLogError(NotSpecified, "RVC App: MapId key is missing"));
self->OnRemoveServiceAreaMap(self->mJsonValue["MapId"].asUInt());
}
else if (name == "RemoveArea")
{
VerifyOrExit(self->mJsonValue.isMember("AreaId"), ChipLogError(NotSpecified, "RVC App: AreaId key is missing"));
self->OnRemoveServiceAreaArea(self->mJsonValue["AreaId"].asUInt());
}
else if (name == "ErrorEvent")
{
std::string error = self->mJsonValue["Error"].asString();
Expand Down Expand Up @@ -149,6 +170,73 @@ void RvcAppCommandHandler::OnAreaCompleteHandler()
mRvcDevice->HandleAreaCompletedEvent();
}

void RvcAppCommandHandler::OnAddServiceAreaMap(Json::Value jsonValue)
{
// Find if self->mJsonValue has the MapId and MapName Keys
if (jsonValue.isMember("MapId") && jsonValue.isMember("MapName"))
{
uint32_t mapId = jsonValue["MapId"].asUInt();
std::string mapName = jsonValue["MapName"].asString();
mRvcDevice->HandleAddServiceAreaMap(mapId, CharSpan(mapName.data(), mapName.size()));
}
else
{
ChipLogError(NotSpecified, "RVC App: MapId and MapName keys are missing");
}
}

void RvcAppCommandHandler::OnAddServiceAreaArea(Json::Value jsonValue)
{
ServiceArea::AreaStructureWrapper area;
area.SetAreaId(jsonValue["AreaId"].asUInt());
if (jsonValue.isMember("MapId"))
{
area.SetMapId(jsonValue["MapId"].asUInt());
}

// Set the location info
if (jsonValue.isMember("LocationName") || jsonValue.isMember("FloorNumber") || jsonValue.isMember("AreaType"))
{
DataModel::Nullable<int16_t> floorNumber = DataModel::NullNullable;
if (jsonValue.isMember("FloorNumber"))
{
floorNumber = jsonValue["FloorNumber"].asInt();
}
DataModel::Nullable<Globals::AreaTypeTag> areaType = DataModel::NullNullable;
if (jsonValue.isMember("AreaType"))
{
areaType = Globals::AreaTypeTag(jsonValue["AreaType"].asUInt());
}
auto locationName = jsonValue["LocationName"].asString();

area.SetLocationInfo(CharSpan(locationName.data(), locationName.size()), floorNumber, areaType);
}

// Set landmark info
if (jsonValue.isMember("LandmarkTag"))
{
DataModel::Nullable<Globals::RelativePositionTag> relativePositionTag = DataModel::NullNullable;
if (jsonValue.isMember("PositionTag"))
{
relativePositionTag = Globals::RelativePositionTag(jsonValue["PositionTag"].asUInt());
}

area.SetLandmarkInfo(Globals::LandmarkTag(jsonValue["LandmarkTag"].asUInt()), relativePositionTag);
}

mRvcDevice->HandleAddServiceAreaArea(area);
}

void RvcAppCommandHandler::OnRemoveServiceAreaMap(uint32_t mapId)
{
mRvcDevice->HandleRemoveServiceAreaMap(mapId);
}

void RvcAppCommandHandler::OnRemoveServiceAreaArea(uint32_t areaId)
{
mRvcDevice->HandleRemoveServiceAreaArea(areaId);
}

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

void OnAreaCompleteHandler();

void OnAddServiceAreaMap(Json::Value jsonValue);

void OnAddServiceAreaArea(Json::Value jsonValue);

void OnRemoveServiceAreaMap(uint32_t mapId);

void OnRemoveServiceAreaArea(uint32_t areaId);

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

void OnClearErrorHandler();
Expand Down
8 changes: 8 additions & 0 deletions examples/rvc-app/rvc-common/include/rvc-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ class RvcDevice

void HandleAreaCompletedEvent();

void HandleAddServiceAreaMap(uint32_t mapId, const CharSpan & mapName);

void HandleAddServiceAreaArea(ServiceArea::AreaStructureWrapper & area);

void HandleRemoveServiceAreaMap(uint32_t mapId);

void HandleRemoveServiceAreaArea(uint32_t areaId);

/**
* 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
16 changes: 15 additions & 1 deletion examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class RvcServiceAreaDelegate : public Delegate
const uint32_t supportedAreaID_C = 10050;
const uint32_t supportedAreaID_D = 0x88888888;

public:
/**
* Set the SupportedMaps and SupportedAreas where the SupportedMaps is not null.
*/
Expand All @@ -73,7 +74,6 @@ class RvcServiceAreaDelegate : public Delegate
*/
void SetNoMapTopology();

public:
CHIP_ERROR Init() override;

// command support
Expand Down Expand Up @@ -101,6 +101,18 @@ class RvcServiceAreaDelegate : public Delegate

bool ClearSupportedAreas() override;

/**
* This is a more sophisticated way of ensuring that we all attributes are still valid when a supported area is removed.
* Rather than clearing all the attributes that depend on the supported aeras, we only remove the elements that point to
* the removed supported areas.
*/
void HandleSupportedAreasUpdated() override;

/**
* Note: Call the HandleSupportedAreasUpdated() method when finished removing supported areas.
*/
bool RemoveSupportedArea(uint32_t areaId);

//*************************************************************************
// Supported Maps accessors

Expand All @@ -118,6 +130,8 @@ class RvcServiceAreaDelegate : public Delegate

bool ClearSupportedMaps() override;

bool RemoveSupportedMap(uint32_t mapId);

//*************************************************************************
// Selected Areas accessors

Expand Down
8 changes: 4 additions & 4 deletions examples/rvc-app/rvc-common/pics/rvc-app-pics-values
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ 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.REMOVE_AREA=1
SEAR.S.M.ADD_AREA=1
SEAR.S.M.REMOVE_MAP=1
SEAR.S.M.ADD_MAP=1
SEAR.S.M.INVALID_STATE_FOR_SELECT_AREAS=1
SEAR.S.M.VALID_STATE_FOR_SELECT_AREAS=0
SEAR.S.M.SELECT_AREAS_WHILE_NON_IDLE=1
Expand Down
22 changes: 22 additions & 0 deletions examples/rvc-app/rvc-common/src/rvc-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,26 @@ void RvcDevice::HandleAreaCompletedEvent()
}
}

void RvcDevice::HandleAddServiceAreaMap(uint32_t mapId, const CharSpan & mapName)
{
mServiceAreaInstance.AddSupportedMap(mapId, mapName);
}

void RvcDevice::HandleAddServiceAreaArea(ServiceArea::AreaStructureWrapper & area)
{
mServiceAreaInstance.AddSupportedArea(area);
}

void RvcDevice::HandleRemoveServiceAreaMap(uint32_t mapId)
{
mServiceAreaDelegate.RemoveSupportedMap(mapId);
}

void RvcDevice::HandleRemoveServiceAreaArea(uint32_t areaId)
{
mServiceAreaDelegate.RemoveSupportedArea(areaId);
}

void RvcDevice::HandleErrorEvent(const std::string & error)
{
detail::Structs::ErrorStateStruct::Type err;
Expand Down Expand Up @@ -406,6 +426,8 @@ void RvcDevice::HandleResetMessage()
mServiceAreaInstance.ClearProgress();
mServiceAreaInstance.SetCurrentArea(DataModel::NullNullable);
mServiceAreaInstance.SetEstimatedEndTime(DataModel::NullNullable);

mServiceAreaDelegate.SetMapTopology();
}

void RvcDevice::UpdateServiceAreaProgressOnExit()
Expand Down
Loading

0 comments on commit ddf44dc

Please sign in to comment.