This commit is contained in:
Matthew Kennedy 2022-07-19 01:02:41 -07:00 committed by GitHub
parent 71b9997383
commit 848fbcf6ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 3 additions and 164 deletions

View File

@ -1,42 +0,0 @@
/*
* FragmentEntry.cpp
*
* Created on: Jan 5, 2022
* @author Andrey Belomutskiy, (c) 2012-2022
*/
#include "pch.h"
#include "FragmentEntry.h"
void copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size) {
int fragmentIndex = 0;
// Find which fragment to start - skip any full fragments smaller than `skip` parameter
while (skip > src.fragments[fragmentIndex].size && fragmentIndex <= src.count) {
skip -= src.fragments[fragmentIndex].size;
fragmentIndex++;
}
int destinationIndex = 0;
while (size > 0) {
if (fragmentIndex >= src.count) {
// somehow we are past the end of fragments - fill with zeros
memset(destination + destinationIndex, 0, size);
return;
}
int copyNowSize = minI(size, src.fragments[fragmentIndex].size - skip);
const uint8_t* fromBase = src.fragments[fragmentIndex].data;
if (!fromBase) {
// we have no buffer for this fragment - fill with zeroes
memset(destination + destinationIndex, 0, copyNowSize);
} else {
memcpy(destination + destinationIndex, fromBase + skip, copyNowSize);
}
destinationIndex += copyNowSize;
skip = 0;
size -= copyNowSize;
fragmentIndex++;
}
}

View File

@ -1,28 +0,0 @@
/*
* FragmentEntry.h
*
* Created on: Jan 5, 2022
* @author Andrey Belomutskiy, (c) 2012-2022
*/
#pragma once
struct FragmentEntry {
template <typename TData>
FragmentEntry(const TData* data)
: data(reinterpret_cast<const uint8_t*>(data))
, size(sizeof(TData))
{
}
const uint8_t* const data;
const size_t size;
};
struct FragmentList {
const FragmentEntry* fragments;
const size_t count;
};
// copy `size` of fragmented outputs in to destination, skipping the first `skip` bytes
void copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size);

View File

@ -1,6 +1,6 @@
#pragma once
#include "FragmentEntry.h"
#include <rusefi/fragments.h>
template <typename TStruct>
const TStruct* getLiveDataAddr();

View File

@ -8,7 +8,6 @@
#pragma once
#include "global.h"
#include "tunerstudio_io.h"
#include "FragmentEntry.h"
typedef struct {
int queryCommandCounter;

View File

@ -6,7 +6,6 @@ TUNERSTUDIO_SRC_CPP = $(PROJECT_DIR)/console/binary/tunerstudio_io.cpp \
$(PROJECT_DIR)/console/binary/ts_can_channel.cpp \
$(PROJECT_DIR)/console/binary/serial_can.cpp \
$(PROJECT_DIR)/console/binary/tunerstudio.cpp \
$(PROJECT_DIR)/console/binary/FragmentEntry.cpp \
$(PROJECT_DIR)/console/binary/tunerstudio_commands.cpp \
$(PROJECT_DIR)/console/binary/bluetooth.cpp \
$(PROJECT_DIR)/console/binary/signature.cpp

@ -1 +1 @@
Subproject commit 7fea28f1c1b1fde209258e97824b8b16ef0ace19
Subproject commit ba9e280fc477c577dda124981b52f6108ff43015

View File

@ -19,6 +19,7 @@
#include <rusefi/arrays.h>
#include <rusefi/crc.h>
#include <rusefi/fragments.h>
#include <rusefi/interpolation.h>
#include <rusefi/isnan.h>
#include <rusefi/math.h>

View File

@ -1,89 +0,0 @@
#include "pch.h"
#include "FragmentEntry.h"
struct obj1 {
const uint8_t x[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
};
static_assert(sizeof(obj1) == 10);
struct obj2 {
const uint8_t x[5] = { 11, 12, 13, 14, 15 };
};
static_assert(sizeof(obj2) == 5);
obj1 buffer10;
obj2 buffer5;
static FragmentEntry fragmentBuffer[] = {
&buffer10,
&buffer5,
reinterpret_cast<obj2*>(0), // null fragment for fun
&buffer10
};
static uint8_t buffer[120];
static void resetBuffer() {
memset(buffer, 0xFF, sizeof(buffer));
}
TEST(outputs, fragments) {
static_assert(4 == efi::size(fragmentBuffer));
FragmentList fragments{ fragmentBuffer, efi::size(fragmentBuffer) };
resetBuffer();
{
// Check overlap between first and second fragments
uint8_t expected[] = {9, 10, 11, 12, 13};
copyRange(buffer, fragments, 8, 5);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check partial of only second fragment
uint8_t expected[] = {13, 14, 15};
copyRange(buffer, fragments, 12, 3);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check overlap between second fragment and null fragment
uint8_t expected[] = {15, 0, 0};
copyRange(buffer, fragments, 14, 3);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check overlap between null fragment and 4th fragment
uint8_t expected[] = {0, 1, 2};
copyRange(buffer, fragments, 19, 3);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check overlap between last fragment and off-end of buffer (off-buffer should give 0s)
uint8_t expected[] = {9, 10, 0, 0};
copyRange(buffer, fragments, 28, 4);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
resetBuffer();
{
// Check way off the end of the buffer
uint8_t expected[] = {0, 0, 0};
copyRange(buffer, fragments, 1000, 3);
EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected)));
}
}

View File

@ -50,7 +50,6 @@ TESTS_SRC_CPP = \
tests/test_dwell_corner_case_issue_796.cpp \
tests/test_idle_controller.cpp \
tests/test_issue_898.cpp \
tests/test_scattered_outputs.cpp \
tests/test_launch.cpp \
tests/test_fuel_map.cpp \
tests/test_gear_detector.cpp \