mirror of
https://github.com/Indy970/QtHPConnect
synced 2024-12-24 21:59:13 +01:00
Lists
This commit is contained in:
parent
230a0598fe
commit
7746d6c283
20 changed files with 780 additions and 110 deletions
|
@ -77,7 +77,8 @@ SOURCES += \
|
|||
hpusb.cpp \
|
||||
hp_settingsdlg.cpp \
|
||||
cntfilesystemmodel.cpp \
|
||||
abstractdata.cpp
|
||||
abstractdata.cpp \
|
||||
matrixdata.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
|
@ -116,7 +117,8 @@ HEADERS += \
|
|||
hp_settingsdlg.h \
|
||||
version.h \
|
||||
cntfilesystemmodel.h \
|
||||
abstractdata.h
|
||||
abstractdata.h \
|
||||
matrixdata.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui \
|
||||
|
|
18
TODO.md
18
TODO.md
|
@ -6,15 +6,21 @@
|
|||
Content - fix resizing
|
||||
Create storage path if it does not exist
|
||||
Load and read program files
|
||||
Load Screen shot and display
|
||||
Add options - set default paths
|
||||
|
||||
Drag and drop from content window to calc
|
||||
|
||||
2 Comms
|
||||
Understand what the calc is doing!
|
||||
|
||||
CAN READ ALL DATA!
|
||||
------------------
|
||||
Tidy hpusb and start decoding
|
||||
Libusb hot swap
|
||||
|
||||
Sections are group by function starting 00 F7
|
||||
Async transfer
|
||||
|
||||
CRC checks are not working - this will be a problem on sending data. Worried that a byte is being
|
||||
gained or lost on transfer
|
||||
|
||||
Decoding data. Lists 90% complete
|
||||
|
||||
Extract vars file
|
||||
|
||||
3 Backup to disk
|
||||
|
|
362
abstractdata.cpp
362
abstractdata.cpp
|
@ -1,8 +1,126 @@
|
|||
#include <QDebug>
|
||||
#include <QTextCodec>
|
||||
#include <QtMath>
|
||||
|
||||
#include "global.h"
|
||||
#include "abstractdata.h"
|
||||
#include "hpusb.h"
|
||||
#include "matrixdata.h"
|
||||
|
||||
uint16_t crc16_block(const uint8_t * buffer, uint32_t len);
|
||||
|
||||
int BCD2I(quint16 num) {
|
||||
|
||||
int ds,ret;
|
||||
if(num>0) {
|
||||
ds=((num&0xF0)>>4)*10;
|
||||
ds+=(num&0x0F);
|
||||
ret=ds;
|
||||
}
|
||||
else {
|
||||
ret=0;
|
||||
}
|
||||
|
||||
// qDebug()<<QString("Num= %1 Ret= %2").arg(num,1,16).arg(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long TwosComplement2Int(long rawValue)
|
||||
{
|
||||
|
||||
long ret;
|
||||
|
||||
qDebug()<<QString("List 2C: %1").arg(rawValue&0x80000000,1,16);
|
||||
|
||||
// If a positive value, return it
|
||||
if ((rawValue & 0x80000000) == 0)
|
||||
{
|
||||
ret = rawValue;
|
||||
}
|
||||
else {
|
||||
// Otherwise perform the 2's complement math on the value
|
||||
qDebug()<<QString("List 2C Negative Detected");
|
||||
|
||||
ret = (long)(~(rawValue - 0x01)) * -1;
|
||||
// ret = ~rawValue;
|
||||
}
|
||||
qDebug()<<QString("List 2C: %1 %2").arg(rawValue,1,16).arg(ret,1,16);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
qint8 TwosComplement2Int(quint8 rawValue)
|
||||
{
|
||||
|
||||
qint8 ret;
|
||||
|
||||
qDebug()<<QString("List 2C UINT8: %1").arg(rawValue&0x80,1,16);
|
||||
|
||||
// If a positive value, return it
|
||||
if ((rawValue & 0x80) == 0)
|
||||
{
|
||||
ret = rawValue;
|
||||
}
|
||||
else {
|
||||
// Otherwise perform the 2's complement math on the value
|
||||
qDebug()<<QString("List 2C UINT8 Negative Detected");
|
||||
|
||||
ret = ~(rawValue - 0x01) * -1;
|
||||
// ret = ~rawValue;
|
||||
}
|
||||
qDebug()<<QString("List 2C UINT8: %1 %2").arg(rawValue,1,16).arg(ret,1,16);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
itemData extractNubmer(QByteArray item) {
|
||||
;
|
||||
itemData listvalue;
|
||||
QString msg;
|
||||
QString value=QStringLiteral("");;
|
||||
qint8 sign;
|
||||
int multi;
|
||||
long exp;
|
||||
double base;
|
||||
double m,ret;
|
||||
int k;
|
||||
|
||||
multi=item[0];
|
||||
base=BCD2I(item[2]);
|
||||
sign=TwosComplement2Int((quint8)item[3]);
|
||||
|
||||
exp=(((((((((qint8)item[7]&0xFF)<<8)+((qint8)item[6]&0xFF))<<8)+((qint8)item[5]&0xFF)))<<8)+((qint8)item[4]&0xFF));
|
||||
exp=TwosComplement2Int(exp);
|
||||
|
||||
m=0;
|
||||
|
||||
for (k=8;k<16;k++) {
|
||||
if(item[k]>0) {
|
||||
m=m*0.01+(double)multi*BCD2I(item[k]);
|
||||
}
|
||||
}
|
||||
ret=sign*m*qPow(base,exp);
|
||||
|
||||
value=QString("%1E%2").arg(m).arg(exp);
|
||||
|
||||
// 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);
|
||||
|
||||
log(msg);
|
||||
// log(value);
|
||||
log((QString("Ans: %1").arg(ret)));
|
||||
qDebug()<<msg;
|
||||
qDebug()<<ret;
|
||||
|
||||
listvalue.dValue=ret;
|
||||
listvalue.sValue=QString("%1").arg(ret);
|
||||
|
||||
return listvalue;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////
|
||||
|
||||
AbstractData::AbstractData(QString name_in, hp_DataType type_in)
|
||||
{
|
||||
|
@ -56,12 +174,17 @@ hp_pkt_type AbstractData::getFileCode() {
|
|||
|
||||
void AbstractData::setData(QByteArray data_in) {
|
||||
data = data_in;
|
||||
parseData();
|
||||
}
|
||||
|
||||
QByteArray AbstractData::getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
void AbstractData::parseData() {
|
||||
qDebug()<<"AbstractData::parseData";
|
||||
}
|
||||
|
||||
//REAL
|
||||
//
|
||||
Application::Application(QString name_in, hp_DataType type_in):
|
||||
|
@ -70,6 +193,9 @@ Application::Application(QString name_in, hp_DataType type_in):
|
|||
setFileCode(HP_TP_FUNCTIONS);
|
||||
}
|
||||
|
||||
void Application::parseData() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//REAL
|
||||
|
@ -80,6 +206,9 @@ Real::Real(QString name_in, hp_DataType type_in):
|
|||
setFileCode(HP_TP_SETTINGS);
|
||||
}
|
||||
|
||||
void Real::parseData() {
|
||||
|
||||
}
|
||||
|
||||
//COMPLEX
|
||||
Complex::Complex(QString name_in, hp_DataType type_in):
|
||||
|
@ -88,12 +217,101 @@ Complex::Complex(QString name_in, hp_DataType type_in):
|
|||
setFileCode(HP_TP_SETTINGS);
|
||||
}
|
||||
|
||||
void Complex::parseData() {
|
||||
|
||||
}
|
||||
|
||||
//LIST
|
||||
List::List(QString name_in, hp_DataType type_in):
|
||||
AbstractData(name_in, type_in) {
|
||||
|
||||
setFileCode(HP_TP_LIST);
|
||||
values.clear();
|
||||
}
|
||||
|
||||
QByteArray List::getData() {
|
||||
|
||||
//temp
|
||||
|
||||
//parseData();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
void List::parseData() {
|
||||
|
||||
QByteArray a1;
|
||||
QByteArray item;
|
||||
itemData listvalue;
|
||||
QString name;
|
||||
int len;
|
||||
int start = 8;
|
||||
int j;
|
||||
|
||||
qDebug()<<"List: Parsing a List";
|
||||
|
||||
name=getName();
|
||||
|
||||
a1=data;
|
||||
len=a1[4];
|
||||
|
||||
for(j=0;j<len;j++) {
|
||||
|
||||
item=a1.mid(start,16);
|
||||
listvalue=extractNubmer(item);
|
||||
setListItem(-1,listvalue);
|
||||
start+=16;
|
||||
}
|
||||
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) {
|
||||
return QString("%1").arg(values.at(row).dValue);
|
||||
}
|
||||
|
||||
//Passes a string representation of the list item in the list at position row
|
||||
void List::setItem(int row, QString string) {
|
||||
|
||||
itemData item;
|
||||
item.dValue=string.toDouble();
|
||||
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;
|
||||
item.dValue=value;
|
||||
item.sValue=string;
|
||||
setListItem(row,item);
|
||||
}
|
||||
|
||||
//Passes the number of entries in the list
|
||||
int List::getListSize() {
|
||||
|
||||
return values.size();
|
||||
}
|
||||
|
||||
//Matrix
|
||||
|
@ -104,6 +322,101 @@ Matrix::Matrix(QString name_in, hp_DataType type_in):
|
|||
setFileCode(HP_TP_MATRIX);
|
||||
}
|
||||
|
||||
void Matrix::parseData() {
|
||||
|
||||
QByteArray a1;
|
||||
QByteArray item;
|
||||
itemData listvalue;
|
||||
QString name;
|
||||
QString msg;
|
||||
QString value=QStringLiteral("");;
|
||||
int len;
|
||||
int start = 8;
|
||||
qint8 sign;
|
||||
int multi;
|
||||
long exp;
|
||||
double base;
|
||||
double m,ret;
|
||||
int k,j;
|
||||
QString ds;
|
||||
|
||||
qDebug()<<"Matrix: Parsing a Matrix";
|
||||
|
||||
name=getName();
|
||||
log(name);
|
||||
|
||||
a1=data;
|
||||
len=a1[4];
|
||||
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;
|
||||
|
||||
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;
|
||||
item.dValue=string.toDouble();
|
||||
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;
|
||||
item.dValue=value;
|
||||
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();
|
||||
}
|
||||
|
||||
//Program
|
||||
Program::Program(QString name_in, hp_DataType type_in, QString data):
|
||||
AbstractData(name_in, type_in) {
|
||||
|
@ -120,23 +433,60 @@ void Program::setProg(QString data_in) {
|
|||
text=data_in;
|
||||
}
|
||||
|
||||
void Program::parseData() {
|
||||
|
||||
int16_t len1,len2;
|
||||
QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
|
||||
|
||||
QByteArray a1;
|
||||
a1=getData();
|
||||
text = codec->toUnicode(a1);
|
||||
}
|
||||
|
||||
|
||||
//Notes
|
||||
Notes::Notes(QString name_in, hp_DataType type_in, QString data):
|
||||
Notes::Notes(QString name_in, hp_DataType type_in, QString data_in):
|
||||
AbstractData(name_in, type_in) {
|
||||
|
||||
setFileCode(HP_TP_NOTE);
|
||||
setNote(data);
|
||||
qDebug()<<"Taking Note";
|
||||
qDebug()<<data;
|
||||
setNote(data_in);
|
||||
}
|
||||
|
||||
QString Notes::getNote() {
|
||||
|
||||
qDebug()<<"Getting Note";
|
||||
qDebug()<<text;
|
||||
return text;
|
||||
}
|
||||
|
||||
void Notes::parseData() {
|
||||
|
||||
// quint16 len1,len2;
|
||||
int formatstart;
|
||||
quint16 crc;
|
||||
QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
|
||||
|
||||
QByteArray a1,a3;
|
||||
|
||||
a1=getData();
|
||||
// crc=qChecksum(a1.mid(4,-1),a1.size()-4,Qt::ChecksumIso3309);
|
||||
// crc=crc16_block((uint8_t *)a1.mid(4,-1).constData(),a1.size()-4);
|
||||
|
||||
/*
|
||||
QDataStream ds(a1);
|
||||
ds.setByteOrder(QDataStream::LittleEndian);
|
||||
|
||||
ds >> len1;
|
||||
ds >> len2;
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
void Notes::setNote(QString data_in) {
|
||||
text=data_in;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include "hpusb.h"
|
||||
#include "matrixdata.h"
|
||||
|
||||
enum hp_DataType{
|
||||
HP_MAIN=0,
|
||||
|
@ -19,6 +20,11 @@ enum hp_DataType{
|
|||
HP_SCREEN=10
|
||||
};
|
||||
|
||||
struct m_Size {
|
||||
int row;
|
||||
int column;
|
||||
};
|
||||
|
||||
class AbstractData
|
||||
{
|
||||
|
||||
|
@ -26,6 +32,8 @@ private:
|
|||
QString name;
|
||||
hp_DataType type;
|
||||
hp_pkt_type file_code;
|
||||
|
||||
protected:
|
||||
QByteArray data;
|
||||
|
||||
public:
|
||||
|
@ -40,54 +48,85 @@ public:
|
|||
hp_pkt_type getFileCode();
|
||||
void setData(QByteArray);
|
||||
QByteArray getData();
|
||||
virtual void parseData();
|
||||
};
|
||||
|
||||
|
||||
class Application: public AbstractData
|
||||
{
|
||||
private:
|
||||
void parseData();
|
||||
public:
|
||||
Application(QString, hp_DataType);
|
||||
};
|
||||
|
||||
class Real: public AbstractData
|
||||
class Real: public AbstractData
|
||||
{
|
||||
private:
|
||||
void parseData();
|
||||
public:
|
||||
Real(QString, hp_DataType);
|
||||
};
|
||||
|
||||
class Complex: public AbstractData
|
||||
{
|
||||
private:
|
||||
void parseData();
|
||||
public:
|
||||
Complex(QString, hp_DataType);
|
||||
};
|
||||
|
||||
class List: public AbstractData
|
||||
|
||||
class List: public AbstractData
|
||||
{
|
||||
private:
|
||||
QList <itemData>values;
|
||||
void parseData();
|
||||
public:
|
||||
List(QString, hp_DataType);
|
||||
QByteArray getData();
|
||||
itemData getListItem(int);
|
||||
void setListItem(int, itemData);
|
||||
QString getItem(int);
|
||||
void setItem(int, QString);
|
||||
void setItem(int, QString, double);
|
||||
int getListSize();
|
||||
};
|
||||
|
||||
class Matrix: public AbstractData
|
||||
class Matrix: public AbstractData
|
||||
{
|
||||
private:
|
||||
MatrixData mdata;
|
||||
void parseData();
|
||||
public:
|
||||
Matrix(QString, hp_DataType);
|
||||
itemData getListItem(int row, int column);
|
||||
void setListItem(int, int, itemData);
|
||||
QString getItem(int row, int column);
|
||||
void setItem(int, int, QString);
|
||||
void setItem(int, int, QString, double);
|
||||
m_Size getMatrixSize();
|
||||
int getMatrixRows();
|
||||
int getMatrixColumns();
|
||||
};
|
||||
|
||||
class Program: public AbstractData
|
||||
class Program: public AbstractData
|
||||
{
|
||||
private:
|
||||
QString text;
|
||||
void parseData();
|
||||
public:
|
||||
Program(QString, hp_DataType, QString);
|
||||
void setProg(QString);
|
||||
QString getProg();
|
||||
};
|
||||
|
||||
class Notes: public AbstractData
|
||||
class Notes: public AbstractData
|
||||
{
|
||||
private:
|
||||
QString text;
|
||||
|
||||
QString format;
|
||||
void parseData();
|
||||
public:
|
||||
Notes(QString, hp_DataType, QString);
|
||||
void setNote(QString);
|
||||
|
|
|
@ -27,16 +27,12 @@ void hp_mdiTextEdit::setup() {
|
|||
QString text;
|
||||
textEdit = new textEditor(this);
|
||||
|
||||
qDebug()<<"hp_mdiTextEdit::setup";
|
||||
|
||||
if (data) {
|
||||
|
||||
qDebug()<<"hp_mdiTextEdit::setup - Data not null";
|
||||
qDebug()<<data->getName();
|
||||
qDebug()<<data->getType();
|
||||
|
||||
if (data->getType()==HP_NOTE) {
|
||||
qDebug()<<"hp_mdiTextEdit::setup - Its a Note";
|
||||
Notes *note;
|
||||
note=(Notes *)data;
|
||||
text=note->getNote();
|
||||
|
|
|
@ -2,24 +2,33 @@
|
|||
#include "hptreeitem.h"
|
||||
|
||||
|
||||
hp_mdiVariableEdit::hp_mdiVariableEdit(QWidget *parent, hpTreeItem * treeItem)
|
||||
hp_mdiVariableEdit::hp_mdiVariableEdit(QWidget *parent,
|
||||
hpTreeItem * treeItem,
|
||||
hpCalcData * dataStore)
|
||||
: QMdiSubWindow(parent)
|
||||
{
|
||||
setMinimumSize(200,200);
|
||||
setMaximumSize(1000,1000);
|
||||
setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
|
||||
setup();
|
||||
|
||||
hptreeitem=treeItem;
|
||||
hpcalc = dataStore;
|
||||
filename=treeItem->getFileName();
|
||||
type=treeItem->getType();
|
||||
|
||||
setup();
|
||||
|
||||
setWindowTitle(treeItem->getFileName());
|
||||
}
|
||||
|
||||
void hp_mdiVariableEdit::setup() {
|
||||
|
||||
tableView = new QTableView(this);
|
||||
varmodel = new varTableModel(this);
|
||||
tableView->setModel(varmodel);
|
||||
setWidget(tableView);
|
||||
|
||||
if (hpcalc) {
|
||||
varmodel = new varTableModel(this,hpcalc,filename,type);
|
||||
tableView = new QTableView(this);
|
||||
tableView->setModel(varmodel);
|
||||
setWidget(tableView);
|
||||
}
|
||||
}
|
||||
|
||||
void hp_mdiVariableEdit::show() {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QMdiSubWindow>
|
||||
#include <QTableView>
|
||||
#include "vartablemodel.h"
|
||||
#include "hpdata.h"
|
||||
|
||||
class hpTreeItem;
|
||||
|
||||
|
@ -14,13 +15,19 @@ class hp_mdiVariableEdit : public QMdiSubWindow
|
|||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
QTableView * tableView;
|
||||
hpTreeItem * hptreeitem;
|
||||
varTableModel * varmodel;
|
||||
QTableView * tableView =nullptr;
|
||||
hpTreeItem * hptreeitem =nullptr;
|
||||
varTableModel * varmodel =nullptr;
|
||||
hpCalcData * hpcalc =nullptr;
|
||||
QString filename;
|
||||
hp_DataType type;
|
||||
void setup();
|
||||
|
||||
public:
|
||||
explicit hp_mdiVariableEdit(QWidget *parent = nullptr, hpTreeItem * treeItem = nullptr);
|
||||
void setup();
|
||||
explicit hp_mdiVariableEdit(QWidget *parent = nullptr,
|
||||
hpTreeItem * treeItem = nullptr,
|
||||
hpCalcData * dataStore =nullptr
|
||||
);
|
||||
void show();
|
||||
~hp_mdiVariableEdit();
|
||||
|
||||
|
|
|
@ -210,6 +210,7 @@ void hpCalcData::recvProg(hp_Prog program) {
|
|||
//qDebug()<<program.prog;
|
||||
|
||||
Program * obj = new Program(program.filename,HP_PROG, program.prog);
|
||||
obj->setData(program.data);
|
||||
addData(obj);
|
||||
|
||||
emit emitChange(HP_PROG);
|
||||
|
@ -224,6 +225,7 @@ void hpCalcData::recvNote(hp_Note note) {
|
|||
qDebug()<<note.filename;
|
||||
|
||||
Notes * obj = new Notes(note.filename,HP_NOTE, note.text);
|
||||
obj->setData(note.data);
|
||||
addData(obj);
|
||||
|
||||
emit emitChange(HP_NOTE);
|
||||
|
@ -238,12 +240,14 @@ void hpCalcData::recvData(hp_Data data) {
|
|||
case HP_APP: {
|
||||
qDebug()<<"hpCalcData::recvData - Application";
|
||||
Application * obj = new Application(data.name,data.type);
|
||||
obj->setData(data.data);
|
||||
addData(obj);
|
||||
emit emitChange(HP_APP);
|
||||
}
|
||||
break;
|
||||
case HP_LIST: {
|
||||
List * obj = new List(data.name,data.type);
|
||||
obj->setData(data.data);
|
||||
addData(obj);
|
||||
emit emitChange(HP_LIST);
|
||||
}
|
||||
|
@ -251,12 +255,12 @@ void hpCalcData::recvData(hp_Data data) {
|
|||
case HP_MATRIX: {
|
||||
qDebug()<<"hpCalcData::recvData - Matrix";
|
||||
Matrix * obj = new Matrix(data.name,data.type);
|
||||
obj->setData(data.data);
|
||||
addData(obj);
|
||||
emit emitChange(HP_MATRIX);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
2
hpdata.h
2
hpdata.h
|
@ -54,11 +54,13 @@ struct hp_Change {
|
|||
struct hp_Prog {
|
||||
QString filename;
|
||||
QString prog;
|
||||
QByteArray data;
|
||||
};
|
||||
|
||||
struct hp_Note {
|
||||
QString filename;
|
||||
QString text;
|
||||
QByteArray data;
|
||||
};
|
||||
|
||||
struct hp_Data {
|
||||
|
|
|
@ -117,21 +117,26 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) {
|
|||
hpvaredit ->show();
|
||||
break;
|
||||
case HP_LIST:
|
||||
qDebug()<<column();
|
||||
if (hpvaredit==nullptr) {
|
||||
if (calc) {
|
||||
data=calc->getData(getFileName(),HP_LIST);
|
||||
}
|
||||
if (data) {
|
||||
hpvaredit = new hp_mdiVariableEdit(mdiwin,this);
|
||||
hpvaredit = new hp_mdiVariableEdit(mdiwin,this,calc);
|
||||
}
|
||||
}
|
||||
if (hpvaredit!=nullptr)
|
||||
hpvaredit ->show();
|
||||
break;
|
||||
case HP_MATRIX:
|
||||
if (hpvaredit==nullptr)
|
||||
hpvaredit = new hp_mdiVariableEdit(mdiwin,this);
|
||||
if (hpvaredit==nullptr) {
|
||||
if (calc) {
|
||||
data=calc->getData(getFileName(),HP_MATRIX);
|
||||
}
|
||||
if (data) {
|
||||
hpvaredit = new hp_mdiVariableEdit(mdiwin,this,calc);
|
||||
}
|
||||
}
|
||||
if (hpvaredit!=nullptr)
|
||||
hpvaredit ->show();
|
||||
break;
|
||||
|
|
146
hpusb.cpp
146
hpusb.cpp
|
@ -17,7 +17,7 @@
|
|||
#include <libusb.h>
|
||||
#include <signal.h>
|
||||
|
||||
static inline uint16_t crc16_block(const uint8_t * buffer, uint32_t len) {
|
||||
uint16_t crc16_block(const uint8_t * buffer, uint32_t len) {
|
||||
static const uint16_t ccitt_crc16_table[256] = {
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
||||
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
||||
|
@ -77,7 +77,7 @@ int hpusb::hp_init()
|
|||
|
||||
if(!(ret=libusb_init(&ctx))) {
|
||||
log("libusb init ok");
|
||||
libusb_set_debug(ctx,LIBUSB_LOG_LEVEL_DEBUG);
|
||||
libusb_set_debug(ctx,LIBUSB_LOG_LEVEL_WARNING);
|
||||
lb_init=1;
|
||||
return ret;
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ int hpusb::extract_header(uint8_t * raw, usb_header * uh) {
|
|||
uh->pkt_size=Int32; //assume third byte is header length
|
||||
uh->num_chunks=uh->pkt_size/PRIME_RAW_DATA_SIZE;
|
||||
uh->name_length=0;
|
||||
uh->embedded_crc = (((uint16_t)(raw[7])) << 8) | ((uint16_t)(raw[8]));
|
||||
uh->embedded_crc = (((uint16_t)(raw[8] & 0xFF)) << 8) | ((uint16_t)(raw[7] & 0xFF));
|
||||
uh->headerlen=14;
|
||||
memcpy(uh->header,raw,HEADER_LEN);
|
||||
QString msg = QString("PNG Header chunks: %1 size: %2 Items: %3")
|
||||
|
@ -387,14 +387,12 @@ int hpusb::extract_header(uint8_t * raw, usb_header * uh) {
|
|||
Int32=(Int32<<8)+raw[4];
|
||||
Int32=(Int32<<8)+raw[5];
|
||||
Int32=(Int32<<8)+raw[6];
|
||||
uh->pkt_size=Int32; //assume third byte is data length
|
||||
uh->pkt_type=raw[7]; //File type being read
|
||||
uh->pkt_size=Int32; //assume third byte is header length
|
||||
uh->num_chunks=uh->pkt_size/PRIME_RAW_DATA_SIZE;
|
||||
uh->name_length=0;
|
||||
uh->headerlen=8;
|
||||
// For whatever reason the CRC seems to be encoded the other way around compared to receiving files
|
||||
uh->embedded_crc = 0;
|
||||
//(((uint16_t)(raw[7])) << 8) | ((uint16_t)(raw[8]));
|
||||
memcpy(uh->header,raw,HEADER_LEN);
|
||||
QString msg = QString("File Header chunks: %1 size: %2 items: %3")
|
||||
.arg(uh->num_chunks).arg(uh->pkt_size).arg(uh->items);
|
||||
|
@ -414,7 +412,7 @@ int hpusb::extract_header(uint8_t * raw, usb_header * uh) {
|
|||
Int32=(Int32<<8)+raw[4];
|
||||
Int32=(Int32<<8)+raw[5];
|
||||
Int32=(Int32<<8)+raw[6];
|
||||
uh->pkt_size=Int32; //assume third byte is header length
|
||||
uh->pkt_size=Int32; //assume third byte is data length
|
||||
uh->num_chunks=uh->pkt_size/PRIME_RAW_DATA_SIZE;
|
||||
uh->name_length=raw[7];
|
||||
uh->headerlen=11;
|
||||
|
@ -424,8 +422,7 @@ int hpusb::extract_header(uint8_t * raw, usb_header * uh) {
|
|||
.arg(uh->num_chunks).arg(uh->pkt_size).arg(uh->items);
|
||||
qDebug()<<msg;
|
||||
}
|
||||
|
||||
qDebug()<<"Unknown Header Found";
|
||||
qDebug()<<"hpusb::extract_header: Unknown Header Found";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -443,13 +440,13 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
|
|||
int extra=0;
|
||||
int bytes_to_read;
|
||||
int exitflag=1;
|
||||
quint16 crc;
|
||||
quint8 crc;
|
||||
|
||||
uint8_t raw[PRIME_RAW_DATA_SIZE];
|
||||
QByteArray in_buffer(PRIME_RAW_DATA_SIZE,0);
|
||||
libusb_device_handle * devh = handle->usbhandle;
|
||||
|
||||
log("Receive...");
|
||||
log("hpusb::submit_sync_r_transfer: Receive...");
|
||||
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
|
||||
|
||||
if (!handle) {
|
||||
|
@ -465,17 +462,18 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
|
|||
|
||||
while(exitflag) {
|
||||
trans_c=0;
|
||||
|
||||
//read
|
||||
memset(raw,0,PRIME_RAW_DATA_SIZE);
|
||||
if ((ret = libusb_interrupt_transfer(devh,ENDPOINT_IN,raw,PRIME_RAW_DATA_SIZE,&trans_c,TIME_OUT))!=0) {
|
||||
qDebug()<<QString("Read Error %1").arg(libusb_error_name(ret));
|
||||
qDebug()<<QString("hpusb::submit_sync_r_transfer: Read Error %1").arg(libusb_error_name(ret));
|
||||
log(QString("Read Error: %1\n").arg( libusb_error_name(ret)));
|
||||
exitflag=0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((trans_c==0)) {
|
||||
qDebug()<<"End Found";
|
||||
qDebug()<<"hpusb::submit_sync_r_transfer: End Found";
|
||||
exitflag=0;
|
||||
}
|
||||
else
|
||||
|
@ -483,24 +481,25 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
|
|||
extract_header(raw,&uh1);
|
||||
|
||||
if ((uh1.type!=HP_HDR_FILE)) {
|
||||
qDebug()<<"Not a file header exit loop";
|
||||
qDebug()<<"hpusb::submit_sync_r_transfer: Not a file header exit loop";
|
||||
exitflag=0;
|
||||
}
|
||||
|
||||
in_buffer.insert(0,(const char *)&raw[uh1.headerlen],trans_c-uh1.headerlen);
|
||||
in_buffer.resize(trans_c-uh1.headerlen);
|
||||
qDebug()<<QString("hpusb::submit_sync_r_transfer: Read %1: Transfered %2").arg(trans_c).arg(trans_c-uh1.headerlen);
|
||||
trans=trans_c-uh1.headerlen;
|
||||
|
||||
q = (uh1.pkt_size-1)/ (PRIME_RAW_DATA_SIZE);
|
||||
r = uh1.pkt_size % (PRIME_RAW_DATA_SIZE);
|
||||
|
||||
qDebug()<<QString("Looking for %1 chunks and %2 bytes read").arg(q).arg(r);
|
||||
qDebug()<<QString("hpusb::submit_sync_r_transfer: Looking for %1 chunks and %2 bytes read").arg(q).arg(r);
|
||||
|
||||
//read additional chunks if they exist
|
||||
for (chunks=1; chunks<=q; chunks++) {
|
||||
extra++;
|
||||
trans_c=0;
|
||||
qDebug()<<"More Chunks to be read";
|
||||
|
||||
if(chunks<q) {
|
||||
bytes_to_read = PRIME_RAW_DATA_SIZE;
|
||||
}
|
||||
|
@ -508,21 +507,20 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
|
|||
//bytes_to_read=uh1.pkt_size-trans+uh1.headerlen;
|
||||
bytes_to_read = PRIME_RAW_DATA_SIZE;
|
||||
}
|
||||
qDebug()<<"Bytes to read "<<bytes_to_read;
|
||||
// qDebug()<<"Bytes to read "<<bytes_to_read;
|
||||
|
||||
memset(raw,0,PRIME_RAW_DATA_SIZE);
|
||||
ret = libusb_interrupt_transfer(devh,ENDPOINT_IN,raw,PRIME_RAW_DATA_SIZE,&trans_c,TIME_OUT);
|
||||
extract_header(raw, &uh2);
|
||||
qDebug()<<QString("x Reading Chuncks read:%1 should have read:%2").arg(trans_c).arg(bytes_to_read);
|
||||
qDebug()<<QString("hpusb::submit_sync_r_transfer: Reading Chuncks read:%1 should have read:%2").arg(trans_c).arg(bytes_to_read);
|
||||
if (trans_c>0) {
|
||||
qDebug()<<QString("Copying %1 bytes").arg(trans_c);
|
||||
in_buffer.append((const char *)&raw[uh2.headerlen],trans_c-uh2.headerlen);
|
||||
qDebug()<<QString("another chunk read %1/%2").arg(chunks).arg(raw[0]);
|
||||
trans+=trans_c-uh2.headerlen;
|
||||
qDebug()<<QString("hpusb::submit_sync_r_transfer: Read %1: Transfered %2: Buffer now %3 ").arg(trans_c).arg(trans_c-uh2.headerlen).arg(trans);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<<QString("End detected %1").arg(chunks);
|
||||
qDebug()<<QString("hpusb::submit_sync_r_transfer End detected %1").arg(chunks);
|
||||
chunks=q;
|
||||
exitflag=0;
|
||||
ret=0;
|
||||
|
@ -530,39 +528,38 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
|
|||
}
|
||||
}
|
||||
|
||||
qDebug()<<QString("Checking for exit trans:%1 pkt_size:%2").arg(trans).arg(uh1.pkt_size);
|
||||
qDebug()<<QString("hpusb::submit_sync_r_transfer: Checking for exit trans:%1 pkt_size:%2").arg(trans).arg(uh1.pkt_size);
|
||||
if (trans+uh1.headerlen>=uh1.pkt_size) {
|
||||
//qDebug()<<QString("Exit flag set %1 %2").arg(trans).arg(uh1.pkt_size);
|
||||
//exitflag=0;
|
||||
}
|
||||
|
||||
//CRC CHECK HERE
|
||||
// pkt.array=in_buffer.mid(0,uh1.pkt_size-uh1.headerlen+3);
|
||||
|
||||
pkt.array=in_buffer.mid(0,uh1.pkt_size-uh1.headerlen+3);
|
||||
QByteArray temp((const char *)&(uh1.header[0]),14);
|
||||
//PROBLEM : Needed to -1 to get text file to work?
|
||||
pkt.array=in_buffer.mid(0,uh1.pkt_size);
|
||||
|
||||
qDebug()<<QString("hpusb::submit_sync_r_transfer: Read %1: Copied %2 ").arg(trans).arg(pkt.array.size());
|
||||
|
||||
QByteArray temp((const char *)&(uh1.header[0]),uh1.headerlen);
|
||||
temp[7]=0x00;
|
||||
temp[8]=0x00;
|
||||
// qDebug()<<temp;
|
||||
temp.append(pkt.array);
|
||||
crc=crc16_block((uint8_t *)temp.constData(),temp.size());
|
||||
|
||||
//crc= qChecksum(pkt.array,pkt.array.size());
|
||||
qDebug()<<QString("CRC calc: x%1").arg(crc,0,16)<<
|
||||
QString("CRC Expected x%1").arg(uh1.embedded_crc,0,16);
|
||||
qDebug()<<"Dispatching pkt";
|
||||
temp.append(pkt.array);
|
||||
// crc=crc16_block((uint8_t *)temp.constData(),temp.size());
|
||||
crc= qChecksum(pkt.array,pkt.array.size());
|
||||
// crc=crc16_block((uint8_t *)pkt.array.constData(),pkt.array.size());
|
||||
qDebug()<<QString("hpusb::submit_sync_r_transfer: CRC calc: x%1").arg(crc,0,16)<<
|
||||
QString("hpusb::submit_sync_r_transfer: CRC Expected x%1").arg(uh1.embedded_crc,0,16);
|
||||
|
||||
pkt.type=uh1.type;
|
||||
pkt.pkt_type=uh1.pkt_type;
|
||||
data_dispatch(&pkt);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//request to recieve a file transfer
|
||||
int hpusb::data_dispatch(hp_pkt_in * pktin) {
|
||||
|
||||
// qDebug()<<"In data dispatch";
|
||||
|
||||
switch(pktin->type) {
|
||||
case HP_HDR_PNG:
|
||||
send_screen_shot(pktin);
|
||||
|
@ -598,9 +595,9 @@ int hpusb::send_info(hp_pkt_in * pkt) {
|
|||
qDebug()<<"hpusb:In send info";
|
||||
if( pkt->calc!=nullptr) {
|
||||
|
||||
log("unpacking data");
|
||||
log("Unpacking Data");
|
||||
int ind=0;
|
||||
QTextCodec * codec = QTextCodec::codecForName("UTF-16 Little Endian");
|
||||
QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
|
||||
QTextCodec * codec8 = QTextCodec::codecForName("UTF-8");
|
||||
QByteArray rd= pkt->array;
|
||||
|
||||
|
@ -612,17 +609,36 @@ int hpusb::send_info(hp_pkt_in * pkt) {
|
|||
name = codec->toUnicode(str1);
|
||||
hpinfo.name=name;
|
||||
|
||||
|
||||
//unsigned char searchstr[] = {0x80,0x20,0x80,0x01,0x62};
|
||||
//ind+=rd.indexOf((char *) searchstr,ind+64);
|
||||
ind +=64;
|
||||
|
||||
//find Application Version
|
||||
str1 =rd.mid(ind,10);
|
||||
//FIX
|
||||
str1 =rd.mid(ind,12);
|
||||
|
||||
//test
|
||||
QTime t;
|
||||
QDataStream ds1(str1);
|
||||
ds1.setByteOrder(QDataStream::LittleEndian);
|
||||
ds1>>t;
|
||||
qDebug()<<t;
|
||||
|
||||
QDataStream ds(str1);
|
||||
ds.setByteOrder(QDataStream::LittleEndian);
|
||||
|
||||
uint16_t num;
|
||||
int j;
|
||||
qint16 listnum[6];
|
||||
for (j=0;j<6;j++) {
|
||||
ds >> listnum[j];
|
||||
qDebug()<<listnum[j];
|
||||
}
|
||||
//end test
|
||||
qDebug()<<str1;
|
||||
QString app;
|
||||
app = codec8->toUnicode(str1);
|
||||
hpinfo.appver=app;
|
||||
hpinfo.appver=QString("v%1").arg(listnum[4]);
|
||||
log(app);
|
||||
|
||||
//find OS Version
|
||||
|
@ -648,7 +664,6 @@ int hpusb::send_info(hp_pkt_in * pkt) {
|
|||
}
|
||||
else {
|
||||
log("Passed a null pointer");
|
||||
qDebug()<<"send_info - null calc pointer";
|
||||
return 1;
|
||||
}
|
||||
//Error
|
||||
|
@ -665,7 +680,7 @@ int hpusb::send_screen_shot(hp_pkt_in * pkt) {
|
|||
if( pkt->calc!=nullptr) {
|
||||
|
||||
endpos = pkt->array.indexOf("IEND");
|
||||
qDebug()<<"End pos:"<<endpos;
|
||||
qDebug()<<"hpusb::send_screen_shot: End pos:"<<endpos;
|
||||
imageData = QByteArray(pkt->array.mid(0,endpos+4));
|
||||
screenShot = new QPixmap();
|
||||
screenShot->loadFromData(imageData);
|
||||
|
@ -680,16 +695,31 @@ int hpusb::send_screen_shot(hp_pkt_in * pkt) {
|
|||
|
||||
//File Processor
|
||||
int hpusb::send_file(hp_pkt_in * pkt) {
|
||||
qDebug()<<"hpusb:In File Processor";
|
||||
|
||||
qDebug()<<"hpusb::send_file: In File Processor";
|
||||
|
||||
QString filename;
|
||||
|
||||
QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
|
||||
QByteArray rd= pkt->array;
|
||||
|
||||
int len;
|
||||
qint8 crc;
|
||||
|
||||
len = rd[0];
|
||||
|
||||
//TODO
|
||||
|
||||
//What is byte rd[1],rd[2]?
|
||||
//Check if CRC
|
||||
|
||||
QByteArray temp((const char *)pkt->array,pkt->array.size());
|
||||
temp[1]=0x00;
|
||||
temp[2]=0x00;
|
||||
crc=crc16_block((uint8_t *)temp.constData(),temp.size());
|
||||
// crc= qChecksum(pkt.array,pkt.array.size());
|
||||
// crc=crc16_block((uint8_t *)pkt.array.constData(),pkt.array.size());
|
||||
qDebug()<<QString(" hpusb::send_file: CRC calc: %1").arg(crc,0,16)<<
|
||||
QString("hpusb::send_file: CRC Expected %1 %2").arg((qint8)rd[0],1,16).arg((qint8)rd[1],1,16);
|
||||
|
||||
//find file name
|
||||
QByteArray str1 =rd.mid(3,len);
|
||||
filename = codec->toUnicode(str1);
|
||||
|
@ -697,21 +727,27 @@ int hpusb::send_file(hp_pkt_in * pkt) {
|
|||
|
||||
qDebug()<<"hpusb:Checking file type";
|
||||
qDebug()<<QString("File: %1 Type: %2").arg(filename).arg(pkt->pkt_type);
|
||||
qDebug()<<QString("%1 %2 %3").arg((uint8_t)rd[0],1,16).arg((uint8_t)rd[1],1,16).arg((uint8_t)rd[2],1,16);
|
||||
qDebug()<<QString("%1 %2 %3 %4")
|
||||
.arg((uint8_t)rd[0],1,16).arg((uint8_t)rd[1],1,16).arg((uint8_t)rd[2],1,16).arg((uint8_t)rd[3],1,16);
|
||||
|
||||
//handle each file type
|
||||
switch (pkt->pkt_type) {
|
||||
|
||||
case HP_TP_SETTINGS:
|
||||
case HP_TP_SETTINGS: {
|
||||
qDebug()<<"hpusb:File type settings";
|
||||
qDebug()<<filename;
|
||||
hp_Data sData;
|
||||
sData.type=HP_MAIN;
|
||||
sData.name=filename;
|
||||
sData.data=rd.mid(len+3,-1);
|
||||
}
|
||||
break;
|
||||
case HP_TP_FUNCTIONS: {
|
||||
qDebug()<<"hpusb:File functions";
|
||||
hp_Data sData;
|
||||
sData.type=HP_APP;
|
||||
sData.name=filename;
|
||||
sData.data=rd.mid(len,-1);
|
||||
sData.data=rd.mid(len+3,-1);
|
||||
pkt->calc->recvData(sData);
|
||||
}
|
||||
break;
|
||||
|
@ -720,7 +756,7 @@ int hpusb::send_file(hp_pkt_in * pkt) {
|
|||
hp_Data sData;
|
||||
sData.type=HP_LIST;
|
||||
sData.name=filename;
|
||||
sData.data=rd.mid(len,-1);
|
||||
sData.data=rd.mid(len+3,-1);
|
||||
pkt->calc->recvData(sData);
|
||||
}
|
||||
break;
|
||||
|
@ -729,7 +765,7 @@ int hpusb::send_file(hp_pkt_in * pkt) {
|
|||
hp_Data sData;
|
||||
sData.type=HP_MATRIX;
|
||||
sData.name=filename;
|
||||
sData.data=rd.mid(len,-1);
|
||||
sData.data=rd.mid(len+3,-1);
|
||||
pkt->calc->recvData(sData);
|
||||
}
|
||||
break;
|
||||
|
@ -742,8 +778,9 @@ int hpusb::send_file(hp_pkt_in * pkt) {
|
|||
|
||||
qDebug()<<QString("%1 %2 %3").arg((uint8_t)rd[len],1,16).arg((uint8_t)rd[len+1],1,16).arg((uint8_t)rd[len+2],1,16);
|
||||
size=rd[len+1]; //Is the byte a size?
|
||||
QByteArray str1 =rd.mid(len+3,rd.size()-len-3);
|
||||
QByteArray str1 =rd.mid(len+3,-1);
|
||||
note.text = codec->toUnicode(str1);
|
||||
note.data=str1;
|
||||
pkt->calc->recvNote(note);
|
||||
}
|
||||
break;
|
||||
|
@ -756,7 +793,8 @@ int hpusb::send_file(hp_pkt_in * pkt) {
|
|||
|
||||
qDebug()<<QString("%1 %2 %3").arg((uint8_t)rd[len],1,16).arg((uint8_t)rd[len+1],1,16).arg((uint8_t)rd[len+2],1,16);
|
||||
size=rd[len+1];
|
||||
QByteArray str1 =rd.mid(len+3,rd.size()-len-3);
|
||||
QByteArray str1 =rd.mid(len+3,-1);
|
||||
prog.data=str1;
|
||||
prog.prog = codec->toUnicode(str1);
|
||||
pkt->calc->recvProg(prog);
|
||||
}
|
||||
|
|
2
hpusb.h
2
hpusb.h
|
@ -141,10 +141,8 @@ struct hp_Information;
|
|||
|
||||
class hpusb
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
|
||||
struct timespec t1, t2;
|
||||
|
||||
enum {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* libhpcables: hand-helds support libraries.
|
||||
* Copyright (C) 2013 Lionel Debroux
|
||||
* Code patterns and snippets borrowed from libticables & libticalcs:
|
||||
* Copyright (C) 1999-2009 Romain Liévin
|
||||
* Copyright (C) 1999-2009 Romain Liévin
|
||||
* Copyright (C) 2009-2013 Lionel Debroux
|
||||
* Copyright (C) 1999-2013 libti* contributors.
|
||||
*
|
||||
|
@ -144,7 +144,7 @@ HPEXPORT int HPCALL hpcables_exit(void) {
|
|||
|
||||
|
||||
HPEXPORT const char* HPCALL hpcables_version_get (void) {
|
||||
return VERSION;
|
||||
return "Test";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ HPEXPORT int HPCALL hpcalcs_exit(void) {
|
|||
|
||||
|
||||
HPEXPORT const char* HPCALL hpcalcs_version_get (void) {
|
||||
return VERSION;
|
||||
return "Test";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* libhpfiles: hand-helds support libraries.
|
||||
* Copyright (C) 2013 Lionel Debroux
|
||||
* Code patterns and snippets borrowed from libticables & libticalcs:
|
||||
* Copyright (C) 1999-2009 Romain Liévin
|
||||
* Copyright (C) 1999-2009 Romain Liévin
|
||||
* Copyright (C) 2009-2013 Lionel Debroux
|
||||
* Copyright (C) 1999-2013 libti* contributors.
|
||||
*
|
||||
|
@ -149,7 +149,7 @@ HPEXPORT int HPCALL hpfiles_exit(void) {
|
|||
|
||||
|
||||
HPEXPORT const char* HPCALL hpfiles_version_get (void) {
|
||||
return VERSION;
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* libhpopers: hand-helds support libraries.
|
||||
* Copyright (C) 2013 Lionel Debroux
|
||||
* Code patterns and snippets borrowed from libticables & libticalcs:
|
||||
* Copyright (C) 1999-2009 Romain Liévin
|
||||
* Copyright (C) 1999-2009 Romain Liévin
|
||||
* Copyright (C) 2009-2013 Lionel Debroux
|
||||
* Copyright (C) 1999-2013 libti* contributors.
|
||||
*
|
||||
|
@ -121,6 +121,6 @@ HPEXPORT int HPCALL hpopers_exit(void) {
|
|||
|
||||
|
||||
HPEXPORT const char* HPCALL hpopers_version_get (void) {
|
||||
return VERSION;
|
||||
return "VERSION";
|
||||
}
|
||||
|
||||
|
|
118
matrixdata.cpp
Normal file
118
matrixdata.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
#include "matrixdata.h"
|
||||
|
||||
MatrixData::MatrixData()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
//Return the item or a zero item
|
||||
itemData MatrixData::at(int row, int column)
|
||||
{
|
||||
QList<itemData> * rowlist;
|
||||
itemData item;
|
||||
|
||||
if (matrix.size()<row) {
|
||||
rowlist=matrix.at(row);
|
||||
if (rowlist) {
|
||||
if (column<rowlist->size()) {
|
||||
item=rowlist->at(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
//Insert a new item and resize the list if larger
|
||||
void MatrixData::insert(int row, int column, itemData data)
|
||||
{
|
||||
QList<itemData> * rowlist;
|
||||
|
||||
if (matrix.size()<row)
|
||||
rowlist=matrix.at(row);
|
||||
if (rowlist) {
|
||||
if (column<rowlist->size()) {
|
||||
rowlist->insert(column,data);
|
||||
}
|
||||
else {
|
||||
resize();
|
||||
}
|
||||
}
|
||||
else {
|
||||
QList<itemData> * newrow = new QList<itemData>;
|
||||
newrow->insert(column,data);
|
||||
matrix.insert(row,newrow);
|
||||
resize();
|
||||
}
|
||||
}
|
||||
|
||||
//get all columns to same size by padding it zero items
|
||||
void MatrixData::resize() {
|
||||
|
||||
QList<itemData> * row;
|
||||
int rows;
|
||||
int maxrows;
|
||||
int columns;
|
||||
int maxcolumns;
|
||||
int i;
|
||||
int j;
|
||||
itemData item;
|
||||
rows = matrix.size();
|
||||
|
||||
for(i=0;i<rows;i++) {
|
||||
columns=matrix.at(i)->size();
|
||||
if (maxcolumns<columns)
|
||||
maxcolumns=columns;
|
||||
}
|
||||
|
||||
for(i=0;i<rows;i++) {
|
||||
columns=matrix.at(i)->size();
|
||||
if (columns<maxcolumns) {
|
||||
row=matrix.at(i);
|
||||
for(j=columns;j<maxcolumns; j++) {
|
||||
row->insert(j,item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MatrixData::clear()
|
||||
{
|
||||
int i;
|
||||
int r;
|
||||
QList<itemData> * row;
|
||||
|
||||
r=rows();
|
||||
|
||||
for(i=0; i<r;i++) {
|
||||
row=matrix.at(i);
|
||||
if (row) {
|
||||
row->clear();
|
||||
delete row;
|
||||
}
|
||||
}
|
||||
matrix.clear();
|
||||
}
|
||||
|
||||
int MatrixData::columns()
|
||||
{
|
||||
QList<itemData> * row;
|
||||
|
||||
if (matrix.size()>0) {
|
||||
row=matrix.at(0);
|
||||
if (row) {
|
||||
return row->size();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MatrixData::rows()
|
||||
{
|
||||
matrix.size();
|
||||
}
|
||||
|
||||
MatrixData::~MatrixData()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
\
|
28
matrixdata.h
Normal file
28
matrixdata.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef MATRIXDATA_H
|
||||
#define MATRIXDATA_H
|
||||
|
||||
#include <QList>
|
||||
|
||||
struct itemData {
|
||||
double dValue=0.0;
|
||||
QString sValue=QStringLiteral("NaH");
|
||||
};
|
||||
|
||||
|
||||
class MatrixData
|
||||
{
|
||||
private:
|
||||
QList<QList<itemData>*> matrix;
|
||||
|
||||
public:
|
||||
MatrixData();
|
||||
itemData at(int,int);
|
||||
void insert(int,int,itemData);
|
||||
void clear();
|
||||
int rows();
|
||||
int columns();
|
||||
void resize();
|
||||
~ MatrixData();
|
||||
};
|
||||
|
||||
#endif // MATRIXDATA_H
|
|
@ -1,27 +1,81 @@
|
|||
#include "global.h"
|
||||
#include "vartablemodel.h"
|
||||
#include "abstractdata.h"
|
||||
|
||||
varTableModel::varTableModel(QObject *parent)
|
||||
varTableModel::varTableModel(QObject *parent,
|
||||
hpCalcData * dataStore,
|
||||
QString file,
|
||||
hp_DataType dtype)
|
||||
:QAbstractTableModel(parent)
|
||||
{
|
||||
hpcalc = dataStore;
|
||||
filename=file;
|
||||
type=dtype;
|
||||
setup();
|
||||
}
|
||||
|
||||
void varTableModel::setup()
|
||||
{
|
||||
if (hpcalc) {
|
||||
|
||||
dataobj=hpcalc->getData(filename,type);
|
||||
|
||||
// qDebug()<<"varTableModel: type"<<dataobj->getType();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int varTableModel::rowCount(const QModelIndex & /*parent*/) const
|
||||
{
|
||||
return 16;
|
||||
int size=16; //should be zero
|
||||
if (type==HP_LIST) {
|
||||
List * list;
|
||||
list = (List *)dataobj;
|
||||
size= list->getListSize();
|
||||
}
|
||||
if (type==HP_MATRIX) {
|
||||
Matrix * matrix;
|
||||
matrix = (Matrix *)dataobj;
|
||||
size= matrix->getMatrixRows();
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int varTableModel::columnCount(const QModelIndex & /*parent*/) const
|
||||
{
|
||||
return 1;
|
||||
int size=1;
|
||||
if (type==HP_MATRIX) {
|
||||
Matrix * matrix;
|
||||
matrix = (Matrix *)dataobj;
|
||||
size= matrix->getMatrixColumns();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
QVariant varTableModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
if (role == Qt::DisplayRole) {
|
||||
|
||||
QString item;
|
||||
|
||||
if (type==HP_LIST) {
|
||||
List * list;
|
||||
list = (List *)dataobj;
|
||||
item = list->getItem(index.row());
|
||||
return item;
|
||||
}
|
||||
if (type==HP_MATRIX) {
|
||||
Matrix * matrix;
|
||||
matrix = (Matrix *)dataobj;
|
||||
item = matrix->getItem(index.row(),index.column());
|
||||
return item;
|
||||
}
|
||||
|
||||
return QString("Row%1, Column%2")
|
||||
.arg(index.row() + 1)
|
||||
.arg(index.column() +1);
|
||||
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
|
|
@ -3,12 +3,26 @@
|
|||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
#include "hpdata.h"
|
||||
#include "abstractdata.h"
|
||||
|
||||
class varTableModel: public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
hpCalcData * hpcalc =nullptr;
|
||||
QString filename;
|
||||
hp_DataType type;
|
||||
AbstractData * dataobj =nullptr;
|
||||
QList<QList<double>> dataarray;
|
||||
void setup();
|
||||
|
||||
public:
|
||||
varTableModel(QObject *parent = nullptr);
|
||||
varTableModel(QObject *parent = nullptr,
|
||||
hpCalcData * dataStore =nullptr,
|
||||
QString file = QStringLiteral(""),
|
||||
hp_DataType dtype = HP_MAIN);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
|
Loading…
Reference in a new issue