-
Notifications
You must be signed in to change notification settings - Fork 117
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
Allow server to handle slave address #141
Conversation
actually, I realise now that I have missed #97 |
Added an example in |
+1 Looking forward to this |
Thanks for your contribution! I am not familiar with the experimental server-side stuff. Maybe someone who actually uses it could spend some time and comment on the changes? |
Hint (for your next PR, not this one): Don't use the main branch in your fork for feature development. Use a feature branch and always pull main from the upstream repo. Reset your main branch to upstream after this PR has been finished. |
yeah it was a feature branch on my repo but I merged It when I considered it "done" for my use case (enough for use in my project) I'm doing PRs to review to my changes to myself before sending it here 😅 |
The bulk of the changes is not "really" changes in the server part I just used generics and RequestThe let response = service.call(request.into()).await.map_err(Into::into)?; instead of let response = service.call(request.pdu.0).await.map_err(Into::into)?; ResponseThen I had to make the response optional so the server is able to not repond to request not intended for it (in rtu bus there are lots of devices, on the same bus, the master sends a request with a slaveId, and only the targeted device should reply or it will create conflict on the bus and the message will be corrupted). So I made the I used Then the only real change is match response.try_into() {
Ok(pdu) => {
framed.send(rtu::ResponseAdu { hdr, pdu }).await?;
}
Err(_) => {
debug!("skipping reponse");
}
} instead of framed
.send(rtu::ResponseAdu {
hdr,
pdu: response.into(),
})
.await?; |
Thank you for the detailed explanations. Sounds reasonable to me. During reviews I always try to add missing pieces and clarifications to the code. Either by making the code more expressive or adding comments and docs as needed. PR conversations are transient and all the efforts put into them get lost. Please rebase and fix the failing checks and builds. |
I think that should fix all the CI errors |
Sorry, I didn't notice that it wasn't you who started importing symbols from the |
np, good occasion to fix the legacy code :) |
and now that I finally figured out that the test suite was in pre-commit all along, this should fix the last tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I'll add a changelog entry.
already on crates ! |
Hi I've made this small change on the server part of the library to allow it to be more useful
I did need to handle the slave address but it was neither passed to the service nor possible for the service to not respond to a valid modbus request on the bus, wich is a problem on a bus with a lot of devices with their own addresses.
I did not see any PR / issue so I made the fix in a fork that I am currently rolling in production.
It is a bit rough for now but I am interested to know if you would be open to merging it ?
Basically all my changes are to make the
Request
andResponse
types in the services types that need to implement respectivelyFrom<RequestAdu>
andTryInto<ResponsePdu>
. The change is 100% backward compatible since the originalRequest
andRespone
object implements the required traits, and allow to use any different request / response custom implementation in the service required in the service development that into/from can work with.Two things I'm not really sure about are:
RequestAdu
andResponsePdu
public for the interface to work though, but I'm not sure that there actually is a much better way.TryInto<ResponsePdu>
vsOption<Into<ResponsePdu>>
for the response type, because I think thetry_into()
is pretty obvious in rust that it is just doing a regularinto()
, but while also taking in account the fact that it might fail, like when no response is supposed to be sent because the message was not destined for that device on the bus, butOption<Into<ResponsePdu>>
makes it more obvious / limiting that is is actually only designed to allow not sending a response as a success case.I've not really wrote tests nor yet, but I'm really interested in your feedback.