felixwrt / sml-rs

Smart Message Language parser written in Rust
Other
11 stars 3 forks source link

How to include parsing of SML bodies #5

Closed torfmaster closed 8 months ago

torfmaster commented 1 year ago

Hi,

while implementing https://github.com/torfmaster/hackdose-server I stumbled upon your project. In my project I implemented (rather naively) extracting complete SML messages to control smart plugs based on data coming from my smart meter. My focus was rather on parsing the body to extract data about power consumption than parsing the whole message (e.g. the checksum) which resulted in writing https://github.com/torfmaster/hackdose-sml-parser, a Parser Expression Grammar based parser which does e.g.

I see that you also have spent quite an effort in doing the encoding part and I wonder whether we could combine the efforts somehow?

I'd be interested in your opinion!

fkohlgrueber commented 1 year ago

Hi,

I just had a quick look at your implementation, very interesting. I haven't used the peg crate yet. The Hackdose project sounds pretty cool. I thought about something similar but never actually started working on it.

Regarding sml-rs: I haven't worked on the project in the last couple of months, but I still intend to continue working on it. I have written a parser using nom that I haven't published yet as it still needs cleanup. I'm not sure which approach works better, but I'd be happy to collaborate on this project. How about this: I'll try to publish my parser soon (say within a week) such that we can discuss which implementation we want to use in sml-rs. Sounds like a plan?

Another thing: Your project is targeted at RPi or similar devices, right? My parser currently uses allocations and I was still figuring out how best to make it work without an allocator. Eventually, I'd like to use sml-rs on microcontrollers like the ESP32-C3 and there, an allocation-free parser would be nice. I'm guessing that you don't need that feature if you're running on RPi, right?

torfmaster commented 1 year ago

Sounds like a plan?

Definitely, it seems like we're targeting different layers of SML (you are targeting transport, I am targeting application layer) so a combination would make sense.

My parser currently uses allocations and I was still figuring out how best to make it work without an allocator.

Some thoughts

fkohlgrueber commented 1 year ago

Definitely, it seems like we're targeting different layers of SML (you are targeting transport, I am targeting application layer) so a combination would make sense.

Not really. I've been focusing my efforts on the transport layer first, but the end goal is to cover the application layer as well. The "old" branch contains an implementation of the application layer I did a while ago.

Regarding allocations: I agree with you that for most projects, requiring an allocator will be totally fine. I'd like to have the library working without dynamic memory allocations anyway eventually, but that's not a priority. It wont't hurt users that will be using alloc (in the same way as the current implementation of the transport layer is usable with and without an allocator). Besides, it's a fun challenge to design a library for no_alloc and might make it work in even more constrained environments. But as I said, no_alloc is not a priority and more of a nice to have feature.

felixwrt commented 1 year ago

I've just released a new version of sml-rs that includes parsing of SML messages. I think that the library should now work for your use-case in hackdose-server. Feel free to check it out and I'm looking forward to hear what you think about it!

felixwrt commented 8 months ago

Closing this as message parsing is now part of the library.