Do you need more info on how can data is pulled in the "autorun.bas" or in the "vehicle_thinkcity.c"?
Both would be nice, but only if it's ok with you :)
Maybe we should comment vehicle_thinkcity.c in this post and autorun.bas in the post for "new nikometer"?
In the following I will sum up some of my findings (from both files) and ask a few questions:
(sorry if those are basic stuff, it's my first look into C-programming).
autorun.bas The function "can addrxchnl" maps one message group to one channel.
E.g. add message 301 to channel 1:
can addrxchnl 1, &h301Then rxchnl number 1 can be used to retrieve parameters in message 301.
In message 301 we find DC current, DC voltage, DOD and temperature. All those parameters are words of 2 bytes / 16 bits, split into high- and low byte.
The data from each parameter (within the message) are pulled with the function rxData(n), where 'n' is the position of each byte (8 bits).
E.g. DOD is the 4th and 5th bye in 301-message -> rxData(4), rxData(5)
In case of parameters containing non-negative numbers (unsigned integer), like DOD or voltage, the function getU16 is used to create a 16 bits long word from a 8 bits word, by multiplying high bits with 256
e.g. 0110 0101 -> 0110 0101 0000 0000
then the low byte is added.
For parameters both negative and positive (signed integer), like DC current, the function getS12 is used to create a 12 bit long word by multiplying the high bits with 256 and then adding the low byte.
Then, if the result is a negative number, hex8000 or greater (most significant bit is set to '1') hexFFFF is subtracted.
If (result > &H8000) Then result = result - &HFFFFThen there is a part I don't understand. Why is the low byte divided with 10?
E.g.
_dod=getU16(rxData(4),rxData(5))/10_dccurrent=getS12(rxData(0),rxData(1))/10Further on, the value in the parameters are formatted and printed like this:
Print Format$(100 - _dod,"% 4.1f");Print Format$(_dccurrent,"%6.1f");I assume the 4.1 and 6.1 notation is describing the length of the number and how many digits behind the decimal pointer?
vehicle_thinkcity.cIn the function vehicle_thinkcity_poll0 the databytes are read into an (array?) of variables, named 'can_databuffer[n]'. It handles unsigned integers, -non-negative numbers.
As for autorun.bas, DOD are found in databyte 4 and 5.
Instead of multiplying the high byte with 256 (adding 8 zeros to the end), they use this:
can_databuffer[4]<<8 (e.g. 0110 0101 -> 0110 0101 0000 0000)
then add the low bytes by:
+ can_databuffer[5])/10)I don't understand the usage of 'this part:
unsigned int id = ((unsigned int)RXB0SIDL >>5)+ ((unsigned int)RXB0SIDH <<3);I assume it's about shifting the bits 5 positions right for rxb0sidl (data low), and 3 positions left for rxb0sidh (data high), but can't figure out why?
How do I read the switch-part? :
car_SOC = 100 - ((((unsigned int)can_databuffer[4]<<8) + can_databuffer[5])/10);How can I handle signed integers (like DC current)?
In vehicle_twizy.c one find:
// POWER:
t = ((unsigned int) (can_databuffer[1] & 0x0f) << 8) + can_databuffer[2];
if (t > 0 && t < 0x0f00)
{
twizy_power = 2000 - (signed int) t;Then I wonder if any other files have to be modified to make it work with other values in the can-messages?
I assume the value of parameter 'car_SOC' is global available in the net_sms.c , net_msg.c and diag.c, making it available via SMS and the mobile app?