updates time scale handling
This commit is contained in:
parent
bf38ccd6db
commit
b391d19303
|
@ -25,6 +25,7 @@ import com.minres.scviewer.database.DoubleVal;
|
||||||
import com.minres.scviewer.database.EventList;
|
import com.minres.scviewer.database.EventList;
|
||||||
import com.minres.scviewer.database.IEventList;
|
import com.minres.scviewer.database.IEventList;
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
|
import com.minres.scviewer.database.IWaveformDb;
|
||||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||||
import com.minres.scviewer.database.InputFormatException;
|
import com.minres.scviewer.database.InputFormatException;
|
||||||
import com.minres.scviewer.database.RelationType;
|
import com.minres.scviewer.database.RelationType;
|
||||||
|
@ -45,17 +46,17 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||||
/** The max time. */
|
/** The max time. */
|
||||||
private long maxTime;
|
private long maxTime;
|
||||||
|
|
||||||
private int timeScale;
|
private long timeScaleFactor;
|
||||||
|
|
||||||
/** The pcs. */
|
/** The pcs. */
|
||||||
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||||
|
|
||||||
static int calculateTimescaleMultipierPower(int power){
|
static long calculateTimescaleMultipierPower(long time_scale){
|
||||||
int answer = 1;
|
long answer = 1;
|
||||||
if(power<=0){
|
if(time_scale<=0){
|
||||||
return answer;
|
return answer;
|
||||||
} else{
|
} else{
|
||||||
for(int i = 1; i<= power; i++)
|
for(int i = 1; i<= time_scale; i++)
|
||||||
answer *= 10;
|
answer *= 10;
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +95,7 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getMaxTime() {
|
public long getMaxTime() {
|
||||||
return maxTime*calculateTimescaleMultipierPower(15+timeScale); // timescape is 1e(timeScale), we calculate in fs
|
return maxTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -149,8 +150,9 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxTime(long maxTime, int timeScale) {
|
public void setMaxTime(long maxTime, int timeScale) {
|
||||||
this.maxTime = maxTime;
|
long eff_time_scale=timeScale-IWaveformDb.databaseTimeScale;
|
||||||
this.timeScale=timeScale;
|
this.timeScaleFactor = calculateTimescaleMultipierPower(eff_time_scale);
|
||||||
|
this.maxTime = maxTime*timeScaleFactor;
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see com.minres.scviewer.database.IWaveformDbLoader#getAllRelationTypes()
|
* @see com.minres.scviewer.database.IWaveformDbLoader#getAllRelationTypes()
|
||||||
|
@ -182,6 +184,6 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||||
|
|
||||||
public void getEvents(int id, int width, IEventList values) {
|
public void getEvents(int id, int width, IEventList values) {
|
||||||
if(values instanceof EventList)
|
if(values instanceof EventList)
|
||||||
parser.getValueChanges(id, width, calculateTimescaleMultipierPower(15+timeScale), (EventList) values);
|
parser.getValueChanges(id, width, timeScaleFactor, (EventList) values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class FstFileParser {
|
||||||
System.out.println(version);
|
System.out.println(version);
|
||||||
long endTime = FstLibrary.fstReaderGetEndTime(fst);
|
long endTime = FstLibrary.fstReaderGetEndTime(fst);
|
||||||
byte timeScale = FstLibrary.fstReaderGetTimescale(fst);
|
byte timeScale = FstLibrary.fstReaderGetTimescale(fst);
|
||||||
builder.setMaxTime(endTime, timeScale);
|
builder.setMaxTime(endTime, -timeScale);
|
||||||
FstLibrary.fstReaderIterateHierRewind(fst);
|
FstLibrary.fstReaderIterateHierRewind(fst);
|
||||||
Pointer p = FstLibrary.fstReaderIterateHier(fst);
|
Pointer p = FstLibrary.fstReaderIterateHier(fst);
|
||||||
while(p!=null && !p.equals(Pointer.NULL)) {
|
while(p!=null && !p.equals(Pointer.NULL)) {
|
||||||
|
@ -77,7 +77,7 @@ class FstFileParser {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getValueChanges(final int id, final int width, int timeScale, final EventList values) {
|
public void getValueChanges(final int id, final int width, long timeScale, final EventList values) {
|
||||||
FstLibrary.fstReaderClrFacProcessMaskAll(fst);
|
FstLibrary.fstReaderClrFacProcessMaskAll(fst);
|
||||||
FstLibrary.fstReaderSetFacProcessMask(fst, id);
|
FstLibrary.fstReaderSetFacProcessMask(fst, id);
|
||||||
FstLibrary.iterateValueChanges(fst, new ValueChangeCallback() {
|
FstLibrary.iterateValueChanges(fst, new ValueChangeCallback() {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import com.minres.scviewer.database.AssociationType;
|
||||||
import com.minres.scviewer.database.DataType;
|
import com.minres.scviewer.database.DataType;
|
||||||
import com.minres.scviewer.database.EventKind;
|
import com.minres.scviewer.database.EventKind;
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
|
import com.minres.scviewer.database.IWaveformDb;
|
||||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||||
import com.minres.scviewer.database.InputFormatException;
|
import com.minres.scviewer.database.InputFormatException;
|
||||||
import com.minres.scviewer.database.RelationType;
|
import com.minres.scviewer.database.RelationType;
|
||||||
|
@ -327,6 +328,17 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||||
/** The loader. */
|
/** The loader. */
|
||||||
final FtrDbLoader loader;
|
final FtrDbLoader loader;
|
||||||
|
|
||||||
|
static long calculateTimescaleMultipierPower(long power){
|
||||||
|
long answer = 1;
|
||||||
|
if(power<=0){
|
||||||
|
return answer;
|
||||||
|
} else{
|
||||||
|
for(int i = 1; i<= power; i++)
|
||||||
|
answer *= 10;
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new text db parser.
|
* Instantiates a new text db parser.
|
||||||
*
|
*
|
||||||
|
@ -347,10 +359,10 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||||
case 6: { // info
|
case 6: { // info
|
||||||
CborDecoder cbd = new CborDecoder(new ByteArrayInputStream(readByteString()));
|
CborDecoder cbd = new CborDecoder(new ByteArrayInputStream(readByteString()));
|
||||||
long sz = cbd.readArrayLength();
|
long sz = cbd.readArrayLength();
|
||||||
assert(sz==3);
|
assert(sz==2);
|
||||||
long time_numerator=cbd.readInt();
|
long time_scale=cbd.readInt();
|
||||||
long time_denominator=cbd.readInt();
|
long eff_time_scale=time_scale-IWaveformDb.databaseTimeScale;
|
||||||
loader.time_scale_factor = 1000000000000000l*time_numerator/time_denominator;
|
loader.time_scale_factor = calculateTimescaleMultipierPower(eff_time_scale);
|
||||||
long epoch_tag = cbd.readTag();
|
long epoch_tag = cbd.readTag();
|
||||||
assert(epoch_tag==1);
|
assert(epoch_tag==1);
|
||||||
cbd.readInt(); // epoch
|
cbd.readInt(); // epoch
|
||||||
|
@ -426,7 +438,7 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||||
ArrayList<String> lst = new ArrayList<>((int)size);
|
ArrayList<String> lst = new ArrayList<>((int)size);
|
||||||
for(long i = 0; i<size; ++i) {
|
for(long i = 0; i<size; ++i) {
|
||||||
long idx = cborDecoder.readInt();
|
long idx = cborDecoder.readInt();
|
||||||
assert(idx==loader.strDict.size()+1);
|
assert(idx==loader.strDict.size()+lst.size());
|
||||||
lst.add(cborDecoder.readTextString());
|
lst.add(cborDecoder.readTextString());
|
||||||
}
|
}
|
||||||
loader.strDict.addAll(lst);
|
loader.strDict.addAll(lst);
|
||||||
|
|
|
@ -519,6 +519,7 @@ public class TextDbLoader implements IWaveformDbLoader {
|
||||||
* @return the long
|
* @return the long
|
||||||
*/
|
*/
|
||||||
private long stringToScale(String scale) {
|
private long stringToScale(String scale) {
|
||||||
|
// TODO: scale to IWaveformDb.databaseTimeScale
|
||||||
String cmp = scale.trim();
|
String cmp = scale.trim();
|
||||||
if ("fs".equals(cmp))
|
if ("fs".equals(cmp))
|
||||||
return 1L;
|
return 1L;
|
||||||
|
|
|
@ -16,12 +16,13 @@ import java.util.*;
|
||||||
|
|
||||||
import com.minres.scviewer.database.BitValue;
|
import com.minres.scviewer.database.BitValue;
|
||||||
import com.minres.scviewer.database.BitVector;
|
import com.minres.scviewer.database.BitVector;
|
||||||
|
import com.minres.scviewer.database.IWaveformDb;
|
||||||
|
|
||||||
class VCDFileParser {
|
class VCDFileParser {
|
||||||
private StreamTokenizer tokenizer;
|
private StreamTokenizer tokenizer;
|
||||||
private IVCDDatabaseBuilder traceBuilder;
|
private IVCDDatabaseBuilder traceBuilder;
|
||||||
private HashMap<String, Integer> nameToNetMap = new HashMap<>();
|
private HashMap<String, Integer> nameToNetMap = new HashMap<>();
|
||||||
private long picoSecondsPerIncrement;
|
private long timeScaleFactor;
|
||||||
private boolean stripNetWidth;
|
private boolean stripNetWidth;
|
||||||
private boolean replaceColon;
|
private boolean replaceColon;
|
||||||
long currentTime;
|
long currentTime;
|
||||||
|
@ -121,29 +122,37 @@ class VCDFileParser {
|
||||||
nextToken();
|
nextToken();
|
||||||
}
|
}
|
||||||
String s = sb.toString();
|
String s = sb.toString();
|
||||||
|
int fac =1;
|
||||||
switch (s.charAt(s.length() - 2)){
|
switch (s.charAt(s.length() - 2)){
|
||||||
|
case 'f': // Nano-seconds
|
||||||
|
fac = -15;
|
||||||
|
s = s.substring(0, s.length() - 2).trim();
|
||||||
|
break;
|
||||||
case 'p': // Nano-seconds
|
case 'p': // Nano-seconds
|
||||||
picoSecondsPerIncrement = 1;
|
fac = -12;
|
||||||
s = s.substring(0, s.length() - 2).trim();
|
s = s.substring(0, s.length() - 2).trim();
|
||||||
break;
|
break;
|
||||||
case 'n': // Nano-seconds
|
case 'n': // Nano-seconds
|
||||||
picoSecondsPerIncrement = 1000;
|
fac = -9;
|
||||||
s = s.substring(0, s.length() - 2).trim();
|
s = s.substring(0, s.length() - 2).trim();
|
||||||
break;
|
break;
|
||||||
case 'u': // Microseconds
|
case 'u': // Microseconds
|
||||||
picoSecondsPerIncrement = 1000000;
|
fac = -6;
|
||||||
s = s.substring(0, s.length() - 2).trim();
|
s = s.substring(0, s.length() - 2).trim();
|
||||||
break;
|
break;
|
||||||
case 'm': // Microseconds
|
case 'm': // Microseconds
|
||||||
picoSecondsPerIncrement = 1000000000;
|
fac = -3;
|
||||||
s = s.substring(0, s.length() - 2).trim();
|
s = s.substring(0, s.length() - 2).trim();
|
||||||
break;
|
break;
|
||||||
default: // Seconds
|
default: // Seconds
|
||||||
picoSecondsPerIncrement = 1000000000000L;
|
fac = 1;
|
||||||
s = s.substring(0, s.length() - 1);
|
s = s.substring(0, s.length() - 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
picoSecondsPerIncrement *= Long.parseLong(s);
|
timeScaleFactor = 1;
|
||||||
|
for(int i = 1; i<= fac-IWaveformDb.databaseTimeScale; i++)
|
||||||
|
timeScaleFactor *= 10;
|
||||||
|
timeScaleFactor = Long.parseLong(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean parseDefinition() throws IOException, ParseException {
|
private boolean parseDefinition() throws IOException, ParseException {
|
||||||
|
@ -171,7 +180,7 @@ class VCDFileParser {
|
||||||
private boolean parseTransition() throws IOException {
|
private boolean parseTransition() throws IOException {
|
||||||
if (!nextToken()) return false;
|
if (!nextToken()) return false;
|
||||||
if (tokenizer.sval.charAt(0) == '#') { // If the line begins with a #, this is a timestamp.
|
if (tokenizer.sval.charAt(0) == '#') { // If the line begins with a #, this is a timestamp.
|
||||||
currentTime = Long.parseLong(tokenizer.sval.substring(1)) * picoSecondsPerIncrement;
|
currentTime = Long.parseLong(tokenizer.sval.substring(1)) * timeScaleFactor;
|
||||||
} else {
|
} else {
|
||||||
if(tokenizer.sval.equals("$comment")){
|
if(tokenizer.sval.equals("$comment")){
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -18,6 +18,11 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public interface IWaveformDb extends IHierNode {
|
public interface IWaveformDb extends IHierNode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the time scale of the database. This is the exponent of the value i.e. -12 is ps
|
||||||
|
*/
|
||||||
|
public static final int databaseTimeScale = -15;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the max time.
|
* Gets the max time.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue