Skip to content

Commit

Permalink
allocate memory to store vehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
xiemengjie-kay committed Jan 29, 2024
1 parent 6aa18b7 commit 106948b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 17 additions & 0 deletions libraries/AP_ODIDScanner/AP_ODIDScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ void AP_ODIDScanner::init() {
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Scanner: Found RID Device");
_port->begin(57600, 512, 512);
}

if (in_state.vehicle_list == nullptr) {
// sanity check param
// in_state.list_size_param.set(constrain_int16(in_state.list_size_param, 1, INT16_MAX));

in_state.list_size_param = RID_MAX_INSTANCES;

in_state.vehicle_list = new rid_vehicle_t[in_state.list_size_param];

if (in_state.vehicle_list == nullptr) {
// dynamic RAM allocation of in_state.vehicle_list[] failed
_init_failed = true;
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "RID: Unable to initialize RID vehicle list");
return;
}
in_state.list_size_allocated = in_state.list_size_param;
}
}

void AP_ODIDScanner::update_recv() {
Expand Down
7 changes: 6 additions & 1 deletion libraries/AP_ODIDScanner/AP_ODIDScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <GCS_MAVLink/GCS.h>
#include <AP_Common/Location.h>

#define RID_MAX_INSTANCES 10 // Maximum number of RID sensor instances available on this platform

struct Loc : Location {
AltType loc_alt_type; // more information on altitude in base class

Expand Down Expand Up @@ -68,11 +70,14 @@ struct rid_vehicle_t {
class AP_ODIDScanner
{
public:

bool _init_failed;

struct {
// list management
AP_Int16 list_size_param;
uint16_t list_size_allocated;
adsb_vehicle_t *vehicle_list;
rid_vehicle_t *vehicle_list;
uint16_t vehicle_count;
AP_Int32 list_radius;
AP_Int16 list_altitude;
Expand Down

0 comments on commit 106948b

Please sign in to comment.