function build(...) if not load_classes() or not load_libraries() then print("Could not load dependencies") return end horus.debug.enable_stack_trace() -- horus.signals.multiplexer.verbose = 2 local args = {...} local configs = {} configs["1"] = config_1 print("[build] arguments:", #args) for k, v in pairs(args) do print(k, v) end if #args < 3 then print("error, too few arguments:\n[build] config recording_folder csv_file") return end local config = configs[args[1]] local recording_folder = args[2] local csv_file = args[3] if config == nill then print("error: unkown config") return end local multiplexer = horus.signals.multiplexer.new() multiplexer.info["lbg_timesync"] = false multiplexer.info["csv_file"] = csv_file multiplexer:add_recording_folder(recording_folder) config(multiplexer) multiplexer:run() end function config_1(multiplexer) multiplexer:primary_signal("csv") multiplexer.info["csv"] = horus.csv.new(multiplexer.info["csv_file"]) multiplexer.info["Frames_writer"] = horus.signals.Frames_writer.new() multiplexer.signals_resolver.events.handlers["configure"] = function(info) local multiplexer = info["Multiplexer"] local resolver = info["Signals_resolver"] resolver.configure(info) resolver.resolvers["NMEA"] = horus.signals.Signal_resolver.new() resolver.add_paplevt1(info, "NMEA", horus.signals.Devicetime_id, false, 1, multiplexer.info["lbg_timesync"]) resolver.add_hrs17(info, "Triggerbox", horus.signals.Devicetime_id, false, 1) if multiplexer.info["lbg_timesync"] then resolver.use_lb_gps_timesync(info, "Ladybug") end end multiplexer.signals_resolver.events.handlers["analyse"] = function(info) local context = info["Signals_context"] local gps_time = context:signal_by_id("NMEA"):find(horus.signals.Devicetime_id) local gps_start = horus.signals.utils.Vi(gps_time, 1) local gps_stop = horus.signals.utils.Vi(gps_time, gps_time.signal:size()) local dt_start = horus.datetime.from_seconds(gps_start) dt_start.sec = dt_start.sec - 1 local dt_stop = horus.datetime.from_seconds(gps_stop) dt_stop.sec = dt_stop.sec + 1 local csv_signal = info["csv"]:filter(dt_start, dt_stop) context:add_signal(csv_signal.id, csv_signal) end multiplexer.signals_evolver.events.handlers["configure"] = function(info) local evolver = info["Signals_evolver"] evolver.time_scalars["NMEA"] = 1 evolver.time_scalars["Triggerbox"] = 0.001 end multiplexer.signals_evolver.events.handlers["run"] = function(info) local evolver = info["Signals_evolver"] evolver.run(info) evolver.grabbertime(info) end multiplexer.signals_correlate.events.handlers["configure"] = function(info) local correlate = info["Signals_correlate"] if not correlate.configured then correlate.configure(info) for _, validators in pairs(correlate.validators) do for i = 1, #validators do validators[i] = function(ccinfo) return true end end end end end multiplexer.signals_export.events.handlers["configure"] = function(info) local export = info["Signals_export"] local multiplexer = info["Multiplexer"] export.configure(info) export.export_type = export.by_frame -- by_signal/by_frame info["my_export"] = {} -- store some context here info["my_export"]["init"] = false export.callback = function(info) local context = info["Signals_context"] local my_export = info["my_export"] local frame_data = info["Frame_data"] local multiplexer = info["Multiplexer"] local frames_writer = info["Frames_writer"] local csv = info["csv"].csv if not info["my_export"]["init"] then info["my_export"]["init"] = true local start = info["primary_index_range"][1] local stop = info["primary_index_range"][2] local primary = frame_data["primary_devtime"] local sec_grabber = frame_data["secondary_devtime"]:find(horus.signals.Grabbertime_id) local grabber_stamp = horus.datetime.from_unix_epoch_microsec(horus.signals.utils.V( sec_grabber.signal:at(frame_data["multiplex_secondary_index"]))) frames_writer:create(stop) local dataset = frames_writer.frames for i = start, stop do local key = horus.signals.utils.Vi(primary, i) local entry = csv[key] local stamp = horus.datetime.from_unix_epoch_microsec(key) stamp.year = grabber_stamp.year stamp.month = grabber_stamp.month stamp.day = grabber_stamp.day local location = dataset:at(i) location:update(tonumber(entry[horus.csv.CSV_LAT]), tonumber(entry[horus.csv.CSV_LON]), tonumber(entry[horus.csv.CSV_ALT]), stamp:to_frames_format(), tonumber(entry[horus.csv.CSV_ROLL]), tonumber(entry[horus.csv.CSV_PITCH]), tonumber(entry[horus.csv.CSV_YAW]), "$DIST," .. entry[horus.csv.CSV_DISTANCE] .. "*00") end end local sec = frame_data["secondary"] local sec_sig = frame_data["secondary_devtime"] local sec_grabber = sec_sig:find(horus.signals.Grabbertime_id) local sec_entry = sec_sig.signal:at(frame_data["multiplex_secondary_index"]) local reader = info["Data_reader"] local dataset = frames_writer.frames local location = dataset:at(frame_data["multiplex_primary_index"]) if sec_sig.info.is_container_signal and horus.signals.is_view_valid(sec_entry) and (sec.flags & horus.signals.Signal_flags.Media_view > 0) then local entry = horus.signals.get_view_index_entry(sec_entry) dataset:set_image(location, "/", sec_sig.info.stem, entry:offset()) end end end multiplexer.signals_export.events.handlers["analyse"] = function(info) local frames_writer = info["Frames_writer"] frames_writer:write_to_file(info["recording_folder"] .. "/frames.xml") end end -- Loads the classes from the Horison framework function load_classes() classes_loader = {"msg", "cmp", "nmea", "signals", "filesystem", "math", "frames"} for key, value in pairs(classes_loader) do if (not horus.sol:load_classes(value, value)) then print("load_classes:", value, "could not be loaded.") return false end end return true end function load_libraries() library_loader = { [1] = {"horus_signals_utils", horus.signals, "utils"}, [2] = {"horus_signals_peaks", horus.signals, "peaks"}, [3] = {"horus_signals_correlate", horus.signals, "correlate"}, [4] = {"horus_signals_frames", horus.signals, "frames"}, [5] = {"horus_signals_multiplexer", horus.signals, "multiplexer"}, [6] = {"horus_debug", horus, "debug"}, [7] = {"horus_filesystem", horus, "fs"}, [8] = {"horus_csv", horus, "csv"}, [9] = {"horus_datetime", horus, "datetime"}, [11] = {"horus_signals_dsp", horus.signals, "dsp"} } for key, value in ipairs(library_loader) do if horus.sol:insert_library_from_search_path(value[1], value[2], value[3]) ~= 1 then print("load_libraries:", value[1], "could not be loaded.") return false end end return true end