From c846e88f353f3bcf13755e4ca0e41e848689b42b Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 30 May 2017 20:42:31 +0300 Subject: [PATCH] Bin2Header util needed by bootloader --- java_tools/bin2header.jar | Bin 0 -> 3228 bytes java_tools/bin2header/Bin2Header.iml | 12 ++++ java_tools/bin2header/build.xml | 24 +++++++ .../bin2header/src/rusefi/Bin2Header.java | 64 ++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 java_tools/bin2header.jar create mode 100644 java_tools/bin2header/Bin2Header.iml create mode 100644 java_tools/bin2header/build.xml create mode 100644 java_tools/bin2header/src/rusefi/Bin2Header.java diff --git a/java_tools/bin2header.jar b/java_tools/bin2header.jar new file mode 100644 index 0000000000000000000000000000000000000000..0820f6de295831fe683a90974c979b1d9db8d356 GIT binary patch literal 3228 zcmWIWW@h1HVBlb2c&)J4ivbC6GO#fCx`sIFdiuHP|2xIN5CB!m!SD*GH0ko5k7YpR zZ9psn#Bim)j((nQuE8OCzHYv!H}V})5NLQfx1~Jc3S$#b){UrXdcCt(Ti(vzv&3>% zGvB_wM^?W6{#?E>^I*_h;iUo3GW5=6U;XH~i+36StTf$wu@|&BosQo8cK?U^|6NtT z`OJ%}IDE8cO-Vh?wDoWLS~rDlnXN&KChmRUv`(Fm`B2ZIsbTgocQPDCc%ZCu zMd#zxzAbIZRwg{fGT|jt9=9x7pHUHdct)SuoGTZ*f~Ag?&N-HCrS`$<_>#V|JqxFq zU;QL@T(WO-mbOWX#imo5#}!SVl$In!H2M{aSmg8-%RIM~>3eA~uVHmgw~T5Zw~U;7 zBxg-u*P-1j9tt^M{%F!X(@tHlt3~k z_nu9!6eU(ie0=S5P-vcd+VR%()jjPg*Aj31$jEILy{*X6HZ8#g)8ubjllGvv z=HLM#wtYv!+4dbXXWJKgF@oPVou{V#z2vREUXjn<9yvTo(n^?f^|jMcm-RX~nX1OV z5}fMd%mfZ-HN}%fEhm zd++l8^80lYPYSJRjQ{YuYh6#;xsz+oZ&-KmiEi2TrQcRL39Gln2Nc_QeCw{2myDI# zH}&m2-QPvCE-jpy(6L1Pt-rt)f5s&<r1Gt)(}D)_tv9#Tv7Hm+%)a_GK!f<`)#&-Sms9OphJVN-;g& zk`tg_)GnJ|a4r1JvIynpex*XXeHy=&O>B%8|2%Gz)1nx&F69(=t9z0%uXg^&?&T}i z#(7P7>37K{vdCpxne%DGtEpyc`XNhZPi5|(Y~I2j8}zp3$%$8=zwdV!TT=3p#VK<6 zicgDlLf0IARTp^b+)0sbm-g=M-lyYxqbKf5<3)3~!rL9o%iF#&K6;_2a<=Z#txlsw z3xCMm&|MKP;mI>WaOKU~mIQ&l()+L12uJ5FKFJdz7-F);VRq-eF7~R+9~0hhtXT2g zg7f)8-!qM~A8LKkt2!eVwd>`|Lkh*yc+M>@O_IwMzFQn&+`jc>K==dwE%zH|=Jc7} zKe%hjwYg6M^VY3bx+LG%Qtuo+#r@F1&7nCSpIHBBtWR3J^JGuh#z@!BYswRnPuvMQ zI{D&-BqjfeX>zh#wy(O8l^5-kI`d@NBu$6C3%|V-z2&B6J>}0#)yf6&{VxLF-t%3e z{Ogu!c>aX?6E$I#8G?J)%kr=Lwtd2rol?hgk0|NhdU`jsM9<(!(DO4EkuleA%Jb(5 zU*4*;`rXnsWhOpryW~oj@vvvSbzJe7G3JF7UzWv|H~;sviJQnQv+X@(|6^|M4*%u$ z9(InOd>fN9G82@x7B18@6b^m!M|k6}3lHF>>1aVYT2PJ_l%oaZXhDgypk!ncVaDB- z1~w~!K!D+`BZ!7Kmmw`{m{#m + + + + + + + + + + + diff --git a/java_tools/bin2header/build.xml b/java_tools/bin2header/build.xml new file mode 100644 index 0000000000..bbb45c0cab --- /dev/null +++ b/java_tools/bin2header/build.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/java_tools/bin2header/src/rusefi/Bin2Header.java b/java_tools/bin2header/src/rusefi/Bin2Header.java new file mode 100644 index 0000000000..fbe789fca9 --- /dev/null +++ b/java_tools/bin2header/src/rusefi/Bin2Header.java @@ -0,0 +1,64 @@ +package rusefi; + +import java.io.*; +import java.nio.file.*; +import java.util.Date; + +public class Bin2Header { + private static final String NL = "\n";//System.getProperty("line.separator"); + private final static char[] hexChars = "0123456789abcdef".toCharArray(); + + private Bin2Header() { + } + + public static void main(String[] args) throws IOException { + if (args.length < 3) { + System.out.println("This tool converts a binary file to C/C++ header file"); + System.out.println("usage:"); + System.out.println("Bin2Header in_file.bin out_file.h arrayVariableDecl"); + return; + } + + String binFile = args[0]; + String hFile = args[1]; + String arrayVariableDecl = args[2]; + + System.out.println("Converting " + binFile + " into " + hFile); + + // This will reference one line at a time + String line = null; + + + BufferedWriter bw = new BufferedWriter(new FileWriter(hFile)); + Path path = Paths.get(binFile); + byte[] data = Files.readAllBytes(path); + + String headerTag = hFile; + int pos = headerTag.lastIndexOf("/"); + if (pos >= 0) + headerTag = headerTag.substring(pos + 1); + headerTag = headerTag.toUpperCase().replace(".", "_") + "_"; + + bw.write("// This file was generated by Bin2Header" + NL); + bw.write("// " + new Date() + NL); + bw.write("#ifndef " + headerTag + NL); + bw.write("#define " + headerTag + NL + NL); + + bw.write(arrayVariableDecl + " = {"); + + for (int i = 0; i < data.length; i++) { + if ((i & 0xf) == 0) + bw.write(NL + "\t"); + int b = data[i] & 0xFF; + bw.write("0x"); + bw.write(hexChars[b >>> 4]); + bw.write(hexChars[b & 0xf]); + bw.write(", "); + } + + bw.write(NL + "};" + NL + NL); + bw.write("#endif /* " + headerTag + " */" + NL + NL); + bw.close(); + } + +}