Skip to content

Commit

Permalink
[link] parameters for period of PING and LINK_REPORT messages
Browse files Browse the repository at this point in the history
closes #1037
  • Loading branch information
flixr committed Apr 28, 2015
1 parent 6656ca7 commit e4c1df3
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions sw/ground_segment/tmtc/link.ml
Expand Up @@ -69,6 +69,10 @@ let gen_stat_trafic = ref false

let add_timestamp = ref None

let status_msg_period = ref 1000 (** ms *)
let ping_msg_period = ref 5000 (** ms *)


let send_message_over_ivy = fun sender name vs ->
let timestamp =
match !add_timestamp with
Expand Down Expand Up @@ -128,8 +132,6 @@ let update_status = fun ?udp_peername ac_id buf_size is_pong ->
if is_pong then
status.last_pong <- Unix.gettimeofday ();;

let status_msg_period = 1000 (** ms *)
let ping_msg_period = 5000 (** ms *)
let status_ping_diff = 500 (* ms *)

let live_aircraft = fun ac_id ->
Expand All @@ -155,7 +157,7 @@ let send_status_msg =
let start = Unix.gettimeofday () in
fun () ->
Hashtbl.iter (fun ac_id status ->
let dt = float status_msg_period /. 1000. in
let dt = float !status_msg_period /. 1000. in
let t = int_of_float (Unix.gettimeofday () -. start) in
let byte_rate = float (status.rx_byte - status.last_rx_byte) /. dt
and msg_rate = float (status.rx_msg - status.last_rx_msg) /. dt in
Expand All @@ -179,7 +181,7 @@ let send_status_msg =
let update_ms_since_last_msg =
fun () ->
Hashtbl.iter (fun ac_id status ->
status.ms_since_last_msg <- status.ms_since_last_msg + status_msg_period / 3)
status.ms_since_last_msg <- status.ms_since_last_msg + !status_msg_period / 3)
statuss

let use_tele_message = fun ?udp_peername ?raw_data_size payload ->
Expand Down Expand Up @@ -483,7 +485,9 @@ let () =
"-xbee_retries", Arg.Set_int XB.my_addr, (sprintf "<nb retries> (%d)" !XB.nb_retries);
"-xbee_868", Arg.Set Xbee.mode868, (sprintf "Enables the 868 protocol");
"-redlink", Arg.Set red_link, (sprintf "Sets whether the link is a redundant link. Set this flag and the id flag to use multiple links");
"-id", Arg.Set_int link_id, (sprintf "Sets the link id. If multiple links are used, each must have a unique id. Default is %i" !link_id)
"-id", Arg.Set_int link_id, (sprintf "<id> Sets the link id. If multiple links are used, each must have a unique id. Default is %i" !link_id);
"-status_period", Arg.Set_int status_msg_period, (sprintf "<period> Sets the period (in ms) of the LINK_REPORT status message. Default is %i" !status_msg_period);
"-ping_period", Arg.Set_int ping_msg_period, (sprintf "<period> Sets the period (in ms) of the PING message sent to aircrafs. Default is %i" !ping_msg_period)
] in
Arg.parse options (fun _x -> ()) "Usage: ";

Expand Down Expand Up @@ -548,10 +552,10 @@ let () =

(** Init and Periodic tasks *)
begin
ignore (Glib.Timeout.add status_msg_period (fun () -> send_status_msg (); true));
ignore (Glib.Timeout.add (status_msg_period / 3) (fun () -> update_ms_since_last_msg (); true));
ignore (Glib.Timeout.add !status_msg_period (fun () -> send_status_msg (); true));
ignore (Glib.Timeout.add (!status_msg_period / 3) (fun () -> update_ms_since_last_msg (); true));
let start_ping = fun () ->
ignore (Glib.Timeout.add ping_msg_period (fun () -> send_ping_msg device; true));
ignore (Glib.Timeout.add !ping_msg_period (fun () -> send_ping_msg device; true));
false in
ignore (Glib.Timeout.add status_ping_diff start_ping);
if !aerocomm then
Expand Down

0 comments on commit e4c1df3

Please sign in to comment.