Skip to content

Commit 7f8f3ab

Browse files
committed
- Add option to save IOP before parsing
- Add iop parser example for IOP parser debugging purposes Fixes #614, needed for Open-Agriculture/AgIsoVirtualTerminal#140
1 parent 3499b10 commit 7f8f3ab

File tree

10 files changed

+79
-3
lines changed

10 files changed

+79
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if(BUILD_EXAMPLES)
6969
add_subdirectory("examples/virtual_terminal/version3_object_pool")
7070
add_subdirectory("examples/virtual_terminal/aux_functions")
7171
add_subdirectory("examples/virtual_terminal/aux_inputs")
72+
add_subdirectory("examples/virtual_terminal/iop_parser_tester")
7273
add_subdirectory("examples/task_controller_client")
7374
add_subdirectory("examples/task_controller_server")
7475
add_subdirectory("examples/guidance")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(iop_parser)
3+
4+
if(NOT BUILD_EXAMPLES)
5+
find_package(isobus REQUIRED)
6+
endif()
7+
find_package(Threads REQUIRED)
8+
9+
add_executable(iop_parser main.cpp ../common/console_logger.cpp)
10+
11+
target_compile_features(iop_parser PUBLIC cxx_std_11)
12+
set_target_properties(iop_parser PROPERTIES CXX_EXTENSIONS OFF)
13+
14+
target_link_libraries(
15+
iop_parser PRIVATE isobus::Isobus Threads::Threads
16+
isobus::HardwareIntegration isobus::Utility)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp"
2+
3+
#include <cstdint>
4+
#include <fstream>
5+
#include <iostream>
6+
#include <vector>
7+
8+
#include "../common/console_logger.cpp"
9+
10+
int main(int argc, char *argv[])
11+
{
12+
if (argc != 2)
13+
{
14+
std::cerr << "Usage: " << argv[0] << " <iop file path>\n";
15+
return 1;
16+
}
17+
18+
const char *filename = argv[1];
19+
std::ifstream file(filename, std::ios::binary);
20+
if (!file)
21+
{
22+
std::cerr << "Unable to open: " << filename << "\n";
23+
return 1;
24+
}
25+
26+
std::vector<std::uint8_t> buffer((std::istreambuf_iterator<char>(file)),
27+
std::istreambuf_iterator<char>());
28+
29+
if (buffer.empty())
30+
{
31+
std::cerr << "File is empty or not readable.\n";
32+
return 1;
33+
}
34+
35+
isobus::CANStackLogger::set_can_stack_logger_sink(&logger);
36+
37+
isobus::VirtualTerminalServerManagedWorkingSet vt;
38+
bool result = vt.parse_iop_into_objects(buffer.data(),
39+
static_cast<std::uint32_t>(buffer.size()));
40+
41+
std::cout << "IOP parse result: " << std::boolalpha << result << "\n";
42+
return 0;
43+
}

examples/virtual_terminal/version3_object_pool/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ if(NOT BUILD_EXAMPLES)
66
endif()
77
find_package(Threads REQUIRED)
88

9-
add_executable(VT3ExampleTarget main.cpp console_logger.cpp objectPoolObjects.h)
9+
add_executable(VT3ExampleTarget main.cpp ../common/console_logger.cpp
10+
objectPoolObjects.h)
1011

1112
target_compile_features(VT3ExampleTarget PUBLIC cxx_std_11)
1213
set_target_properties(VT3ExampleTarget PROPERTIES CXX_EXTENSIONS OFF)

examples/virtual_terminal/version3_object_pool/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "isobus/isobus/isobus_virtual_terminal_client_update_helper.hpp"
88
#include "isobus/utility/iop_file_interface.hpp"
99

10-
#include "console_logger.cpp"
10+
#include "../common/console_logger.cpp"
1111
#include "objectPoolObjects.h"
1212

1313
#include <atomic>
@@ -102,7 +102,7 @@ int main()
102102
// Automatically load the desired CAN driver based on the available drivers
103103
std::shared_ptr<isobus::CANHardwarePlugin> canDriver = nullptr;
104104
#if defined(ISOBUS_SOCKETCAN_AVAILABLE)
105-
canDriver = std::make_shared<isobus::SocketCANInterface>("can0");
105+
canDriver = std::make_shared<isobus::SocketCANInterface>("vcan0");
106106
#elif defined(ISOBUS_WINDOWSPCANBASIC_AVAILABLE)
107107
canDriver = std::make_shared<isobus::PCANBasicWindowsPlugin>(PCAN_USBBUS1);
108108
#elif defined(ISOBUS_WINDOWSINNOMAKERUSB2CAN_AVAILABLE)

isobus/include/isobus/isobus/isobus_virtual_terminal_server.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ namespace isobus
267267
/// @returns The background color on the softkey mask
268268
virtual std::uint8_t get_user_layout_softkeymask_bg_color() const;
269269

270+
/// @brief Callback function which is called before the transferred IOP data parsing is started
271+
/// Useful to save IOP data for debugging purposes in the case if the parsing would lead to a crash
272+
/// @param ws[in] the working set which object pool processing is about to be started
273+
virtual void transferred_object_pool_parse_start(std::shared_ptr<VirtualTerminalServerManagedWorkingSet> &ws) const;
274+
270275
//-------------- Callbacks/Event driven interface ---------------------
271276

272277
/// @brief Returns the event dispatcher for repaint events

isobus/include/isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ namespace isobus
141141
/// @brief The object pool processing thread will execute this function when it runs
142142
void worker_thread_function();
143143

144+
std::string debugIopSavePath; ///< A path where the IOP will be saved before parsing if it is not an empty string
144145
std::unique_ptr<std::thread> objectPoolProcessingThread = nullptr; ///< A thread to process the object pool with, since that can be fairly time consuming.
145146
std::shared_ptr<ControlFunction> workingSetControlFunction = nullptr; ///< Stores the control function associated with this working set
146147
std::vector<isobus::EventCallbackHandle> callbackHandles; ///< A convenient way to associate callback handles to a working set

isobus/src/isobus_virtual_terminal_server.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ namespace isobus
9999
return 0;
100100
}
101101

102+
void VirtualTerminalServer::transferred_object_pool_parse_start(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> &ws) const
103+
{
104+
(void)ws;
105+
}
106+
102107
std::uint8_t VirtualTerminalServer::get_user_layout_datamask_bg_color() const
103108
{
104109
LOG_ERROR("[VT Server]: The Get User Layout Datamask background color is not implemented, returning with black");
@@ -589,6 +594,7 @@ namespace isobus
589594
{
590595
if (cf->get_any_object_pools())
591596
{
597+
parentServer->transferred_object_pool_parse_start(cf);
592598
cf->start_parsing_thread();
593599
}
594600
else

isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "isobus/utility/to_string.hpp"
1414

1515
#include <cstring>
16+
#include <fstream>
17+
#include <iostream>
1618

1719
namespace isobus
1820
{
@@ -183,6 +185,7 @@ namespace isobus
183185
LOG_INFO("[WS]: Beginning parsing of object pool. This pool has " +
184186
isobus::to_string(static_cast<int>(iopFilesRawData.size())) +
185187
" IOP components.");
188+
186189
for (std::size_t i = 0; i < iopFilesRawData.size(); i++)
187190
{
188191
if (!parse_iop_into_objects(iopFilesRawData[i].data(), static_cast<std::uint32_t>(iopFilesRawData[i].size())))

0 commit comments

Comments
 (0)