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 1 GUI
matrix data output to correct format matrix data output to correct format
For real done
Compex matrix required
list data output list data output
confirm output formats are correct confirm output formats are correct
2 Comms 2 Comms

View file

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

View file

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

View file

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

View file

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