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.IEventList;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
@ -45,17 +46,17 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||
/** The max time. */
|
||||
private long maxTime;
|
||||
|
||||
private int timeScale;
|
||||
private long timeScaleFactor;
|
||||
|
||||
/** The pcs. */
|
||||
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
|
||||
static int calculateTimescaleMultipierPower(int power){
|
||||
int answer = 1;
|
||||
if(power<=0){
|
||||
static long calculateTimescaleMultipierPower(long time_scale){
|
||||
long answer = 1;
|
||||
if(time_scale<=0){
|
||||
return answer;
|
||||
} else{
|
||||
for(int i = 1; i<= power; i++)
|
||||
for(int i = 1; i<= time_scale; i++)
|
||||
answer *= 10;
|
||||
return answer;
|
||||
}
|
||||
@ -94,7 +95,7 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||
*/
|
||||
@Override
|
||||
public long getMaxTime() {
|
||||
return maxTime*calculateTimescaleMultipierPower(15+timeScale); // timescape is 1e(timeScale), we calculate in fs
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@ -149,8 +150,9 @@ public class FstDbLoader implements IWaveformDbLoader, IFstDatabaseBuilder {
|
||||
}
|
||||
|
||||
public void setMaxTime(long maxTime, int timeScale) {
|
||||
this.maxTime = maxTime;
|
||||
this.timeScale=timeScale;
|
||||
long eff_time_scale=timeScale-IWaveformDb.databaseTimeScale;
|
||||
this.timeScaleFactor = calculateTimescaleMultipierPower(eff_time_scale);
|
||||
this.maxTime = maxTime*timeScaleFactor;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @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) {
|
||||
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);
|
||||
long endTime = FstLibrary.fstReaderGetEndTime(fst);
|
||||
byte timeScale = FstLibrary.fstReaderGetTimescale(fst);
|
||||
builder.setMaxTime(endTime, timeScale);
|
||||
builder.setMaxTime(endTime, -timeScale);
|
||||
FstLibrary.fstReaderIterateHierRewind(fst);
|
||||
Pointer p = FstLibrary.fstReaderIterateHier(fst);
|
||||
while(p!=null && !p.equals(Pointer.NULL)) {
|
||||
@ -77,7 +77,7 @@ class FstFileParser {
|
||||
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.fstReaderSetFacProcessMask(fst, id);
|
||||
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.EventKind;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
@ -327,6 +328,17 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||
/** The 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.
|
||||
*
|
||||
@ -347,10 +359,10 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||
case 6: { // info
|
||||
CborDecoder cbd = new CborDecoder(new ByteArrayInputStream(readByteString()));
|
||||
long sz = cbd.readArrayLength();
|
||||
assert(sz==3);
|
||||
long time_numerator=cbd.readInt();
|
||||
long time_denominator=cbd.readInt();
|
||||
loader.time_scale_factor = 1000000000000000l*time_numerator/time_denominator;
|
||||
assert(sz==2);
|
||||
long time_scale=cbd.readInt();
|
||||
long eff_time_scale=time_scale-IWaveformDb.databaseTimeScale;
|
||||
loader.time_scale_factor = calculateTimescaleMultipierPower(eff_time_scale);
|
||||
long epoch_tag = cbd.readTag();
|
||||
assert(epoch_tag==1);
|
||||
cbd.readInt(); // epoch
|
||||
@ -426,7 +438,7 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||
ArrayList<String> lst = new ArrayList<>((int)size);
|
||||
for(long i = 0; i<size; ++i) {
|
||||
long idx = cborDecoder.readInt();
|
||||
assert(idx==loader.strDict.size()+1);
|
||||
assert(idx==loader.strDict.size()+lst.size());
|
||||
lst.add(cborDecoder.readTextString());
|
||||
}
|
||||
loader.strDict.addAll(lst);
|
||||
|
@ -519,6 +519,7 @@ public class TextDbLoader implements IWaveformDbLoader {
|
||||
* @return the long
|
||||
*/
|
||||
private long stringToScale(String scale) {
|
||||
// TODO: scale to IWaveformDb.databaseTimeScale
|
||||
String cmp = scale.trim();
|
||||
if ("fs".equals(cmp))
|
||||
return 1L;
|
||||
|
@ -16,12 +16,13 @@ import java.util.*;
|
||||
|
||||
import com.minres.scviewer.database.BitValue;
|
||||
import com.minres.scviewer.database.BitVector;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
|
||||
class VCDFileParser {
|
||||
private StreamTokenizer tokenizer;
|
||||
private IVCDDatabaseBuilder traceBuilder;
|
||||
private HashMap<String, Integer> nameToNetMap = new HashMap<>();
|
||||
private long picoSecondsPerIncrement;
|
||||
private long timeScaleFactor;
|
||||
private boolean stripNetWidth;
|
||||
private boolean replaceColon;
|
||||
long currentTime;
|
||||
@ -121,29 +122,37 @@ class VCDFileParser {
|
||||
nextToken();
|
||||
}
|
||||
String s = sb.toString();
|
||||
int fac =1;
|
||||
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
|
||||
picoSecondsPerIncrement = 1;
|
||||
fac = -12;
|
||||
s = s.substring(0, s.length() - 2).trim();
|
||||
break;
|
||||
case 'n': // Nano-seconds
|
||||
picoSecondsPerIncrement = 1000;
|
||||
fac = -9;
|
||||
s = s.substring(0, s.length() - 2).trim();
|
||||
break;
|
||||
case 'u': // Microseconds
|
||||
picoSecondsPerIncrement = 1000000;
|
||||
fac = -6;
|
||||
s = s.substring(0, s.length() - 2).trim();
|
||||
break;
|
||||
case 'm': // Microseconds
|
||||
picoSecondsPerIncrement = 1000000000;
|
||||
fac = -3;
|
||||
s = s.substring(0, s.length() - 2).trim();
|
||||
break;
|
||||
default: // Seconds
|
||||
picoSecondsPerIncrement = 1000000000000L;
|
||||
fac = 1;
|
||||
s = s.substring(0, s.length() - 1);
|
||||
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 {
|
||||
@ -171,7 +180,7 @@ class VCDFileParser {
|
||||
private boolean parseTransition() throws IOException {
|
||||
if (!nextToken()) return false;
|
||||
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 {
|
||||
if(tokenizer.sval.equals("$comment")){
|
||||
do {
|
||||
|
@ -18,6 +18,11 @@ import java.util.List;
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user