diff options
Diffstat (limited to 'smartpen.cc')
-rw-r--r-- | smartpen.cc | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/smartpen.cc b/smartpen.cc index 6df3fd1..13743ab 100644 --- a/smartpen.cc +++ b/smartpen.cc @@ -1,16 +1,20 @@ #include <QtCore/QDateTime> #include <QtCore/QDebug> +#include <QtCore/QStringList> #include <QtCore/QtEndian> #include <usb.h> #include "xmlutils.h" #include "smartpen.h" -#define PEN_EPOCH (1289335960000LL) +#define PEN_EPOCH (1289335960000LL) // This is probably not correct #define PEN_MTU 900 #define PEN_TIMEOUT_SECONDS 10 #define INVALID_CID 0xFFFFFFFFU +static const char pen_serial_chars[] = "ABCDEFGHJKMNPQRSTUWXYZ23456789"; +static const unsigned int pen_serial_num_chars = sizeof(pen_serial_chars) - 1; + /* Terrible hack comes now: */ struct obex_usb_intf_transport_t { struct obex_usb_intf_transport_t *prev, *next; /* Next and previous interfaces in the list */ @@ -155,6 +159,10 @@ QList<Smartpen::ChangeReport> Smartpen::getChangeList(const QDateTime &from) report.guid = attrs.value("guid").toString(); report.title = attrs.value("title").toString(); result.append(report); + } else if (attrs.hasAttribute("classname")) { + report.className = attrs.value("classname").toString(); + report.title = attrs.value("title").toString(); + result.append(report); } r.skipCurrentElement(); } else { @@ -174,6 +182,11 @@ QByteArray Smartpen::getLspData(const QString &name, const QDateTime &from) return getObject(QString("lspdata?name=%1&start_time=%2").arg(name).arg(toPenTime(from))); } +QByteArray Smartpen::getPaperReplay(const QDateTime &from) +{ + return getObject(QString("lspdata?name=com.livescribe.paperreplay.PaperReplay&start_time=%1&returnVersion=0.3&remoteCaller=WIN_LD_200").arg(toPenTime(from))); +} + qint64 Smartpen::toPenTime(const QDateTime &dt) { if (dt.isValid()) { @@ -208,6 +221,19 @@ QString Smartpen::toPenSerial(quint64 id) return serial; } +quint64 Smartpen::toPenId(const QString &serial) +{ + QStringList segments = serial.split('-'); + if (segments.size() != 4) { + return 0; + } + + quint64 id = quint64(fromPenSerialSegment(segments[0])) << 32; + id |= fromPenSerialSegment(segments[1] + segments[2]) * 0x36D; + id |= fromPenSerialSegment(segments[3]); + return id; +} + bool Smartpen::connectToPen(const Address &addr) { if (_obex) { @@ -389,19 +415,31 @@ void Smartpen::handleObexRequestDone(obex_object_t *object, int obex_cmd, int ob QString Smartpen::toPenSerialSegment(quint32 id, int len) { - static const char chars[] = "ABCDEFGHJKMNPQRSTUWXYZ23456789"; - static const unsigned int num_chars = sizeof(chars) - 1; QString segment(len, Qt::Uninitialized); for (int i = 0; i < len; i++) { - segment[len - (i + 1)] = chars[id % num_chars]; - id /= num_chars; + segment[len - (i + 1)] = pen_serial_chars[id % pen_serial_num_chars]; + id /= pen_serial_num_chars; } return segment; } +quint32 Smartpen::fromPenSerialSegment(const QString &s) +{ + const int len = s.length(); + quint32 id = 0; + + for (int i = 0; i < len; i++) { + uint val = qFind(&pen_serial_chars[0], &pen_serial_chars[pen_serial_num_chars], s[i]) - &pen_serial_chars[0]; + if (val >= pen_serial_num_chars) return 0; + id = val + id * pen_serial_num_chars; + } + + return id; +} + QByteArray Smartpen::encodeUtf16(const QString &s) { const int size = s.size(); |