mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-17 11:10:45 +00:00
CMS50 Importer Bug fixes
This commit is contained in:
parent
4dfa38bc41
commit
79a2b1abc3
56
oximetry.cpp
56
oximetry.cpp
@ -1,5 +1,6 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QProgressBar>
|
#include <QProgressBar>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "oximetry.h"
|
#include "oximetry.h"
|
||||||
#include "ui_oximetry.h"
|
#include "ui_oximetry.h"
|
||||||
@ -410,6 +411,9 @@ void DumpBytes(int blocks, unsigned char * b,int len)
|
|||||||
// Move this code to CMS50 Importer??
|
// Move this code to CMS50 Importer??
|
||||||
void Oximetry::on_ImportButton_clicked()
|
void Oximetry::on_ImportButton_clicked()
|
||||||
{
|
{
|
||||||
|
QMessageBox msgbox(QMessageBox::Information,"Importing","Please Wait",QMessageBox::NoButton,this);
|
||||||
|
msgbox.show();
|
||||||
|
|
||||||
Machine *mach=profile->GetMachine(MT_OXIMETER);
|
Machine *mach=profile->GetMachine(MT_OXIMETER);
|
||||||
if (!mach) {
|
if (!mach) {
|
||||||
CMS50Loader *l=dynamic_cast<CMS50Loader *>(GetLoader("CMS50"));
|
CMS50Loader *l=dynamic_cast<CMS50Loader *>(GetLoader("CMS50"));
|
||||||
@ -419,14 +423,15 @@ void Oximetry::on_ImportButton_clicked()
|
|||||||
|
|
||||||
qDebug() << "Needed to create Oximeter device";
|
qDebug() << "Needed to create Oximeter device";
|
||||||
}
|
}
|
||||||
unsigned char b1[2];
|
const int rb_size=0x200;
|
||||||
unsigned char b2[3];
|
static unsigned char b1[2]={0xf5,0xf5};
|
||||||
unsigned char rb[0x20];
|
static unsigned char b2[3]={0xf6,0xf6,0xf6};
|
||||||
b1[0]=0xf5;
|
static unsigned char rb[rb_size];
|
||||||
b1[1]=0xf5;
|
//b1[0]=0xf5;
|
||||||
b2[0]=0xf6;
|
//b1[1]=0xf5;
|
||||||
b2[1]=0xf6;
|
//b2[0]=0xf6;
|
||||||
b2[2]=0xf6;
|
//b2[1]=0xf6;
|
||||||
|
//b2[2]=0xf6;
|
||||||
unsigned char * buffer=NULL;
|
unsigned char * buffer=NULL;
|
||||||
ui->SerialPortsCombo->setEnabled(false);
|
ui->SerialPortsCombo->setEnabled(false);
|
||||||
ui->RunButton->setText("&Start");
|
ui->RunButton->setText("&Start");
|
||||||
@ -472,26 +477,34 @@ void Oximetry::on_ImportButton_clicked()
|
|||||||
qprogress->show();
|
qprogress->show();
|
||||||
int fails=0;
|
int fails=0;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
|
||||||
//port->setRts(true);
|
|
||||||
if (port->write((char *)b1,2)==-1) {
|
if (port->write((char *)b1,2)==-1) {
|
||||||
qDebug() << "Couldn't write 2 lousy bytes to CMS50";
|
qDebug() << "Couldn't write 2 lousy bytes to CMS50";
|
||||||
}
|
}
|
||||||
//usleep(500);
|
|
||||||
// port->setRts(false);
|
|
||||||
//qDebug() << "Available " << port->bytesAvailable();
|
|
||||||
blocks=0;
|
blocks=0;
|
||||||
int startpos=0;
|
int startpos=0;
|
||||||
unsigned int length=0;
|
unsigned int length=0;
|
||||||
|
int dr;
|
||||||
|
int ec;
|
||||||
do {
|
do {
|
||||||
bool fnd=false;
|
bool fnd=false;
|
||||||
res=port->read((char *)rb,0x20);
|
dr=0;
|
||||||
|
ec=0;
|
||||||
|
do {
|
||||||
|
res=port->read((char *)rb,rb_size);
|
||||||
DumpBytes(blocks,rb,res);
|
DumpBytes(blocks,rb,res);
|
||||||
|
if (blocks>0) break;
|
||||||
|
if (res<=0) ec++;
|
||||||
|
dr+=res;
|
||||||
|
} while ((res<=5) && (dr<0x200) && (ec<5));
|
||||||
|
|
||||||
|
//if (res>5) DumpBytes(blocks,rb,res);
|
||||||
|
|
||||||
|
|
||||||
done=false;
|
done=false;
|
||||||
if (blocks==0) {
|
if (blocks==0) {
|
||||||
for (int i=0;i<res-1;i++) {
|
if (res>5)
|
||||||
if ((rb[i]==0xf2) && (rb[i+1]==0x80)) { // && (rb[i+2]==0x00)) {
|
for (int i=0;i<res-2;i++) {
|
||||||
|
if ((rb[i]==0xf2) && (rb[i+1]==0x80) && (rb[i+2]==0x00)) {
|
||||||
fnd=true;
|
fnd=true;
|
||||||
startpos=i+9;
|
startpos=i+9;
|
||||||
break;
|
break;
|
||||||
@ -509,13 +522,17 @@ void Oximetry::on_ImportButton_clicked()
|
|||||||
// 84 95 7c
|
// 84 95 7c
|
||||||
// 0x10556 bytes..
|
// 0x10556 bytes..
|
||||||
// 0x82b blocks
|
// 0x82b blocks
|
||||||
length=(rb[startpos++] & 0x7f) << 14;
|
length=0;
|
||||||
|
while (rb[startpos]!=0xf0) {
|
||||||
|
length=(length << 7) | (rb[startpos++] & 0x7f);
|
||||||
|
}
|
||||||
|
/*length=(rb[startpos++] & 0x7f) << 14;
|
||||||
length|=(rb[startpos++] & 0x7f) << 7;
|
length|=(rb[startpos++] & 0x7f) << 7;
|
||||||
length|=(rb[startpos++] & 0x7f);
|
length|=(rb[startpos++] & 0x7f);
|
||||||
if (!(rb[startpos]&0x80)) {
|
if (!(rb[startpos]&0x80)) {
|
||||||
length <<= 8;
|
length <<= 8;
|
||||||
length|=rb[startpos++];
|
length|=rb[startpos++];
|
||||||
}
|
}*/
|
||||||
/*length=(rb[startpos] ^ 0x80)<< 7 | (rb[startpos+1]);
|
/*length=(rb[startpos] ^ 0x80)<< 7 | (rb[startpos+1]);
|
||||||
startpos+=2;
|
startpos+=2;
|
||||||
if (!(rb[startpos]&0x80)) {
|
if (!(rb[startpos]&0x80)) {
|
||||||
@ -534,7 +551,7 @@ void Oximetry::on_ImportButton_clicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
blocks++;
|
blocks++;
|
||||||
if (res<0x20) {
|
if (res<rb_size) {
|
||||||
qDebug() << "Read "<< bytes << " bytes of " << length;
|
qDebug() << "Read "<< bytes << " bytes of " << length;
|
||||||
done=true;
|
done=true;
|
||||||
break;
|
break;
|
||||||
@ -599,6 +616,7 @@ void Oximetry::on_ImportButton_clicked()
|
|||||||
}
|
}
|
||||||
delete port;
|
delete port;
|
||||||
port=NULL;
|
port=NULL;
|
||||||
|
msgbox.hide();
|
||||||
qprogress->hide();
|
qprogress->hide();
|
||||||
ui->SerialPortsCombo->setEnabled(true);
|
ui->SerialPortsCombo->setEnabled(true);
|
||||||
qstatus->setText("Ready");
|
qstatus->setText("Ready");
|
||||||
|
Loading…
Reference in New Issue
Block a user