From: Jérémie D. <Ba...@us...> - 2011-03-18 22:20:00
|
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 b628b5a4fac1280c9f818dad667e8ba832222d4d (commit) from 184d207e0be5f4a681e76f3bd4cea8b59476b414 (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 b628b5a4fac1280c9f818dad667e8ba832222d4d Author: Jérémie Dimino <je...@di...> Date: Fri Mar 18 23:18:11 2011 +0100 [info] correct implementation of timestamps using ioctls ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/can/can_stubs.c b/info/control2011/src/can/can_stubs.c index c2a1876..93d63fb 100644 --- a/info/control2011/src/can/can_stubs.c +++ b/info/control2011/src/can/can_stubs.c @@ -48,29 +48,19 @@ CAMLprim value ocaml_can_recv(value val_fd) CAMLparam1(val_fd); CAMLlocal3(val_result, val_frame, val); - struct msghdr msg; - struct iovec iov; - uint64_t timestamp; struct can_frame frame; - /* Prepare the IO vector. */ - iov.iov_base = &frame; - iov.iov_len = sizeof(frame); - - /* Prepare the message. */ - memset(&msg, 0, sizeof(msg)); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = ×tamp; - msg.msg_controllen = sizeof(timestamp); - /* Receive one frame. */ - int ret = recvmsg(Int_val(val_fd), &msg, 0); - if (ret < 0) uerror("recvmsg", Nothing); + int ret = recv(Int_val(val_fd), &frame, sizeof(frame), 0); + if (ret < 0) uerror("recv", Nothing); /* It is an error if we do not receive exactly one frame. */ if (ret != sizeof(frame)) caml_failwith("recvmsg: invalid size"); + /* Receive the timestamp. */ + struct timeval tv; + if (ioctl(Int_val(val_fd), SIOCGSTAMP, &tv) < 0) uerror("ioctl", Nothing); + /* Build the caml frame. */ val_frame = caml_alloc_tuple(5); Field(val_frame, 0) = Val_int(frame.can_id & CAN_EFF_MASK); @@ -83,24 +73,18 @@ CAMLprim value ocaml_can_recv(value val_fd) /* Build the result containing the timestamp and the frame. */ val_result = caml_alloc_tuple(2); - val = caml_copy_double(timestamp * 1e-9); + val = caml_copy_double(tv.tv_sec + tv.tv_usec * 1e-6); Store_field(val_result, 0, val); Store_field(val_result, 1, val_frame); CAMLreturn(val_result); } -CAMLprim value ocaml_can_send(value val_fd, value val_arg) +CAMLprim value ocaml_can_send(value val_fd, value val_frame) { - struct msghdr msg; - struct iovec iov; - uint64_t timestamp; struct can_frame frame; - timestamp = (uint64_t)(Double_val(Field(val_arg, 0)) * 1e9); - /* Build the can frame. */ - value val_frame = Field(val_arg, 1); frame.can_id = Int_val(Field(val_frame, 0)) | (Int_val(Field(val_frame, 1)) >> 29) | (Int_val(Field(val_frame, 2)) >> 30) | @@ -109,19 +93,8 @@ CAMLprim value ocaml_can_send(value val_fd, value val_arg) frame.can_dlc = caml_string_length(val_data); memcpy(frame.data, String_val(val_data), caml_string_length(val_data)); - /* Prepare the IO vector. */ - iov.iov_base = &frame; - iov.iov_len = sizeof(frame); - - /* Prepare the message. */ - memset(&msg, 0, sizeof(msg)); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = ×tamp; - msg.msg_controllen = sizeof(timestamp); - - /* Receive one frame. */ - int ret = sendmsg(Int_val(val_fd), &msg, 0); + /* Send the frame. */ + int ret = send(Int_val(val_fd), &frame, sizeof(frame), 0); if (ret < 0) uerror("sendmsg", Nothing); /* It is an error if we do not sent exactly one frame. */ diff --git a/info/control2011/src/can/krobot_can_bus.ml b/info/control2011/src/can/krobot_can_bus.ml index b3b88db..f0c419f 100644 --- a/info/control2011/src/can/krobot_can_bus.ml +++ b/info/control2011/src/can/krobot_can_bus.ml @@ -46,10 +46,10 @@ let close bus = bus#close +-----------------------------------------------------------------+ *) external can_recv : Unix.file_descr -> float * Krobot_can.frame = "ocaml_can_recv" -external can_send : Unix.file_descr -> float * Krobot_can.frame -> unit = "ocaml_can_send" +external can_send : Unix.file_descr -> Krobot_can.frame -> unit = "ocaml_can_send" let recv bus = Lwt_unix.wrap_syscall Lwt_unix.Read bus#fd (fun () -> can_recv (Lwt_unix.unix_file_descr bus#fd)) -let send bus arg = - Lwt_unix.wrap_syscall Lwt_unix.Write bus#fd (fun () -> can_send (Lwt_unix.unix_file_descr bus#fd) arg) +let send bus (_, frame) = + Lwt_unix.wrap_syscall Lwt_unix.Write bus#fd (fun () -> can_send (Lwt_unix.unix_file_descr bus#fd) frame) hooks/post-receive -- krobot |