Skip to content

Commit

Permalink
Initial check-in of the pydbc python module.
Browse files Browse the repository at this point in the history
  • Loading branch information
ihedvall committed Jan 24, 2024
1 parent 7ba4913 commit 5baf218
Show file tree
Hide file tree
Showing 41 changed files with 1,917 additions and 181 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ jobs:
# CXX: clang++
# pack: 1
#
# - name: win64
# os: windows-latest
# ninja_platform: win
# msvc_arch: x64
# cmake_env:
# CMAKE_RC_FLAGS: "/C 1252"
# CC: clang
# CXX: clang++
# pack: 1
- name: win64
os: windows-latest
ninja_platform: win
msvc_arch: x64
cmake_env:
CMAKE_RC_FLAGS: "/C 1252"
CC: clang
CXX: clang++
pack: 1
#
# - name: win32
# os: windows-latest
Expand All @@ -60,7 +60,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Ninja
uses: seanmiddleditch/gha-setup-ninja@v3
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
run: |
mkdir -p build/release
cd build/release
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ${{ env.CMAKE_FLAGS }} ${{ matrix.env.cmake_flags }} ../..
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DDBC_PYTHON=ON ${{ env.CMAKE_FLAGS }} ${{ matrix.env.cmake_flags }} ../..
- name: Build
run: |
Expand Down
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

8 changes: 7 additions & 1 deletion .idea/dbclib.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ endif()
option(BUILD_SHARED_LIBS "Static libraries are preferred" OFF)
option(DBC_DOC "If doxygen is installed, then build documentation in Release mode" OFF)
option(DBC_TOOLS "Building applications" OFF)
option(DBC_TEST "Building unit test" ON)
option(DBC_PYTHON "Building Python module" ON)
option(DBC_TEST "Building unit test" OFF)
option(DBC_PYTHON "Building Python module" OFF)

