Skip to content

Commit

Permalink
refactor: putIntNonBlocking
Browse files Browse the repository at this point in the history
fix

fix
  • Loading branch information
Edison-CBS committed Mar 3, 2024
1 parent d6a51d0 commit 63a5fe6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions common/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class Params {
inline void putBoolNonBlocking(const std::string &key, bool val) {
putNonBlocking(key, val ? "1" : "0");
}
void putIntNonBlocking(const std::string &key, const std::string &val);
inline void putIntNonBlocking(const std::string &key, int val) {
putNonBlocking(key, std::to_string(val));
}

private:
void asyncWriteThread();
Expand Down
3 changes: 1 addition & 2 deletions common/params.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from openpilot.common.params_pyx import Params, ParamKeyType, UnknownKeyName, put_int_nonblocking
from openpilot.common.params_pyx import Params, ParamKeyType, UnknownKeyName
assert Params
assert ParamKeyType
assert UnknownKeyName
assert put_int_nonblocking

if __name__ == "__main__":
import sys
Expand Down
10 changes: 6 additions & 4 deletions common/params_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from libcpp cimport bool
from libcpp.string cimport string
from libcpp.vector cimport vector
import threading

cdef extern from "common/params.h":
cpdef enum ParamKeyType:
Expand All @@ -23,6 +22,7 @@ cdef extern from "common/params.h":
int put(string, string) nogil
void putNonBlocking(string, string) nogil
void putBoolNonBlocking(string, bool) nogil
void putIntNonBlocking(string, int) nogil
int putBool(string, bool) nogil
int putInt(string, int) nogil
bool checkKey(string) nogil
Expand Down Expand Up @@ -129,8 +129,10 @@ cdef class Params:
cdef string key_bytes = ensure_bytes(key)
return self.p.getParamPath(key_bytes).decode("utf-8")

def put_int_nonblocking(self, key, int val):
cdef string k = self.check_key(key)
with nogil:
self.p.putIntNonBlocking(k, val)

def all_keys(self):
return self.p.allKeys()

def put_int_nonblocking(key, int val, d=""):
threading.Thread(target=lambda: Params(d).put_int(key, val)).start()
4 changes: 2 additions & 2 deletions selfdrive/car/toyota/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from openpilot.common.conversions import Conversions as CV
from openpilot.common.numpy_fast import mean
from openpilot.common.filter_simple import FirstOrderFilter
from openpilot.common.params import Params, put_int_nonblocking
from openpilot.common.params import Params
from openpilot.common.realtime import DT_CTRL
from opendbc.can.can_define import CANDefine
from opendbc.can.parser import CANParser
Expand Down Expand Up @@ -187,7 +187,7 @@ def update(self, cp, cp_cam):
self.distance_lines = max(cp.vl["PCM_CRUISE_SM"]["DISTANCE_LINES"] - 1, 0)

if self.distance_lines != self.previous_distance_lines:
put_int_nonblocking('LongitudinalPersonality', self.distance_lines)
self.params.put_int_nonblocking('LongitudinalPersonality', self.distance_lines)
self.previous_distance_lines = self.distance_lines

return ret
Expand Down

0 comments on commit 63a5fe6

Please sign in to comment.