Skip to content

Commit

Permalink
Read installation parameters (#2)
Browse files Browse the repository at this point in the history
* read installation parameters
  • Loading branch information
iyuner authored Feb 1, 2021
1 parent 3585e3c commit 1b5e2d9
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/cpp_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ for reading data of different types.
* `all_echosounder_depth` - Kongsberg single echosounder depth data
* `all_sound_speed_profile` - Sound speed profile data
* `all_raw_range_and_beam_angle` - Raw range and beam angle data
* `all_installation_param` - Installation parameters
* `xtf_data` - for reading `.xtf` sidescan files
* `xtf_sss_ping` - xtf side scan swath data structure
* `gsf_data` - for reading `.gsf` files containing various sensor data
Expand Down
24 changes: 24 additions & 0 deletions src/data_tools/include/data_tools/all_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ struct all_raw_range_and_beam_angle {
}
};

struct all_installation_param {

using EntriesT = std::vector<all_installation_param, Eigen::aligned_allocator<all_installation_param> >;

unsigned int id_;
std::string time_string_; // readable time stamp string
long long time_stamp_; // posix time stamp
unsigned int system_serial_number_;
unsigned int secondary_system_serial_number_;
std::unordered_map<std::string, std::string> param_;
bool first_in_file_;

template <class Archive>
void serialize( Archive & ar )
{
ar(CEREAL_NVP(id_), CEREAL_NVP(time_string_), CEREAL_NVP(time_stamp_), CEREAL_NVP(system_serial_number_),
CEREAL_NVP(secondary_system_serial_number_), CEREAL_NVP(param_), CEREAL_NVP(first_in_file_));
}
};

std_data::mbes_ping::PingsT convert_matched_entries(all_mbes_ping::PingsT& pings, all_nav_entry::EntriesT& entries);
std_data::mbes_ping::PingsT match_attitude(std_data::mbes_ping::PingsT& pings, all_nav_attitude::EntriesT& entries);
csv_data::csv_asvp_sound_speed::EntriesT convert_sound_speeds(const all_mbes_ping::PingsT& pings);
Expand Down Expand Up @@ -261,6 +281,10 @@ all_data::all_sound_speed_profile::EntriesT parse_file(const boost::filesystem::
template <>
all_data::all_raw_range_and_beam_angle::EntriesT parse_file(const boost::filesystem::path& file);

// actually there will be only one all_installation_param, so return size should be one
template <>
all_data::all_installation_param::EntriesT parse_file(const boost::filesystem::path& file);

}

#endif // ALL_DATA_H
17 changes: 17 additions & 0 deletions src/data_tools/include/liball/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,23 @@ PACK(struct all_raw_range_and_beam_angle_datagram_repeat_received {
unsigned char spare;
});

PACK(struct all_installation_para_datagram {
// common header, see all_common_header

// data description
unsigned short model_nbr; // EM model number (Example: EM 710 = 710)
unsigned int date; // Date at start of data record = year*10000 + month*100 + day (Example: Sep 26, 2005 = 20050926)
unsigned int time; // Time at start of data record since midnight in milliseconds (Example: 08:12:51.234 = 29570234)
unsigned short installation_datagram_count; // installation datagram count (0 to 65534)
unsigned short serial_nbr; // System serial number
unsigned short secondary_serial_nbr; // Secondary system serial number

// ASCII

// unsigned char spare; // not necessary, needed if to get even length,
// end of repeat cycle, see all_common_end
});

#undef PACK

#endif // ALL_H
51 changes: 41 additions & 10 deletions src/data_tools/src/all_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <liball/all.h>
//#include <endian.h>
#include <fstream>
#include <string>

