probonopd / ESP8266iTachEmulator

Send infrared remote control signals via WLAN using an ESP8266
MIT License
19 stars 7 forks source link

Code refactoring #4

Open sle118 opened 7 years ago

sle118 commented 7 years ago

I did a complete code refactoring exercise from .ino files to .cpp, and rewrote a few things along the way to prevent wdt from happening if clients hold the connection for too long. From there, I'm planning on splitting the lirc server from iTach in distinct classes derived from a "server" type. Servers in need for ir send/receive will implement an ir listener interface with some delegate listeners.

Let me know if you're interested in branching this

probonopd commented 7 years ago

Hi @sle118 where can I see i?

sle118 commented 7 years ago

I'm going to do some cleanup today and push to my git so you can have a look. I'm not quite satisfied yet, but it will open the door to discussions.

It would be nice to roll off some of the code as stand alone libraries, for example the iTach server code.

probonopd commented 7 years ago

Maybe @bengtmartensson might be interested in this, too.

sle118 commented 7 years ago

Yes, I've been following you both and I'm a fan.

One thing I have in mind right now is to use a nodemcu's large spiff to store IR timings in a way that would enable sending commands like send/sony/models/play with some Java/Ajax page logic served from the ESP to set it up.

I looked at having the irp rendering straight from the ESP, but don't have the bandwidth to port the existing code from Java. So I guess wrapping the current IrScrutinizer's code wrapped in a rest service is the way to go.

sle118 commented 7 years ago

@probonopd

Some updates

I have sacrificed many hours of sleep and evenings to this and made significant progress on the refactoring. I made heavily usage of delegates to implement functionality. The base server class handles low level stuff like TCP IP connection handling and dispatching, and derived classes define supported commands using delegate functions. Infrared sending is queued through an asynchronous scheduler which handles raw it codes emitting while keeping an eye on timeouts so that no task hold the system for to long.

Once I have ironed out the last couple of wdt crashes and refractored to my taste, I'll be able to share the resul with you. Hopefully, this might get some traction in the community.

Next on my plate would be to see if we could implement an irp interpreter in C++ which would fit on an ESP platform.

probonopd commented 7 years ago

Hi @sle118 thanks for your work, looking forward to seeing your refactored code.

Next on my plate would be to see if we could implement an irp interpreter in C++ which would fit on an ESP platform.

That would be super awesome!

bengtmartensson commented 7 years ago

Are you sure you really "need" a full IRP renderer/recognizer? Have you considered code generation for generating code for the protocols you need?

Having said that, creating a C++ version of (a subset of) IrpTransmogrifier should be do-able. Start by having antlr4 to generate C++ from the grammar; should be easy.

sle118 commented 7 years ago

having a full IRP renderer isn't required, given that in most use cases it's a "setup and forget" kind of use where number of devices are limited. However, I sort of like the idea of having a self-contained, space efficient, way to store codes on the device as it would probably make setup easier (and avoid a lot of the external dependencies associated with this).

sle118 commented 7 years ago

I got the code to a rather stable state but couldn't resist another refactoring to split my base IR server class as a stand-alone library. Unless you'd like to give me some feedback at this point, I'll delay committing to github. @probonopd, I think I will publish the code as a new repo instead of doing a pull request to your existing code as there isn't much left of our original code. I will give credits where appropriate and if you want, I will add you as a contributor. Same for @bengtmartensson if you're interested in being a contributor as well.

I have leveraged the tools from platformio,org, which I am starting to like for keeping a tab on my dependencies.

sle118 commented 7 years ago

@probonopd @bengtmartensson I have pushed the TCP IP Infrared server base class to github. The base class contains the boiler plate code for getting commands from clients, managing connection limits, scheduling IR transmits with delegate callbacks, etc.

Soon I'll push the actual iTach Server class with a fully working example https://github.com/sle118/IrServiceBase

Stay tuned

sle118 commented 7 years ago

Allright!

I have committed the iTach library as well. I think there is still some cleanup to do there, but it's a start! I have the library running right now 24h/7 on a nodemcu, changing channels on a set top box for my NextPVR rig and it works really well.

I have a custom c# command line tool that reads the irsend format from the XML files exported by irScrutinizer and sends tcp ip commands to the device. I might publish this too at some point.

probonopd commented 7 years ago

Thanks for sharing https://github.com/sle118/ESPITachEmulator @sle118

sle118 commented 7 years ago

I'm still resolving the dependencies for platformio to work OK, but the libraries are now published.

I've given some more thoughts on my requirements and I think my next step will be to