Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library linting #1

Merged
merged 3 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: ad3154
7 changes: 7 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# AgIsoStack-Arduino
AgIsoStack is a free ISOBUS (ISO11783) and SAE J1939 compatible CAN stack that makes communication on off-highway vehicle CAN networks easy.

Currently this library is compatible with Teensy hardware only. ESP32 support will likely be added at some point, but for now PlatformIO + ESP-IDF is supported for ESP32 platforms via the [main repo](https://github.com/Open-Agriculture/AgIsoStack-plus-plus).
This library is based on the larger [AgIsoStack++ project](https://github.com/Open-Agriculture/AgIsoStack-plus-plus), which provides a CMake build system and additional supported CAN hardware.

Currently this Arduino library is compatible with Teensy hardware only. ESP32 support will likely be added at some point, but for now PlatformIO + ESP-IDF is supported for ESP32 platforms via the [main repo](https://github.com/Open-Agriculture/AgIsoStack-plus-plus).

### Features

Expand Down
9,399 changes: 9,399 additions & 0 deletions examples/VirtualTerminal/ObjectPool.cpp

Large diffs are not rendered by default.

160 changes: 160 additions & 0 deletions examples/VirtualTerminal/VirtualTerminal.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#include <AgIsoStack.hpp>

#include "ObjectPool.cpp"

using namespace isobus;

auto can0 = std::make_shared<FlexCANT4Plugin>(0);
std::shared_ptr<InternalControlFunction> ISOBUSControlFunction = nullptr;
std::shared_ptr<DiagnosticProtocol> ISOBUSDiagnostics = nullptr;
std::shared_ptr<VirtualTerminalClient> ExampleVirtualTerminalClient = nullptr;
std::shared_ptr<void> softKeyListener = nullptr;
std::shared_ptr<void> buttonListener = nullptr;

// A log sink for the CAN stack
class CustomLogger : public isobus::CANStackLogger
{
public:
void sink_CAN_stack_log(CANStackLogger::LoggingLevel level, const std::string &text) override
{
switch (level)
{
case LoggingLevel::Debug:
{
Serial.print("[Debug]: ");
}
break;

case LoggingLevel::Info:
{
Serial.print("[Info]: ");
}
break;

case LoggingLevel::Warning:
{
Serial.print("[Warning]: ");
}
break;

case LoggingLevel::Error:
{
Serial.print("[Error]: ");
}
break;

case LoggingLevel::Critical:
{
Serial.print("[Critical]: ");
}
break;
}
Serial.println(text.c_str());
}
};

static CustomLogger logger;

// This callback will provide us with event driven notifications of button presses from the stack
void handleVTKeyEvents(const VirtualTerminalClient::VTKeyEvent &event)
{
static std::uint32_t exampleNumberOutput = 214748364; // In the object pool the output number has an offset of -214748364 so we use this to represent 0.

switch (event.keyEvent)
{
case VirtualTerminalClient::KeyActivationCode::ButtonUnlatchedOrReleased:
{
switch (event.objectID)
{
case Plus_Button:
{
ExampleVirtualTerminalClient->send_change_numeric_value(ButtonExampleNumber_VarNum, ++exampleNumberOutput);
}
break;

case Minus_Button:
{
ExampleVirtualTerminalClient->send_change_numeric_value(ButtonExampleNumber_VarNum, --exampleNumberOutput);
}
break;

case alarm_SoftKey:
{
ExampleVirtualTerminalClient->send_change_active_mask(example_WorkingSet, example_AlarmMask);
}
break;

case acknowledgeAlarm_SoftKey:
{
ExampleVirtualTerminalClient->send_change_active_mask(example_WorkingSet, mainRunscreen_DataMask);
}
break;

default:
break;
}
}
break;

default:
break;
}
}

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
CANStackLogger::set_can_stack_logger_sink(&logger);
CANStackLogger::set_log_level(isobus::CANStackLogger::LoggingLevel::Debug);
// Optional, add delay() here to give you time to connect to the serial logger
CANHardwareInterface::set_number_of_can_channels(1);
CANHardwareInterface::assign_can_channel_frame_handler(0, can0);
CANHardwareInterface::start();
CANHardwareInterface::update();

NAME deviceNAME(0);
// Make sure you change these for your device
// This is an example device that is using a manufacturer code that is currently unused at time of writing
deviceNAME.set_arbitrary_address_capable(true);
deviceNAME.set_industry_group(0);
deviceNAME.set_device_class(0);
deviceNAME.set_function_code(static_cast<std::uint8_t>(isobus::NAME::Function::SteeringControl));
deviceNAME.set_identity_number(2);
deviceNAME.set_ecu_instance(0);
deviceNAME.set_function_instance(0);
deviceNAME.set_device_class_instance(0);
deviceNAME.set_manufacturer_code(64);
// Change 0x81 to be your preferred address, but 0x81 is the base arbitrary address
ISOBUSControlFunction = InternalControlFunction::create(deviceNAME, 0x81, 0);
ISOBUSDiagnostics = std::make_shared<DiagnosticProtocol>(ISOBUSControlFunction);
ISOBUSDiagnostics->initialize();

// Change these to be specific to your device
ISOBUSDiagnostics->set_product_identification_brand("Arduino");
ISOBUSDiagnostics->set_product_identification_code("123456789");
ISOBUSDiagnostics->set_product_identification_model("Example");
ISOBUSDiagnostics->set_software_id_field(0, "0.0.1");
ISOBUSDiagnostics->set_ecu_id_field(DiagnosticProtocol::ECUIdentificationFields::HardwareID, "Hardware ID");
ISOBUSDiagnostics->set_ecu_id_field(DiagnosticProtocol::ECUIdentificationFields::Location, "The Aether");
ISOBUSDiagnostics->set_ecu_id_field(DiagnosticProtocol::ECUIdentificationFields::ManufacturerName, "None");
ISOBUSDiagnostics->set_ecu_id_field(DiagnosticProtocol::ECUIdentificationFields::PartNumber, "1234");
ISOBUSDiagnostics->set_ecu_id_field(DiagnosticProtocol::ECUIdentificationFields::SerialNumber, "1");
ISOBUSDiagnostics->set_ecu_id_field(DiagnosticProtocol::ECUIdentificationFields::Type, "AgISOStack");

// Set up virtual terminal client
const NAMEFilter filterVirtualTerminal(NAME::NAMEParameters::FunctionCode, static_cast<std::uint8_t>(NAME::Function::VirtualTerminal));
const std::vector<NAMEFilter> vtNameFilters = { filterVirtualTerminal };
auto TestPartnerVT = PartneredControlFunction::create(0, vtNameFilters);
ExampleVirtualTerminalClient = std::make_shared<VirtualTerminalClient>(TestPartnerVT, ISOBUSControlFunction);
ExampleVirtualTerminalClient->set_object_pool(0, VirtualTerminalClient::VTVersion::Version3, VT3TestPool, sizeof(VT3TestPool), "AIS1");
softKeyListener = ExampleVirtualTerminalClient->add_vt_soft_key_event_listener(handleVTKeyEvents);
buttonListener = ExampleVirtualTerminalClient->add_vt_button_event_listener(handleVTKeyEvents);
ExampleVirtualTerminalClient->initialize(false);
}

void loop() {
// put your main code here, to run repeatedly:
ISOBUSDiagnostics->update(); // Update diagnostics interface
ExampleVirtualTerminalClient->update(); // Update VT client
CANHardwareInterface::update(); // Update CAN stack
}
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name=AgIsoStack-plus-plus
name=AgIsoStack
version=0.1.0
license=MIT
author=Adrian Del Grosso <[email protected]>
Expand All @@ -7,6 +7,6 @@ sentence=A free ISOBUS (ISO11783) and J1939 CAN Stack for Teensy.
paragraph=Includes ISOBUS virtual terminal client, task controller client, and transport layer functionality. Based on the CMake AgIsoStack++ at https://github.com/Open-Agriculture/AgIsoStack-plus-plus.
category=Communication
architectures=teensy
includes=isobus.hpp
includes=AgIsoStack.hpp
url=https://github.com/Open-Agriculture/AgIsoStack-Arduino

8 changes: 4 additions & 4 deletions src/isobus.hpp → src/AgIsoStack.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*******************************************************************************
** @file isobus.hpp
** @file AgIsoStack.hpp
** @author Automatic Code Generation
** @date September 09, 2023 at 11:11:41
** @brief Includes all important files in the AgIsoStack library.
**
** Copyright 2023 The AgIsoStack++ Developers
*******************************************************************************/

#ifndef ISOBUS_HPP
#define ISOBUS_HPP
#ifndef AG_ISO_STACK_HPP
#define AG_ISO_STACK_HPP

#include <can_address_claim_state_machine.hpp>
#include <can_badge.hpp>
Expand Down Expand Up @@ -58,4 +58,4 @@
#include <system_timing.hpp>
#include <to_string.hpp>

#endif // ISOBUS_HPP
#endif // AG_ISO_STACK_HPP