commit dc46de78901ea08c284ab887e411ca530e0f9fdf
Author: d3fault <d3fault@d3fault.net>
Date:   Mon May 29 17:02:44 2017 -0700

    wasdf: wrote pc sending side of checksumming

diff --git a/.lastModifiedTimestamps b/.lastModifiedTimestamps
index 23c3158..1d7dccf 100644
--- a/.lastModifiedTimestamps
+++ b/.lastModifiedTimestamps
@@ -5932,18 +5932,18 @@ Projects/wasdf/design/checksummed.message.protocol.txt:1496025143
Projects/wasdf/design/mouse.action.serialization.stream.is.likely.to.become.desynced.and.cause.total.system.failure.here.is.a.solution.to.it.but.also.the.keyboard.could.desync.too.etc.txt:1495912877
Projects/wasdf/design/pin.detection.and.finger.mapping.are.same.step.as.calibration.txt:1495315077
Projects/wasdf/design/renaming.from.MusicFingers.txt:1495250184
Projects/wasdf/src/:1495913297Projects/wasdf/src/:1496102485
Projects/wasdf/src/cli/:1495395081
Projects/wasdf/src/cli/main.cpp:1495395081
Projects/wasdf/src/cli/wasdfcli.cpp:1495394570
Projects/wasdf/src/cli/wasdfcli.h:1495394574
Projects/wasdf/src/lib/:1495913246Projects/wasdf/src/lib/:1496102440
Projects/wasdf/src/lib/fingeriteratororderedbymostusedfingers.cpp:1495480054
Projects/wasdf/src/lib/fingeriteratororderedbymostusedfingers.h:1495480049
Projects/wasdf/src/lib/wasdf.cpp:1495770648
Projects/wasdf/src/lib/wasdf.h:1495654643
Projects/wasdf/src/lib/wasdfarduino.cpp:1495656263
Projects/wasdf/src/lib/wasdfarduino.h:1495419683Projects/wasdf/src/lib/wasdfarduino.cpp:1496102440
Projects/wasdf/src/lib/wasdfarduino.h:1496101750
Projects/wasdf/src/lib/wasdfcalibrationatrestdetector.cpp:1495592857
Projects/wasdf/src/lib/wasdfcalibrationatrestdetector.h:1495591219
Projects/wasdf/src/lib/wasdfcalibrationconfigurationsettingsreaderwriter.cpp:1495913246
diff --git a/Projects/wasdf/src/lib/wasdfarduino.cpp b/Projects/wasdf/src/lib/wasdfarduino.cpp
index 177d431..78533eb 100644
--- a/Projects/wasdf/src/lib/wasdfarduino.cpp
+++ b/Projects/wasdf/src/lib/wasdfarduino.cpp
@@ -3,6 +3,7 @@
#include <QtSerialPort/QSerialPort>
#include <QStringList>
#include <QHashIterator>
#include <QCryptographicHash>
#include <QDebug>

#include "wasdf.h"
@@ -40,11 +41,35 @@ void WasdfArduino::openSerialPortIfNotOpen()
        }
    }
}
QByteArray WasdfArduino::checksum(const QByteArray &input)
{
    return QCryptographicHash::hash(input, QCryptographicHash::Md5); //MD5 is overkill for checksum, but underkill for cyrpto. I had trouble getting numerous other checksums and cryptographic hashes working on my arduino (or they had insufficient (or no) licensing)
}
void WasdfArduino::sendCommandToArduino(const QString &commandToSendToArduino)
{
    Q_ASSERT(commandToSendToArduino.length()//send SYNC, then checksumOfSize, then sizeOfData, then checksumOfData, then commandToSendToArduino, which should (will TODOreq) be a json document in string form
    //m_SerialPortTextStream << "SYNC";
    //m_SerialPortTextStream << checksumOfData;
    //^this isn't like QDataStream, I'm sending the ASCII representation of numbers when I do it like this. so maybe I should NOT use a textStream so my commands are binary? the problem, then, becomes portability. I'm pretty damn sure Arduino uses a stable integer size, so if I use qint32 (etc) then I should be able to always work with arduino
    QByteArray sync("SYNC"); //TODOoptimization: make this a member and it's initialization in construction phase
    QByteArray commandToSendToArduinoAsLatin1(commandToSendToArduino.toLatin1());
    typedef qint32 size_t_ofSizeOfCommand;
    size_t_ofSizeOfCommand sizeOfCommand = commandToSendToArduino.size();
    QByteArray sizeOfCommandAsByteArray = QByteArray::fromRawData((const char*)(&sizeOfCommand), sizeof(size_t_ofSizeOfCommand));
    QByteArray checksumOfSizeOfCommand = checksum(sizeOfCommandAsByteArray);
    qDebug() << checksumOfSizeOfCommand.size(); //TODOreq: this is for testing only. I think it should be 4 bytes?
    QByteArray checksumOfCommand = checksum(commandToSendToArduinoAsLatin1);

    m_SerialPort->write(sync); //fixed size
    m_SerialPort->write(checksumOfSizeOfCommand); //fixed size
    m_SerialPort->write(sizeOfCommandAsByteArray); //fixed size
    m_SerialPort->write(checksumOfCommand); //fixed size
    m_SerialPort->write(commandToSendToArduinoAsLatin1); //variable size

    //TODOreq: merge below with above
    //Q_ASSERT(commandToSendToArduino.length() < (1024)); //TODOreq: 1024 should be in a shared header file between sketch and this. the arduino calls String.reserve(1024) in setup()
    m_SerialPortTextStream//m_SerialPortTextStream << commandToSendToArduino << "\n"; //don't use endl, that uses \r\n sometimes I think but might be wrong since the QIODevice isn't using QIODevice::Text? fuggit
    m_SerialPortTextStream.flush();//m_SerialPortTextStream.flush();
}
void WasdfArduino::startInCalibrationMode()
{
diff --git a/Projects/wasdf/src/lib/wasdfarduino.h b/Projects/wasdf/src/lib/wasdfarduino.h
index ca0e399..a43cacf 100644
--- a/Projects/wasdf/src/lib/wasdfarduino.h
+++ b/Projects/wasdf/src/lib/wasdfarduino.h
@@ -16,6 +16,7 @@ public:
    explicit WasdfArduino(QObject *parent = 0);
private:
    void openSerialPortIfNotOpen();
    static QByteArray checksum(const QByteArray &input);
    void sendCommandToArduino(const QString &command);

    QSerialPort *m_SerialPort;