LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Turning on/off output (https://www.linuxquestions.org/questions/linux-newbie-8/turning-on-off-output-4175604742/)

mackowiakp 04-27-2017 02:27 AM

Turning on/off output
 
I have unit named ARCO connected over USB to Tomato based ASUS router.
It is equipped in /bin/sh not in bash. The unit is equipped in 4 relay outputs. The command
Code:

./arco
returns current output states in the form of one hex digit command. If I want to set for example output no 2 I have to use command:
Code:

./arco 2
But the number after ./arco command must be in decimal form.
I want to turn off/on particular output in pre-defined time.

The part of program responsible for that looks like this:

Code:

if [ "$czas" -gt "$out4_off" -o "$czas" -lt "$out4_on" ]                   
then                                                                       
set=$((0x$out & ~2))                                                       
else                                                                       
set=$((0x$out |2))                                                         
fi                                                                         
if [ "$czas" -gt "$out4_off_1" -o "$czas" -lt "$out4_on_1" ]               
then                                                                       
set=$((0x$out & ~2))                                                       
else                                                                       
set=$((0x$out | 2))                                                       
fi

The variables represents as follows:
Code:

czas - actual time in my time-zone
out4_off - time of turning off particular output for the first time
out4_on - time of turning on particular output for the first time
out4_off_1 - time of turning off particular output for the second time
out4_on_1 - time of turning on particular output for the second time
set - represents number which will be written to ARCO unit over USB

All time values are represented in minutes from midnight.

Value of out4_on_1 is grater than out4_on
and similar
Value of out4_off_1 is grater than out4_off

In case of my program, the first "if" will for example set output to ON, but the second "if" statement set it again to OFF.
How can I modify the program above, to be sure that the result of first "if" statement will not be overwritten by second "if" and vice-versa.
Any idea?

syg00 04-27-2017 05:05 AM

Depending on what that shell actually is, you may have else-if support; something like this
Code:

if [ "$czas" -gt "$out4_off" -o "$czas" -lt "$out4_on" ]                   
then                                                                       
  set=$((0x$out & ~2))                                                       
else if [ "$czas" -gt "$out4_off_1" -o "$czas" -lt "$out4_on_1" ]               
then                                                                       
  set=$((0x$out & ~2))                                                       
else                                                                       
  set=$((0x$out | 2))                                                       
fi

untested of course ...


All times are GMT -5. The time now is 01:56 PM.