Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sfp-plus-i2c
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
sfp-plus-i2c
Commits
079364c3
Commit
079364c3
authored
Apr 11, 2017
by
Vincent van Beveren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved export
parent
c7acd993
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
33 deletions
+103
-33
nikhef-tools.jar
sw/nikhef-tools/nikhef-tools.jar
+0
-0
Utils.java
sw/nikhef-tools/src/nl/nikhef/tools/Utils.java
+2
-2
ModuleManager.java
sw/safaripark/src/nl/nikhef/safaripark/ModuleManager.java
+101
-31
No files found.
sw/nikhef-tools/nikhef-tools.jar
View file @
079364c3
No preview for this file type
sw/nikhef-tools/src/nl/nikhef/tools/Utils.java
View file @
079364c3
...
...
@@ -71,7 +71,7 @@ public final class Utils {
}
public
static
void
dumpHex
(
PrintWriter
pw
,
byte
[]
data
,
boolean
extended
)
{
public
static
void
dumpHex
(
PrintWriter
pw
,
byte
[]
data
,
boolean
extended
,
int
offset
)
{
StringBuilder
sbC
=
new
StringBuilder
();
StringBuilder
sbH
=
new
StringBuilder
();
...
...
@@ -79,7 +79,7 @@ public final class Utils {
if
(
i
%
16
==
0
&&
extended
)
{
pw
.
printf
(
"%04x: "
,
i
);
pw
.
printf
(
"%04x: "
,
i
+
offset
);
}
char
c
=
(
char
)
data
[
i
];
...
...
sw/safaripark/src/nl/nikhef/safaripark/ModuleManager.java
View file @
079364c3
...
...
@@ -9,7 +9,11 @@ import java.io.IOException;
import
java.io.PrintWriter
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.List
;
import
javax.swing.Action
;
import
javax.swing.BorderFactory
;
...
...
@@ -17,6 +21,7 @@ import javax.swing.BoxLayout;
import
javax.swing.ButtonGroup
;
import
javax.swing.JFileChooser
;
import
javax.swing.JLabel
;
import
javax.swing.JOptionPane
;
import
javax.swing.JPanel
;
import
javax.swing.JRadioButton
;
...
...
@@ -55,9 +60,9 @@ public class ModuleManager implements BaySelectionListener
_ddmi
=
ddmiLoader
.
getDDMI
();
ButtonGroup
bg
=
new
ButtonGroup
();
_binary
=
new
JRadioButton
(
"Binary"
);
_plainhex
=
new
JRadioButton
(
"Plain Hex"
);
_extendedhex
=
new
JRadioButton
(
"Extended Hex"
);
_binary
=
new
JRadioButton
(
"Binary
(multiple files)
"
);
_plainhex
=
new
JRadioButton
(
"Plain Hex
(multiple files)
"
);
_extendedhex
=
new
JRadioButton
(
"Extended Hex
(single file)
"
);
bg
.
add
(
_plainhex
);
bg
.
add
(
_extendedhex
);
bg
.
add
(
_binary
);
...
...
@@ -108,61 +113,126 @@ public class ModuleManager implements BaySelectionListener
String
filebasebase
=
String
.
format
(
"sfp_%s_%s"
,
_moduleName
,
_fileDateFormat
.
format
(
new
Date
()));
for
(
DataSource
ds
:
_ddmi
.
getSources
())
{
if
(!
ds
.
isValid
(
_ctx
))
continue
;
System
.
out
.
println
(
"Exporting datasource "
+
ds
);
List
<
String
>
filesWritten
=
new
ArrayList
<
String
>();
List
<
DataSource
>
orderedSources
=
new
ArrayList
<
DataSource
>();
orderedSources
.
addAll
(
_ddmi
.
getSources
());
Comparator
<
DataSource
>
comparator
=
new
Comparator
<
DataSource
>()
{
@Override
public
int
compare
(
DataSource
left
,
DataSource
right
)
{
return
left
.
getPath
().
compareTo
(
right
.
getPath
());
}
};
Collections
.
sort
(
orderedSources
,
comparator
);
if
(
_extendedhex
.
isSelected
())
{
String
filename
=
filebasebase
+
".txt"
;
try
{
PrintWriter
pw
=
new
PrintWriter
(
new
FileWriter
(
new
File
(
f
,
filename
)));
byte
[]
data
=
ds
.
read
(
_ctx
,
ds
.
start
,
ds
.
size
());
String
filebase
=
String
.
format
(
"sfp_%s_%s_%s"
,
_fileDateFormat
.
format
(
new
Date
()),
_moduleName
,
ds
.
getPath
());
if
(
_plainhex
.
isSelected
())
{
exportHex
(
f
,
filebase
,
data
,
false
);
}
if
(
_binary
.
isSelected
())
{
exportBinary
(
f
,
filebase
,
data
);
}
if
(
_extendedhex
.
isSelected
())
{
exportHex
(
f
,
filebase
,
data
,
true
);
try
{
for
(
DataSource
ds
:
orderedSources
)
{
if
(!
ds
.
isValid
(
_ctx
))
continue
;
System
.
out
.
println
(
"Exporting datasource "
+
ds
);
try
{
byte
[]
data
=
ds
.
read
(
_ctx
,
ds
.
start
,
ds
.
size
());
pw
.
println
(
"Section: "
+
ds
.
getPath
());
exportHex
(
f
,
pw
,
data
,
true
,
ds
.
start
);
pw
.
println
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
continue
;
}
}
}
finally
{
filesWritten
.
add
(
filename
);
try
{
pw
.
close
();
}
catch
(
Exception
e
)
{};
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
continue
;
}
catch
(
IOException
io
)
{
}
}
else
{
for
(
DataSource
ds
:
orderedSources
)
{
if
(!
ds
.
isValid
(
_ctx
))
continue
;
System
.
out
.
println
(
"Exporting datasource "
+
ds
);
try
{
byte
[]
data
=
ds
.
read
(
_ctx
,
ds
.
start
,
ds
.
size
());
String
filebase
=
filebasebase
+
"_"
+
ds
.
getPath
();
if
(
_plainhex
.
isSelected
())
{
exportHex
(
filesWritten
,
f
,
filebase
,
data
,
false
,
0
);
}
if
(
_binary
.
isSelected
())
{
exportBinary
(
filesWritten
,
f
,
filebase
,
data
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
continue
;
}
}
}
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"Following file(s) have been written:\n"
);
for
(
String
s
:
filesWritten
)
{
sb
.
append
(
" * "
+
s
+
"\n"
);
}
sb
.
append
(
"In directory: \n"
);
sb
.
append
(
" "
+
f
.
getPath
());
JOptionPane
.
showMessageDialog
(
parent
,
sb
.
toString
(),
"Export success!"
,
JOptionPane
.
INFORMATION_MESSAGE
);
}
private
void
exportHex
(
File
f
,
String
filebase
,
byte
[]
content
,
boolean
extended
)
throws
IOException
private
void
exportHex
(
List
<
String
>
filesWritten
,
File
f
,
String
filebase
,
byte
[]
content
,
boolean
extended
,
int
offset
)
throws
IOException
{
PrintWriter
pw
=
new
PrintWriter
(
new
FileWriter
(
new
File
(
f
,
filebase
+
(
extended
?
".txt"
:
".hex"
))));
try
{
Utils
.
dumpHex
(
pw
,
content
,
extended
);
exportHex
(
f
,
pw
,
content
,
extended
,
offset
);
filesWritten
.
add
(
filebase
+
(
extended
?
".txt"
:
".hex"
));
}
finally
{
pw
.
close
();
}
}
private
void
exportBinary
(
File
f
,
String
filebase
,
byte
[]
content
)
throws
IOException
private
void
exportHex
(
File
f
,
PrintWriter
pw
,
byte
[]
content
,
boolean
extended
,
int
offset
)
throws
IOException
{
Utils
.
dumpHex
(
pw
,
content
,
extended
,
offset
);
}
private
void
exportBinary
(
List
<
String
>
filesWritten
,
File
f
,
String
filebase
,
byte
[]
content
)
throws
IOException
{
FileOutputStream
fos
=
new
FileOutputStream
(
new
File
(
f
,
filebase
+
".bin"
));
try
{
fos
.
write
(
content
);
filesWritten
.
add
(
filebase
+
".bin"
);
}
finally
{
fos
.
close
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment