add functions to pprz transport lib

This commit is contained in:
Pascal Brisset
2009-10-15 07:04:49 +00:00
parent 74bb7e92c9
commit 7a11e0d555
2 changed files with 23 additions and 2 deletions
+19 -1
View File
@@ -296,7 +296,25 @@ let rec sprint_value = fun buf i _type v ->
String.blit s 0 buf (i+1) n;
1 + n
| (Scalar x|ArrayType x), _ -> failwith (sprintf "Pprz.sprint_value (%s)" x)
let hex_of_int_array = function
Array array ->
let n = Array.length array in
(* One integer -> 2 chars *)
let s = String.create (2*n) in
Array.iteri
(fun i dec ->
let x = int_of_value array.(i) in
assert (0 <= x && x <= 0xff);
let hex = sprintf "%02x" x in
String.blit hex 0 s (2*i) 2)
array;
s
| value ->
failwith (sprintf "Error: expecting array in Pprz.hex_of_int_array, found %s" (string_of_value value))
exception Unknown_msg_name of string * string
+4 -1
View File
@@ -72,7 +72,7 @@ val types : (string * type_descr) list
type values = (string * value) list
val assoc : string -> values -> value
(** Safe assoc taking into accound characters case *)
(** Safe assoc taking into accound characters case. May raise Failure ... *)
val string_assoc : string -> values -> string
(** May raise Not_found *)
@@ -82,6 +82,9 @@ val int_assoc : string -> values -> int
val int32_assoc : string -> values -> Int32.t
(** May raise Not_found or Invalid_argument *)
val hex_of_int_array : value -> string
(** Returns the hexadecimal string of an array of integers *)
exception Unknown_msg_name of string * string
(** [Unknown_msg_name (name, class_name)] Raised if message [name] is not
found in class [class_name]. *)