mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-08-04 15:56:05 +08:00
Bug: Param Store Cache (#1025)
* cache * Clear every 10 iterations, which means 100hz * 10 * Revert "Clear every 10 iterations, which means 100hz * 10" This reverts commit 4eda3079e6cfc83008b8df0d41094ce52237faf7. * Apply suggestion from @devtekve * Apply suggestion from @devtekve --------- Co-authored-by: DevTekVE <devtekve@gmail.com>
This commit is contained in:
committed by
GitHub
parent
d0bd8cc4a3
commit
394603727e
@@ -22,14 +22,16 @@ class ParamStore:
|
||||
|
||||
self.keys = universal_params + brand_params
|
||||
self.values = {}
|
||||
self.cached_params_list: list[capnp.lib.capnp._DynamicStructBuilder] | None = None
|
||||
|
||||
def update(self, params: Params) -> None:
|
||||
old_values = dict(self.values)
|
||||
self.values = {k: params.get(k, encoding='utf8') or "0" for k in self.keys}
|
||||
if old_values != self.values:
|
||||
self.cached_params_list = None
|
||||
|
||||
def publish(self) -> list[capnp.lib.capnp._DynamicStructBuilder]:
|
||||
params_list: list[capnp.lib.capnp._DynamicStructBuilder] = []
|
||||
|
||||
for k in self.keys:
|
||||
params_list.append(custom.CarControlSP.Param(key=k, value=self.values[k]))
|
||||
|
||||
return params_list
|
||||
if self.cached_params_list is None:
|
||||
# TODO-SP: Why are we doing a list instead of a dictionary here?
|
||||
self.cached_params_list = [custom.CarControlSP.Param(key=k, value=self.values[k]) for k in self.keys]
|
||||
return self.cached_params_list
|
||||
|
||||
Reference in New Issue
Block a user