Skip to content

Commit

Permalink
[#82] CAPS devices improvements and bugfixes (Part 4: Changed semanti…
Browse files Browse the repository at this point in the history
…cs of correctional "offset")
  • Loading branch information
tomas-nestorovic committed Sep 27, 2024
1 parent 9a85b8a commit 0e267df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
14 changes: 7 additions & 7 deletions Main/src/CapsBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,8 +1685,8 @@
, indexTiming(true)
, cellCountPerTrack(true)
, fitFluxesIntoIwMiddles(true)
, firstSectorTime(false)
, firstSectorMicroseconds(1500) {
, offsetIndices(false)
, indexOffsetMicroseconds(1500) {
// - attempting to load existing values from last session
if (const DWORD settings=app.GetProfileInt(iniSection,iniName,0)) // do Valid settings exist?
*(PDWORD)this=settings;
Expand All @@ -1712,13 +1712,13 @@
tmp=corr.fitFluxesIntoIwMiddles;
DDX_Check( pDX, ID_ACCURACY, tmp );
corr.fitFluxesIntoIwMiddles=tmp!=BST_UNCHECKED;
tmp=corr.firstSectorTime;
tmp=corr.offsetIndices;
DDX_Check( pDX, ID_ADDRESS, tmp );
corr.firstSectorTime=tmp!=BST_UNCHECKED;
tmp=corr.firstSectorMicroseconds;
corr.offsetIndices=tmp!=BST_UNCHECKED;
tmp=corr.indexOffsetMicroseconds;
DDX_Text( pDX, ID_TIME, tmp );
DDV_MinMaxInt( pDX, tmp, SHRT_MIN, SHRT_MAX );
corr.firstSectorMicroseconds=tmp;
corr.indexOffsetMicroseconds=tmp;
}
public:
TCorrections corr;
Expand All @@ -1741,7 +1741,7 @@
ASSERT( valid );
if (use)
return trw.NormalizeEx(
firstSectorTime ? firstSectorMicroseconds*1000 : 0, // micro- to nanoseconds
offsetIndices ? TIME_MICRO(indexOffsetMicroseconds) : 0, // micro- to nanoseconds
fitFluxesIntoIwMiddles,
cellCountPerTrack,
indexTiming
Expand Down
4 changes: 2 additions & 2 deletions Main/src/CapsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
WORD indexTiming:1;
WORD cellCountPerTrack:1;
WORD fitFluxesIntoIwMiddles:1;
WORD firstSectorTime:1;
short firstSectorMicroseconds;
WORD offsetIndices:1;
short indexOffsetMicroseconds;

TCorrections(); // no Corrections
TCorrections(LPCTSTR iniSection,LPCTSTR iniName=_T("crt"));
Expand Down
2 changes: 1 addition & 1 deletion Main/src/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@
void AddIndexTime(TLogTime logTime);
WORD WriteData(TLogTime idEndTime,const TProfile &idEndProfile,WORD nBytesToWrite,PCBYTE buffer,TFdcStatus sr);
bool Normalize();
TStdWinError NormalizeEx(TLogTime timeOffset,bool fitTimesIntoIwMiddles,bool correctCellCountPerRevolution,bool correctRevolutionTime);
TStdWinError NormalizeEx(TLogTime indicesOffset,bool fitTimesIntoIwMiddles,bool correctCellCountPerRevolution,bool correctRevolutionTime);
CTrackReaderWriter &Reverse();
};

Expand Down
29 changes: 10 additions & 19 deletions Main/src/Image_TrackRW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@
return true;
}

TStdWinError CImage::CTrackReaderWriter::NormalizeEx(TLogTime timeOffset,bool fitTimesIntoIwMiddles,bool correctCellCountPerRevolution,bool correctRevolutionTime){
TStdWinError CImage::CTrackReaderWriter::NormalizeEx(TLogTime indicesOffset,bool fitTimesIntoIwMiddles,bool correctCellCountPerRevolution,bool correctRevolutionTime){
// True <=> all Revolutions of this Track successfully normalized using specified parameters, otherwise False
// - if the Track contains less than two Indices, we are successfully done
if (nIndexPulses<2)
Expand All @@ -1544,6 +1544,15 @@
const Medium::PCProperties mp=Medium::GetProperties(mediumType);
if (!mp)
return ERROR_UNRECOGNIZED_MEDIA;
// - shifting Indices by shifting all Times in oposite direction
if (indicesOffset){
for( DWORD i=0; i<nLogTimes; logTimes[i++]-=indicesOffset ); // shift all Times in oposite direction
for( DWORD i=0; i<nLogTimes; i++ ) // discard negative Times
if (logTimes[i]>=0){
::memcpy( logTimes, logTimes+i, (nLogTimes-=i)*sizeof(TLogTime) );
break;
}
}
// - ignoring what's before the first Index
TLogTime tCurrIndexOrg=RewindToIndex(0);
// - normalization
Expand Down Expand Up @@ -1573,24 +1582,6 @@
while (*this && logTimes[iNextTime]<tNextIndexOrg)
ptModified[iTime++]=ReadTime();
DWORD iModifRevEnd=iTime;
// . offsetting all LogicalTimes in this Revolution
if (timeOffset){
timeOffset= nAlignedCells>0 // do we have time-corrected cells from above?
? timeOffset/profile.iwTimeDefault*profile.iwTimeDefault // rounding down to whole multiples of correctly-sized cells
: (LONGLONG)timeOffset*(tNextIndexOrg-tCurrIndexOrg)/mp->revolutionTime;
ptModified[iModifRevEnd]=INT_MAX-timeOffset; // stop-condition
for( iTime=iModifRevStart; ptModified[iTime]+timeOffset<=tCurrIndexOrg; iTime++ ); // ignoring Times that would end up before this Revolution has begun
iModifRevEnd=iModifRevStart;
if (nAlignedCells>0){ // are we working with time-corrected cells?
const TLogTime tLastAlignedCell= tCurrIndexOrg + nAlignedCells*profile.iwTimeDefault;
while (( ptModified[iModifRevEnd]=ptModified[iTime++]+timeOffset )<tLastAlignedCell) // adjusting Times that remain within this Revolution
iModifRevEnd++;
if (iModifRevEnd>iModifRevStart) // at least one Time
nAlignedCells=(ptModified[iModifRevEnd-1]-tCurrIndexOrg)/profile.iwTimeDefault;
}else
while (( ptModified[iModifRevEnd]=ptModified[iTime++]+timeOffset )<tNextIndexOrg) // adjusting Times that remain within this Revolution
iModifRevEnd++;
}
// . shortening/prolonging this revolution to correct number of cells
if (correctCellCountPerRevolution){
ptModified[iModifRevEnd]=INT_MAX; // stop-condition
Expand Down

0 comments on commit 0e267df

Please sign in to comment.