30,6 → 30,7 |
#include <assert.h> |
#include <kmessagebox.h> |
#include <klocale.h> |
#include <qfileinfo.h> |
|
static char G50_KEY[] = "A8A423B9F55E63C1"; // garmin network key |
|
78,17 → 79,17 |
qFile = false; |
} |
|
device.setName (fl.name ()); |
device.setFileName (fl.fileName ()); |
|
if (!device.exists ()) |
{ |
KMessageBox::error (0, i18n("Device %1 does not exist!").arg(fl.name())); |
KMessageBox::error (0, i18n("Device %1 does not exist!").arg(fl.fileName())); |
return false; |
} |
|
if (!device.open (IO_Raw | IO_ReadWrite)) |
if (!device.open (QIODevice::ReadWrite)) |
{ |
KMessageBox::error (0, i18n("Error opening device %1.").arg(fl.name()), |
KMessageBox::error (0, i18n("Error opening device %1.").arg(fl.fileName()), |
device.errorString()); |
return false; |
} |
107,7 → 108,7 |
qFile = false; |
} |
|
f.setName (fl); |
f.setFileName (fl); |
return setDevice (f); |
} |
|
138,7 → 139,7 |
|
if ((4 + i) != (nw = write(device.handle(), buf, 4 + i))) |
{ |
KMessageBox::error (0, i18n("Error writing to device %1").arg(device.name())); |
KMessageBox::error (0, i18n("Error writing to device %1").arg(device.fileName())); |
return false; |
} |
|
620,9 → 621,9 |
state = 0; |
authfd = false; |
|
faf.setName (af); |
faf.setFileName (af); |
|
if (!faf.open (IO_Raw | IO_ReadWrite)) |
if (!faf.open (QIODevice::ReadWrite)) |
{ |
KMessageBox::error (0, i18n("Error opening device %1.").arg(af), |
faf.errorString()); |
630,6 → 631,7 |
|
authfile = af; |
authfd = true; |
tmpOut.setFileName(QString(tmpnam(NULL))); |
} |
|
gant::~gant () |
636,6 → 638,10 |
{ |
if (authfd) |
faf.close(); |
|
// if the file is still open, this function closes it before |
// it is removed. |
tmpOut.remove(); |
} |
|
uint gant::randno () |
685,7 → 691,7 |
// garmin moved to phase 1 in response to sendack1 |
int nr; |
// printf("reading auth data from %s\n", authfile); |
authfd = open(authfile, O_RDONLY); |
authfd = open(authfile.toAscii(), O_RDONLY); |
|
if (!authfd || faf.size () < 32) |
{ |
862,13 → 868,16 |
{ |
fprintf(stderr, "receiving\n"); |
once = 1; |
tmpOut.open (QIODevice::ReadWrite | QIODevice::Truncate); |
} |
|
nw = write(faf.handle(), cbuf, 8); |
// FIXME: Here we should fill our buffer, instead of writing |
// everything into a file. |
nw = write(tmpOut.handle(), cbuf, 8); |
|
if (nw != 8) |
{ |
KMessageBox::error(0, i18n ("Write to auth file %1 failed!").arg(authfile)); |
KMessageBox::error(0, i18n ("Failed to write to a temporary file!")); |
return false; |
} |
|
876,6 → 885,7 |
{ |
state++; // just to exit |
//state = 20; // to delete logs |
tmpOut.close(); |
} |
} |
else if (state == 10) |
974,7 → 984,7 |
|
case MESG_OPEN_CHANNEL_ID: |
state++; |
fprintf(stderr, "channel open, waiting for broadcast\n", state); |
fprintf(stderr, "channel open (%d), waiting for broadcast\n", state); |
break; |
|
default: |
1108,3 → 1118,45 |
|
return commfn (); |
} |
|
uchar *gant::getBuffer (int *size) |
{ |
QFileInfo fi; |
uchar *buffer; |
long sz; |
|
fi.setFile (tmpOut); |
|
if (!fi.exists() || fi.size() > 1000000) |
return 0; |
|
sz = fi.size(); |
*size = 0; |
|
if (!(buffer = new uchar[sz+1])) |
{ |
KMessageBox::error(0, i18n("Error allocating %1 bytes of memory!").arg(sz+1)); |
return 0; |
} |
|
if (tmpOut.handle() == -1) |
{ |
if (!tmpOut.open(QIODevice::ReadOnly)) |
{ |
KMessageBox::error(0, i18n("Error opening a temporary file for reading!"), tmpOut.errorString()); |
delete buffer; |
return 0; |
} |
} |
|
if (read (tmpOut.handle(), buffer, sz) < sz) |
{ |
KMessageBox::error(0, i18n("Error reading from a temporary file!")); |
tmpOut.close(); |
delete buffer; |
return 0; |
} |
|
*size = (int)sz; |
return buffer; |
} |