Ignore:
Timestamp:
Sep 29, 2010, 12:44:04 PM (9 years ago)
Author:
sacerdot
Message:

More cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/IntelHex.ml

    r138 r139  
    3434    | 'F' -> 15 | _ -> assert false
    3535
    36 (* CSC: tipare piu' strettamente: prendere la taglia del vettore in input
    37    come taglia della stringa *)
    38 let vect_of_hex_string s size =
    39   let int_of_hex_string h =
    40     let rec aux l p =
    41       match l with
    42         [] -> 0
    43       | hd::tl ->
    44           hex_digit_of_char hd * p + aux tl (p * 16)
    45     in
    46       aux (List.rev $ char_list_of_string h) 1
    47   in
    48     let i_str = int_of_hex_string s in
    49       vect_of_int i_str size
    50 ;;
    51 
    5236let hex_string_of_vect v = Printf.sprintf "%0 2X" (int_of_vect v);;
    5337
     
    6953;;
    7054
     55let prs_nibble =
     56         prs_hex_digit >>=
     57fun a -> return $ vect_of_int (hex_digit_of_char a) `Four
     58;;
     59
    7160let prs_byte =
    72          prs_hex_digit >>=
    73 fun a -> prs_hex_digit >>=
    74 fun b -> return $ vect_of_hex_string (String.make 1 a ^ String.make 1 b) `Eight
     61         prs_nibble >>=
     62fun a -> prs_nibble >>=
     63fun b -> return $ mk_byte a b
    7564;;
    7665
    7766let prs_word =
    78          prs_hex_digit >>=
    79 fun a -> prs_hex_digit >>=
    80 fun b -> prs_hex_digit >>=
    81 fun c -> prs_hex_digit >>=
    82 fun d -> return $ vect_of_hex_string (String.make 1 a ^ String.make 1 b ^ String.make 1 c ^ String.make 1 d) `Sixteen
     67         prs_byte >>=
     68fun a -> prs_byte >>=
     69fun b -> return $ mk_word a b
    8370;;
    8471
     
    9481  let a_as_hex = hex_digit_of_char a in
    9582  let b_as_hex = hex_digit_of_char b in
     83(*CSC: is next line correct??? *)
    9684  let total = a_as_hex + b_as_hex in
    9785    return $ intel_hex_entry_type_of_int total
     
    120108fun b -> prs_addr      >>=
    121109fun c -> prs_type      >>=
    122 fun d ->
    123   let len = int_of_vect b in
    124     prs_data len       >>=
     110fun d -> prs_data (int_of_vect b) >>=
    125111fun e -> prs_checksum  >>=
    126112fun f -> prs_eof       >>=
     
    149135    | (prs,_)::_ -> Some prs
    150136
    151 (* DPM: BUG --- length and addr hex values are sometimes shortened if the hex
    152         string begins with a zero.  All length strings should be two hex chars
    153         long, and all addr strings should be four.                            *)
    154137let string_of_intel_hex_entry entry =
    155138  let length_string = hex_string_of_vect entry.record_length in
    156139  let addr_string = hex_string_of_vect entry.record_addr in
    157140  let checksum_string = hex_string_of_vect entry.data_checksum in
    158   let type_string =
    159     match entry.record_type with
    160       Data -> "00"
    161     | End -> "01"
    162     | ExtendedSeg -> "02"
    163     | ExtendedLinear -> "04" in
     141  let type_string = Printf.sprintf "%0 2d" (int_of_intel_hex_entry_type entry.record_type) in
    164142  let data_string = String.concat "" (List.map hex_string_of_vect entry.data_field) in
    165143    ":" ^ length_string ^ addr_string ^ type_string ^ data_string ^ checksum_string
Note: See TracChangeset for help on using the changeset viewer.