Добавить общие графики, декодер KONOR и порт STM32 bxCAN

This commit is contained in:
2026-09-04 12:22:17 +03:00
parent af82687e42
commit e163d9ba55
51 changed files with 5040 additions and 15 deletions

View File

@@ -4,6 +4,95 @@
#include <string.h>
#include "setprotocol_abi.h"
#include "set_trends.h"
#include "set_spectrum.h"
JNIEXPORT jdoubleArray JNICALL
Java_ru_setcorp_setprotocol_NativeSetProtocol_nativeSpectrum(
JNIEnv *env, jobject self, jdoubleArray times, jdoubleArray values, jint max_size,
jint window, jint filter, jdouble low_hz, jdouble high_hz, jboolean remove_mean)
{
(void)self;
if (times == NULL || values == NULL || max_size < 16 || max_size > (jint)SET_SPECTRUM_MAX ||
(max_size & (max_size - 1)) != 0) return NULL;
jsize count = (*env)->GetArrayLength(env, times);
if ((*env)->GetArrayLength(env, values) != count) return NULL;
/* Only the analyzed tail crosses JNI; allocations cannot grow with file length. */
jsize used = count < max_size ? count : max_size;
size_t bins = (size_t)max_size / 2 + 1;
double *buffer = (double *)calloc((size_t)used * 2 + bins + 4, sizeof(double));
if (buffer == NULL) return NULL;
double *t = buffer, *v = t + used, *out = v + used;
(*env)->GetDoubleArrayRegion(env, times, count - used, used, t);
(*env)->GetDoubleArrayRegion(env, values, count - used, used, v);
if ((*env)->ExceptionCheck(env)) { free(buffer); return NULL; }
int status = set_spectrum_analyze(t, v, (size_t)used, (size_t)max_size,
window, filter, low_hz, high_hz, remove_mean, out + 4, bins, out + 1);
out[0] = (double)status;
jsize length = status == SET_SPECTRUM_OK ? (jsize)out[1] / 2 + 5 : 4;
jdoubleArray result = (*env)->NewDoubleArray(env, length);
if (result != NULL) (*env)->SetDoubleArrayRegion(env, result, 0, length, out);
free(buffer);
return result;
}
JNIEXPORT jint JNICALL
Java_ru_setcorp_setprotocol_NativeSetProtocol_nativeTrendCanValue(
JNIEnv *env, jobject self, jint source, jlong address, jint device_type,
jint device, jint byte_offset, jboolean extended, jboolean is_signed,
jlong can_id, jint flags, jbyteArray input)
{
(void)self;
jsize size = (*env)->GetArrayLength(env, input);
if (size < 2 || size > 8) return SET_TREND_NO_VALUE;
jbyte data[8];
(*env)->GetByteArrayRegion(env, input, 0, size, data);
return set_trend_can_value((uint8_t)source, (uint32_t)address,
(uint8_t)device_type, (uint8_t)device, (uint8_t)byte_offset,
(uint8_t)extended, (uint8_t)is_signed, (uint32_t)can_id,
(uint8_t)flags, (const uint8_t *)data, (size_t)size);
}
JNIEXPORT jbyteArray JNICALL
Java_ru_setcorp_setprotocol_NativeSetProtocol_nativeTrendWatchRequest(
JNIEnv *env, jobject self, jint period, jintArray input)
{
(void)self;
jsize count = (*env)->GetArrayLength(env, input);
if (count > (jsize)SET_TREND_WATCH_MAX || period < 0 || period > 65535) return NULL;
jint values[SET_TREND_WATCH_MAX];
uint16_t addresses[SET_TREND_WATCH_MAX];
uint8_t output[4U + 2U * SET_TREND_WATCH_MAX];
(*env)->GetIntArrayRegion(env, input, 0, count, values);
for (jsize i = 0; i < count; ++i) {
if (values[i] < 0 || values[i] > 65535) return NULL;
addresses[i] = (uint16_t)values[i];
}
size_t size = set_trend_watch_request((uint16_t)period, addresses, (size_t)count, output, sizeof(output));
if (size == 0U) return NULL;
jbyteArray result = (*env)->NewByteArray(env, (jsize)size);
if (result != NULL) (*env)->SetByteArrayRegion(env, result, 0, (jsize)size, (const jbyte *)output);
return result;
}
JNIEXPORT jintArray JNICALL
Java_ru_setcorp_setprotocol_NativeSetProtocol_nativeTrendWatchValues(
JNIEnv *env, jobject self, jbyteArray input)
{
(void)self;
jsize size = (*env)->GetArrayLength(env, input);
if (size < 6 || size > (jsize)(6U + 2U * SET_TREND_WATCH_MAX)) return NULL;
jbyte payload[6U + 2U * SET_TREND_WATCH_MAX];
uint16_t words[SET_TREND_WATCH_MAX];
jint values[SET_TREND_WATCH_MAX];
(*env)->GetByteArrayRegion(env, input, 0, size, payload);
int count = set_trend_watch_values((const uint8_t *)payload, (size_t)size, words, SET_TREND_WATCH_MAX);
if (count < 0) return NULL;
for (int i = 0; i < count; ++i) values[i] = words[i];
jintArray result = (*env)->NewIntArray(env, count);
if (result != NULL) (*env)->SetIntArrayRegion(env, result, 0, count, values);
return result;
}
typedef struct {
uint8_t *storage;