<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><span style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;">Hi </span><font face="Calibri,sans-serif">Nikolay,</font></div><div style="font-size: 14px; font-family: Calibri, sans-serif; color: rgb(0, 0, 0);"><br></div><div style="font-size: 14px; font-family: Calibri, sans-serif; color: rgb(0, 0, 0);">That code won't quite work for two reasons.</div><div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;"><br></div><div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;">The third data byte has index 2.</div><div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;"><br></div><div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;">Also, since the CarOn field is a single bit, you have to set it to 0 or 1. Your code is setting to either 0x00 or 0x04, both of which will set the CarOn bit to zero because they both have the low bit off. I would do it this way:</div><div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;"><br></div><div><font face="Calibri,sans-serif">car_doors1bits.CarON = (can_databuffer[2] & 0x04) >> 2;</font></div><div><font face="Calibri,sans-serif"><br></font></div><div><font face="Calibri,sans-serif">or</font></div><div><font face="Calibri,sans-serif"><br></font></div><div><span style="font-family: Calibri, sans-serif;">car_doors1bits.CarON = (can_databuffer[2] & 0x04) ? 1 : 0;</span></div><div><span style="font-family: Calibri, sans-serif;"><br></span></div><div><font face="Calibri,sans-serif">I'm not sure which of those will produce the smallest code on the PIC. If the compiler is really smart, it will produce the same optimal code for either. I favor the second for clarity.</font></div><div><font face="Calibri,sans-serif"><br></font></div><div><font face="Calibri,sans-serif">    Tom</font></div><div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;"><br></div><span id="OLK_SRC_BODY_SECTION" style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;"><div><div>On 6/16/14, 6:42 AM, "Nikolay Shishkov" <<a href="mailto:nshishkov@yahoo.com">nshishkov@yahoo.com</a>> wrote:</div></div><div><br></div><div><div><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><pre class="" style="">Thanks Mark, </pre><pre class="" style="">With some help I found a message on the canbus that reflects the status of the "Ready" light in the car. </pre><pre class="" style="">Please note that the key position may be in "on", that does not mean that the car can drive. I have seen this behavior (the switch is on, but then it takes half second and the car is "ready", most of the time) in the old RAV4 EV, Nissan Leaf, the Mitsubishi Miev trio of cars, Think City EV. </pre><pre class="" style="">I don't remember how it works in the Roadster or the Model S. </pre><pre class="" style=""><span style="font-size: 12pt;" class="">So if no one minds I will be setting the CarON when the "Ready" bit is set in that CANBus message. </span></pre><pre class="" style=""><span style="font-size: 12pt;" class="">Can someone please confirm that my code will extract the correct bit - I think I got it right, but sometimes I confuse the zerobased indexing and the </span><span style="font-size: 12pt;">endianness of a system.</span></pre><pre class="" style=""><span style="font-size: 12pt;" class="">The CAN bus message id is 0x424 -</span><br class="" style=""></pre><pre class="" style=""><span class="" style="">
Here with ready OFF:
424 43 00 08 00 00 AE 01 FF

And here with ready ON:
424 43 00 0C 00 00 AE 01 FF</span></pre><pre class="" style="">So I am looking for the the 3rd bit in the 3rd byte of the message and <span style="font-size: 12pt;" class="">I am thinking of doing something like this:</span></pre><pre class="" style=""><span class="" style="">car_doors1bits.CarON = can_databuffer[3] & (1<<2);<font size="3" class="" style=""><br class="" style=""></font></span></pre><pre class="" style=""><span class="" style="">or maybe </span></pre><pre class="" style=""><span class="" style="">car_doors1bits.CarON = can_databuffer[3] & 4;</span></pre><pre class="" style=""><span style="font-size: 12pt;">Is this correct?</span><br></pre><pre class="" style=""><span style="font-size: 12pt;" class="">Nikolay</span></pre><pre class="" style=""><span style="font-size: 12pt;" class=""><br></span></pre><pre class="" style=""><span style="font-size: 12pt;" class=""><br></span></pre><pre class="" style=""><span style="font-size:
 12pt;" class=""><br></span></pre><pre class="" style=""><span style="font-size: 12pt;" class=""><br></span></pre><pre class="" style=""><span style="font-size: 12pt;" class="">Nikolay,</span><br class="" style=""></pre><pre class="" style=""><span style="font-size: 12pt;">unsigned char car_doors1 [bit 7]</span><br></pre><pre class="" style="">A bit used to signal whether the car is turned on or off. Set to 1 if the car ignition switch is ON, otherwise 0. 


If the state of the ignition switch is not readable on the bus, the vehicle not being in 'P' gear or handbrake not appied (and not charging), would be acceptable.

Regards, Mark.

On 15 Jun, 2014, at 9:38 pm, Nikolay Shishkov <<a href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev" class="" style="">nshishkov at yahoo.com</a>> wrote:

><i class="" style=""> As the subject says - what does CarOn mean? Is it key in position 3, or car in "Ready" state? Or something even more remote like shifter not in "P"?
</i>><i class="" style=""> 
</i>><i class="" style=""> Nikolay</i></pre><div class="" style=""><br style=""></div></div></div></div>_______________________________________________
OvmsDev mailing list
<a href="mailto:OvmsDev@lists.teslaclub.hk">OvmsDev@lists.teslaclub.hk</a>
<a href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev">http://lists.teslaclub.hk/mailman/listinfo/ovmsdev</a>
</span></body></html>