KimBP / AIS

An Arduino library able to decode AIS messages
Other
30 stars 9 forks source link

List of AIS vessels #11

Closed rgroothuis closed 3 years ago

rgroothuis commented 3 years ago

Thanks for building this AIS NMEA message processing class. I've been playing around with it for a couple of days, do not understand everything yet, but more and more becomes clear over time.

Question: how would you recommend to maintain a list of vessels using your AIS class? In other words, I'm using your AIS class to process the VDM messages that I'm receiving. Then I want to display a list of vessels and each time update the vessel in that list when a new AIS message for that vessel arrives.

Do you have any suggestions on how to build that? Could your provide a recommendation on how to implement this using your AIS class?

I was thinking about building a list of my own AISVessel class. Once a VDM message comes in, I want to process this with you AIS class, based on the processed data I want to update the vessel (based on MMSI) record with the processed data. Is that the way you would address this problem?

KimBP commented 3 years ago

Hi rgroothuis Basically I can't really see how this AIS class relates to the list you ask for. This AIS class is just convenience for parsing the coded AIS message. That said - a simple approach would be something like this:

First a class to store a Vessel

class Vessel {
public:
 Vessel();
 Vessel(const std::string& name, uint32_t mmsi);
 virtual ~Vessel(); 
  void setName(const std::string& name) { this->name = name; }
  void setMmsi(uint32_t mmsi) { this->mmsi = mmsi; }
  void setCourse(double course) {this->course = course; }
  double getCourse() const { return course; }

private:
  std::string name;
  uint32_t mmsi;
  double course;
  // add other attributes
}

Then the Vessel list

class VesselList {
public:
  VesselList();
  virtual ~VesselList();
  void update(AIS& vdm) {
    // Inhere extract the MMSI from vdm
    std::string mmsi = vdm.get_mmsi();
   Vessel& vessel = vessels[mmsi]; // This will either find the old Vessel object with this mmsi or create a new one
   vessel.setName (vdm.get_shipname()); // In case of a new one you'll have to set the name
    vessel.setMmsi(mmsi);
    vessel.setCourse(vdm.get_COG());
  }
private:
  std::map<uint32_t, Vessel> vessels; // Use mmsi as key - you could consider then remove it from class Vessel

From your application you'll have to:


VesselList vesselList;

while(1) {
  AIS aisObj( get_ais_message()):

  vesselList.update(aisObj);
  // do other stuff
}

Hope you can use some of it

rgroothuis commented 3 years ago

Thanks for the feedback and suggestions, I was not planning to use the AIS as or in a list. I was wondering the best way how to build a list of vessels. Your above suggested give a good indication. Thanks.

KimBP commented 3 years ago

You are welcome. I'll close this issue. Feel free to reopen or create a new if you have further questions