mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-03 20:42:09 +08:00
07fbcc5dc2
4f82d01e gitignore
5cb83454 Honda FCM: diagnostic signals
d309cdce Added linter to opendbc (#203)
d452706f add requirements.txt
ec3b4595 deterministic dependency order
a265d351 Azure pipelines ci (#202)
bce9a2e1 packer depends on libdbc
5d5fdd6a no more python version of libdbc, everything through cython
541705bf move CANDefine to parser code
da25c52a add test for can define
0ba7926b unify can packer and parser
25d88009 consistent naming
a5c640a5 fix linter
be210fef remove obsolete make file
ffd9dca7 opendbc needs cereal
b559f63d remove more make
d0929496 seems to work now
41e80836 don't make
3254d1fc think scons works
eb78f6aa scons sort of working
0ef1e35d fix gitignore
e155e017 Can migration (#199)
3eded83a Honda: correct steering torque sensor sign to be consistent with standard convention (left+)
32f70e2f Fix outback endianness consistency (#196)
a7da471f Update subaru_outback_2015_eyesight.dbc (#195)
git-subtree-dir: opendbc
git-subtree-split: 4f82d01ebc78109888954d9807d320e3c27896fd
old-commit-hash: 683b6151ce
71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <map>
|
|
#include <unordered_map>
|
|
|
|
#include "common_dbc.h"
|
|
#include <capnp/serialize.h>
|
|
#include "cereal/gen/cpp/log.capnp.h"
|
|
|
|
#define MAX_BAD_COUNTER 5
|
|
|
|
// Helper functions
|
|
unsigned int honda_checksum(unsigned int address, uint64_t d, int l);
|
|
unsigned int toyota_checksum(unsigned int address, uint64_t d, int l);
|
|
void init_crc_lookup_tables();
|
|
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l);
|
|
unsigned int pedal_checksum(uint64_t d, int l);
|
|
uint64_t read_u64_be(const uint8_t* v);
|
|
uint64_t read_u64_le(const uint8_t* v);
|
|
|
|
class MessageState {
|
|
public:
|
|
uint32_t address;
|
|
unsigned int size;
|
|
|
|
std::vector<Signal> parse_sigs;
|
|
std::vector<double> vals;
|
|
|
|
uint16_t ts;
|
|
uint64_t seen;
|
|
uint64_t check_threshold;
|
|
|
|
uint8_t counter;
|
|
uint8_t counter_fail;
|
|
|
|
bool parse(uint64_t sec, uint16_t ts_, uint8_t * dat);
|
|
bool update_counter_generic(int64_t v, int cnt_size);
|
|
};
|
|
|
|
class CANParser {
|
|
private:
|
|
const int bus;
|
|
|
|
const DBC *dbc = NULL;
|
|
std::unordered_map<uint32_t, MessageState> message_states;
|
|
|
|
public:
|
|
bool can_valid = false;
|
|
uint64_t last_sec = 0;
|
|
|
|
CANParser(int abus, const std::string& dbc_name,
|
|
const std::vector<MessageParseOptions> &options,
|
|
const std::vector<SignalParseOptions> &sigoptions);
|
|
void UpdateCans(uint64_t sec, const capnp::List<cereal::CanData>::Reader& cans);
|
|
void UpdateValid(uint64_t sec);
|
|
void update_string(std::string data, bool sendcan);
|
|
std::vector<SignalValue> query_latest();
|
|
};
|
|
|
|
class CANPacker {
|
|
private:
|
|
const DBC *dbc = NULL;
|
|
std::map<std::pair<uint32_t, std::string>, Signal> signal_lookup;
|
|
std::map<uint32_t, Msg> message_lookup;
|
|
|
|
public:
|
|
CANPacker(const std::string& dbc_name);
|
|
uint64_t pack(uint32_t address, const std::vector<SignalPackValue> &signals, int counter);
|
|
};
|