Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock senso #138

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Mock senso #138

wants to merge 5 commits into from

Conversation

krksgbr
Copy link
Contributor

@krksgbr krksgbr commented May 17, 2024

This extends the replay tool into a utility that can mock a Senso's functions more broadly. It retains the replay tool's original functionality, so it can still replay both Senso and Senso Flex recordings. Additional functionality:

  • Simulate DFU mode and firmware updates
  • Respond to device info and status with configurable information
  • Respond to multi-block commands

The motivation was to not have to be completely dependent on the controller board while working on the firmware update feature, but I think it can be useful for testing any hardware related work on the client.

Usage:

nix develop
mock-senso --help

I mostly tested on macOS, so I'm curious to see how well it works on Linux.

During the limited testing I did on nixOS, I noticed there can be issues with discovering the mock service. Sometimes the go library that the driver uses for mdns discovery returns the service entry without any ip addresses causing the entry to get thrown away. I think it's an issue with the go library, because avahi-browse has no trouble discovering the service. This only seems to happen on linux and the mock-senso. I haven't seen this on macOS or with the development controller board.

Checklist

  • [] Changelog updated
  • Code documented

krksgbr added 5 commits May 17, 2024 15:42
This builds on the existing replay tool, extending it with a richer
set of features to simulate a Senso:

- Simulate DFU mode and firmware updates
- Respond to device info and status with configurable information
- Respond to multi-block commands

Like the replayer, it still supports replaying flex and senso recordings.
By using the tftp port announced in the mDNS service entry, we
can allow the mock senso to expose its tftp server on port 6969.
This is necessary, because binding to the standard tftp port (69)
would require root privileges.
Remove scripts and dependencies that have been moved to the `mock-senso`
project.
Most of the documentation is removed from the Readme, as `mock-senso --help` provides both documentation and usage examples.
@krksgbr krksgbr requested a review from guyonvarch May 17, 2024 13:53
@krksgbr krksgbr added the reviewable Ready for initial or iterative review. label May 17, 2024
@guyonvarch
Copy link
Member

I am running the driver and mock-senso, but I can’t connect with Play.

$ mock-senso mock-senso/recordings/senso/simple.dat
Starting control mode
Senso in control mode at 0.0.0.0:55567
Published mDNS service {
  name: 'Mock Senso',
  type: '_sensoControl._tcp',
  txt: { ser_no: '10-00000000', mode: 'Application' },
  port: 55567
}

This is working with --flex to simulate a Senso flex though.

@guyonvarch guyonvarch added details needed Further information requested to better evaluate changes and removed reviewable Ready for initial or iterative review. labels May 22, 2024
@guyonvarch
Copy link
Member

The driver is producing these logs:

$ bin/dividat-driver
INFO[0000] Dividat Driver starting                       arch=amd64 machineId=4417cc08c9fa15f91aa47037b1e45a047550b3cddb91cff5489a5794b71eab22 os=linux version=2.3.0-110-gf0cdf97
INFO[0000] Starting HTTP server.                         arch=amd64 machineId=4417cc08c9fa15f91aa47037b1e45a047550b3cddb91cff5489a5794b71eab22 os=linux package=server port=8382 version=2.3.0-110-gf0cdf97
INFO[0026] WebSocket connection opened                   arch=amd64 clientAddress="127.0.0.1:49856" machineId=4417cc08c9fa15f91aa47037b1e45a047550b3cddb91cff5489a5794b71eab22 os=linux package=senso userAgent="Mozilla/5.0 (Windows NT 10.0; rv:125.0) Gecko/20100101 Firefox/125.0" version=2.3.0-110-gf0cdf97
INFO[0026] WebSocket connection opened                   arch=amd64 clientAddress="127.0.0.1:49868" machineId=4417cc08c9fa15f91aa47037b1e45a047550b3cddb91cff5489a5794b71eab22 os=linux package=flex userAgent="Mozilla/5.0 (Windows NT 10.0; rv:125.0) Gecko/20100101 Firefox/125.0" version=2.3.0-110-gf0cdf97
DEBU[0026] Received command.                             arch=amd64 clientAddress="127.0.0.1:49856" command=GetStatus machineId=4417cc08c9fa15f91aa47037b1e45a047550b3cddb91cff5489a5794b71eab22 os=linux package=senso userAgent="Mozilla/5.0 (Windows NT 10.0; rv:125.0) Gecko/20100101 Firefox/125.0" version=2.3.0-110-gf0cdf97
DEBU[0026] Received command.                             arch=amd64 clientAddress="127.0.0.1:49856" command=Discover machineId=4417cc08c9fa15f91aa47037b1e45a047550b3cddb91cff5489a5794b71eab22 os=linux package=senso userAgent="Mozilla/5.0 (Windows NT 10.0; rv:125.0) Gecko/20100101 Firefox/125.0" version=2.3.0-110-gf0cdf97
INFO[0030] Monitoring runtime.                           arch=amd64 heapAlloc=1124040 machineId=4417cc08c9fa15f91aa47037b1e45a047550b3cddb91cff5489a5794b71eab22 os=linux package=monitor routines=29 version=2.3.0-110-gf0cdf97
DEBU[0034] Received command.                             arch=amd64 clientAddress="127.0.0.1:49856" command=GetStatus machineId=4417cc08c9fa15f91aa47037b1e45a047550b3cddb91cff5489a5794b71eab22 os=linux package=senso userAgent="Mozilla/5.0 (Windows NT 10.0; rv:125.0) Gecko/20100101 Firefox/125.0" version=2.3.0-110-gf0cdf97
DEBU[0043] Received command.                             arch=amd64 clientAddress="127.0.0.1:49856" command=GetStatus machineId=4417cc08c9fa15f91aa47037b1e45a047550b3cddb91cff5489a5794b71eab22 os=linux package=senso userAgent="Mozilla/5.0 (Windows NT 10.0; rv:125.0) Gecko/20100101 Firefox/125.0" version=2.3.0-110-gf0cdf97

@stoeffel
Copy link
Contributor

Works well on OSX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
details needed Further information requested to better evaluate changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants