<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div><span>Thanks Tom, </span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;"><span><br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;"><span>After some trial and error last night I figured the indexing and bit testing/setting out. </span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;"><br></div><div style="color: rgb(0, 0, 0);
font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;"><span>The devil is in the detail!</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;"><span><br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;">Nikolay</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;"><span><br></span></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div
style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Tuesday, June 17, 2014 7:42 AM, Tom Saxton <tom@idleloop.com> wrote:<br> </font> </div> <br><br> <div class="y_msg_container"><div id="yiv8735289552"><div><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 clear="none"></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 clear="none"></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 clear="none"></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 clear="none"></div><div><font face="Calibri,sans-serif">car_doors1bits.CarON = (can_databuffer[2] & 0x04) >> 2;</font></div><div><font face="Calibri,sans-serif"><br clear="none"></font></div><div><font face="Calibri,sans-serif">or</font></div><div><font face="Calibri,sans-serif"><br clear="none"></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 clear="none"></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 clear="none"></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 clear="none"></div><span id="yiv8735289552OLK_SRC_BODY_SECTION" style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;"></span><div class="yiv8735289552yqt7994293873" id="yiv8735289552yqt77907"><div><div>On 6/16/14, 6:42 AM, "Nikolay Shishkov" <<a rel="nofollow" shape="rect"
ymailto="mailto:nshishkov@yahoo.com" target="_blank" href="mailto:nshishkov@yahoo.com">nshishkov@yahoo.com</a>> wrote:</div></div><div><br clear="none"></div><div><div><div style="color: rgb(0, 0, 0); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt; background-color: rgb(255, 255, 255);"><pre class="yiv8735289552" style="">Thanks Mark, </pre><pre class="yiv8735289552" 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="yiv8735289552" 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="yiv8735289552" style="">I don't remember how it works in the
Roadster or the Model S. </pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" style="font-size:12pt;">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="yiv8735289552" style=""><span class="yiv8735289552" style="font-size:12pt;">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="yiv8735289552" style=""><span class="yiv8735289552" style="font-size:12pt;">The CAN bus message id is 0x424 -</span><br clear="none" class="yiv8735289552" style=""></pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" 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="yiv8735289552" style="">So I am looking for the the 3rd bit in the 3rd byte of the message and <span class="yiv8735289552" style="font-size:12pt;">I am thinking of doing something like this:</span></pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" style="">car_doors1bits.CarON = can_databuffer[3] & (1<<2);<font class="yiv8735289552" size="3" style=""><br clear="none" class="yiv8735289552" style=""></font></span></pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" style="">or maybe </span></pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" style="">car_doors1bits.CarON = can_databuffer[3] & 4;</span></pre><pre class="yiv8735289552" style=""><span style="font-size:12pt;">Is this correct?</span><br clear="none"></pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" style="font-size:12pt;">Nikolay</span></pre><pre
class="yiv8735289552" style=""><span class="yiv8735289552" style="font-size:12pt;"><br clear="none"></span></pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" style="font-size:12pt;"><br clear="none"></span></pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" style="font-size:12pt;"><br clear="none"></span></pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" style="font-size:12pt;"><br clear="none"></span></pre><pre class="yiv8735289552" style=""><span class="yiv8735289552" style="font-size:12pt;">Nikolay,</span><br clear="none" class="yiv8735289552" style=""></pre><pre class="yiv8735289552" style=""><span style="font-size:12pt;">unsigned char car_doors1 [bit 7]</span><br clear="none"></pre><pre class="yiv8735289552" 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 rel="nofollow" shape="rect" class="yiv8735289552" target="_blank" href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev" style="">nshishkov at yahoo.com</a>> wrote:
><i class="yiv8735289552" 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="yiv8735289552" style="">
</i>><i class="yiv8735289552" style=""> Nikolay</i></pre><div class="yiv8735289552" style=""><br clear="none" style=""></div></div></div></div></div>_______________________________________________
OvmsDev mailing list
<a rel="nofollow" shape="rect" ymailto="mailto:OvmsDev@lists.teslaclub.hk" target="_blank" href="mailto:OvmsDev@lists.teslaclub.hk">OvmsDev@lists.teslaclub.hk</a>
<a rel="nofollow" shape="rect" target="_blank" href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev">http://lists.teslaclub.hk/mailman/listinfo/ovmsdev</a>
</div></div><br><div class="yqt7994293873" id="yqt25545">_______________________________________________<br clear="none">OvmsDev mailing list<br clear="none"><a shape="rect" ymailto="mailto:OvmsDev@lists.teslaclub.hk" href="mailto:OvmsDev@lists.teslaclub.hk">OvmsDev@lists.teslaclub.hk</a><br clear="none"><a shape="rect" href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev" target="_blank">http://lists.teslaclub.hk/mailman/listinfo/ovmsdev</a><br clear="none"></div><br><br></div> </div> </div> </div> </div></body></html>