From: Jérémie D. <Ba...@us...> - 2011-03-29 13:02:14
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via fd224ab8ffc2fdc42e03a8aed77b0818592a0844 (commit) from 03506f5a382fb6d9d49d8fdcaa332db3e1a6c112 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit fd224ab8ffc2fdc42e03a8aed77b0818592a0844 Author: Jérémie Dimino <je...@di...> Date: Tue Mar 29 14:53:03 2011 +0200 [info] do not get stuck while waiting for the reply to a CAN request When waiting for a CAN data, if it does not come after a timeout (0.1 second by default), we resend the request. ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_message.ml b/info/control2011/src/lib/krobot_message.ml index debdc1d..c0a5414 100644 --- a/info/control2011/src/lib/krobot_message.ml +++ b/info/control2011/src/lib/krobot_message.ml @@ -9,6 +9,7 @@ open Krobot_can open Printf +open Lwt open Lwt_react (* +-----------------------------------------------------------------+ @@ -220,15 +221,29 @@ let recv bus = E.map (fun (timestamp, frame) -> (timestamp, decode frame)) (Krob | Calls | +-----------------------------------------------------------------+ *) -let motor_status bus = +let wait_timeout = 0.1 + +let send_and_recv bus req f = let t = E.next (E.fmap (fun (ts, frame) -> - match frame with - | Motor_status status -> Some(ts, status) - | _ -> None) + match f frame with + | Some x -> Some(`Value(ts, x)) + | None -> None) (recv bus)) in lwt () = send bus (Unix.gettimeofday (), Req_motor_status) in - t + let rec loop () = + lwt () = send bus (Unix.gettimeofday (), req) in + match_lwt choose [t; Lwt_unix.sleep wait_timeout >|= fun () -> `Timeout] with + | `Value x -> return x + | `Timeout -> loop () + in + loop () + +let motor_status bus = + send_and_recv bus Req_motor_status + (function + | Motor_status status -> Some status + | _ -> None) hooks/post-receive -- krobot |