diff options
-rw-r--r-- | smartpen.cc | 26 | ||||
-rw-r--r-- | smartpen.h | 15 | ||||
-rw-r--r-- | smartpensyncer.cc | 10 |
3 files changed, 40 insertions, 11 deletions
diff --git a/smartpen.cc b/smartpen.cc index 686170d..12e2ac2 100644 --- a/smartpen.cc +++ b/smartpen.cc @@ -87,7 +87,7 @@ QByteArray Smartpen::getObject(const QString &name) QByteArray Smartpen::getParameter(Parameter parameter) { - QString objectName = QString("ppdata?key=pp%1").arg(uint(parameter), 4, 16); + QString objectName = QString("ppdata?key=pp%1").arg(uint(parameter), 4, 16, QChar('0')); QByteArray data = getObject(objectName); QXmlStreamReader r(data); @@ -109,14 +109,34 @@ QByteArray Smartpen::getParameter(Parameter parameter) return QByteArray(); } +Smartpen::PenId Smartpen::getPenId() +{ + PenId id; + QByteArray value = getParameter(Parameter::Id); + if (value.isEmpty() || value.size() != 1 + sizeof(Smartpen::PenId)) { + qWarning() << "got invalid value for pen id: " << value.toHex(); + return 0; + } + QDataStream ds(value); + ds.setByteOrder(QDataStream::BigEndian); + ds.skipRawData(1); // Unclear what first byte is + ds >> id; + return id; +} + +QString Smartpen::getPenSerial() +{ + return toPenSerial(getPenId()); +} + QString Smartpen::getPenName() { - return QString::fromUtf8(getParameter(PenName)); + return QString::fromUtf8(getParameter(Parameter::Name)); } Smartpen::PenTime Smartpen::getPenTime(Parameter parameter) { - Smartpen::PenTime time; + PenTime time; QByteArray value = getParameter(parameter); if (value.isEmpty() || value.size() != sizeof(Smartpen::PenTime)) { qWarning() << "got invalid value for pen time: " << value.toHex(); @@ -45,18 +45,21 @@ public: bool isConnected() const; - enum Parameter : quint16 { - /// The offset between the PenTime (see below) and the user's configured time. This value is static. - PenUserTime = 0x8003, + enum class Parameter : quint16 { + Id = 0x0000, + /// The offset between the RtcTime (see below) and the user's configured time. This value is fixed at setup time. + UserTime = 0x8003, /// The current time as reported by the pen's rtc - PenRtcTime = 0x8004, - PenType = 0x8006, - PenName = 0x8011 + RtcTime = 0x8004, + Type = 0x8006, + Name = 0x8011 }; QByteArray getObject(const QString& name); QByteArray getParameter(Parameter parameter); + PenId getPenId(); + QString getPenSerial(); QString getPenName(); PenTime getPenTime(Parameter parameter); diff --git a/smartpensyncer.cc b/smartpensyncer.cc index 794b7c5..3556f77 100644 --- a/smartpensyncer.cc +++ b/smartpensyncer.cc @@ -181,6 +181,12 @@ void SmartpenSyncer::run() _penName = _pen->getPenName(); qDebug() << "got pen name:" << _penName; + + if (_penName.isEmpty()) { + _penName = _pen->getPenSerial(); + qDebug() << "pen with no name, using pen serial instead:" << _penName; + } + emit gotPenName(_penName); QVariantMap penInfo = _pen->getPenInfo(); @@ -222,11 +228,11 @@ bool SmartpenSyncer::syncPen() // Get the current user time offset from the pen // and store it so that we have it even when the pen is offline TimestampFile userTimeFile(_penDataDir.filePath(PEN_USER_TIME_FILE)); - Smartpen::PenTime userTime = _pen->getPenTime(Smartpen::PenUserTime); + Smartpen::PenTime userTime = _pen->getPenTime(Smartpen::Parameter::UserTime); userTimeFile.set(userTime); qDebug() << "pen time base:" << userTime << Smartpen::fromPenTime(userTime, 0); - Smartpen::PenTime penTime = _pen->getPenTime(Smartpen::PenRtcTime); + Smartpen::PenTime penTime = _pen->getPenTime(Smartpen::Parameter::RtcTime); qDebug() << "pen current time:" << penTime << Smartpen::fromPenTime(userTime, penTime); // Read when is the last time we synchronized with this pen (in PenTime, not user time) |