Steve,
With the test data I get the same results as you. It looks like I did implement your gain unpack code correctly.
Raw Gain
13F1C 1.012906
fff1c 0.988906
88888 1.088888
Since I'm allowing the user to edit a gain or offset value I first must unpack the data. After the user submits the revised value I then re-pack it with a new checksum.
It looks like the problem is in my code to re-pack the gain value. I'm getting different results on two of the three test gains.
Decode Value Encode Value
13F1C 1.012906 13F1c 1.012906
FFF1C 0.988906 0110F 1.001099
88888 1.088888 FFFFE 0.988888
It looks like what I need is a correct algorithm for re-packing the gain into the meter calibration format. Mine is not working correctly for all gain values.
Would you or fenugrec be able to help me get the gain data properly re-packed? Also, let me know if I need to make changes in the unpack algorithm.
Below is the flawed function that I'm currently using.
function RevGain$(g)
'reverse gain. calculate gain encoded value in hex.
'Uncompressed gain in g. Returns encoded gain in RevGain$
gt=g-1 '?? 1 is a constant & not used in the calc. is this correct ??
RevGain$="" 'Build new string into a null string.
for i = 6 to 2 step -1
'Add any needed trailing 0's to get i digits in number
gd=val(right$(mid$(str$(gt)+"00000",1,i+2),1))
if gd>5 then
cd=gd+6
gt=gt+(10-gd)*10^-i
else
cd=gd
gt=gt-gd*10^-i
end if
gt=int((gt+(5*10^-11))*10^10)/10^10 'round off to fix compiler math error
RevGain$=dechex$(cd)+RevGain$ 'Build compressed gain hex string.
next i
end function