auto-sync
This commit is contained in:
parent
f17a25641a
commit
34ffd33468
|
@ -36,6 +36,7 @@ class cyclic_buffer
|
||||||
void add(T value);
|
void add(T value);
|
||||||
T get(int index);
|
T get(int index);
|
||||||
T sum(int length);
|
T sum(int length);
|
||||||
|
T maxValue(int length);
|
||||||
void setSize(int size);
|
void setSize(int size);
|
||||||
int getSize();
|
int getSize();
|
||||||
void clear();
|
void clear();
|
||||||
|
@ -124,6 +125,27 @@ T cyclic_buffer<T>::get(int index) {
|
||||||
return elements[index];
|
return elements[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T cyclic_buffer<T>::maxValue(int length) {
|
||||||
|
if (length > count) {
|
||||||
|
length = count;
|
||||||
|
}
|
||||||
|
int ci = currentIndex; // local copy to increase thread-safety
|
||||||
|
T result = 0; // todo: better min value?
|
||||||
|
for (int i = 0; i < length; ++i) {
|
||||||
|
int index = ci - i;
|
||||||
|
while (index < 0) {
|
||||||
|
index += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elements[index] > result) {
|
||||||
|
result = elements[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T cyclic_buffer<T>::sum(int length) {
|
T cyclic_buffer<T>::sum(int length) {
|
||||||
if (length > count) {
|
if (length > count) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ void testCrc(void) {
|
||||||
|
|
||||||
const char * A = "A";
|
const char * A = "A";
|
||||||
|
|
||||||
assertEqualsM("crc8", 168, calc_crc((const crc_t *)A, 1));
|
assertEqualsM("crc8", 168, calc_crc((const crc_t *) A, 1));
|
||||||
int c = crc32(A, 1);
|
int c = crc32(A, 1);
|
||||||
printf("crc32(A)=%x\r\n", c);
|
printf("crc32(A)=%x\r\n", c);
|
||||||
assertEqualsM("crc32", 0xd3d99e8b, crc32(A, 1));
|
assertEqualsM("crc32", 0xd3d99e8b, crc32(A, 1));
|
||||||
|
@ -55,12 +55,26 @@ void testOverflow64Counter(void) {
|
||||||
void testCyclicBuffer(void) {
|
void testCyclicBuffer(void) {
|
||||||
print("*************************************** testCyclicBuffer\r\n");
|
print("*************************************** testCyclicBuffer\r\n");
|
||||||
|
|
||||||
|
{
|
||||||
sb.add(10);
|
sb.add(10);
|
||||||
|
|
||||||
assertEquals(10, sb.sum(3));
|
assertEquals(10, sb.sum(3));
|
||||||
|
|
||||||
sb.add(2);
|
sb.add(2);
|
||||||
assertEquals(12, sb.sum(2));
|
assertEquals(12, sb.sum(2));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
sb.clear();
|
||||||
|
|
||||||
|
sb.add(1);
|
||||||
|
sb.add(2);
|
||||||
|
sb.add(3);
|
||||||
|
sb.add(4);
|
||||||
|
|
||||||
|
assertEquals(4, sb.maxValue(3));
|
||||||
|
assertEquals(4, sb.maxValue(113));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testHistogram(void) {
|
void testHistogram(void) {
|
||||||
|
@ -169,7 +183,7 @@ void testMalfunctionCentral(void) {
|
||||||
assertEquals(code, localCopy.error_codes[0]);
|
assertEquals(code, localCopy.error_codes[0]);
|
||||||
|
|
||||||
// let's remove value which is not in the collection
|
// let's remove value which is not in the collection
|
||||||
removeError((obd_code_e)22);
|
removeError((obd_code_e) 22);
|
||||||
// element not present - nothing to removed
|
// element not present - nothing to removed
|
||||||
assertEquals(1, localCopy.count);
|
assertEquals(1, localCopy.count);
|
||||||
assertEquals(code, localCopy.error_codes[0]);
|
assertEquals(code, localCopy.error_codes[0]);
|
||||||
|
@ -250,12 +264,12 @@ void testGpsParser(void) {
|
||||||
assertEqualsM("3 speed", 11.2, GPSdata.speed);
|
assertEqualsM("3 speed", 11.2, GPSdata.speed);
|
||||||
// assertEqualsM("3 altitude", 0, GPSdata.altitude); // GPRMC not overwrite altitude
|
// assertEqualsM("3 altitude", 0, GPSdata.altitude); // GPRMC not overwrite altitude
|
||||||
assertEqualsM("3 course", 0, GPSdata.course);
|
assertEqualsM("3 course", 0, GPSdata.course);
|
||||||
assertEqualsM("3 GPS yy",2006, GPSdata.GPStm.tm_year+1900);
|
assertEqualsM("3 GPS yy", 2006, GPSdata.GPStm.tm_year + 1900);
|
||||||
assertEqualsM("3 GPS mm",12, GPSdata.GPStm.tm_mon);
|
assertEqualsM("3 GPS mm", 12, GPSdata.GPStm.tm_mon);
|
||||||
assertEqualsM("3 GPS yy",26, GPSdata.GPStm.tm_mday);
|
assertEqualsM("3 GPS yy", 26, GPSdata.GPStm.tm_mday);
|
||||||
assertEqualsM("3 GPS hh",11, GPSdata.GPStm.tm_hour);
|
assertEqualsM("3 GPS hh", 11, GPSdata.GPStm.tm_hour);
|
||||||
assertEqualsM("3 GPS mm",16, GPSdata.GPStm.tm_min);
|
assertEqualsM("3 GPS mm", 16, GPSdata.GPStm.tm_min);
|
||||||
assertEqualsM("3 GPS ss",9, GPSdata.GPStm.tm_sec);
|
assertEqualsM("3 GPS ss", 9, GPSdata.GPStm.tm_sec);
|
||||||
|
|
||||||
// check again first one
|
// check again first one
|
||||||
// we need to pass a mutable string, not a constant because the parser would be modifying the string
|
// we need to pass a mutable string, not a constant because the parser would be modifying the string
|
||||||
|
@ -292,7 +306,6 @@ void testConsoleLogic(void) {
|
||||||
strcpy(buffer, "\"echo\"");
|
strcpy(buffer, "\"echo\"");
|
||||||
assertTrueM("unquote quoted", strEqual("echo", unquote(buffer)));
|
assertTrueM("unquote quoted", strEqual("echo", unquote(buffer)));
|
||||||
|
|
||||||
|
|
||||||
char *ptr = validateSecureLine(UNKNOWN_COMMAND);
|
char *ptr = validateSecureLine(UNKNOWN_COMMAND);
|
||||||
assertEquals(0, strcmp(UNKNOWN_COMMAND, ptr));
|
assertEquals(0, strcmp(UNKNOWN_COMMAND, ptr));
|
||||||
assertEquals(10, tokenLength(UNKNOWN_COMMAND));
|
assertEquals(10, tokenLength(UNKNOWN_COMMAND));
|
||||||
|
@ -321,12 +334,10 @@ void testConsoleLogic(void) {
|
||||||
assertEquals(111, atoi(lastFirst));
|
assertEquals(111, atoi(lastFirst));
|
||||||
assertEquals(333, atoi(lastThird));
|
assertEquals(333, atoi(lastThird));
|
||||||
|
|
||||||
|
|
||||||
strcpy(buffer, "echosss \" 1\" 222 333");
|
strcpy(buffer, "echosss \" 1\" 222 333");
|
||||||
handleConsoleLine(buffer);
|
handleConsoleLine(buffer);
|
||||||
assertTrue(strEqual("\" 1\"", lastFirst));
|
assertTrue(strEqual("\" 1\"", lastFirst));
|
||||||
|
|
||||||
|
|
||||||
//addConsoleActionSSS("GPS", testGpsParser);
|
//addConsoleActionSSS("GPS", testGpsParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue