Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Suterusu

Code Snipper for Modem Messages

Question

I want to be able to "listen for" and "transmit" modem messages concurently.

 

Basically, I want to activley be listening for incoming messages, but during that time I may want to send messages as well.  Additionally, once a message is received, I want to do something about it, whilst going back to "listening" for messages again.

 

Listener()

  -> Add incoming message to queue

Processor()

 -> Process message queue

Sender()

  -> Send messages as needed

 

I have the general idea, I am just unsure how to execute this (if even possible) with LUA and OC.

 

Any psudo code or hints/help would be greatly appreciated!

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Incoming modem messages are processed as events, so you'll probably just want to use event.listen:

event.listen("modem_message", function(localAddress, remoteAddress, port, message)
   -- Incoming message handler
end

A separate Processor and Sender is unnecessairy if you ask me, as there is no real parallelism in lua anyway

Link to post
Share on other sites
  • 0

Although there is no parallelism in LUA you still need to have a program that kind of does multithreading by executing only tiny pieces of code one after another so that you can listen to the modem fast enough as it sadly has no buffer. If you stay too long at some calculations you could easily miss 1 to 10 modem messages. That makes it a bit hard and I understand your problem as I ran into exactly the same thing.

 

My solution was to program a complete modem handler that works together with my "request handler" (did not have a better name^^).

What these two basically do is the following:

the request handler takes care of a command queue and executes one after another and after every execution it pulls the registered events like modem messages and adds it to the command queue. This way I ensure that I can keep a program running and "simultaniously" receive all message the modem gets. Well at least if all additional software is properly coded and divided into little pieces and actively use my API. The modem handler additionally filters duplicate messages and has a little blacklist module (But spamming and relaying of messages is a huge problem for server performance anyways).

 

This started very little but in the end (which is not yet reached^^) it took me a few days of programming. It works perfectly now even between two PCs but still needs a little bit of debugging, cleaning and documentation.

Hopefully you get an idea of how to realize what you planned.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.