#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/date_time.hpp>
Expand Down Expand Up @@ -117,7 +118,7 @@ vector<ReturnType, Eigen::aligned_allocator<ReturnType> > parse_file(const boost
*/

template <typename ReturnType, typename AllHeaderType>
ReturnType read_datagram(std::istream& input, const AllHeaderType& header)
ReturnType read_datagram(std::istream& input, const AllHeaderType& header, int ascii_buffer_length = 0)
{
ReturnType rtn;
return rtn;
Expand Down Expand Up @@ -161,8 +162,8 @@ vector<ReturnType, Eigen::aligned_allocator<ReturnType> > parse_stream_impl(istr
AllHeaderType header;
//cout << "Is a MB reading, code: " << int(data_type) << endl;
input.read(reinterpret_cast<char*>(&header), sizeof(header));
returns.push_back(read_datagram<ReturnType, AllHeaderType>(input, header));
//input.read(reinterpret_cast<char*>(&spare), sizeof(spare));
int ascii_length = nbr_bytes - sizeof(start_id)- sizeof(data_type) - sizeof(header) - sizeof(end_ident)- sizeof(end_ident);
returns.push_back(read_datagram<ReturnType, AllHeaderType>(input, header, ascii_length));
input.read(reinterpret_cast<char*>(&end_ident), sizeof(end_ident));
input.read(reinterpret_cast<char*>(&checksum), sizeof(checksum));
//cout << "End identifier: " << end_ident << endl;
Expand Down Expand Up @@ -235,7 +236,7 @@ pair<long long, string> parse_all_time(unsigned int date, unsigned int time)
}

template <>
all_mbes_ping read_datagram<all_mbes_ping, all_xyz88_datagram>(std::istream& input, const all_xyz88_datagram& header)
all_mbes_ping read_datagram<all_mbes_ping, all_xyz88_datagram>(std::istream& input, const all_xyz88_datagram& header, int ascii_buffer_length)
{
//cout << "Total number of beams: " << header.nbr_beams << endl;
//cout << "Valid number of beams: " << header.nbr_valid << endl;
Expand Down Expand Up @@ -272,7 +273,7 @@ all_mbes_ping read_datagram<all_mbes_ping, all_xyz88_datagram>(std::istream& inp
}

template <>
all_nav_entry read_datagram<all_nav_entry, all_position_datagram>(std::istream& input, const all_position_datagram& header)
all_nav_entry read_datagram<all_nav_entry, all_position_datagram>(std::istream& input, const all_position_datagram& header, int ascii_buffer_length)
{
//cout << "Got a position datagram, skipping: " << int(header.nbr_bytes_input) << endl;

Expand Down Expand Up @@ -300,7 +301,7 @@ all_nav_entry read_datagram<all_nav_entry, all_position_datagram>(std::istream&
}

template <>
all_nav_depth read_datagram<all_nav_depth, all_depth_datagram>(std::istream& input, const all_depth_datagram& header)
all_nav_depth read_datagram<all_nav_depth, all_depth_datagram>(std::istream& input, const all_depth_datagram& header, int ascii_buffer_length)
{
all_nav_depth entry;
entry.id_ = header.height_count;
Expand All @@ -313,7 +314,7 @@ all_nav_depth read_datagram<all_nav_depth, all_depth_datagram>(std::istream& inp
}

template <>
all_nav_attitude read_datagram<all_nav_attitude, all_attitude_datagram>(std::istream& input, const all_attitude_datagram& header)
all_nav_attitude read_datagram<all_nav_attitude, all_attitude_datagram>(std::istream& input, const all_attitude_datagram& header, int ascii_buffer_length)
{
all_nav_attitude entry;
entry.id_ = header.attitude_count;
Expand All @@ -340,7 +341,7 @@ all_nav_attitude read_datagram<all_nav_attitude, all_attitude_datagram>(std::ist
}

template <>
all_echosounder_depth read_datagram<all_echosounder_depth, all_echosounder_depth_datagram>(std::istream& input, const all_echosounder_depth_datagram& header)
all_echosounder_depth read_datagram<all_echosounder_depth, all_echosounder_depth_datagram>(std::istream& input, const all_echosounder_depth_datagram& header, int ascii_buffer_length)
{
all_echosounder_depth entry;
entry.id_ = header.echo_count;
Expand All @@ -352,7 +353,7 @@ all_echosounder_depth read_datagram<all_echosounder_depth, all_echosounder_depth
}

template <>
all_sound_speed_profile read_datagram<all_sound_speed_profile, all_sound_speed_profile_datagram>(std::istream& input, const all_sound_speed_profile_datagram& header)
all_sound_speed_profile read_datagram<all_sound_speed_profile, all_sound_speed_profile_datagram>(std::istream& input, const all_sound_speed_profile_datagram& header, int ascii_buffer_length)
{

all_sound_speed_profile entry;
Expand All @@ -370,7 +371,7 @@ all_sound_speed_profile read_datagram<all_sound_speed_profile, all_sound_speed_p
}

template <>
all_raw_range_and_beam_angle read_datagram<all_raw_range_and_beam_angle, all_raw_range_and_beam_angle_datagram>(std::istream& input, const all_raw_range_and_beam_angle_datagram& header)
all_raw_range_and_beam_angle read_datagram<all_raw_range_and_beam_angle, all_raw_range_and_beam_angle_datagram>(std::istream& input, const all_raw_range_and_beam_angle_datagram& header, int ascii_buffer_length)
{
all_raw_range_and_beam_angle raw;
raw.id_ = header.ping_count;
Expand Down Expand Up @@ -403,6 +404,29 @@ all_raw_range_and_beam_angle read_datagram<all_raw_range_and_beam_angle, all_raw
return raw;
}

template <>
all_installation_param read_datagram<all_installation_param, all_installation_para_datagram>(std::istream& input, const all_installation_para_datagram& header, int ascii_buffer_length)
{
all_installation_param param;
param.id_ = header.installation_datagram_count;
tie(param.time_stamp_, param.time_string_) = parse_all_time(header.date , header.time);
param.system_serial_number_ = header.serial_nbr;
param.secondary_system_serial_number_ = header.secondary_serial_nbr;
char * buffer = new char [ascii_buffer_length];
input.read (buffer, ascii_buffer_length);
stringstream str(buffer);
string x;
while (getline(str, x, ',')) {
size_t split_pos = x.find("=");
string key = x.substr(0, split_pos);
string value = x.substr(split_pos + 1);
param.param_[key] = value;
// cout<< x <<", " << key <<", " << value << endl;
}
return param;
}


mbes_ping::PingsT convert_matched_entries(all_mbes_ping::PingsT& pings, all_nav_entry::EntriesT& entries)
{
mbes_ping::PingsT new_pings;
Expand Down Expand Up @@ -715,4 +739,11 @@ all_raw_range_and_beam_angle::EntriesT parse_file<all_raw_range_and_beam_angle>(
return parse_file_impl<all_raw_range_and_beam_angle, all_raw_range_and_beam_angle_datagram, 78>(file);
}

template <>
all_installation_param::EntriesT parse_file<all_installation_param>(const boost::filesystem::path& file)
{
// actually there will be only one all_installation_param, so return size should be one
return parse_file_impl<all_installation_param, all_installation_para_datagram, 73>(file);
}

} // namespace std_data
1 change: 1 addition & 0 deletions src/data_tools/src/test_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ int main(int argc, char** argv)
all_nav_entry::EntriesT entries = parse_file<all_nav_entry>(path);
all_sound_speed_profile::EntriesT sound_speed_profile = parse_file<all_sound_speed_profile>(path);
all_raw_range_and_beam_angle::EntriesT raw_range_and_angle = parse_file<all_raw_range_and_beam_angle>(path);
all_installation_param::EntriesT installation_param = parse_file<all_installation_param>(path);
//all_nav_entry::EntriesT entries = parse_folder<all_nav_entry>(path);
//all_mbes_ping::PingsT pings = parse_folder<all_mbes_ping>(path);

Expand Down
12 changes: 12 additions & 0 deletions src/pydata_tools/src/pyall_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ PYBIND11_MODULE(all_data, m) {
.def_static("parse_folder", &parse_folder_from_str<all_raw_range_and_beam_angle>, "Parse all_raw_range_and_beam_angle from folder of .all files")
.def_static("read_data", &read_data_from_str<all_raw_range_and_beam_angle::EntriesT>, "Read all_raw_range_and_beam_angle::EntriesT from .cereal file");

py::class_<all_installation_param>(m, "all_installation_param", "Class for the installation parameters")
.def(py::init<>())
.def_readwrite("id_", &all_installation_param::id_, "Sequential ID of measurement")
.def_readwrite("time_string_", &all_installation_param::time_string_, "Readable date of measurement")
.def_readwrite("time_stamp_", &all_installation_param::time_stamp_, "UNIX timestamp")
.def_readwrite("system_serial_number_", &all_installation_param::system_serial_number_, "System serial number")
.def_readwrite("secondary_system_serial_number_", &all_installation_param::secondary_system_serial_number_, "Secondary system serial number")
.def_readwrite("param_", &all_installation_param::param_, "Dict of ascii parameters")
.def_readwrite("first_in_file_", &all_installation_param::first_in_file_, "Is first measurement in file?")
.def_static("parse_file", &parse_file_from_str<all_installation_param>, "Parse all_installation_param from .all file")
.def_static("parse_folder", &parse_folder_from_str<all_installation_param>, "Parse all_installation_param from folder of .all files")
.def_static("read_data", &read_data_from_str<all_installation_param::EntriesT>, "Read all_installation_param::EntriesT from .cereal file");

m.def("write_data", &write_data_from_str<all_mbes_ping::PingsT>, "Write all_mbes_ping::PingsT to .cereal file");
m.def("write_data", &write_data_from_str<all_nav_entry::EntriesT>, "Write all_nav_entry::EntriesT to .cereal file");
Expand Down

0 comments on commit 1b5e2d9

Please sign in to comment.