Reviewing this, I find:

extern signed char car_ambient_temp; // Ambient Temperature (celcius)
extern signed char car_tpem;         // Tpem
extern unsigned char car_tmotor;     // Tmotor
extern signed char car_tpms_t[4];    // TPMS temperature

The car_tbattery and car_cooldown_tbattery are already signed int.

I propose to change car_ambient_temp, car_tpem, car_tmotor and car_tpms_t to signed int. For the sake of 7 bytes I don't think it is worth the risk.

Code in vehicle_twizy.c is a good example of guarding for this:

      // MOTOR TEMPERATURE:
      if (CAN_BYTE(5) > 40 && CAN_BYTE(5) < 0xf0)
        car_tmotor = CAN_BYTE(5) - 40;
      else
        car_tmotor = 0; // unsigned, no negative temps allowed...

Simplifying code like that will probably save as much flash as we lose in going from 8 to 16 bits.

Once we've got over the current compilation flags / space issue with the 1.6 firmware, I'll make this change.

Regards, Mark.

On 13 Jan, 2014, at 10:46 pm, Mark Webb-Johnson <mark@webb-johnson.net> wrote:

Sound advise.

Given just a handful of temperatures, it is probably least impacting to just change to 16 bit signed and put this one to rest. It keeps coming back, and it would be good to solve it once and for all. Impact is 1 byte extra ram per temperature, plus some flash for the 16 vs 8 bit.

Moving to a 40C offset is tricky to maintain backwards compatibility.

Regards, Mark

On 13 Jan, 2014, at 9:51 pm, Collin Kidder <collink@kkmfg.com> wrote:

I don't think you'd want to do that. 127 deg C really isn't that terribly hot and -128C is extremely cold. If it is necessary to retain use of an 8 bit variable then the standard solution is to just offset the temperature stored by -40. That way you can read -40 to 215C which is a pretty reasonable range. Unfortunately, I fear such a change would necessitate many other changes in code. It might be better to expand to a signed 16 bit integer.


On Mon, Jan 13, 2014 at 7:50 AM, Håkon Markussen <hakon.markussen@gmail.com> wrote:
Hi (Mark).

In ovms.h the motor temperature is defined as unsigned char (non-negative):
extern unsigned char car_tmotor; // Tmotor

Currently the weather is cold in Norway (-15 C) and I noticed that motor temp was 244C.


Is it possible to update the car_tmotor to
extern signed char car_tmotor; // Tmotor
 in ovms.h?

Best regards
Håkon

_______________________________________________
OvmsDev mailing list
OvmsDev@lists.teslaclub.hk
http://lists.teslaclub.hk/mailman/listinfo/ovmsdev


_______________________________________________
OvmsDev mailing list
OvmsDev@lists.teslaclub.hk
http://lists.teslaclub.hk/mailman/listinfo/ovmsdev
_______________________________________________
OvmsDev mailing list
OvmsDev@lists.teslaclub.hk
http://lists.teslaclub.hk/mailman/listinfo/ovmsdev