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

Add IOControl library #2492

Merged
merged 7 commits into from
Feb 18, 2022
Merged

Add IOControl library #2492

merged 7 commits into from
Feb 18, 2022

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Feb 15, 2022

The IO Control library is an asynchronous Input/Output device stack for embedded devices such as the ESP8266.
The main reason for building this was to provide a mechanism for serialising modbus requests along with commands to other types of device such as DMX512 dimmers and 433MHz light switches.

This PR is related to #1991.

todo:

  • Thorough test with real hardware

@slaff slaff added this to the 4.6.0 milestone Feb 16, 2022
@mikee47
Copy link
Contributor Author

mikee47 commented Feb 16, 2022

@slaff
Copy link
Contributor

slaff commented Feb 16, 2022

I've tried running the sample under Host but it segfaults with assert. Is that expected under Host or I am doing something wrong?

2745898 MB: Sent 8 bytes...
2746493 devmgrCallback: 00000000 / 00000000
2748053 Request 4d93bc0 created
2750213 setCommand(0x00000009: adjust)
2757379 Request 4d93bc0 (adjust#7) complete - success
app: /tmp/Sming/Sming/Libraries/IOControl/src/Controller.cpp:213: virtual void IO::Controller::handleEvent(IO::Request*, IO::Event): Assertion `m_queue.head() == request' failed.

signal_handler: SIGABRT - usually caused by an abort() or assert()

@mikee47
Copy link
Contributor Author

mikee47 commented Feb 16, 2022

The DMX driver needs looking at. If you want to continue testing without it just remove the corresponding call to registerDeviceClass. I'm not actively using DMX (yet) and the library has been through some major revisions, so clearly I broke something!

DMX requests aren't queued as they update internal state.
Add second DMX device to sample and demonstrate JSON requests
@slaff
Copy link
Contributor

slaff commented Feb 16, 2022

Mike, can you run codespell to fix small spelling mistakes?

Use default baudrate if not specified
Line break not released as it should be
Request 'value' must be signed so 'adjust' command works as intended
Fix fade timing
Fix race hazard in RS485 driver
@slaff
Copy link
Contributor

slaff commented Feb 16, 2022

@mikee47 Do you want to make the best of your IDE and replace the occurrences of, if I am not mistaken, Hungarian Notation for variables? I guess these are left-overs from previous versions.

@mikee47 mikee47 force-pushed the feature/io-control branch 2 times, most recently from 3c51ace to 6de9e19 Compare February 16, 2022 21:34
@slaff
Copy link
Contributor

slaff commented Feb 17, 2022

https://github.com/mikee47/IOControl/blob/13976f4b98b8bc5b80ce258d874444264eb77710/src/Modbus/R421A/Device.cpp#L43

@mikee47 replace:

	debug_d("Device %s has %u channels", id().c_str(), channelCount);

with

	debug_d("Device %s has %u channels", getId().c_str(), channelCount);

@slaff
Copy link
Contributor

slaff commented Feb 17, 2022

There might be still concurrency issue(s) and the application is segfaulting. Steps to reproduce it is to compile the sample.

cd samples/Basic_RS485
make SMING_ARCH=Host DEBUG_VERBOSE_LEVEL=3 ENABLE_GDB=1
make run

And wait. Soon the application segfaults during release of a request.

28126301 Executing request 57120070, : update
28126310 [DMX512] updateSlaves()
>: 00000000 00 00 00 27 00 00 00 00 1a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ...'............................
...
  ................................
   00000200 00 00 00                                                                                         ...
28128732 Request 57120070 () complete - success
28128746 Request 57120070 () destroyed

signal_handler: SIGSEGV - segmentation fault

My wild guess is that this request is still used somewhere after it was freed. This seems to be a timing issue and, unfortunately, I cannot reproduce it under valgrind or gdb.

Can you reproduce it on your system?

@mikee47
Copy link
Contributor Author

mikee47 commented Feb 17, 2022

I managed to get it once, using --cpulimit=2 and running other CPU intensive stuff at the same time. I'm doing the same in debugger and so far behaving itself... It could be the host serial emulation (or threading) again...

Different error though:

11612979 Executing request 56ad2f40, : update
11613002 [DMX512] updateSlaves()
>: 00000000 00 00 00 0e ...
11613818 Request 56ad2f40 () complete - success
Device.cpp:200: virtual void IO::DMX512::Device::handleEvent(IO::Request*, IO::Event): Assertion `updating' failed.

signal_handler: SIGABRT - usually caused by an abort() or assert()

@mikee47 mikee47 closed this Feb 17, 2022
@mikee47 mikee47 reopened this Feb 17, 2022
@mikee47
Copy link
Contributor Author

mikee47 commented Feb 17, 2022

OK, found and fixed problem.

Don't add delay on receive completion - protocol-specific and not generally necessary
Switch transceiver back to idle promptly
@slaff slaff merged commit 97ded58 into SmingHub:develop Feb 18, 2022
@slaff
Copy link
Contributor

slaff commented Feb 18, 2022

@mikee47 I am very glad that the long-awaited IOControl library made it into the official develop branch. Thanks a lot for your work ! :)

@mikee47 mikee47 deleted the feature/io-control branch February 18, 2022 08:54
@slaff slaff mentioned this pull request Feb 18, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants