[Ovmsdev] Extended metrics persistence

Michael Balzer dexter at expeedo.de
Mon Jan 18 02:16:56 HKT 2021


Everyone,

I've managed to extend the persistent metrics storage structure to 
support 100 instead of the former 30 metrics with even a slight 
reduction in memory usage:

OVMS# metrics persist
version 3, serial 2, 820 bytes, and 77 of 100 slots used

This is achieved by replacing the metric names as 24 byte keys by their 
4 byte hash keys.

There's a potential disadvantage from this to be noted: hash collisions 
may occur. I've tested a full persistent metrics set including the new 
TPMS arrays, no collisions with the current hash function. If a 
collision occurs, the metric won't get added to the persistent set (or 
will be removed, see below), and an error log message is generated. If 
you add new persistences for standard or custom metrics, check the log.

A special case are vector metrics. These are implemented by allocating 
one slot to the vector size using the metric's base name, and one slot 
for each element using the base name extended by the index. If the 
vector grows, it will try to allocate new persistent slots as needed. If 
that fails, persistence is dropped for the whole vector. So if you add a 
new persistent vector, be sure to check for element hash collisions by 
setting it manually to a full expected element set at least once. You 
can do so easily by the "metrics set" command.

If we run into hash collisions, there are some options, e.g. using 
another hash function. Extending the storage structure to support 
chained chunks of values is another option.

Persistence is currently limited to values fitting into 4 bytes. 
OvmsMetricFloat, Int and Bool work, and vectors fitting that element 
size. String, Set, BitSet are todo.

I've added persistence to a number of state and counter metrics formerly 
lacking persistence. The new set of persistent metrics is:

OVMS# metrics list -p
v.b.12v.voltage.ref                      12.6V
v.b.cac                                  160Ah
v.b.coulomb.recd
v.b.coulomb.recd.total
v.b.coulomb.used
v.b.coulomb.used.total
v.b.energy.recd
v.b.energy.recd.total
v.b.energy.used
v.b.energy.used.total
v.b.range.est                            160km
v.b.range.ideal                          200km
v.b.soc                                  50%
v.b.soh                                  100%
v.b.temp                                 25°C
v.c.12v.temp
v.c.charging
v.c.climit
v.c.kwh
v.c.kwh.grid
v.c.kwh.grid.total
v.c.limit.range
v.c.limit.soc
v.c.temp                                 22°C
v.c.time                                 0Sec
v.c.timermode
v.c.timerstart
v.d.cp
v.e.aux12v
v.e.awake
v.e.cabintemp
v.e.charging12v
v.e.drivemode
v.e.drivetime                            0Sec
v.e.locked
v.e.on
v.e.parktime                             275Sec
v.e.temp                                 22°C
v.e.valet
v.g.climit
v.g.generating
v.g.kwh
v.g.kwh.grid
v.g.kwh.grid.total
v.g.limit.range
v.g.limit.soc
v.g.temp
v.g.time
v.g.timermode
v.g.timerstart
v.i.temp                                 22°C
v.m.temp                                 30°C
v.p.altitude                             329.3m
v.p.latitude                             51.3024
v.p.longitude                            7.38979
v.p.odometer                             100000km
v.p.trip
v.t.alert                                0,0,0,1
v.t.health                               95,93,96,74%
v.t.pressure 206.843,216.483,275.79,175.79kPa
v.t.temp                                 33,33,34,38°C


If you still miss something here, let me know.

Regards,
Michael

-- 
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20210117/7f50a3eb/attachment-0001.sig>


More information about the OvmsDev mailing list