I searched for a possible solution in many forums for several days, but I was out of luck; (I am posting my question here, and your answer is greatly appreciated.
IDEA: Use a script to control lights (in C under Linux)
SCENARIO OF APPLICATION I have three lights: red, blue and green. The script has graphs for managing them. For example, After 10 seconds, turn on the red light for 2 seconds; From now on, after 15 seconds turn on the blue light for 10 seconds; From now on, after 21 seconds turn on the red light for 5 seconds; After 5 seconds, turn on the green light for 7 seconds; From now on, after 103 seconds, turn on the green light for 11 seconds; ..... When and for how long to turn on the light, they are absolutely arbitrary. And this program should be able to expand to hundreds of light and thousands of schedules.
HOW TO COD THIS My idea is to have two processes and one mailbox: The first process reads the script file and analyzes the graphs in many timers. After the timer expires, it sends a message (including the light identifier and the action is ON or OFF) to the mailbox. The second process is to turn on or off the specified light based on the message from the mailbox.
Each schedule will be analyzed for two timers: Schedule: now after 10 seconds turn on the red light for 2 seconds; Designed for: Timer 1: The timer expires in 10 seconds; after the expiration, it sends the light identifier (red light) and the action (ON) as a message to the mailbox; Timer 2: the timer expires in (10 + 2) seconds; after the expiration of the term, it passes the light identifier (red light) and the action (OFF) as a message in the mailbox;
The second process constantly checks the mailbox and takes the right action with the right lighting based on the message received.
MY QUESTION The timer on Linux () only emits the same expired SIGALRM signal. Unable to transfer the identifier and the action of the light to the mailbox. Do I have another way to do this? Thank you very much.
source share