Feature #1201
closed
Add Pairing apps to launcher in imrest
Added by Hammel 3 months ago.
Updated about 1 month ago.
Description
The launcher should allow enabling of pairing devices on Ironman. This would allow removal of the GPIO hardware hack.
The pairing feature needs to be dynamically loaded into the status bar and a touch on it's icon sends an IPC message to imrest to enable pairing.
- Blocked by Feature #1202: Add support for dynamically loading features. added
- Subject changed from Add Pairing feature as an add-on to launcher to Add Pairing apps to launcher in imrest
- Severity changed from 02 - High to 01 - Critical
imrest needs a simple app (binary or script) that is run via the launcher's status bar to toggle pairing mode.
The app will contact imrest via a UNIX_DOMAIN socket. The contact will enough to toggle the current state.
The app will then need to update the status bar icon. This will need to be done by one of the following methods.
- Change a symlink between active and inactive icon for pairing
- Change app config by notifying launcher via a UNIX_DOMAIN socket to swap the active icon.
The former is simpler but lacks synchronization. No synchronization requires the launcher to poll icons for changes or schedule status bar updates.
The latter is more complex but is synchronized. Synchronization will allow the launcher to update the icon on notification.
I also need icons for active and inactive states for the pairing mode. The icons should be installed to /etc/launcher/icons.
I also need an xml config for the app that is installed to /etc/launcher/.statusbar.
- Status changed from New to In Progress
- % Done changed from 0 to 10
I think it would be simpler to just create a shared memory segment. That way I can open the reader in imrest and watch for updates and the app would just be imrest with a special command line option that messages the server version of imrest and updates the icon in the launcher.
videoe has inotify setup and a thread for notification that is must about the same thing - it doesn't care about what the notification is.
- % Done changed from 10 to 50
I opted for a UNIX_DOMAIN socket. It's now implemented in imrest and I've made imrest act as an launcher status bar app when run as imrest-app. This compiles cleanly but needs testing on hardware.
It also still needs a launcher app.xml added to the packaging.
- % Done changed from 50 to 60
xml file added. Just need testing now.
- % Done changed from 60 to 70
It mostly worked but there was a bug. I've fixed the bug and tested imrest-app manually and it seems to work. Now I need to retest on hardware.
Touches are not always working in the status bar. Also, when the touch does work and imrest-app is called, nothing happens.
iconTouchGTK[launcher.c:202] INFO Processing touch request.
iconTouchGTK[launcher.c:215] INFO Status Bar Index: 1
touchProcessor[touchProcessor.c:380] INFO TSLIB: sample 1745374360.777265: 749 4 255
touchProcessor[touchProcessor.c:382] INFO TSLIB: last 1745374360.537276: 750 4 255
touchProcessor[touchProcessor.c:394] INFO 1. diff.sec: 0 -- diff.usec: 239989
touchProcessor[touchProcessor.c:397] INFO --- Skipping fast repeat
touchProcessor[touchProcessor.c:376] INFO TSLIB: not pressed.
notify[launcher.c:871] INFO Command to run: /usr/bin/imrest-app
$ tail -f /tmp/imrest.log
initSetup[init.c:56] INFO init.setup has been called.
initSetup[init.c:75] INFO Webroot directory : /home/httpd/imrest
initSetup[init.c:76] INFO Ironman directory : /home/httpd/imrest/ironman
initSetup[init.c:77] INFO Monitor directory : /home/httpd/imrest/monitor
initSetup[init.c:78] INFO Stamp directory : /home/httpd/imrest/ironman/jarvis/
initSetup[init.c:79] INFO IoT directory : /home/httpd/imrest/ironman/iot/
initSetup[init.c:80] INFO Descriptor file : /home/httpd/imrest/monitor/descriptor
initSetup[init.c:82] INFO Monitor UUID : 827dce7d-d536-4599-a26e-6989c7a8fbe0
main[imrest.c:348] INFO Running from /home/httpd/imrest.
startWatcherProcessor[watcher.c:224] INFO imrest: Started watcher thread.
It looks like when
/usr/bin/imrest-app
is called the app doesn't realize it's being called AS the app and tries to run the full imrest server again. I probably need to use basename() on arg0 to fix that.
- % Done changed from 70 to 90
Looks like it's working now.
$ /usr/bin/imrest-app
Config file tag: verbose
Config file tag: debugfile
Verbosity level: 3
$ cat /tmp/imrest.log
main[imrest.c:314] INFO Log file: /tmp/imrest.log
main[imrest.c:326] INFO Running as the app.
pairApp[pair-app.c:75] INFO Current icon: /etc/launcher/icons/imrest-off.png
pairApp[pair-app.c:80] INFO Current basename: imrest-off.png
pairApp[pair-app.c:81] INFO IMREST_PAIR_ON: imrest-on.png
pairApp[pair-app.c:82] INFO IMREST_PAIR_OFF: imrest-off.png
pairApp[pair-app.c:93] INFO Setting pairing to ON.
pairApp[pair-app.c:106] INFO symlink /etc/launcher/icons/imrest-on.png /etc/launcher/icons/imrest.png
pairApp[pair-app.c:142] INFO Pairapp is exiting.
The only thing left is to check the touch presses from launcher and the icon updates.
One last thing: On reboot the imrest-app needs to be called to disable pairing, so we always start in non-pair mode.
Also, imrest itself should reset the state when it restarts. The server is the last word on the current state.
Reset function implemented. Just needs to be tested on hardware. Currently running lockup test, however, which needs to run for a day or so.
Updated package is installed on hardware - just need to enable pairing and then reboot to make sure it comes back in non-pair mode.
After testing that reboot comes back in non-pair mode, verify pairing actually works when enabled via the launcher.
Not working.
- reboot -f: doesn't clean up so on restart it's got the wrong icon and doesn't work to start/stop pairing.
- imrest: goes 25% cpu load when pairing enabled. Without pairing it is at 0% cpu load.
- icon off: imrest does not reset from 25% cpu load
If "reboot" alone is used, then the icons are okay because init script shutdown cleans up.
Probably need to have init script always reset on start. Maybe by using imrest-app to simply clean up, ie. via command line argument.
Definitely doesn't work: watcher.c has calls to togglePairState() #if 0'd. So when the imrest-app signals imrest, the latter fails to go into pair mode.
Additionally, the devicePairIot() and devicePairJarvis() are still using utils.c:gpioRead() calls. So I need
- Enabled togglePairState() in watcher.c
- Add togglePairState to pair.c
- Add calls to test pair state in existing pair.c functions.
- Add mutex in pair.c for setting and testing pair state.
This is addition to
- reboot -f: doesn't clean up so on restart it's got the wrong icon and doesn't work to start/stop pairing.
- imrest: goes 25% cpu load when pairing enabled. Without pairing it is at 0% cpu load.
- icon off: imrest does not reset from 25% cpu load
I implemented this but realized the imrest-app can't get the pair_state of the running imrest.
So instead of handling the icon updates itself, it should simply "ping/toggle" imrest and let imrest handle the pair_state update, including the icon update.
This will fix synchronization issues.
I've cleaned up the implementation quite a bit, but I still don't know what is causing the 25% load.
I've got a build ready for testing. This should sync better with the launcher icon button.
If the load is still there, then I'll need to enable debug for imrest and watch the log.
There is a continuous loop when you press the launcher icon.
watcherProcessor[watcher.c:171] INFO Toggling pairing state.
updatePairIcon[pair.c:126] INFO Setting pairing to OFF.
updatePairIcon[pair.c:142] INFO symlink /etc/launcher/icons/imrest-off.png /etc/launcher/icons/imrest.png
watcherProcessor[watcher.c:171] INFO Toggling pairing state.
updatePairIcon[pair.c:130] INFO Setting pairing to ON.
Okay this is working now. The loop was because I used a select() with a timeout to allow easy exit from the watcher but left out the required accept() when select() doesn't error or timeout.
I've also verified that the app resets to OFF on exit AND on start, so it is guaranteed to be in OFF at startup.
The only thing that might need to be added is an inotify() on the launcher's icon directory to make appropriate updates when apps make changes to the icons.
This was tested manually, without using the launcher UI. I need to test it once more with the launcher UI, and then verify that a sensor can pair with Ironman.
- % Done changed from 90 to 100
This has been fully tested on hardware now and seems to work okay. The looping error has been fixed and the launcher is showing the proper pair state.
Code updates for both imrest and launcher have been committed and pushed.
Closing issue.
- Status changed from In Progress to Closed
Also available in: Atom
PDF