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

Add support for SocketCAN for Linux platforms #13

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion scripts/download-CanBridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import axios from 'axios';
import AdmZip from 'adm-zip';
import { platform, arch } from 'os';

const canBridgeTag = "v2.3.6";
const canBridgeTag = "v2.4.0";
const canBridgeReleaseAssetUrlPrefix = `https://github.com/unofficial-rev-port/CANBridge/releases/download/${canBridgeTag}`;

const externalCompileTimeDepsPath = 'externalCompileTimeDeps';
Expand Down
37 changes: 37 additions & 0 deletions src/SocketCANDeviceWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <rev/Drivers/SocketCAN/SocketCANDevice.h>
#include <napi.h>
#include <typeinfo>
#include <iostream>

class NapiWinUSBDevice : public Napi::ObjectWrap<NapiSocketCANDevice> {
public:
static Napi::Object Init(Napi::Env env, Napi::Object exports);
NapiSocketCANDevice(const Napi::CallbackInfo& info);
Napi::Value GetName(const Napi::CallbackInfo& info);
void SetDevice(std::unique_ptr<rev::usb::CANDevice>);

private:
std::unique_ptr<rev::usb::CANDevice> device;
};

Napi::Object NapiSocketCANDevice::Init(Napi::Env env, Napi::Object exports) {
Napi::Function func = DefineClass(env, "NapiSocketCANDevice", {
InstanceMethod("GetName", &NapiSocketCANDevice::GetName)
});

Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
exports.Set("NapiSocketCANDevice", func);

return exports;
}

NapiSocketCANDevice::NapiSocketCANDevice(const Napi::CallbackInfo& info) : Napi::ObjectWrap<NapiSocketCANDevice>(info) {
Napi::Env env = info.Env();
std::cout << "Creating device " << std::endl;
}

Napi::Value NapiSocketCANDevice::GetName(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
return Napi::String::New(env, this->device->GetName());
}
9 changes: 9 additions & 0 deletions src/canWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
#include <rev/CANMessage.h>
#include <rev/CANStatus.h>
#include <rev/CANBridgeUtils.h>
#ifdef _WIN32
#include <rev/Drivers/CandleWinUSB/CandleWinUSBDriver.h>
#include <rev/Drivers/CandleWinUSB/CandleWinUSBDevice.h>
#elif __linux__
#include <rev/Drivers/SocketCAN/SocketCANDriver.h>
#include <rev/Drivers/SocketCAN/SocketCANDevice.h>
#endif
#include <utils/ThreadUtils.h>
#include <hal/HAL.h>
#include <hal/CAN.h>
Expand Down Expand Up @@ -32,7 +37,11 @@
uint8_t disabledSparkHeartbeat[] = {0, 0, 0, 0, 0, 0, 0, 0};
uint8_t disabledRevCommonHeartbeat[] = {0};

#ifdef _WIN32
rev::usb::CandleWinUSBDriver* driver = new rev::usb::CandleWinUSBDriver();
#elif __linux__
rev::usb::SocketCANDriver* driver = new rev::usb::SocketCANDriver();
#endif

std::set<std::string> devicesRegisteredToHal; // TODO(Noah): Protect with mutex
bool halInitialized = false;
Expand Down
Loading