QtHPConnect/abstractdata.cpp

1034 lines
22 KiB
C++
Raw Normal View History

2019-02-26 20:56:39 +01:00
#include <QDebug>
2019-03-02 20:20:23 +01:00
#include <QTextCodec>
#include <QtMath>
2019-03-09 21:11:43 +01:00
#include <QByteArrayMatcher>
2019-04-02 21:14:31 +02:00
#include <QByteArray>
2019-02-26 20:56:39 +01:00
#include "global.h"
2019-02-25 08:32:15 +01:00
#include "abstractdata.h"
2019-02-25 08:36:58 +01:00
#include "hpusb.h"
2019-03-02 20:20:23 +01:00
#include "matrixdata.h"
uint16_t crc16_block(const uint8_t * buffer, uint32_t len);
2019-03-09 15:39:38 +01:00
int BCD2I(quint8 num) {
2019-03-02 20:20:23 +01:00
int ds,ret;
if(num>0) {
ds=((num&0xF0)>>4)*10;
ds+=(num&0x0F);
ret=ds;
}
else {
ret=0;
}
2019-03-09 21:11:43 +01:00
log(QString("Num= %1 Ret= %2").arg(num,1,16).arg(ret));
2019-03-02 20:20:23 +01:00
return ret;
}
2019-09-15 17:23:44 +02:00
qint32 TwosComplement2Int(quint32 rawValue)
2019-03-02 20:20:23 +01:00
{
2019-09-15 17:23:44 +02:00
qint32 ret;
2019-03-02 20:20:23 +01:00
2019-03-16 20:34:09 +01:00
log(QString("2C: %1").arg(rawValue& 0x80000000,1,16));
2019-03-02 20:20:23 +01:00
// If a positive value, return it
if ((rawValue & 0x80000000) == 0)
{
2019-09-15 17:23:44 +02:00
ret = static_cast<qint32>(rawValue);
2019-03-02 20:20:23 +01:00
}
else {
// Otherwise perform the 2's complement math on the value
2019-03-16 20:34:09 +01:00
log(QString("List 2C Negative Detected"));
2019-03-02 20:20:23 +01:00
2019-09-15 17:23:44 +02:00
ret = static_cast<qint32>(~(rawValue - 0x01)) * - 1;
2019-03-02 20:20:23 +01:00
// ret = ~rawValue;
}
2019-03-16 20:34:09 +01:00
log(QString("2C: %1 %2").arg(rawValue,1,16).arg(ret,1,16));
2019-03-02 20:20:23 +01:00
return ret;
}
2019-09-15 17:23:44 +02:00
qint16 TwosComp2Int_8(qint16 rawValue)
2019-03-02 20:20:23 +01:00
{
2019-03-09 15:39:38 +01:00
qint16 ret;
2019-03-02 20:20:23 +01:00
// If a positive value, return it
2019-03-09 15:39:38 +01:00
if ((rawValue & 0x800) == 0)
2019-03-02 20:20:23 +01:00
{
ret = rawValue;
}
else {
// Otherwise perform the 2's complement math on the value
2019-03-09 15:39:38 +01:00
ret = (~(rawValue - 0x01)&(0x0FFF)) * -1;
2019-03-02 20:20:23 +01:00
// ret = ~rawValue;
}
return ret;
}
2019-03-16 20:34:09 +01:00
QString value2Str(int sign, double m, double exp) {
QString value;
QString neg=QStringLiteral("");
if (sign<0) {
neg=QStringLiteral("-");
}
2019-09-15 17:23:44 +02:00
if (exp!=0.0) {
2019-03-16 20:34:09 +01:00
value=neg+QString("%1E%2").arg(m).arg(exp);
}
else {
2019-09-15 17:23:44 +02:00
if (m==0.0) {
2019-03-16 20:34:09 +01:00
value=neg+QString("0");
}
else
value=neg+QString("%1").arg(m);
}
return value;
}
QString complex2Str(QString real, QString imag) {
QString value;
if((imag[0]!="+")&&(imag[0]!="-")) {
value = real+"+"+imag+"*i";
}
else
{
value = real+imag+"*i";
}
if(real=="0") {
value = imag+"*i";
}
if ((real!="0")&&(imag=="0")) {
value = real;
}
return value;
}
2019-03-02 20:20:23 +01:00
2019-03-09 15:39:38 +01:00
itemData extract16(QByteArray item) {
2019-03-02 20:20:23 +01:00
;
itemData listvalue;
QString msg;
2019-03-16 20:34:09 +01:00
QString value=QStringLiteral("");
QString neg=QStringLiteral("");
2019-03-02 20:20:23 +01:00
qint8 sign;
int multi;
long exp;
double base;
double m,ret;
int k;
2019-03-16 20:34:09 +01:00
multi=1;
// base=BCD2I(item[2]);
base=10;
2019-09-15 17:23:44 +02:00
sign=TwosComplement2Int(static_cast<qint8>(item[3]));
2019-03-02 20:20:23 +01:00
2019-09-15 17:23:44 +02:00
exp=((((((((static_cast<qint8>(item[7])&0xFF)<<8)+(static_cast<qint8>(item[6])&0xFF))<<8)+(static_cast<qint8>(item[5])&0xFF)))<<8)
+(static_cast<qint8>(item[4])&0xFF));
2019-03-16 20:34:09 +01:00
log(QString("extract16: exp %1").arg(exp));
// exp=TwosComplement2Int(exp);
2019-03-02 20:20:23 +01:00
m=0;
for (k=8;k<16;k++) {
2019-09-15 17:23:44 +02:00
if(static_cast<quint8>(item[k])!=0) {
m=m*0.01+static_cast<double>(multi)*BCD2I(static_cast<quint8>(item[k]));
2019-03-02 20:20:23 +01:00
}
}
ret=sign*m*qPow(base,exp);
2019-03-16 20:34:09 +01:00
value = value2Str(sign,m,exp);
2019-03-02 20:20:23 +01:00
2019-03-09 21:11:43 +01:00
msg=QString("multi:%1 base:%2 sign:%3 exp:%4 m:%5").arg(multi).arg(base).arg(sign).arg(exp).arg(m);
// msg=QString("value: %1").arg(value);
2019-03-02 20:20:23 +01:00
log(msg);
log((QString("Ans: %1").arg(ret)));
2019-03-16 20:34:09 +01:00
listvalue.dReal=ret;
listvalue.sValue=value;
2019-03-02 20:20:23 +01:00
return listvalue;
}
2019-03-09 15:39:38 +01:00
itemData extract8(QByteArray item) {
;
itemData listvalue;
QString value=QStringLiteral("");;
qint8 sign=1;
2019-09-15 17:23:44 +02:00
quint8 l;
2019-03-09 15:39:38 +01:00
qint8 v;
int multi;
qint16 exp=0;
double base;
double m,ret,n;
int k;
multi=1;
base=10;
2019-09-15 17:23:44 +02:00
exp=(((((static_cast<qint8>(item[1])&0x0F)))<<8)+(static_cast<qint8>(item[0])&0xFF));
2019-03-09 15:39:38 +01:00
exp=TwosComp2Int_8(exp);
m=0;
l=item[7]&0xF0;
if ((l&0xFF)==0x90) {
sign=-1;
}
for (k=1;k<8;k++) {
v=item[k];
if (k==7) {
v=v&0x0F;
}
if (k==1) {
v=v&0xF0;
}
2019-09-15 17:23:44 +02:00
n=static_cast<double>(multi)*BCD2I(v);
2019-03-09 15:39:38 +01:00
m=m*0.01+n;
if(k!=7) {
if ((m>0)||(k>5))
value=QString("%1").arg(n,0)+value;
}
else
value=QString("%1.").arg(n,0)+value;
}
ret=sign*m*qPow(base,exp);
2019-03-16 20:34:09 +01:00
if(sign<0) {
2019-03-09 15:39:38 +01:00
value=QString("-")+value;
2019-03-16 20:34:09 +01:00
}
2019-03-09 15:39:38 +01:00
if(exp!=0)
value=value+"E"+QString("%1").arg(exp,0);
2019-03-16 20:34:09 +01:00
listvalue.dReal=ret;
2019-03-09 15:39:38 +01:00
listvalue.sValue=value;
return listvalue;
}
2019-03-02 20:20:23 +01:00
////////////////////////
2019-02-25 08:32:15 +01:00
2019-02-25 08:36:58 +01:00
AbstractData::AbstractData(QString name_in, hp_DataType type_in)
2019-02-25 08:32:15 +01:00
{
2019-02-26 20:56:39 +01:00
// qDebug()<<"base class called "<<name_in;
2019-02-25 08:36:58 +01:00
setName(name_in);
setType(type_in);
}
//Equivalence on name and type NOT on data
inline bool AbstractData::operator ==(AbstractData& lhs) {
if(name==lhs.getName()&&type==lhs.getType())
return true;
else
return false;
}
//Equivalence on name and type NOT on data
bool AbstractData::equivalent(QString name_in, hp_DataType type_in) {
if((name==name_in)&&(type==type_in))
return true;
else
return false;
}
void AbstractData::setName(QString name_in) {
name = name_in;
}
QString AbstractData::getName() {
return name;
}
void AbstractData::setType(hp_DataType type_in) {
type = type_in;
}
hp_DataType AbstractData::getType() {
return type;
}
void AbstractData::setFileCode(hp_pkt_type type_in) {
file_code = type_in;
}
hp_pkt_type AbstractData::getFileCode() {
return file_code;
}
void AbstractData::setData(QByteArray data_in) {
data = data_in;
2019-03-02 20:20:23 +01:00
parseData();
2019-02-25 08:36:58 +01:00
}
QByteArray AbstractData::getData() {
return data;
}
2019-09-15 17:23:44 +02:00
QByteArray AbstractData::fileOut() {
return getData();
}
2019-03-02 20:20:23 +01:00
void AbstractData::parseData() {
qDebug()<<"AbstractData::parseData";
}
2019-09-15 17:23:44 +02:00
void AbstractData::parseData(QDataStream& ) {
2019-04-02 21:14:31 +02:00
qDebug()<<"AbstractData::parseData";
}
2019-09-15 17:23:44 +02:00
AbstractData::~AbstractData() {
qDebug()<<"~AbstractData";
}
2019-02-25 19:28:45 +01:00
//REAL
//
Application::Application(QString name_in, hp_DataType type_in):
AbstractData(name_in, type_in) {
setFileCode(HP_TP_FUNCTIONS);
}
2019-03-02 20:20:23 +01:00
void Application::parseData() {
}
2019-02-25 19:28:45 +01:00
2019-02-25 08:36:58 +01:00
//REAL
//
Real::Real(QString name_in, hp_DataType type_in):
AbstractData(name_in, type_in) {
setFileCode(HP_TP_SETTINGS);
}
2019-03-09 21:11:43 +01:00
//Find the vars in the calc.hpsettings file. Marker b4 01 00
2019-03-02 20:20:23 +01:00
void Real::parseData() {
2019-03-09 15:39:38 +01:00
QByteArray a1;
2019-03-09 21:11:43 +01:00
int ind=0;
int len;
int j;
int start;
2019-03-16 20:34:09 +01:00
QByteArray searchstr=QByteArrayLiteral("\x0c\x00\xc0\x05");
2019-03-09 21:11:43 +01:00
QByteArrayMatcher matcher(searchstr);
2019-03-09 15:39:38 +01:00
2019-03-09 21:11:43 +01:00
QByteArray item;
2019-03-16 20:34:09 +01:00
itemData value1,value2;
2019-03-09 21:11:43 +01:00
itemData listvalue;
2019-03-16 20:34:09 +01:00
2019-03-09 15:39:38 +01:00
QString name;
2019-03-09 21:11:43 +01:00
log("Real: Parsing Vars");
2019-03-09 15:39:38 +01:00
name=getName();
log(name);
2019-03-09 21:11:43 +01:00
a1.clear();
a1=getData();
main_err->dump((uint8_t *)searchstr.constData(),4);
// ind=a1.indexOf(searchstr,0);
ind=matcher.indexIn(a1,0);
2019-03-16 20:34:09 +01:00
if (ind>0)
len=((((a1[ind-3])&0x0F)<<8)+((a1[ind-4])&0xFF)-4)/16;
else
len=0;
2019-03-09 21:11:43 +01:00
2019-03-16 20:34:09 +01:00
log(QString("Real: %1 %2 %3").arg(ind,0,10)
2019-03-09 21:11:43 +01:00
.arg(searchstr.size())
2019-03-16 20:34:09 +01:00
.arg(len,2,10));
// ind=a1.indexOf(searchstr,0);
ind=matcher.indexIn(a1,0);
if (ind>0)
len=((((a1[ind-3])&0x0F)<<8)+((a1[ind-4])&0xFF)-4)/16;
else
len=0;
start=ind+4;
qDebug()<<start;
for(j=0;j<len;j++) {
item=a1.mid(start,16);
2019-09-15 17:23:44 +02:00
if (static_cast<int>(item[2])==0x13) {
2019-03-16 20:34:09 +01:00
main_err->dump((uint8_t *)item.constData(),16);
value1=extract16(item);
j++;
start=start+16;
item=a1.mid(start,16);
main_err->dump((uint8_t *)item.constData(),16);
value2=extract16(item);
listvalue.dReal=value1.dReal;
listvalue.sValue=value1.sValue;
listvalue.dImaginary=value2.dReal;
listvalue.sValue=complex2Str(value1.sValue,value2.sValue);
start=start+16;
}
else {
main_err->dump((uint8_t *)item.constData(),16);
listvalue=extract16(item);
start=start+16;
}
2019-03-09 21:11:43 +01:00
setListItem(getListSize(),listvalue);
2019-03-16 20:34:09 +01:00
}
// log("Real Dump");
// main_err->dump((uint8_t *)a1.constData(),a1.size());
2019-03-09 21:11:43 +01:00
}
//Gets a list item from the list
itemData Real::getListItem(int row) {
itemData null;
if (row<values.size()) {
return values.at(row);
}
return null;
2019-03-02 20:20:23 +01:00
}
2019-02-25 08:36:58 +01:00
2019-03-09 21:11:43 +01:00
//Gets a list item in the list at position row
void Real::setListItem(int row, itemData item) {
//May need to pad for missing items
values.insert(row,item);
}
//Gets a string representation of the list item in the list at position row
QString Real::getItem(int row) {
2019-03-16 20:34:09 +01:00
return QString("%1").arg(values.at(row).dReal);
2019-03-09 21:11:43 +01:00
}
//Passes a string representation of the list item in the list at position row
void Real::setItem(int row, QString string) {
itemData item;
2019-03-16 20:34:09 +01:00
item.dReal=string.toDouble();
2019-03-09 21:11:43 +01:00
item.sValue=string;
setListItem(row,item);
}
//Passes a string representation of the list item in the list at position row
void Real::setItem(int row, QString string, double value) {
itemData item;
2019-03-16 20:34:09 +01:00
item.dReal=value;
2019-03-09 21:11:43 +01:00
item.sValue=string;
setListItem(row,item);
}
//Passes the number of entries in the list
int Real::getListSize() {
return values.size();
}
2019-02-25 08:36:58 +01:00
//COMPLEX
Complex::Complex(QString name_in, hp_DataType type_in):
AbstractData(name_in, type_in) {
setFileCode(HP_TP_SETTINGS);
}
2019-03-02 20:20:23 +01:00
void Complex::parseData() {
2019-03-16 20:34:09 +01:00
qDebug()<<"Complex: Parsing Vars";
2019-03-09 15:39:38 +01:00
QByteArray a1;
2019-03-16 20:34:09 +01:00
int ind=0;
int len;
int j;
int start;
QByteArray searchstr=QByteArrayLiteral("\x0c\x00\x80\x05");
QByteArrayMatcher matcher(searchstr);
2019-03-02 20:20:23 +01:00
2019-03-16 20:34:09 +01:00
QByteArray item;
itemData value1;
itemData value2;
itemData listvalue;
2019-03-09 15:39:38 +01:00
QString name;
2019-03-16 20:34:09 +01:00
log("Complex: Parsing Vars");
2019-03-09 15:39:38 +01:00
name=getName();
log(name);
2019-03-16 20:34:09 +01:00
a1.clear();
a1=getData();
// ind=a1.indexOf(searchstr,0);
ind=matcher.indexIn(a1,0);
if (ind>0)
len=((((a1[ind-3])&0x0F)<<8)+((a1[ind-4])&0xFF)-4)/16;
else
len=0;
log(QString("Real: %1 %2 %3").arg(ind,0,10)
.arg(searchstr.size())
.arg(len,2,10));
// ind=a1.indexOf(searchstr,0);
ind=matcher.indexIn(a1,0);
if (ind>0)
len=((((a1[ind-3])&0x0F)<<8)+((a1[ind-4])&0xFF)-4)/16;
else
len=0;
start=ind+4;
qDebug()<<start;
for(j=0;j<len;j++) {
item=a1.mid(start,16);
2019-09-15 17:23:44 +02:00
if (static_cast<int>(item[2])==0x13) {
2019-03-16 20:34:09 +01:00
main_err->dump((uint8_t *)item.constData(),16);
value1=extract16(item);
j++;
start=start+16;
item=a1.mid(start,16);
main_err->dump((uint8_t *)item.constData(),16);
value2=extract16(item);
listvalue.dReal=value1.dReal;
listvalue.sValue=value1.sValue;
listvalue.dImaginary=value2.dReal;
listvalue.sValue=complex2Str(value1.sValue,value2.sValue);
start=start+16;
}
else {
main_err->dump((uint8_t *)item.constData(),16);
listvalue=extract16(item);
start=start+16;
}
setListItem(getListSize(),listvalue);
}
2019-03-09 21:11:43 +01:00
// main_err->dump((uint8_t *)a1.constData(),a1.size());
2019-03-02 20:20:23 +01:00
}
2019-02-25 08:36:58 +01:00
2019-03-16 20:34:09 +01:00
//Gets a list item from the list
itemData Complex::getListItem(int row) {
itemData null;
if (row<values.size()) {
return values.at(row);
}
return null;
}
//Gets a list item in the list at position row
void Complex::setListItem(int row, itemData item) {
//May need to pad for missing items
values.insert(row,item);
}
//Gets a string representation of the list item in the list at position row
QString Complex::getItem(int row) {
// return QString("%1+%2i").arg(values.at(row).dReal).arg(values.at(row).dImaginary);
return values.at(row).sValue;
}
//Passes a string representation of the list item in the list at position row
void Complex::setItem(int row, QString string) {
itemData item;
item.dReal=string.toDouble();
item.sValue=string;
setListItem(row,item);
}
//Passes a string representation of the list item in the list at position row
void Complex::setItem(int row, QString string, double value) {
itemData item;
item.dReal=value;
item.sValue=string;
setListItem(row,item);
}
//Passes the number of entries in the list
int Complex::getListSize() {
return values.size();
}
2019-02-25 08:36:58 +01:00
//LIST
List::List(QString name_in, hp_DataType type_in):
AbstractData(name_in, type_in) {
setFileCode(HP_TP_LIST);
2019-03-02 20:20:23 +01:00
values.clear();
}
QByteArray List::getData() {
return data;
}
void List::parseData() {
QByteArray a1;
QByteArray item;
2019-03-16 20:34:09 +01:00
itemData listvalue,value1,value2;
2019-03-02 20:20:23 +01:00
QString name;
int len;
2019-03-09 15:39:38 +01:00
int ind;
2019-03-02 20:20:23 +01:00
int start = 8;
int j;
2019-03-09 15:39:38 +01:00
unsigned char searchstr[] = {0xFF,0x16,0x00};
2019-03-02 20:20:23 +01:00
qDebug()<<"List: Parsing a List";
name=getName();
a1=data;
2019-09-15 17:23:44 +02:00
ind=a1.indexOf(reinterpret_cast<char *>(searchstr),0);
2019-03-09 15:39:38 +01:00
//look for FF 16 00
len=a1[ind+3];
2019-03-02 20:20:23 +01:00
for(j=0;j<len;j++) {
item=a1.mid(start,16);
2019-09-15 17:23:44 +02:00
if (static_cast<int>(item[2])==0x13) {
main_err->dump((uint8_t *)(item.constData()),16);
2019-03-16 20:34:09 +01:00
value1=extract16(item);
j++;
start=start+16;
item=a1.mid(start,16);
main_err->dump((uint8_t *)item.constData(),16);
value2=extract16(item);
listvalue.dReal=value1.dReal;
listvalue.sValue=value1.sValue;
listvalue.dImaginary=value2.dReal;
listvalue.sValue=complex2Str(value1.sValue,value2.sValue);
start=start+16;
}
else {
main_err->dump((uint8_t *)item.constData(),16);
listvalue=extract16(item);
start=start+16;
}
2019-03-02 20:20:23 +01:00
setListItem(-1,listvalue);
2019-03-16 20:34:09 +01:00
2019-03-02 20:20:23 +01:00
}
main_err->dump((uint8_t *)a1.constData(),a1.size());
}
//Gets a list item from the list
itemData List::getListItem(int row) {
itemData null;
if (row<values.size()) {
return values.at(row);
}
return null;
}
//Gets a list item in the list at position row
void List::setListItem(int row, itemData item) {
//May need to pad for missing items
values.insert(row,item);
}
//Gets a string representation of the list item in the list at position row
QString List::getItem(int row) {
2019-03-16 20:34:09 +01:00
return QString("%1").arg(values.at(row).dReal);
2019-03-02 20:20:23 +01:00
}
//Passes a string representation of the list item in the list at position row
void List::setItem(int row, QString string) {
itemData item;
2019-03-16 20:34:09 +01:00
item.dReal=string.toDouble();
2019-03-02 20:20:23 +01:00
item.sValue=string;
setListItem(row,item);
}
//Passes a string representation of the list item in the list at position row
void List::setItem(int row, QString string, double value) {
itemData item;
2019-03-16 20:34:09 +01:00
item.dReal=value;
2019-03-02 20:20:23 +01:00
item.sValue=string;
setListItem(row,item);
}
//Passes the number of entries in the list
int List::getListSize() {
return values.size();
2019-02-25 08:36:58 +01:00
}
//Matrix
Matrix::Matrix(QString name_in, hp_DataType type_in):
AbstractData(name_in, type_in) {
setFileCode(HP_TP_MATRIX);
}
2019-03-02 20:20:23 +01:00
void Matrix::parseData() {
QByteArray a1;
QByteArray item;
2019-03-16 20:34:09 +01:00
itemData listvalue,value1,value2;
2019-03-02 20:20:23 +01:00
QString name;
QString msg;
QString value=QStringLiteral("");;
2019-03-09 15:39:38 +01:00
int mrows;
int mcolumns;
int start;
2019-03-02 20:20:23 +01:00
int k,j;
2019-03-09 15:39:38 +01:00
int ind;
2019-03-16 20:34:09 +01:00
int flag =0;
2019-09-15 17:23:44 +02:00
qint8 vtype;
2019-03-16 20:34:09 +01:00
2019-03-02 20:20:23 +01:00
QString ds;
2019-03-16 20:34:09 +01:00
// QByteArray searchstr((char *)std::begin<quint8>({0x01,0x00}),2);
//Start keeps changing 01 or 02
//0x14 real 0x94 Complex
2019-03-02 20:20:23 +01:00
qDebug()<<"Matrix: Parsing a Matrix";
name=getName();
log(name);
a1=data;
2019-03-16 20:34:09 +01:00
// ind=a1.indexOf(searchstr,0);
ind=0;
vtype=a1[ind+2];
log(QString("vtype=%1").arg(vtype,1,16));
2019-09-15 17:23:44 +02:00
if ((vtype&0x7F)==0x14) {
2019-03-16 20:34:09 +01:00
log("matrix found");
flag =1;
}
log(QString("vtype=%1").arg(vtype&0x7F,1,16));
if ((vtype&0x80)==0x80) {
log("complex found");
flag =2;
}
log(QString("vtype=%1").arg(vtype&0x80,1,16));
2019-03-09 15:39:38 +01:00
//look for 00 14
log(QString("Found string at %1").arg(ind));
2019-03-16 20:34:09 +01:00
mcolumns=a1[ind+12];
mrows=a1[ind+8];
2019-03-09 15:39:38 +01:00
qDebug()<<QString("Matrix: Row %1 Column %2").arg(mrows).arg(mcolumns);
log(QString("Matrix: Row %1 Column %2").arg(mrows).arg(mcolumns));
2019-03-16 20:34:09 +01:00
start=ind+16;
2019-03-09 15:39:38 +01:00
for(j=0;j<mrows;j++) {
for(k=0;k<mcolumns;k++) {
2019-03-16 20:34:09 +01:00
2019-03-09 15:39:38 +01:00
item=a1.mid(start,8);
qDebug()<<item;
listvalue=extract8(item);
2019-03-16 20:34:09 +01:00
start+=8;
//if complex
if (flag==2) {
item=a1.mid(start,8);
start+=8;
value2=extract8(item);
2019-09-15 17:23:44 +02:00
if ((value2.dReal) != 0.0) {
2019-03-16 20:34:09 +01:00
listvalue.dImaginary=value2.dReal;
listvalue.sValue=complex2Str(listvalue.sValue,value2.sValue);
}
}
2019-03-09 15:39:38 +01:00
setListItem(j,k,listvalue);
}
}
2019-03-02 20:20:23 +01:00
main_err->dump((uint8_t *)a1.constData(),a1.size());
}
//Gets a item from the matrix
itemData Matrix::getListItem(int row, int column) {
itemData data;
data=mdata.at(row,column);
return data;
}
//Gets a list item in the matrix at position row,column
void Matrix::setListItem(int row, int column, itemData item) {
mdata.insert(row,column,item);
}
//Gets a string representation of the list item in the matrix at position row,column
QString Matrix::getItem(int row, int column) {
itemData data;
QString item;
data=mdata.at(row,column);
item=data.sValue;
2019-03-16 20:34:09 +01:00
// item=QString("%1").arg(data.dReal,5);
2019-03-02 20:20:23 +01:00
return item;
}
//Passes a string representation of the item in the matrix at position position row,column
void Matrix::setItem(int row, int column, QString string) {
itemData item;
2019-03-16 20:34:09 +01:00
item.dReal=string.toDouble();
2019-03-02 20:20:23 +01:00
item.sValue=string;
setListItem(row,column, item);
}
//Passes a string representation of the list item in the matrix at position row,column
void Matrix::setItem(int row, int column, QString string, double value) {
itemData item;
2019-03-16 20:34:09 +01:00
item.dReal=value;
2019-03-02 20:20:23 +01:00
item.sValue=string;
setListItem(row,column,item);
}
//Passes the number of entries in the list
m_Size Matrix::getMatrixSize() {
m_Size size;
size.row=mdata.rows();
size.column=mdata.columns();
return size;
}
//Passes the number of entries in the list
int Matrix::getMatrixRows() {
return mdata.rows();
}
//Passes the number of entries in the list
int Matrix::getMatrixColumns() {
return mdata.columns();
}
2019-02-25 08:36:58 +01:00
//Program
Program::Program(QString name_in, hp_DataType type_in, QString data):
AbstractData(name_in, type_in) {
setFileCode(HP_TP_PROG);
setProg(data);
}
QString Program::getProg() {
2019-02-26 20:56:39 +01:00
return text;
2019-02-25 08:36:58 +01:00
}
void Program::setProg(QString data_in) {
2019-04-02 21:14:31 +02:00
data=data_in.toUtf8();
2019-02-26 20:56:39 +01:00
text=data_in;
2019-02-25 08:36:58 +01:00
}
2019-03-02 20:20:23 +01:00
void Program::parseData() {
2019-04-02 21:14:31 +02:00
QTextCodec * codec = QTextCodec::codecForName("UTF8");
2019-03-02 20:20:23 +01:00
QByteArray a1;
a1=getData();
text = codec->toUnicode(a1);
2019-04-02 21:14:31 +02:00
}
2019-03-02 20:20:23 +01:00
2019-04-02 21:14:31 +02:00
void Program::parseData(QDataStream& in) {
2019-09-15 17:23:44 +02:00
QTextCodec * codec = QTextCodec::codecForName("UTF-16");
QByteArrayMatcher matcher;
QByteArray search;
QByteArray phrase;
int ind;
int pos;
2019-04-02 21:14:31 +02:00
QString str;
in.setByteOrder(QDataStream::LittleEndian);
2019-09-15 17:23:44 +02:00
qint8 c;
2019-04-02 21:14:31 +02:00
QByteArray a1;
2019-09-15 17:23:44 +02:00
uint length;
length=16;
2019-04-02 21:14:31 +02:00
2019-09-15 17:23:44 +02:00
in.startTransaction();
2019-04-02 21:14:31 +02:00
while(!in.atEnd()) {
2019-09-15 17:23:44 +02:00
in>>c;
a1.append(c);
}
main_err->dump((uint8_t *)a1.constData(),a1.size());
search="\x7c\x61";
matcher.setPattern(search);
ind=matcher.indexIn(a1,0);
if (ind>-1) {
search=QByteArrayLiteral("\x54\x0\x0\x0\x44\x0\x0\x0");
main_err->dump((uint8_t *)search.data(),search.length());
matcher.setPattern(search);
pos=0;
while(pos>-1) {
pos=matcher.indexIn(a1,ind);
if (pos>-1) {
ind=pos+10;
phrase=a1.mid(ind,16*3);
//add array to catch variable list
str=codec->toUnicode(phrase);
log(QString("TD...%1 %2").arg(pos,0,16).arg(ind));
main_err->dump((uint8_t *)phrase.data(),3*16);
log(str);
}
}
}
else {
log("Data is not a program file");
2019-04-02 21:14:31 +02:00
}
2019-09-15 17:23:44 +02:00
// char cstr[20];
2019-04-02 21:14:31 +02:00
// in.readRawData(cstr,20);
// str=QString(cstr);
// qDebug()<<str;
// a1=getData();
text = codec->toUnicode(a1);
}
2019-03-02 20:20:23 +01:00
2019-09-15 17:23:44 +02:00
QByteArray Program::fileOut() {
QByteArray out;
out.clear();
out.append("\x7c\x61\x8a\x62\xfe\xff\xff\xff\x00\x00\x00\x00\x08\x00\x00\x00");
out.append("\x05\xff\x7f\x00\x00\x00\x00\x00\x08\x00\x00\x00\x05\xff\x3f\x02");
out.append(data); //temp should be string text
qDebug()<<out;
return out;
}
2019-02-25 08:36:58 +01:00
//Notes
2019-03-02 20:20:23 +01:00
Notes::Notes(QString name_in, hp_DataType type_in, QString data_in):
2019-02-25 08:36:58 +01:00
AbstractData(name_in, type_in) {
2019-02-25 08:32:15 +01:00
2019-02-26 20:56:39 +01:00
setFileCode(HP_TP_NOTE);
2019-03-02 20:20:23 +01:00
setNote(data_in);
2019-02-26 20:56:39 +01:00
}
QString Notes::getNote() {
return text;
}
2019-03-02 20:20:23 +01:00
void Notes::parseData() {
// quint16 len1,len2;
int formatstart;
QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
QByteArray a1,a3;
a1=getData();
formatstart=a1.indexOf("C\x00S\x00W\x0D\x001\x001\x00");
a3=a1.mid(formatstart,-1);
a1=a1.mid(0,formatstart);
text = codec->toUnicode(a1);
format = codec->toUnicode(a3);
}
2019-02-26 20:56:39 +01:00
void Notes::setNote(QString data_in) {
text=data_in;
2019-02-25 08:32:15 +01:00
}
2019-03-09 15:39:38 +01:00
//Variables
Variables::Variables(QString name_in, hp_DataType type_in):
AbstractData(name_in, type_in) {
setFileCode(HP_TP_SETTINGS);
}
void Variables::parseData() {
// quint16 len1,len2;
QByteArray a1,a3;
a1=getData();
}
//CAS Variables
CASVariables::CASVariables(QString name_in, hp_DataType type_in):
AbstractData(name_in, type_in) {
setFileCode(HP_TP_SETTINGS);
}
void CASVariables::parseData() {
// quint16 len1,len2;
QByteArray a1,a3;
a1=getData();
}
//Settings
Settings::Settings(QString name_in, hp_DataType type_in):
AbstractData(name_in, type_in) {
setFileCode(HP_TP_SETTINGS);
}
void Settings::parseData() {
// quint16 len1,len2;
QByteArray a1,a3;
a1=getData();
}
2019-04-02 21:14:31 +02:00
void Settings::setData(QByteArray datain) {
qDebug()<<"Settings Compare:";
int len1=data.size();
int len2=datain.size();
log(QString("Settings Compare %1 %2").arg(len1).arg(len2));
int i=0;
while ((i<len1)&&(i<len2)) {
if (data[i]!=datain[i]) {
log(QString("Settings diff at:%1").arg(i));
}
i++;
}
data = datain;
len1=data.size();
len2=datain.size();
log(QString("Settings Compare 2 %1 %2").arg(len1).arg(len2));
//parseData();
}