Revert "CANParser: add field for all updated values (#548)"

This reverts commit da47fe5e45.
This commit is contained in:
Adeeb Shihadeh 2022-02-09 22:01:25 -08:00
parent 6770f1cdfb
commit 24538ceb04
6 changed files with 17 additions and 55 deletions

View File

@ -32,7 +32,6 @@ public:
std::vector<Signal> parse_sigs;
std::vector<double> vals;
std::vector<std::vector<double>> updated_vals;
uint64_t seen;
uint64_t check_threshold;
@ -69,7 +68,7 @@ public:
#endif
void UpdateCans(uint64_t sec, const capnp::DynamicStruct::Reader& cans);
void UpdateValid(uint64_t sec);
std::vector<SignalValue> update_vl();
std::vector<SignalValue> query_latest();
};
class CANPacker {

View File

@ -62,7 +62,6 @@ cdef extern from "common_dbc.h":
uint32_t address
const char* name
double value
vector[double] updated_values
cdef struct SignalPackValue:
string name
@ -76,7 +75,7 @@ cdef extern from "common.h":
bool can_valid
CANParser(int, string, vector[MessageParseOptions], vector[SignalParseOptions])
void update_string(string, bool)
vector[SignalValue] update_vl()
vector[SignalValue] query_latest()
cdef cppclass CANPacker:
CANPacker(string)

View File

@ -25,8 +25,7 @@ struct MessageParseOptions {
struct SignalValue {
uint32_t address;
const char* name;
double value; // latest value
std::vector<double> updated_values; // values updated this cycle
double value;
};
enum SignalType {

View File

@ -83,13 +83,13 @@ bool MessageState::parse(uint64_t sec, uint8_t * dat) {
}
vals[i] = tmp * sig.factor + sig.offset;
updated_vals[i].push_back(vals[i]);
}
seen = sec;
return true;
}
bool MessageState::update_counter_generic(int64_t v, int cnt_size) {
uint8_t old_counter = counter;
counter = v;
@ -147,7 +147,6 @@ CANParser::CANParser(int abus, const std::string& dbc_name,
if (sig->type != SignalType::DEFAULT) {
state.parse_sigs.push_back(*sig);
state.vals.push_back(0);
state.updated_vals.push_back({});
}
}
@ -161,7 +160,6 @@ CANParser::CANParser(int abus, const std::string& dbc_name,
&& sig->type == SignalType::DEFAULT) {
state.parse_sigs.push_back(*sig);
state.vals.push_back(0);
state.updated_vals.push_back({});
break;
}
}
@ -190,7 +188,6 @@ CANParser::CANParser(int abus, const std::string& dbc_name, bool ignore_checksum
const Signal *sig = &msg->sigs[j];
state.parse_sigs.push_back(*sig);
state.vals.push_back(0);
state.updated_vals.push_back({});
}
message_states[state.address] = state;
@ -282,11 +279,12 @@ void CANParser::UpdateValid(uint64_t sec) {
}
}
std::vector<SignalValue> CANParser::update_vl() {
std::vector<SignalValue> CANParser::query_latest() {
std::vector<SignalValue> ret;
for (auto& kv : message_states) {
auto& state = kv.second;
for (const auto& kv : message_states) {
const auto& state = kv.second;
if (last_sec != 0 && state.seen != last_sec) continue;
for (int i=0; i<state.parse_sigs.size(); i++) {
const Signal &sig = state.parse_sigs[i];
@ -294,9 +292,7 @@ std::vector<SignalValue> CANParser::update_vl() {
.address = state.address,
.name = sig.name,
.value = state.vals[i],
.updated_values = state.updated_vals[i],
});
state.updated_vals[i].clear(); // reset updated values for next cycle
}
}

View File

@ -29,7 +29,6 @@ cdef class CANParser:
cdef readonly:
string dbc_name
dict vl
dict updated
bool can_valid
int can_invalid_cnt
@ -42,7 +41,6 @@ cdef class CANParser:
if not self.dbc:
raise RuntimeError(f"Can't find DBC: {dbc_name}")
self.vl = {}
self.updated = {}
self.can_invalid_cnt = CAN_INVALID_CNT
@ -56,8 +54,6 @@ cdef class CANParser:
self.address_to_msg_name[msg.address] = name
self.vl[msg.address] = {}
self.vl[name] = {}
self.updated[msg.address] = {}
self.updated[name] = {}
# Convert message names into addresses
for i in range(len(signals)):
@ -106,13 +102,13 @@ cdef class CANParser:
cdef string sig_name
cdef unordered_set[uint32_t] updated_val
can_values = self.can.update_vl()
can_values = self.can.query_latest()
valid = self.can.can_valid
# Update invalid flag
self.can_invalid_cnt += 1
if valid:
self.can_invalid_cnt = 0
self.can_invalid_cnt = 0
self.can_valid = self.can_invalid_cnt < CAN_INVALID_CNT
for cv in can_values:
@ -123,11 +119,7 @@ cdef class CANParser:
self.vl[cv.address][cv_name] = cv.value
self.vl[name][cv_name] = cv.value
self.updated[cv.address][cv_name] = cv.updated_values
self.updated[name][cv_name] = cv.updated_values
if cv.updated_values.size():
updated_val.insert(cv.address)
updated_val.insert(cv.address)
return updated_val
@ -136,10 +128,13 @@ cdef class CANParser:
return self.update_vl()
def update_strings(self, strings, sendcan=False):
for s in strings:
self.can.update_string(s, sendcan)
updated_vals = set()
return self.update_vl()
for s in strings:
updated_val = self.update_string(s, sendcan)
updated_vals.update(updated_val)
return updated_vals
cdef class CANDefine():
cdef:

View File

@ -119,32 +119,6 @@ class TestCanParserPacker(unittest.TestCase):
idx += 1
def test_updated(self):
"""Test updated value dict"""
dbc_file = "honda_civic_touring_2016_can_generated"
signals = [("USER_BRAKE", "VSA_STATUS")]
checks = [("VSA_STATUS", 50)]
parser = CANParser(dbc_file, signals, checks, 0)
packer = CANPacker(dbc_file)
# Make sure nothing is updated
self.assertEqual(len(parser.updated["VSA_STATUS"]["USER_BRAKE"]), 0)
# Ensure CANParser holds the values of any duplicate messages
user_brake_vals = [4, 5, 6, 7]
msgs = []
for user_brake in user_brake_vals:
values = {"USER_BRAKE": user_brake}
msgs.append(packer.make_can_msg("VSA_STATUS", 0, values))
parser.update_strings([can_list_to_can_capnp(msgs)])
updated = parser.updated["VSA_STATUS"]["USER_BRAKE"]
self.assertEqual(updated, user_brake_vals)
self.assertEqual(updated[-1], parser.vl["VSA_STATUS"]["USER_BRAKE"])
if __name__ == "__main__":
unittest.main()