if(DBC_TOOLS AND USE_VCPKG)
list(APPEND VCPKG_MANIFEST_FEATURES "tools")
Expand Down
22 changes: 12 additions & 10 deletions dbcviewer/src/childframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,8 +1241,9 @@ void ChildFrame::OnShowMessageData(wxCommandEvent &event) {
const auto& signal_list = message->Signals();
for (const auto& itr : signal_list) {
const auto& signal = itr.second;
auto observer = std::make_unique<SignalObserver>(signal);
observer_list->push_back(std::move(observer));
auto observer = SignalObserver::CreateSignalObserver(signal);
observer_list->emplace_back(observer);

}
file->ReparseMessageList();

Expand Down Expand Up @@ -1311,8 +1312,8 @@ void ChildFrame::OnShowSignalData(wxCommandEvent &event) {
title << "/" << file->Name();

auto observer_list = std::make_unique<SignalObserverList>();
auto observer = std::make_unique<SignalObserver>(*signal);
observer_list->push_back(std::move(observer));
auto observer = SignalObserver::CreateSignalObserver(*signal);
observer_list->emplace_back(observer);

file->ReparseMessageList();

Expand Down Expand Up @@ -1385,18 +1386,19 @@ void ChildFrame::OnPlotSignalData(wxCommandEvent &event) {
}
auto& app = wxGetApp();
// Create the observer list
auto observer_list = std::make_unique<SignalObserverList>();
auto observer = std::make_unique<SignalObserver>(*signal);
observer_list->push_back(std::move(observer));
SignalObserverList observer_list;
auto observer = SignalObserver::CreateSignalObserver(*signal);
observer_list.emplace_back(observer);

file->ReparseMessageList();
const auto* obs = observer_list->front().get();
const auto* obs = observer_list.front().get();
if (obs == nullptr || obs->NofValidSamples() < 2) {
wxMessageBox("There is not enough valid samples to plot");
return;
}
// Produce a CSV file with the data for later use with the gnuplot script
auto csv_file = CreateCsvFile(*observer_list);
auto gp_file = CreateGnuPlotFile(*observer_list, csv_file, title.str());
auto csv_file = CreateCsvFile(observer_list);
auto gp_file = CreateGnuPlotFile(observer_list, csv_file, title.str());
if (csv_file.empty() || gp_file.empty()) {
wxMessageBox("Failed to create CSV or GP files.\nMore information in log file.");
return;
Expand Down
6 changes: 3 additions & 3 deletions dbcviewer/src/dbcdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void DbcDocument::OnImportCanMessageFile(wxCommandEvent &event) {
LOG_ERROR() << "No header block in file. File: "
<< reader.ShortName();
}
const auto* data_group = reader.GetDataGroup(0);
auto* data_group = header->LastDataGroup();
if (data_group == nullptr) {
LOG_ERROR() << "No data in file. File: "
<< reader.ShortName();
Expand Down Expand Up @@ -177,8 +177,8 @@ void DbcDocument::OnImportCanMessageFile(wxCommandEvent &event) {
return;
}
size_t count_messages = 0;
dbc_file_->SetMessageSize(0);
dbc_file_->SetMessageSize(nof_messages);
dbc_file_->MessageSize(0);
dbc_file_->MessageSize(nof_messages);
for (size_t sample = 0; sample < nof_messages; ++sample) {
uint64_t time = 0;
const auto time_valid = rel_time->GetChannelValue(sample, time);
Expand Down
2 changes: 2 additions & 0 deletions include/dbc/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ enum class AttributeValueType : int {
*/
class Attribute {
public:
Attribute() = default; ///< Default constructor

/** \brief Constructor for an attribute or definition. */
Attribute( AttributeType type, const std::string& name );

Expand Down
2 changes: 1 addition & 1 deletion include/dbc/dbcfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class DbcFile {
*
*/
void ReparseMessageList();

void ClearObserverList();
private:
/** \brief Parses standard CAN messages. */
bool ParseStandardCAN(const DbcMessage& message);
Expand Down
3 changes: 1 addition & 2 deletions include/dbc/dbcmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ class DbcMessage {
DbcMessage(uint64_t time, uint32_t can_id, std::vector<uint8_t> data);
DbcMessage(const DbcMessage& message) = default; ///< Default destructor.


void Time(uint64_t ns1970) {time_ = ns1970;} ///< Sets the time.
[[nodiscard]] uint64_t Time() const {return time_;} ///< Message time.

void CanId(uint32_t can_id) {can_id_ = can_id;} ///< Sets the CAN ID.
[[nodiscard]] uint32_t CanId() const {return can_id_;} ///< CAN ID.

/** \brief Sets the CAN data bytes. */
void Data(const std::vector<uint8_t>& data) {data_ = data;}
void Data(const std::vector<uint8_t>& data) { data_ = data;}
/** \brief Returns the CAN data bytes. */
[[nodiscard]] const std::vector<uint8_t>& Data() const {return data_;}

Expand Down
2 changes: 2 additions & 0 deletions include/dbc/envvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ enum class AccessType : int {
/** \brief Wrapper around an environment DBC variable. */
class EnvVar {
public:
EnvVar() = default;

/** \brief Sets the name. */
void Name(const std::string& name) { name_ = name; }
/** \brief Retuns the name. */
Expand Down
7 changes: 5 additions & 2 deletions include/dbc/isampleobserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ namespace dbc {
*/
class ISampleObserver {
public:
ISampleObserver() = default; ///< Default constructor.

virtual ~ISampleObserver() = default; ///< Default destructor.

virtual void OnSample() = 0; ///< Handle a sample.
virtual void DetachObserver() = 0; ///< Detach the observer object.

protected:
ISampleObserver() = default; ///< Default constructor.
};

} // namespace dbc
11 changes: 9 additions & 2 deletions include/dbc/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ using SignalList = std::map<std::string, Signal>;
/** \brief DBC message configuration object. */
class Message {
public:
void Ident(uint64_t ident) { ///< Sets the message ID (29-bit)
/**
* \brief Sets the message ID.
*
* Sets the message ID. The extended CAN ID is max 29-bit. to indicate
* that the ID is extended, bit 32 should be set.
* @param ident Message ID
*/
void Ident(uint64_t ident) {
ident_ = ident;
}
[[nodiscard]] uint64_t Ident() const { ///< Returns the message ID.
Expand Down Expand Up @@ -115,7 +122,7 @@ class Message {
/** \brief Reset the internal sequence counter. */
void ResetSequenceNumber() {sequence_number_ = 0;}
/** \brief Returns the next sequence number. */
uint8_t NextSequenceNumber() const {return sequence_number_;}
[[nodiscard]] uint8_t NextSequenceNumber() const {return sequence_number_;}

void ResetSampleCounter() const; ///< Reset the sample counters.
/** \brief Increments the internal sample counters. */
Expand Down
2 changes: 1 addition & 1 deletion include/dbc/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Network {
void Comment(const std::string& comment) {
comment_ = comment;
}
/** \brief Returns the desciptive text. */
/** \brief Returns the descriptive text. */
[[nodiscard]] const std::string& Comment() const { return comment_; }

/** \brief Returns the node by its name. */
Expand Down
Loading

0 comments on commit 5baf218

Please sign in to comment.