From: Jérémie D. <Ba...@us...> - 2010-03-20 14:12:01
|
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 f2213bbbf674944c0d841ddb4a7e71d25010bb2e (commit) from 6d667aa1190fcbab5bf284bb921129d239df39b9 (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 f2213bbbf674944c0d841ddb4a7e71d25010bb2e Author: Jérémie Dimino <je...@di...> Date: Sat Mar 20 15:09:42 2010 +0100 Handle errors as responses ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/driver/driver.ml b/PC_Mainboard/driver/driver.ml index 804c532..8705b76 100644 --- a/PC_Mainboard/driver/driver.ml +++ b/PC_Mainboard/driver/driver.ml @@ -388,14 +388,14 @@ struct dev.state <- Trajectory trajectory; let thread = Lwt_event.next dev.traj_completed >> return () in lwt () = - select [waiter; - (lwt () = - if dist > 0 then - USB_commands.Motors.forward dev.card dist velocity acc - else - USB_commands.Motors.backward dev.card (-dist) velocity acc - in - thread)] + pick [waiter; + (lwt () = + if dist > 0 then + USB_commands.Motors.forward dev.card dist velocity acc + else + USB_commands.Motors.backward dev.card (-dist) velocity acc + in + thread)] in dev.state <- Static; return (if trajectory.stopped then `Stopped else `OK) @@ -424,14 +424,14 @@ struct dev.state <- Trajectory trajectory; let thread = Lwt_event.next dev.traj_completed >> return () in lwt () = - select [waiter; - (lwt () = - if angle > 0 then - USB_commands.Motors.left dev.card angle velocity acc - else - USB_commands.Motors.right dev.card (-angle) velocity acc - in - thread)] + pick [waiter; + (lwt () = + if angle > 0 then + USB_commands.Motors.left dev.card angle velocity acc + else + USB_commands.Motors.right dev.card (-angle) velocity acc + in + thread)] in dev.state <- Static; return (if trajectory.stopped then `Stopped else `OK) @@ -468,16 +468,16 @@ struct dev.state <- Trajectory trajectory; let thread = Lwt_event.next dev.traj_completed >> return () in lwt () = - select [waiter; - (lwt () = - USB_commands.Motors.goto dev.card - ~x ~y - ~velocity:velocity - ~acceleration:acc - ~mode - ~bypass_distance - in - thread)] + pick [waiter; + (lwt () = + USB_commands.Motors.goto dev.card + ~x ~y + ~velocity:velocity + ~acceleration:acc + ~mode + ~bypass_distance + in + thread)] in dev.state <- Static; return (if trajectory.stopped then `Stopped else `OK) diff --git a/PC_Mainboard/driver/krobot_card.ml b/PC_Mainboard/driver/krobot_card.ml index 3370f59..d89b116 100644 --- a/PC_Mainboard/driver/krobot_card.ml +++ b/PC_Mainboard/driver/krobot_card.ml @@ -11,6 +11,29 @@ module Log = Lwt_log.Make(struct let section = "card" end) open Lwt +let error_messages = [ + PcInterface.err_unknown_cmd, "unknown command"; + PcInterface.err_unknown_get, "unknown get request"; + PcInterface.err_unknown_set, "unknown set request"; + PcInterface.err_invalid_response, "invalid response"; + PcInterface.err_ax12_wrong_packet, "invalid AX12 packet"; + PcInterface.err_ax12_error, "AX12 error"; + PcInterface.err_ax12_chksum, "invalid checksum of AX12 packet"; + PcInterface.err_cmp03_not_responding, "cmp03 not responding"; + PcInterface.err_adjd_s371_not_responding, "adjd_s371 not responding"; + PcInterface.err_lm_command_error, "lm command error"; + PcInterface.err_lm_position_error, "lm position error"; + PcInterface.err_invalid_axis, "invalid axis"; +] + +let error_message error = + try + List.assoc error error_messages + with Not_found -> + Printf.sprintf "unknown error (%d)" error + +exception Error of string + (* +-----------------------------------------------------------------+ | Messages | +-----------------------------------------------------------------+ *) @@ -161,8 +184,8 @@ let dropped typ card msg = host_serial = %d device_serial = %d command = %d -error = %d -data:" msg.host_serial msg.device_serial msg.command msg.error in +error = %s +data:" msg.host_serial msg.device_serial msg.command (if msg.error <> 0 then error_message msg.error else "none") in Lwt_stream.iter_s (fun line -> Log.warning line) (Lwt_stream.hexdump (Lwt_stream.of_string msg.data)) (* Dispatch incomming messages continously *) @@ -170,11 +193,11 @@ let rec dispatch card = let buffer = String.create 64 in begin try_lwt - select [card.abort_waiter; - USB.interrupt_recv - ~handle:card.handle - ~endpoint:1 - buffer 0 64] >|= fun len -> `OK len + pick [card.abort_waiter; + USB.interrupt_recv + ~handle:card.handle + ~endpoint:1 + buffer 0 64] >|= fun len -> `OK len with exn -> return (`Error exn) end >>= function @@ -195,7 +218,10 @@ let rec dispatch card = | Some wakener -> card.reply_waiters <- Int_map.remove msg.host_serial card.reply_waiters; card.serial_pool <- card.serial_pool @ [msg.host_serial]; - Lwt.wakeup wakener msg.data + if msg.error <> 0 then + Lwt.wakeup_exn wakener (Error(error_message msg.error)) + else + Lwt.wakeup wakener msg.data | None -> ignore (dropped "response" card msg) end else begin @@ -267,7 +293,7 @@ let rec make ~name ~handle = +-----------------------------------------------------------------+ *) let send card buffer = - lwt len = select [card.abort_waiter; USB.interrupt_send ~handle:card.handle ~endpoint:1 buffer 0 64] in + lwt len = pick [card.abort_waiter; USB.interrupt_send ~handle:card.handle ~endpoint:1 buffer 0 64] in if len <> 64 then begin let msg = Printf.sprintf "write on %s card returned %d instead of 64" card.wrapper.name len in lwt () = Log.error msg in diff --git a/PC_Mainboard/driver/krobot_card.mli b/PC_Mainboard/driver/krobot_card.mli index 06063a3..8c65caf 100644 --- a/PC_Mainboard/driver/krobot_card.mli +++ b/PC_Mainboard/driver/krobot_card.mli @@ -30,6 +30,9 @@ exception Card_closed exception Card_crashed of string (** Exception raised when a fatal error happen on the card *) +exception Error of string + (** An error returned by a card *) + (** {6 Card opening/closing} *) val make : name : string -> handle : USB.handle -> t Lwt.t hooks/post-receive -- krobot |