Matrix update

This commit is contained in:
Ian Gebbie 2021-04-18 20:41:41 +02:00
parent 0a69a38559
commit e277b719da
5 changed files with 65 additions and 68 deletions

View file

@ -2,9 +2,11 @@
1 GUI
matrix data output to correct format
For real done
Compex matrix required
list data output
confirm output formats are correct
2 Comms

View file

@ -294,73 +294,73 @@ return out;
bool BCD(QDataStream &ds, double real) {
double base=0.0;
quint16 expn;
int i;
qDebug()<<"BCD from "<<real;
double fractpart, intpart;
quint8 num1;
quint8 num2;
quint8 num;
double F = abs(real);
double Sign = step(0.0,-real);
double Exponent = floor(log10(F));
double Mantissa = real/(pow(10,Exponent));
double sign;
double exponent = floor(log10(F));
double mantissa = F/(pow(10,exponent));
quint8 data[8];
/*
if(Mantissa < 1)
Exponent -= 1;
Exponent += 127;
*/
qDebug()<<F;
qDebug()<<Exponent;
qDebug()<<Mantissa;
qDebug()<<Sign;
qDebug()<<"---";
qDebug()<<"BCD from "<<real;
base=Mantissa;
if(exponent < 0)
exponent += 0x1000;
if (real<0)
sign=1;
else
sign =0;
qDebug()<<F;
qDebug()<<exponent;
qDebug()<<mantissa;
qDebug()<<sign;
qDebug()<<"---";
base=mantissa;
//**TODO --- Reverse Order - LittleEndine
if (sign==1)
num1=9;
else
num1=0;
for (i=0;i<6;i++) {
if (i>0) {
fractpart=modf(base,&intpart);
num1=(quint8)intpart;
base=fractpart*10.0;
// num1=i*2;
}
fractpart=modf(base,&intpart);
num2=(quint8)intpart;
base=fractpart*10.0;
// num2=i*2+1;
num=BCDi(num1,num2);
qDebug()<<"base: "<<base;
ds<<(quint8)num;
// ds<<(quint8)num;
data[7-i]=(quint8)num;
qDebug()<<"i= "<<i<<": "<<hex<<num;
}
base=Exponent;
for (i=0;i<2;i++) {
fractpart=modf(base,&intpart);
num1=(quint8)intpart;
base=fractpart*10.0;
// num1=i*2;
fractpart=modf(base,&intpart);
num2=(quint8)intpart;
base=fractpart*10.0;
// num2=i*2+1;
num=BCDi(num1,num2);
expn=(quint16)exponent;
//EXP is in binary
qDebug()<<hex<<expn;
ds<<expn;
qDebug()<<"base: "<<base;
ds<<(quint8)num;
qDebug()<<"i= "<<i<<": "<<hex<<num;
for (i=2; i<8; i++) {
ds<<data[i];
}
// ds<<(quint8)Sign;
return true;
return true;
}
@ -874,7 +874,8 @@ void Matrix::parseData(QDataStream & in) {
parseData();
}
//Parse a matrix
//
void Matrix::parseData() {
QByteArray a1;
@ -893,8 +894,16 @@ void Matrix::parseData() {
QString ds;
// QByteArray searchstr((char *)std::begin<quint8>({0x01,0x00}),2);
//Matrix header
//Start keeps changing 01 or 02
//0x00
//0x14 real 0x94 Complex
//0x80?? CRC??
//0x02
//0x00
//0x00
//0x00
qDebug()<<"Matrix: Parsing a Matrix";

View file

@ -166,13 +166,10 @@ bool hp_mdiVariableEdit::saveFile(const QFileInfo fileinfo)
QApplication::setOverrideCursor(Qt::WaitCursor);
QDataStream ds(&file);
ds.setByteOrder(QDataStream::LittleEndian);
varmodel->getData(ds);
//reset busy cursor
QApplication::restoreOverrideCursor();
varmodel->resetModified();

View file

@ -61,6 +61,9 @@ void MatrixData::insert(int row, int column, itemData data)
if(rowlist) {
rowlist->replace(column,data);
}
//TODO
//If data is complex convert to matric to a complex matrix
}
//Add a new row
@ -99,7 +102,7 @@ bool MatrixData::dataOut(QDataStream & ds) {
QString str;
//header
// static const quint8 mydata[] = {0x02, 0x01, 0x04,0x03,0x06,0x05,0x08,0x07};
// static const quint8 mydata[] = {0x02, 0x01, 0x04,0x03,0x06,0x05,0x08,0x07};
//QByteArray test= QByteArray::fromRawData((char *)mydata,sizeof (mydata));
@ -107,9 +110,9 @@ bool MatrixData::dataOut(QDataStream & ds) {
//ds.writeRawData((char *)mydata,sizeof(mydata));
ds<<(quint16)0x0001;
ds<<(quint16)0x8014;
ds<<(quint16)0x0001; //somes time 02?
ds<<(quint8)0x14; //94 when complex TODO - manage change
ds<<(quint8)0x80; //CRC??
ds<<(quint16)0x0002;
ds<<(quint16)0x0000;
@ -117,6 +120,7 @@ bool MatrixData::dataOut(QDataStream & ds) {
ds<<static_cast<quint32>(column);
//body
//If real type matrix _ TODO
double real;
QStringList l1;
quint8 g;
@ -127,23 +131,10 @@ bool MatrixData::dataOut(QDataStream & ds) {
real=item.dReal;
BCD(ds,real);
// if(j!=column)
// out.append("");
}
// if (i!=row)
// out.append("");
}
//footer
ds.device()->seek(0);
ds>>g;
qDebug()<<g;
return true;
}

View file

@ -282,18 +282,16 @@ QVariant varTableModel::headerData(int section, Qt::Orientation orientation, in
bool varTableModel::getData(QDataStream &ds) {
QByteArray buf;
buf.clear();
QDataStream ds_test(&buf, QIODevice::ReadWrite);
//buf.open(QIODevice::ReadWrite);
ds_test.setByteOrder(QDataStream::LittleEndian);
// QByteArray buf;
// buf.clear();
// QDataStream ds_test(&buf, QIODevice::ReadWrite);
// ds_test.setByteOrder(QDataStream::LittleEndian);
if(dataobj!=nullptr) {
dataobj->getData(ds_test);
qDebug()<<"VarTableModel::getData";
qDebug()<<"Out:"<<buf.toHex();
dataobj->getData(ds);
// dataobj->getData(ds_test);
// qDebug()<<"VarTableModel::getData";
// qDebug()<<"Out:"<<buf.toHex();
return true;
}