Добавить общие графики, декодер KONOR и порт STM32 bxCAN
This commit is contained in:
27
c/set-protocol/tests/fixtures/plot-v1.json
vendored
Normal file
27
c/set-protocol/tests/fixtures/plot-v1.json
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"version": 1,
|
||||
"cases": [
|
||||
{"name":"zoom_x_anchor","op":0,"input":[0,0,1,1,2,1,0,0,0.25,0.5],"output":[0.125,0,0.5,1]},
|
||||
{"name":"zoom_y_anchor","op":0,"input":[0,0,1,1,1,4,0,0,0.5,0.75],"output":[0,0.5625,1,0.25]},
|
||||
{"name":"pan_clamp","op":0,"input":[0.25,0.25,0.5,0.5,1,1,20,-20,0.5,0.5],"output":[0,0.5,0.5,0.5]},
|
||||
{"name":"zoom_limit","op":0,"input":[0,0,1,1,1000,1000,0,0,0.5,0.5],"output":[0.49609375,0.49609375,0.0078125,0.0078125]},
|
||||
{"name":"ignore_invalid_zoom","op":0,"input":[0.25,0.25,0.5,0.5,0,1,0,0,0.5,0.5],"output":[0.25,0.25,0.5,0.5]},
|
||||
{"name":"horizontal_spread","op":1,"input":[100,2,8],"output":[1]},
|
||||
{"name":"vertical_contract","op":1,"input":[2,-100,8],"output":[2]},
|
||||
{"name":"touch_jitter","op":1,"input":[3,-4,8],"output":[0]},
|
||||
{"name":"diagonal_tie_x","op":1,"input":[20,20,8],"output":[1]},
|
||||
{"name":"x_fraction","op":2,"input":[15,10,30,0],"output":[0.25]},
|
||||
{"name":"y_fraction","op":2,"input":[15,10,30,1],"output":[0.75]},
|
||||
{"name":"outside_view","op":2,"input":[40,10,30,0],"output":[1.5]},
|
||||
{"name":"y_coordinate","op":3,"input":[0.75,10,30,1],"output":[15]},
|
||||
{"name":"drag_x","op":4,"input":[15,50,200,10,30,0],"output":[20]},
|
||||
{"name":"drag_y","op":4,"input":[0,100,500,-10,10,1],"output":[-4]},
|
||||
{"name":"drag_clamp","op":4,"input":[15,500,200,10,30,0],"output":[30]},
|
||||
{"name":"ticks","op":5,"input":[100,800],"output":[20]},
|
||||
{"name":"negative_delta","op":6,"input":[10,0,1],"output":[-10]},
|
||||
{"name":"milliseconds","op":6,"input":[0,0.01,1000],"output":[10]},
|
||||
{"name":"zero_range","op":2,"input":[1,1,1,0],"output":null},
|
||||
{"name":"zero_pixels","op":4,"input":[0,1,0,0,1,0],"output":null},
|
||||
{"name":"bad_viewport","op":0,"input":[0,0,0,1,2,1,0,0,0.5,0.5],"output":null}
|
||||
]
|
||||
}
|
||||
19
c/set-protocol/tests/fixtures/trends-v1.json
vendored
Normal file
19
c/set-protocol/tests/fixtures/trends-v1.json
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"format": "setflash-trends",
|
||||
"version": 1,
|
||||
"profiles": {
|
||||
"TMS2812": [
|
||||
{"id":"tms-1","order":1,"name":"Ток фазы А","source":"TMS_MEMORY","address":"0x00000100","color":"#2F91FF","visible":true,"valueType":"INT16","deviceType":7,"device":13,"byteOffset":0,"extended":true}
|
||||
],
|
||||
"SET_V1": [
|
||||
{"id":"set-gas-1","order":1,"name":"Регистр GAS","source":"SET_GAS","address":"0xFF00","color":"#52D6A4","visible":true,"valueType":"UINT16","deviceType":7,"device":13,"byteOffset":0,"extended":true},
|
||||
{"id":"sensor-1","order":2,"name":"Температура","source":"SET_SENSOR","address":"28-01-02-03-04-05-06-07","color":"#F8798D","visible":false,"valueType":"UINT16","deviceType":7,"device":13,"byteOffset":0,"extended":true}
|
||||
],
|
||||
"CAN_BRIDGE": [
|
||||
{"id":"gas-1","order":1,"name":"GAS узла 13","source":"CAN_GAS","address":"0x1235","color":"#FFB547","visible":true,"valueType":"INT16","deviceType":7,"device":13,"byteOffset":0,"extended":true}
|
||||
],
|
||||
"BALZAM_CAN": [
|
||||
{"id":"raw-1","order":3,"name":"Слово CAN","source":"CAN_RAW","address":"0x00BA0010","color":"#B79AFF","visible":true,"valueType":"UINT16","deviceType":7,"device":13,"byteOffset":6,"extended":true}
|
||||
]
|
||||
}
|
||||
}
|
||||
31
c/set-protocol/tests/test_plot.c
Normal file
31
c/set-protocol/tests/test_plot.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "set_plot.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
double output[5] = {0, 0, 0, 0, 12345};
|
||||
const double zoom[] = {0, 0, 1, 1, 2, 1, 0, 0, .25, .5};
|
||||
const double y[] = {15, 10, 30, 1};
|
||||
const double drag[] = {0, 100, 500, -10, 10, 1};
|
||||
double back[4], bad[] = {NAN, 10, 8};
|
||||
assert(set_plot_abi_version() == 1);
|
||||
assert(set_plot_eval(SET_PLOT_TRANSFORM, zoom, 10, output, 4) == 4);
|
||||
assert(output[0] == .125 && output[1] == 0 && output[2] == .5 && output[3] == 1);
|
||||
assert(output[4] == 12345);
|
||||
assert(set_plot_eval(SET_PLOT_TRANSFORM, zoom, 10, output, 3) == 0);
|
||||
assert(set_plot_eval(SET_PLOT_TRANSFORM, zoom, 9, output, 4) == 0);
|
||||
assert(set_plot_eval(999, zoom, 10, output, 4) == 0);
|
||||
assert(set_plot_eval(SET_PLOT_FRACTION, NULL, 4, output, 4) == 0);
|
||||
assert(set_plot_eval(SET_PLOT_FRACTION, y, 4, NULL, 4) == 0);
|
||||
assert(set_plot_eval(SET_PLOT_AXIS, bad, 3, output, 4) == 0);
|
||||
assert(set_plot_eval(SET_PLOT_FRACTION, y, 4, output, 4) == 1);
|
||||
assert(output[0] == .75);
|
||||
back[0] = output[0]; back[1] = y[1]; back[2] = y[2]; back[3] = y[3];
|
||||
assert(set_plot_eval(SET_PLOT_VALUE, back, 4, output, 4) == 1);
|
||||
assert(output[0] == y[0]);
|
||||
assert(set_plot_eval(SET_PLOT_DRAG, drag, 6, output, 4) == 1);
|
||||
assert(output[0] == -4);
|
||||
puts("shared plot: OK");
|
||||
return 0;
|
||||
}
|
||||
22
c/set-protocol/tests/test_spectrum.c
Normal file
22
c/set-protocol/tests/test_spectrum.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "set_spectrum.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
double times[32], values[32], output[18], meta[3];
|
||||
for (size_t i = 0; i < 32; ++i) { times[i] = (double)i / 32; values[i] = sin(2 * 3.14159265358979323846 * 4 * times[i]); }
|
||||
output[17] = 12345;
|
||||
assert(set_spectrum_analyze(times, values, 32, 32, SET_WINDOW_HANN, 0, 0, 0, 1, output, 17, meta) == SET_SPECTRUM_OK);
|
||||
assert(meta[0] == 32 && meta[1] == 32);
|
||||
assert(fabs(output[4] - 1.0) < 1e-12 && output[17] == 12345);
|
||||
assert(set_spectrum_analyze(times, values, 32, 32, 0, 0, 0, 0, 1, output, 16, meta) == SET_SPECTRUM_INVALID);
|
||||
assert(set_spectrum_analyze(times, values, 15, 32, 0, 0, 0, 0, 1, output, 17, meta) == SET_SPECTRUM_SHORT);
|
||||
assert(set_spectrum_analyze(times, values, 32, 32, 0, 99, 0, 0, 1, output, 17, meta) == SET_SPECTRUM_INVALID);
|
||||
assert(set_spectrum_analyze(times, values, 32, 32, 0, SET_FILTER_LOW_PASS, 0, 16, 1, output, 17, meta) == SET_SPECTRUM_CUTOFF);
|
||||
times[12] = times[11];
|
||||
assert(set_spectrum_analyze(times, values, 32, 32, 0, 0, 0, 0, 1, output, 17, meta) == SET_SPECTRUM_TIMING);
|
||||
puts("shared spectrum: OK");
|
||||
return 0;
|
||||
}
|
||||
43
c/set-protocol/tests/test_trends.c
Normal file
43
c/set-protocol/tests/test_trends.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "set_trends.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const uint8_t data[] = {1, 0, 254, 255};
|
||||
const uint32_t id = 0x1FD31234UL; /* priority 1, from device, type 7, dev 13, GAS */
|
||||
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 0, id, 1, data, 4) == 65534);
|
||||
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 1, id, 1, data, 4) == -2);
|
||||
assert(set_trend_can_value(1, 0x1233, 7, 13, 0, 1, 0, id, 1, data, 4) == SET_TREND_NO_VALUE);
|
||||
assert(set_trend_can_value(1, 0x1236, 7, 13, 0, 1, 0, id, 1, data, 4) == SET_TREND_NO_VALUE);
|
||||
assert(set_trend_can_value(1, 0x1235, 6, 13, 0, 1, 0, id, 1, data, 4) == SET_TREND_NO_VALUE);
|
||||
assert(set_trend_can_value(1, 0x1235, 7, 12, 0, 1, 0, id, 1, data, 4) == SET_TREND_NO_VALUE);
|
||||
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 0, id ^ 0x08000000UL, 1, data, 4) == SET_TREND_NO_VALUE);
|
||||
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 0, id, 1, data, 3) == SET_TREND_NO_VALUE);
|
||||
for (unsigned flag = 2; flag <= 8; flag <<= 1) {
|
||||
assert(set_trend_can_value(1, 0x1235, 7, 13, 0, 1, 0, id, (uint8_t)(1 | flag), data, 4) == SET_TREND_NO_VALUE);
|
||||
}
|
||||
assert(set_trend_can_value(2, 0x321, 0, 0, 2, 0, 1, 0x321, 0, data, 4) == -2);
|
||||
assert(set_trend_can_value(2, 0x321, 0, 0, 3, 0, 1, 0x321, 0, data, 4) == SET_TREND_NO_VALUE);
|
||||
assert(set_trend_word_value(0x8000, 1) == -32768);
|
||||
assert(set_trend_word_value(0xFFFF, 0) == 65535);
|
||||
const uint16_t addresses[] = {0x1234, 0xFFFF};
|
||||
const uint8_t expected[] = {232, 3, 2, 0, 52, 18, 255, 255};
|
||||
uint8_t output[132];
|
||||
assert(set_trend_watch_request(1000, addresses, 2, output, sizeof(output)) == 8);
|
||||
assert(memcmp(expected, output, 8) == 0);
|
||||
assert(set_trend_watch_request(1000, addresses, 65, output, sizeof(output)) == 0);
|
||||
assert(set_trend_watch_request(1000, NULL, 2, output, sizeof(output)) == 0);
|
||||
assert(set_trend_watch_request(1000, addresses, 2, output, 7) == 0);
|
||||
assert(set_trend_watch_ack(expected, 4, 1000, 2));
|
||||
assert(!set_trend_watch_ack(expected, 4, 1000, 3));
|
||||
const uint8_t packet[] = {1, 2, 3, 4, 2, 0, 52, 18, 255, 255};
|
||||
uint16_t words[64];
|
||||
assert(set_trend_watch_values(packet, sizeof(packet), words, 64) == 2);
|
||||
assert(words[0] == 0x1234 && words[1] == 0xFFFF);
|
||||
assert(set_trend_watch_values(packet, sizeof(packet) - 1, words, 64) == -1);
|
||||
assert(set_trend_watch_values(packet, sizeof(packet), words, 1) == -1);
|
||||
puts("Shared trend tests passed");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user