1 /*--------------------------------------------------------------------------*/
4 // This file is part of ruwai.
6 // If you use ruwai_parser in any program or publication, please inform and
7 // acknowledge its author Stefan Mertl (stefan@mertl-research.at).
9 // ruwai is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /*--------------------------------------------------------------------------*/
40 #define BOOST_NO_CXX11_SCOPED_ENUMS // Bug fix for an linking error caused by boost::filesystem::copy_file
41 #define BOOST_NO_SCOPED_ENUMS // This define has to be used for boost versions below 1.51. BBB has 1.49
42 #include <boost/format.hpp>
43 #include <boost/filesystem.hpp>
44 #include <boost/algorithm/string.hpp>
45 #undef BOOST_NO_CXX11_SCOPED_ENUMS
46 #undef BOOST_NO_SCOPED_ENUMS
48 //#include <sys/types.h>
49 //#include <sys/stat.h>
53 #include <libmseed/libmseed.h>
55 #include "rw_protocol.h"
57 //! The supported GPSfix types.
58 typedef enum gpsfix_e
{
60 FIX_DEAD_RECKONING_ONLY
= 1,
63 FIX_GPS_AND_DEAD_RECKONING
= 4,
68 typedef struct timestamp_s
{
77 void record_handler (char *record
, int reclen
, void *ptr
);
81 Recorder(std::string serial_number
, unsigned int total_channels
, std::vector
<unsigned int> record_channels
, unsigned int sps
, std::string sd_mnt
, std::string tmp_dir
, unsigned int file_length
);
82 void add_sample(rw_smp_24bit_t paket
);
83 void add_timestamp_sample(rw_smp_24bit_tsp_t paket
);
84 void handle_timestamp_sample(rw_smp_24bit_tsp_t paket
);
85 void pack_samplebuffer(void);
86 bool check_output_dir_structure(void);
87 void copy_files(std::vector
<std::string
> files
);
88 timestamp_t
get_last_timestamp(void);
91 std::string serial_number
; // The serial number of the ruwai Arduino stack.
92 unsigned int sps
; // The sampling rate of the data.
93 unsigned int n_channels
; // The number of channels to record.
94 std::vector
<unsigned int> record_channels
; // The channel number to record to file.
95 unsigned int write_limit
; // The size of the sample_buffer when to copy the samples to the ms_trace.
97 std::mutex mut_sample_buffer
;
98 std::mutex mut_timestamps
;
99 std::mutex mut_last_timestamp
;
103 std::string sd_mnt_point
; // The name of the SD card mount point.
104 std::string data_dir
; // The name of the folder where to store the miniseed files.
105 std::string tmp_dir
; // The name of the folder where to store the data files which are currently used for recording.
107 std::vector
<std::vector
<std::int32_t> > sample_buffer
; // The buffers holding the samples.
108 std::vector
<std::vector
<int> > timestamp_pos
; // The timestamp positions in the sample vector.
109 std::vector
<timestamp_t
> timestamps
; // The timestamp values.
110 std::vector
<MSTrace
*> traces
; // The miniseed traces. One for each channel.
112 //MSTraceGroup *mstg;
114 //hptime_t span_start;
116 unsigned int file_length
; // The lenght of the data files in seconds.
117 double tow_sub_ms_scale
; // The scaling factor of the tow_sub_ms value of the GPS timing paket.
119 // The state of the recorder.
120 bool state_first_timestamp_received
;
121 bool state_gps_fix_init
;
122 //gpsfix_t state_gps_fix;
123 //bool state_gps_fix_ok;
125 timestamp_t last_timestamp
;
128 void init_msr(MSRecord
* msr
, unsigned int channel_number
);
129 void set_msr_timeflags(MSRecord
* msr
, std::vector
<timestamp_t
>& timestamps
);
130 bool msr_fits_to_end(MSTrace
* mst
, MSRecord
* msr
);
131 std::string
get_filename(BTime start_time
, char* channel
);
132 std::string
write_trace_to_file(MSTrace
* mst
, bool flush
, MSRecord
* msr_template
);
135 #endif /* RECORDER_H */