Skip to content

Commit

Permalink
Csg/test event 3.1 merge (#47)
Browse files Browse the repository at this point in the history
* Add simple xml rpc server to chip device controller

* Fix RPC Server address

* Remove message lowercasing on rpc

* Remove redundant code

* Place all rpc, csg changes at the bottom of the file

* Add todo comment

* Add extra newlines

* Move the csg additions to above the main method, cannot forward declare the methods

* Open qr_code_parse to dict api for RPC server

* Added development guide

* Added Setup and Testing guide for Real and Virtual BLE Accessories

* Updating Linux Lighting app docker file

* demarcator added in setup_payload, new line at the end

* Implemented Resolve method.

* Code review comments resolved.

* Implementation of ble-scan method with returning discovered devices (#18)

* Implemented ble_scan with peripheral list return.

* Update chip-device-ctrl.py

* Implementation of ZCL AddNetwork and EnableNetwork methods (#23)

RPC methods for Resolve and Zcl - AddNetwork and EnableNetwork implemented.

* Add the test_client sample program

* Updated Readme

* Added new lines

* Updated comments and readme

* Updated README

* Updated readme

* Update chip-device-ctrl.py

* Update chip-device-ctrl.py

* Csg/feature/get pase data (#30)

* Remove message lowercasing on rpc

* Remove redundant code

* Move the csg additions to above the main method, cannot forward declare the methods

* Remove message lowercasing on rpc

* Add debug prints and extra getpase command

* Add get pase session

* Initial PASE data fetch skeleton

* Add separate csg folder to hold constants and utils

* Add macros

* GetPaseData should return a yaml str.

* Add #defines, refactor into csg utilities, deserialize yaml

* Fix linter, comments, add copyright

* added get_pase_data RPC

* refactor methods and variables

* Add PASE Response parameters

* Debuggin additions

* Remove debugging additions

* Fix RPC to allow none values

* Remove pase from BLE call

* Added response, pake 1,2,3 parameters

* Remove merge artifact

* Remove unnecessary edits

* Add debug messages

* Remove debug messages

* Add todo

Co-authored-by: Mikael H. Moeller <mikaelhm@apple.com>

* Get fabric ID (#35)

* Get fabric ID

* Added Introspection for RPC methods (#39)

* Added Introspection for RPC methods

* Add pin code parsing

* Update setup payload return

* Remove extra spaces, extra newline

* Rename to pin_code_parse

* Add ble close

* Add build_sdk only script

* Remove extra space from argument assignment

* Add new line at the end

* Refactor test client build scripts

* Add new line

* Added resolve instruction and dockerfile fixes

* Implement a generic cluster RPC call

* Implement a generic cluster RPC call

* removing unwanted comment

* Addressing PR comments

* Addressing PR review comments

* correcting typing errors

* Update chip-device-ctrl.py

* Undo merge changes

Co-authored-by: Xiaolei Zhou <xiole@amazon.com>
Co-authored-by: SaileeG <SaileeG@github.com>
Co-authored-by: Nirav Shah <nirav_shah2@cable.comcast.com>
Co-authored-by: Nirav Shah <shah.niravk@gmail.com>
Co-authored-by: Mikael H. Moeller <mikaelhm@apple.com>
Co-authored-by: SaileeG <skorgaonkar@google.com>
Co-authored-by: SaileeG <69006439+SaileeG@users.noreply.github.com>
  • Loading branch information
8 people authored Jul 23, 2021
1 parent 75495a4 commit 7fe369e
Show file tree
Hide file tree
Showing 25 changed files with 946 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@
"ratio": "cpp",
"set": "cpp",
"stack": "cpp",
"regex": "cpp"
"regex": "cpp",
"compare": "cpp",
"concepts": "cpp",
"numeric": "cpp",
"random": "cpp",
"ranges": "cpp",
"variant": "cpp"
},
"files.eol": "\n",
"editor.formatOnSave": true,
Expand Down
7 changes: 7 additions & 0 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,13 @@ CHIP_ERROR DeviceCommissioner::Shutdown()
return CHIP_NO_ERROR;
}

#if CHIP_CSG_TEST_HARNESS //CSG_TRACE_BEGIN
PASESession *DeviceCommissioner::GetPASESession()
{
return &mPairingSession;
}
#endif //CSG_TRACE_END

CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParameters & params)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down
3 changes: 3 additions & 0 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, public SessionEst
*/
CHIP_ERROR Shutdown() override;

#if CHIP_CSG_TEST_HARNESS //CSG_TRACE_BEGON
PASESession *GetPASESession();
#endif //CSH_TRACE_END
// ----- Connection Management -----
/**
* @brief
Expand Down
16 changes: 16 additions & 0 deletions src/controller/python/ChipDeviceController-ScriptBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pychip_DeviceController_GetAddressAndPort(chip::Controller::DeviceCommissioner *
uint64_t maxAddressLen, uint16_t * outPort);
CHIP_ERROR pychip_DeviceController_GetFabricId(chip::Controller::DeviceCommissioner * devCtrl, uint64_t * outFabricId);

#if CHIP_CSG_TEST_HARNESS //CSG_TRACE_BEGIN
const char * pychip_DeviceController_GetPASEData(chip::Controller::DeviceCommissioner * devCtrl);
#endif //CSG_TRACE_END
// Rendezvous
CHIP_ERROR pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissioner * devCtrl, uint16_t discriminator,
uint32_t setupPINCode, chip::NodeId nodeid);
Expand Down Expand Up @@ -232,6 +235,19 @@ void pychip_DeviceController_SetLogFilter(uint8_t category)
#endif
}

#if CHIP_CSG_TEST_HARNESS //CSG_TRACE_BEGIN
const char * pychip_DeviceController_GetPASEData(chip::Controller::DeviceCommissioner * devCtrl)
{
PASESession *pase_session = devCtrl->GetPASESession();
std::map<std::string, std::map<std::string, std::string>> *paseTrace = pase_session->getPASETrace();
/*
TODO: Fix the string return memory leak
https://github.com/chip-csg/connectedhomeip/issues/32
*/
return yaml_string_for_map(paseTrace);
}
#endif //CSG_TRACE_END

CHIP_ERROR pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissioner * devCtrl, uint16_t discriminator,
uint32_t setupPINCode, chip::NodeId nodeid)
{
Expand Down
87 changes: 87 additions & 0 deletions src/controller/python/DEVELOPMENT_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Admin Flow

* CHIP SDK is maintained on a main branch `master` and release branches cut out for specific deliverables like `test_event2.2`
* CSG fork of the CHIP SDK is maintained with all existing main and release branches left untouched and pristine.
* All CSG specific changes should be done on newly created branches (with a `csg/` prefix) based on these release branches. eg: `test_event2.2` -> `csg/test_event2.2`
* Only admins on the repo have access to pull in changes from the upstream repo and update all local main and release branches using the following commands or equivalent:
```bash
git fetch upstream
git pull upstream
git push origin
```
* Once updated create a local version of the release branch with a csg prefix to add our changes. This branch will be the main merge target for all the PRs in this dev period.

# Development Flow

* Developers must create a branch with the following prefix `csg/fix` or `csg/feature` and submit their PRs to be merged to only the csg version of the release branch.
* If the admins upstream the branches, the developers must rebase their changes resolve their conflicts locally before submitting the PR
* Changes should be only additive, isolated and minimal, effort should be made to minimize the footprint on changes in the existing code.

# Building

* At the root directory:
```bash
source scripts/activate.sh
gn gen --args='chip_mdns="platform"' out/debug
ninja -C out/debug
```
* A .whl file is generate at `out/debug/controller/python/chip-0.0-cp37-abi3-linux_aarch64.whl`
* Copy this wheel file into the sample test client folder or into the test harness controller dockerfile folder.

# Testing with a real accessory
* You need to map the the system dbus to the docker dbus and run the docker with --privileged to be able to communicate with the real accessory
* Launch the a Docker container for chip device controller
Sample Docker File Used: https://docs.google.com/document/d/1-CMDrKEBGnHhSvAUMHH7ZSRDiKhuu2iwI-GYVUjI7DY/edit?resourcekey=0-VTKXbTk9YYQmdq10xa_f7g#heading=h.yzihj7w54f7a
docker run --name docker-python-controller -v /var/run/dbus:/var/run/dbus --privileged -it <Docker Image>

* From the Launched Python controller Docker container run the chip device controller with the BLE adapter parameter set to hci0
chip-device-ctrl --bluetooth-adapter=hci0
* You should now be able to run 'ble-scan' and 'connect -ble' actions from the chip device controller

# Testing with virtual BLE accessory
* For this you will need to create virtual BLE interfaces in the Test harness Docker dev Container
* You need to map the the system dbus to the docker dbus and run the docker with --privileged to be able to create the virtual ble interfaces using Bluez

* Setting up the Virtual BLE interfaces from Inside a docker container to be used by Other docker containers on the same host:
The bluez in ubuntu seems already the same as the version as CHIP repo, so we don't have to build bluetoothd by ourselves.
Bluetoothd will start on the host on boot, So we infact skip the bluetoothd setup

You still need to install bluez inside container

* Starting with a Clean Raspi host post Bootup:
ubuntu@ubuntu:~$ ps -a
PID TTY TIME CMD
2357 pts/0 00:00:00 ps

hci0: Type: Primary Bus: UART
BD Address: B8:27:EB:C4:E2:93 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:794 acl:0 sco:0 events:52 errors:0
TX bytes:2760 acl:0 sco:0 commands:52 errors:0

* Bringing up the Virtual Interfaces in Docker container 1:
Follow the instructions as mentioned on chip-device-controller documentation
```bash
cd third_party/bluez/repo/
./bootstrap
./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental --with-systemdsystemunitdir=/lib/systemd/system --with-systemduserunitdir=/usr/lib/systemd --enable-deprecated --enable-testing --enable-tools
make
emulator/btvirt -L -l<Number of Virtual BLE interfaces to be created> &
```
* Check hciconfig to confirm the said number of Virtual BLE interfaces are created

* Launch the a Docker container for chip Linux Lighting app
Sample Docker File used: https://docs.google.com/document/d/1xOizHV3ZeG_mu70CJWp-tN4xYoDxRhjEnwFKzhkIiC0/edit#heading=h.9hjqswbm7x50
docker run --name docker-chip-lighting-app -v /var/run/dbus:/var/run/dbus --privileged -it <Docker Image>

* Launch the Linux Lighting App in the docker-chip-lighting-app Docker container specifying the ble-device parameter as follows:
./chip-lighting-app --ble-device 1 --wifi

* Launch the Chip Device controller in a different container(ex: docker-python-controller docker container as mentioned above in Testing with real accessory)
* Run the chip device controller with --ble-adapter set to one of the virtual BLE interfaces(ex: hci2 this interface has to be different then one used by the virtual BLE accessory) as follows:
chip-device-ctrl --bluetooth-adapter=hci2
* You should now be able to run 'ble-scan' and 'connect -ble' actions from the chip device controller

# Testing with Hybrid setup with Real and Virtual BLE accessories
* When we have a real accessory along with a virtual ble accessory you will be able to interact/control with only one accessory at a time. In such Hybrid Setup you will have to switch between BLE adapters in chip-device-controller to handle respective accessories.
* To switch between ble interfaces run "ble-adapter-select <adapter number example: hci1 to scan and connect to virtual accessory and hci0 to scan and connect to real accessory>"
Loading

0 comments on commit 7fe369e

Please sign in to comment.