Skip to content

Commit

Permalink
implement setupCan in openblt_jni.cpp #6358
Browse files Browse the repository at this point in the history
only: well at least it compiles
  • Loading branch information
rusefillc committed Apr 13, 2024
1 parent b3e552a commit 4fda062
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions misc/libopenblt_jni/openblt_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ static bool loadFirmware(JNIEnv* env, jstring jFilename, jobject jCallbacks) {
}

static tBltSessionSettingsXcpV10 xcpSettings;
static tBltTransportSettingsXcpV10Rs232 transportSettings;
static char s_portName[256];

static bool setupSerial(JNIEnv* env, jstring jSerialPort, jobject jCallbacks) {
Callbacks cb(env, jCallbacks, "Start session", false);

static void setXcpSettings() {
xcpSettings.timeoutT1 = 1000;
xcpSettings.timeoutT3 = 2000;
xcpSettings.timeoutT4 = 10000;
Expand All @@ -93,6 +90,13 @@ static bool setupSerial(JNIEnv* env, jstring jSerialPort, jobject jCallbacks) {
xcpSettings.timeoutT7 = 2000;
xcpSettings.seedKeyFile = nullptr;
xcpSettings.connectMode = 0;
}

static bool setupSerial(JNIEnv* env, jstring jSerialPort, jobject jCallbacks) {
static tBltTransportSettingsXcpV10Rs232 transportSettings;
Callbacks cb(env, jCallbacks, "Start session", false);

setXcpSettings();

const char* portName = env->GetStringUTFChars(jSerialPort, 0);
strncpy(s_portName, portName, sizeof(s_portName));
Expand All @@ -112,10 +116,31 @@ static bool setupSerial(JNIEnv* env, jstring jSerialPort, jobject jCallbacks) {
}

static bool setupCan(JNIEnv* env, jobject jCallbacks) {
Callbacks cb(env, jCallbacks, "Setup CAN", false);
static tBltTransportSettingsXcpV10Can canSettings;
Callbacks cb(env, jCallbacks, "Start CAN session", false);

setXcpSettings();

cb.error("CAN not supported yet!");
return false;
#if defined(_WIN32)
canSettings.deviceName = "peak_pcanusb";
#else
canSettings.deviceName = "can0";
#endif
canSettings.deviceChannel = 0;
canSettings.baudrate = 500000;
canSettings.transmitId = 0x667;
canSettings.receiveId = 0x7E1;
canSettings.useExtended = false;

BltSessionInit(BLT_SESSION_XCP_V10, &xcpSettings, BLT_TRANSPORT_XCP_V10_USB, &canSettings);

if (BltSessionStart() != BLT_RESULT_OK) {
cb.error("BltSessionStart() failed");
cb.error(canSettings.deviceName);
return false;
}

return true;
}

static bool erase(JNIEnv* env, jobject jCallbacks) {
Expand All @@ -129,7 +154,7 @@ static bool erase(JNIEnv* env, jobject jCallbacks) {
uint8_t const * segmentData;

/* Erase the memory segments on the target that are covered by the firmwware data. */
for (segmentIdx = 0; segmentIdx < BltFirmwareGetSegmentCount(); segmentIdx++)
for (segmentIdx = 0; segmentIdx < BltFirmwareGetSegmentCount(); segmentIdx++)
{
/* Extract segment info. */
segmentData = BltFirmwareGetSegment(segmentIdx, &segmentBase, &segmentLen);
Expand Down Expand Up @@ -195,7 +220,7 @@ static bool program(JNIEnv* env, jobject jCallbacks) {
int lastPercent = -1;

/* Program the memory segments on the target with the firmware data. */
for (segmentIdx = 0; segmentIdx < BltFirmwareGetSegmentCount(); segmentIdx++)
for (segmentIdx = 0; segmentIdx < BltFirmwareGetSegmentCount(); segmentIdx++)
{
/* Extract segment info. */
segmentData = BltFirmwareGetSegment(segmentIdx, &segmentBase, &segmentLen);
Expand Down

0 comments on commit 4fda062

Please sign in to comment.