-
Notifications
You must be signed in to change notification settings - Fork 55
/
debugPL.ml
46 lines (43 loc) · 1.48 KB
/
debugPL.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(*
* Debugging facilities
*
* Copyright (C) 2004 CENA/ENAC, Pascal Brisset, Antoine Drouin
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*)
let level = ref (try Sys.getenv "PPRZ_DEBUG" with Not_found -> "")
let log = ref stderr
let call lev f =
assert( (* assert permet au compilo de tout virer avec l'option -noassert *)
if (CompatPL.bytes_contains !level '*' || CompatPL.bytes_contains !level lev)
then begin
f !log;
flush !log
end;
true)
let trace lev s = call lev (fun f -> Printf.fprintf f "%s\n" s)
let xprint = fun s ->
let n = CompatPL.bytes_length s in
let a = CompatPL.bytes_make (3*n) ' ' in
for i = 0 to n - 1 do
let x = Printf.sprintf "%02x" (Char.code s.[i]) in
CompatPL.bytes_set a (3*i) x.[0];
CompatPL.bytes_set a (3*i+1) x.[1]
done;
a