We are wanting to develop a universal app for phones such as Windows phone but having problems figuring out the 8bit code. We building part in php and am wondering if there anyone that can help with the code for reading relay positions in php or JavaScript. Thanks.
Joel
Assistance with new app
Re: Assistance with new app
I'm assuming you are familiar with connecting to RA and pulling XML data, correct?
Do, looking at the XML data, you will have <R>, <RON> and <ROFF>
<R> represents the state of the relay ports in auto mode.
<RON> represents the state of the override on ports
<ROFF> represents the state of the override off ports, but it is on inverted state.
All you need to do is convert the decimal numbers presented to you into binary.
So, let's start with <R> examples:
<R>24</R> - 00011000
The decimal value 24, represents 00011000 in binary. The ones represent ports that are supposed to be on. In this example, ports 4 and 5 are on.
More <R> examples:
<R>168</R> - 10101000
<R>77</R> - 01001101
Same thing for <RON>
<RON>8</RON> - 00001000
The decimal number 8 represents 00001000 in binary. As you can see, Port4 would be overridden on.
<ROFF> is the opposite of the other two.
<ROFF>253</ROFF> - 11111101
The decimal number 253 represents 11111101 in binary. In this case, Port2 would be overridden off
That's how you interpret each one of the XML tags.
To get the final status of the ports after masks on/off are applied, you need to do a math bitwise AND/OR like this:
( <R> & <ROFF> ) | <RON>
Do, looking at the XML data, you will have <R>, <RON> and <ROFF>
<R> represents the state of the relay ports in auto mode.
<RON> represents the state of the override on ports
<ROFF> represents the state of the override off ports, but it is on inverted state.
All you need to do is convert the decimal numbers presented to you into binary.
So, let's start with <R> examples:
<R>24</R> - 00011000
The decimal value 24, represents 00011000 in binary. The ones represent ports that are supposed to be on. In this example, ports 4 and 5 are on.
More <R> examples:
<R>168</R> - 10101000
<R>77</R> - 01001101
Same thing for <RON>
<RON>8</RON> - 00001000
The decimal number 8 represents 00001000 in binary. As you can see, Port4 would be overridden on.
<ROFF> is the opposite of the other two.
<ROFF>253</ROFF> - 11111101
The decimal number 253 represents 11111101 in binary. In this case, Port2 would be overridden off
That's how you interpret each one of the XML tags.
To get the final status of the ports after masks on/off are applied, you need to do a math bitwise AND/OR like this:
( <R> & <ROFF> ) | <RON>
Roberto.
Re: Assistance with new app
I have php code you can use to parse everything. Take a look at the custom portal I setup
http://forum.reefangel.com/viewtopic.php?f=20&t=3403
I have a package you can download as well with all my php / javascript / etc. Should get you started at least.
http://forum.reefangel.com/viewtopic.php?f=20&t=3403
I have a package you can download as well with all my php / javascript / etc. Should get you started at least.
-
- Posts: 58
- Joined: Sat Jan 26, 2013 1:27 am
Re: Assistance with new app
Thanks guys will keep you posted.
Joel
Joel
-
- Posts: 58
- Joined: Sat Jan 26, 2013 1:27 am
Re: Assistance with new app
Thanks for the php. I noticed an issue that i came accross with my original code too. Where the last port 0-7 ( port 8 ) is always incorrect. I see this php has the same issue. I wrote a class myself that also had this issue where the last port is manual off - it shows as auto off yet all other ports are correct however you switch them.
Any thoughts would be greatly appreciated.
Any thoughts would be greatly appreciated.
-
- Posts: 58
- Joined: Sat Jan 26, 2013 1:27 am
Re: Assistance with new app
Issue seems to be if it is usually in auto off position and is switched to manual off, it doesn't show as such it remains as auto off.
Re: Assistance with new app
Actually, there is no difference in my code between auto-off and manual-off and likewise between auto-on and manual-on if the port is set to auto-on...
Rather than having an indicator to show an override, I went with a different approach...
In my code, the color of the LED indicates what the auto-mode is. So, an auto-off and manual-off when the port is off will both be an dark-red.
I do the opposite for on. If it's auto then green-led's are used. If it's Green and dark, that means we've overriden the port off. If it's green and lit, then it's auto-on and perhaps manual-on as well.
What I did was set the relay toggle between auto and override. So my GUI does not allow for an override to the default mode.
Rather than having an indicator to show an override, I went with a different approach...
In my code, the color of the LED indicates what the auto-mode is. So, an auto-off and manual-off when the port is off will both be an dark-red.
I do the opposite for on. If it's auto then green-led's are used. If it's Green and dark, that means we've overriden the port off. If it's green and lit, then it's auto-on and perhaps manual-on as well.
What I did was set the relay toggle between auto and override. So my GUI does not allow for an override to the default mode.