[Ovmsdev] V3 progress
Mark Webb-Johnson
mark at webb-johnson.net
Tue Oct 3 21:30:30 HKT 2017
Tom,
> When I play a can bus recording I see the metrics update!
Sounds great. It is pretty cool to see the metrics populated. Much easier to ensure everything is working than with v2.
> I see that quite a few of the metrics used on the leaf are missing. Do I just add them to metrics_standard.cpp? None of them are particularly leaf specific, so this seems the right place.
I just added the very basic ones, as a starting point and proof of concept. Hadn’t decided if I needed anything special for the bitmapped ones at the time (either a new MetricBitmap type, or extend MetricInt). Looking at how things have evolved, and bearing in mind the GAPP bluetooth stuff, and OVMS v3 MQTT, it seems that each bit should be a metric of their own. Not too hard for ovms_server_v2 to convert that back to an integer bitmap, for backwards compatibility. To do that, car_doors1 becomes:
v.d.frontleft: bool
v.d.frontright: bool
v.d.chargeport: bool
v.c.pilot: bool
v.c.charging: bool
v.e.handbrake: bool
v.e.caron: bool
N.B. The ‘v.’ is the prefix for vehicle metrics, then the second part becomes the area of the vehicle (‘b.’ for battery, ‘p.’ for position, ‘tp.’ for tpms, ‘d.’ for doors, ‘c.’ for charger, etc).
So, if you have time, please go ahead and add the other standard ones that are simple and shared across all cars. You need to add a '#define MS_V_…’ for the string name, then a ‘ms_v_…’ member variable to MetricsStandard, then change MetricsStandard::MetricsStandard() constructor to create the metric itself and store a pointer in the member variable.
I guess we need to add all the car_ ones from ovms.h in the v2 project. Here are the ones outstanding:
extern unsigned int car_linevoltage; // Line Voltage
extern unsigned char car_chargecurrent; // Charge Current
extern unsigned char car_chargelimit; // Charge Limit (amps)
extern unsigned int car_chargeduration; // Charge Duration (minutes)
extern unsigned char car_chargestate; // 1=charging, 2=top off, 4=done, 13=preparing to charge, 21-25=stopped charging
extern unsigned char car_chargesubstate;
extern unsigned char car_chargemode; // 0=standard, 1=storage, 3=range, 4=performance
extern unsigned char car_charge_b4; // B4 byte of charge state
extern unsigned int car_chargekwh; // Energy charged (1/10 kWh)
extern chargetype car_chargetype;
extern unsigned int car_chargepower; // Charge Power (1/10 kW)
extern unsigned int car_battvoltage; // Battery Voltage (1/10 V)
extern unsigned char car_doors1;
typedef struct {
unsigned FrontLeftDoor:1; // 0x01
unsigned FrontRightDoor:1; // 0x02
unsigned ChargePort:1; // 0x04
unsigned PilotSignal:1; // 0x08
unsigned Charging:1; // 0x10
unsigned :1; // 0x20
unsigned HandBrake:1; // 0x40
unsigned CarON:1; // 0x80
} car_doors1bits_t;
#define car_doors1bits (*((car_doors1bits_t*)&car_doors1))
extern unsigned char car_doors2;
typedef struct {
unsigned :1; // 0x01
unsigned :1; // 0x02
unsigned :1; // 0x04
unsigned CarLocked:1; // 0x08
unsigned ValetMode:1; // 0x10
unsigned Headlights:1; // 0x20
unsigned Bonnet:1; // 0x40
unsigned Trunk:1; // 0x80
} car_doors2bits_t;
#define car_doors2bits (*((car_doors2bits_t*)&car_doors2))
extern unsigned char car_doors3;
typedef struct {
unsigned CarAwake:1; // 0x01
unsigned CoolingPump:1; // 0x02
unsigned :1; // 0x04
unsigned :1; // 0x08
unsigned :1; // 0x10
unsigned :1; // 0x20
unsigned CtrlLoggedIn:1; // 0x40 - logged into controller
unsigned CtrlCfgMode:1; // 0x80 - controller in configuration mode
} car_doors3bits_t;
#define car_doors3bits (*((car_doors3bits_t*)&car_doors3))
extern unsigned char car_doors4;
typedef struct {
unsigned :1; // 0x01
unsigned AlarmSounds:1; // 0x02
unsigned :1; // 0x04
unsigned :1; // 0x08
unsigned :1; // 0x10
unsigned :1; // 0x20
unsigned :1; // 0x40
unsigned :1; // 0x80
} car_doors4bits_t;
#define car_doors4bits (*((car_doors4bits_t*)&car_doors4))
extern unsigned char car_doors5;
typedef struct {
unsigned RearLeftDoor:1; // 0x01
unsigned RearRightDoor:1; // 0x02
unsigned Frunk:1; // 0x04
unsigned :1; // 0x08
unsigned Charging12V:1; // 0x10
unsigned :1; // 0x20
unsigned :1; // 0x40
unsigned HVAC:1; // 0x80
} car_doors5bits_t;
extern unsigned char car_lockstate; // Lock State
extern unsigned char car_drivemode; // Car specific encoding of current drive mode
extern signed int car_power; // Current battery power level (1/10 kW)
extern unsigned long car_energy_used; // Energy used on trip (Wh)
extern unsigned long car_energy_recd; // Energy recovered on trip (Wh)
extern unsigned long car_time; // UTC Time
extern unsigned long car_parktime; // UTC time car was parked (or 0 if not)
extern unsigned char car_stopped_mincnt; // Minute countdown while stopped
extern signed char car_timermode; // Timer mode (0=onplugin, 1=timer)
extern unsigned int car_timerstart; // Timer start
extern unsigned char car_gpslock; // GPS lock status & satellite count
#define GPS_LOCK() ((car_gpslock & 0b11000000) >> 6)
#define GPS_SATCNT() (car_gpslock & 0b00111111)
extern signed char car_stale_ambient; // 0 = Ambient temperature is stale
extern signed char car_stale_temps; // 0 = Powertrain temperatures are stale
extern signed char car_stale_gps; // 0 = gps is stale
extern signed char car_stale_tpms; // 0 = tpms is stale
extern signed char car_stale_timer; // 0 = timer is stale
extern unsigned char net_reg; // Network registration
extern unsigned char net_link; // Network link status
extern unsigned char net_iccid[MAX_ICCID]; // ICCID
extern char net_apps_connected; // Network apps connected
extern char sys_features[FEATURES_MAX]; // System features
extern unsigned char net_sq; // GSM Network Signal Quality
extern unsigned int car_12v_current; // 12V (DC converter) current in 1/10 A
extern unsigned char car_gsmcops[9]; // GSM provider
extern signed int car_chargefull_minsremaining; // ETR for 100%
extern signed int car_chargelimit_minsremaining_range; // ETR for range limit
extern signed int car_chargelimit_minsremaining_soc; // ETR for SOC limit
extern unsigned int car_chargelimit_rangelimit; // Range limit (in vehicle units)
extern unsigned char car_chargelimit_soclimit; // SOC% limit
extern unsigned int car_max_idealrange; // Maximum ideal range in miles
extern signed char car_coolingdown; // >=0 if car is cooling down
extern unsigned char car_cooldown_chargemode; // 0=standard, 1=storage, 3=range, 4=performance
extern unsigned char car_cooldown_chargelimit; // Charge Limit (amps)
extern signed int car_cooldown_tbattery; // Cooldown temperature limit
extern unsigned int car_cooldown_timelimit; // Cooldown time limit (minutes) remaining
extern unsigned char car_cooldown_wascharging; // TRUE if car was charging when cooldown started
extern int car_chargeestimate; // ACC: charge time estimation for current charger capabilities (min.)
extern unsigned char car_SOCalertlimit; // Low limit of SOC at which alert should be raised
#define CAR_IS_ON (car_doors1bits.CarON)
#define CAR_IS_CHARGING (car_doors1bits.Charging)
#define CAR_IS_HEATING (car_chargestate==0x0f)
Now, a bunch of those aren’t necessary to convert.
We have ‘modifiers’ to track whether something has been modified, and I’ve just added m_lastmodified (and GetLastModified()), and m_stale (and SetStale()) to metrics, to allow us to know if a metric is stale or not. So, now all those _stale variables can go (and ovms_server_v2 can work it out itself).
Then we have a bunch that seem to be not actually used in protocol messages. Those should either be vehicle-specific (so not in standard_metrics), or just stored in the vehicle module itself.
> Is anyone working on the v2 server support code to send the S and D messages?
Nope. Not at the moment. I’ve stubbed it.
The v2 code used CRCs to check if something has been modified. The stubbed version doesn’t use that. I think we can use modifiers on the metrics to know whether the metric itself has changed. I tried implementing one (TransmitMsgTPMS) and that went quite cleanly. It was wordy, but overall looked neat. Certainly easier for the vehicle modules not to have to maintain these CRCs and decrementing timers.
Let me know what you think, and if you have time to try to implement some of this.
Regards, Mark.
> On 3 Oct 2017, at 5:33 PM, Tom Parker <tom at carrott.org> wrote:
>
> Hi all,
>
> I got my USB CAN bus interface working with the OVMS v3 hardware on my desk, it turns out you need at least one terminator before the bus will work!
>
> I cargo culted (I've never written C++) my way through transposing the Leaf OVMS v2 can bus decoder into the v3 code. When I play a can bus recording I see the metrics update!
>
> I see that quite a few of the metrics used on the leaf are missing. Do I just add them to metrics_standard.cpp? None of them are particularly leaf specific, so this seems the right place.
>
> Is anyone working on the v2 server support code to send the S and D messages?
>
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.teslaclub.hk
> http://lists.teslaclub.hk/mailman/listinfo/ovmsdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20171003/2eecb861/attachment.htm>
More information about the OvmsDev
mailing list