Skip to content

Commit

Permalink
Tools: factor out common library for GSOF
Browse files Browse the repository at this point in the history
* Add tests too

Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 committed May 27, 2024
1 parent 8d70a40 commit 5abfae8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions Tools/ardupilotwaf/ardupilotwaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'AP_Compass',
'AP_Declination',
'AP_GPS',
'AP_GSOF',
'AP_HAL',
'AP_HAL_Empty',
'AP_InertialSensor',
Expand Down
1 change: 1 addition & 0 deletions Tools/scripts/run_astyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, *, dry_run=DRY_RUN_DEFAULT):
self.directories_to_check = [
'libraries/AP_DDS',
'libraries/AP_ExternalControl',
'libraries/AP_GSOF',
]
self.files_to_check = [
pathlib.Path(s) for s in [
Expand Down
24 changes: 24 additions & 0 deletions libraries/AP_GSOF/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# GSOF Tests

A UDP packet of binary GSOF data is attached in the `gsof_data` file.


## Questions

* How to split up dependencies on GPS types in parser - do we care?

* Fixing endianness messy code:
* Define LE structins in AP_GSOF, do the function to convert the endianness for fields that need it. Takes a list of field to call the swaps.
* To determien which field swapping, do an array of field pointers
* Could declare it as a union of strucutres, one with native BE, other place that swaps the endianess.
* Declare the union in the for loop on msg type
* Pull out data_left from "a" in the for loop to check there's enough room. Should be exactly equal.
* Tricky - variable-length packets.
* Can do the union stuff soon.
* Can we dump some small binary data in the tests folder of the parser, or should I write it in the code?
* UDP - much less code to NET_ to use virtual serial ports, treat as UART.
* On UDP, it's already packetized, but could use NET API for ethernet only
* There will be people that want serial though, serial over CAN
* ON UDP, we get configuration on UDP on two ports, multiple sockets.
* Could recommend Trimble as networking only
* Trimble PX1 support.
Binary file added libraries/AP_GSOF/tests/gsof_gps.dat
Binary file not shown.
20 changes: 17 additions & 3 deletions libraries/AP_GSOF/tests/test_gsof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@

#include <AP_GSOF/AP_GSOF.h>

#include <cstdio>
#include <cstdlib>

const AP_HAL::HAL &hal = AP_HAL::get_HAL();


TEST(AP_GSOF, incomplete_packet)
{
AP_GSOF gsof;
EXPECT_FALSE(gsof.parse(0));
EXPECT_FALSE(gsof.parse(0, 5));
}

TEST(AP_GSOF, packet1)
{
// 02084072580000010a1e02e0680909009400000218000000000000000000000000000000000000000000000000080d000000000000000000000000000910000000000000000000000000000000000c260000000000000000000000000000000000000000000000000000000000000000000000000000a503
FILE* fp = std::fopen("libraries/AP_GSOF/tests/gsof_gps.dat", "rb");
EXPECT_NE(fp, nullptr);
AP_GSOF gsof;
EXPECT_FALSE(gsof.parse(0));
char c = 0;
bool parsed = false;
while (c != EOF) {
c = fgetc (fp);
parsed |= gsof.parse((uint8_t)c, 5);
}

EXPECT_TRUE(parsed);

fclose(fp);

}

AP_GTEST_MAIN()

0 comments on commit 5abfae8

Please sign in to comment.