commit 5f9b051e4244afabc3fc6301bcd40fc0b870f551
Author: d3fault <d3fault@d3fault.net>
Date:   Tue May 30 16:20:15 2017 -0700

    wasdf: refactor message checksumming/headers sending on pc side because my testing of binary protocol didn't work and this will make things easier to understand at least, even though it'll be less efficient

diff --git a/.lastModifiedTimestamps b/.lastModifiedTimestamps
index 41dd9e6..46efb37 100644
--- a/.lastModifiedTimestamps
+++ b/.lastModifiedTimestamps
@@ -44,7 +44,7 @@ Documents/minddump/2016/4/1459968855-LhX846.txt:1459969203
Documents/minddump/2016/4/1459969303-nnS846.txt:1459969688
Documents/minddump/2016/4/1459984685-TJ2423.txt:1459985236
Documents/minddump/2017/:1495179528
Documents/minddump/2017/5/:1496026763Documents/minddump/2017/5/:1496184085
Documents/minddump/2017/5/1495171253-Kauai.0a-MTJ783.txt:1495179507
Documents/minddump/2017/5/1495214940-MTJ843.txt:1495215210
Documents/minddump/2017/5/1495323758-TJ2659.txt:1495323774
@@ -70,6 +70,7 @@ Documents/minddump/2017/5/1496022570-LhX790.txt:1496022707
Documents/minddump/2017/5/1496023209-MTJ782.txt:1496023629
Documents/minddump/2017/5/1496023906-MTJ789.txt:1496024169
Documents/minddump/2017/5/1496026719-MTJ876.txt:1496026750
Documents/minddump/2017/5/1496183595-LhX832.txt:1496184067
Documents/minddump/couchbase/:1340207540
Documents/minddump/couchbase/Couchbase.Questions.for.forum.or.something.txt:1340102585
Documents/minddump/couchbase/asflksjdfoiuwerlkjsdfouwrlkjsdfasou.txt:1340015923
@@ -4105,7 +4106,7 @@ Projects/LossyDirectoryCopier/src/main.cpp:1386648220
Projects/MindDumper/:1496033126
Projects/MindDumper/design/:1456001533
Projects/MindDumper/design/initial.idea.txt:1456001533
Projects/MindDumper/src/:1496100200Projects/MindDumper/src/:1496183557
Projects/MindDumper/src/MindDumper.pro:1496029635
Projects/MindDumper/src/main.cpp:1495215671
Projects/MindDumper/src/minddumpdocument.cpp:1456174998
@@ -5923,8 +5924,8 @@ Projects/libAvGraphicsItem3/src/main.cpp:1327003410
Projects/wasdf/:1496105472
Projects/wasdf/assets/:1463107603
Projects/wasdf/assets/ArduinoSketches/:1463107625
Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/:1496176139
Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino:1496176139Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/:1496185352
Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino:1496185352
Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/Makefile:1495394559
Projects/wasdf/design/:1496025670
Projects/wasdf/design/checksummed.message.protocol.notes.on.when.to.read.the.message.header.txt:1496025871
@@ -5932,17 +5933,17 @@ 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/:1496108230Projects/wasdf/src/:1496186324
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/:1496106289Projects/wasdf/src/lib/:1496186294
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:1496106289Projects/wasdf/src/lib/wasdfarduino.cpp:1496186294
Projects/wasdf/src/lib/wasdfarduino.h:1496101750
Projects/wasdf/src/lib/wasdfcalibrationatrestdetector.cpp:1495592857
Projects/wasdf/src/lib/wasdfcalibrationatrestdetector.h:1495591219
diff --git a/Documents/minddump/2017/5/1496183595-LhX832.txt b/Documents/minddump/2017/5/1496183595-LhX832.txt
new file mode 100644
index 0000000..0a57dda
--- /dev/null
+++ b/Documents/minddump/2017/5/1496183595-LhX832.txt
@@ -0,0 +1,9 @@
By saying (understanding?) "At least I can save myself", and then doing so, I become a part of the problem. We, as a species, have really bad case of voters fallacy. If we were to all simultaneously try to "save everyone", then it would work.

OT'ish: I am saving myself, but I'm not going to be a hypocrite about it; I admit that in doing so I am part of the problem.

I don't really want to [waste my time] but I can't live with myself if I don't at least dispatch a low priority background thread to try to solve the problem. We really just need a vote, but I'm not even sure such "federal doanything" votes exist. states have them apparently (weed just become legal because of popular vote), but does the federal government? I don't think it does, which means in it's current form (had:state) it's a piece of shit. I, a citizen, must be able to call to vote anything at all on a federal level. If the "constitution" or whatever core document doesn't allow for this, it should be altered (or rewritten) so that it does. If you say "but a cititzen can't modify those core documents", then I question the validity of those documents to begin with; after all, they were made by just random ass humans (that gave themselves fancy titles, but that's irrelevant).

A politician can't block this because the entire purpose of it is to side-step political corruption in the first place.

Meh in all honesty, holding a vote yourself and it passing is plausible, but what then? Aren't taxes supposed to be used to create those solar powered food farms? Randomly winning some "unofficial" (by their definition) vote doesn't all-of-the-sudden give you tax spending abilities. Remember they'd DIE before giving up their power? Hmm so the vote would need to be official -- meh this'd never happen (but still I should press on (low priority background task), I must. I can't not)
diff --git a/Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino b/Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino
index 0abc3f2..3b55c39 100644
--- a/Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino
+++ b/Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino
@@ -25,18 +25,19 @@ static const int MAX_MESSAGE_SIZE = 1024;
//TODOmb: when in calibrating mode maybe I should blink pin 13 rapidly, and when normal mode starts I should do 3 long pulses and then disable it (because leaving it on is dumb)
//TODOreq: during testing I noticed that the analog pin values with no sensor connected were "floating". not floating point or whatever, but their values were not zero and they also weren't consistent. they seemed to change WITH the analog pin that had a sensor connected, as it moved (I only tested with 1, but it probably applies with more than 1), but their values didn't match. I need to verify that my "pin detection" stuff is ok/safe to use (it seems to be fine despite that random floating/changing, but maybe I'm only getting lucky). If it isn't, I need to "require" 10 pins always connected, and only do FINGER DETECTION only by using the same code that I do right now for "pin detection to finger mapping", but altered slightly to only do it on  10 pins.  The default analog pins should be 0-9, but there should be a way for the user to pass in pins ("range" parsing is perhaps (but perhaps not after more thinking about it) a GUI thing, the business object wants those pin numbers in a QList<int>). What I need to verify is that the "total accrued distance moved" will always be greater on anlog pins with sensors connected; greater than pins with no sensors connected. but for now I'll just say fuck it (but maybe once 10 are connected it won't work ofc)
//TODOreq: any time a message header doesn't check out (checksum failure) or the data doesn't check out (checksum failure or just unknown command (same thing as message), we should just blink pin 13 to indicate error. this would at the very least tell us we need to reset the arduino. since input commands are so rare (FOR NOW. for my 0.1 target), so too will be the errors where I need to restart the arduino. ultimately though it would be nice to be fault tolerant, and there are TODOreq comments littered in this code indicating places where faults are detected
void fatalErrorBlinkPin13()fatalErrorBlinkPin13(int blinkIntervalSec)
{
    //hmm I thought about keeping track of the time using millis etc, but might as well just use a while(true) loop to simplify my life. this is a FATAL error after all :-D
    int blinkIntervalMSec = blinkIntervalSec*1000; //TODOkek: blink in morse code spelling out the function that called fatalErrorBlinkPin13() or the line number (if this wasn't a single-file dev enviornment (which is dumb, fkn arduino meh) then I'd say out put the filename and line number). of course another way of solving it is to attach an LCD, but that is not as kek
    pinMode(13, OUTPUT);
    while(true)
    {
        while(Serial.available())
            Serial.read();
        digitalWrite(13, HIGH);
        delay(100);delay(blinkIntervalMSec);
        digitalWrite(13, LOW);
        delay(100);delay(blinkIntervalMSec);
    }
}
bool newSensorValueHasChangedEnoughThatWeWantToReportIt(int oldSensorValue, int newSensorValue)
@@ -82,7 +83,7 @@ public:
        {
            //reset();
            //TODOprobably: I suppose we SHOULD start looking for the next SYNC immediately after the one that we saw to get us here. maybe that one was a false positive and there was a legit one immediately after it! fuck, my brain!! still, this should work... eventually(?)...
            fatalErrorBlinkPin13();fatalErrorBlinkPin13(1);
            return 0;
        }
        Serial.readBytes((char*)m_ChecksumOfData, SizeOfaChecksum);
@@ -124,7 +125,7 @@ private:
        {
            reset();

            fatalErrorBlinkPin13();fatalErrorBlinkPin13(2);
            return false;
            //TODOreq: handle SYNC failures gracefully ofc. I think the below recursive call (to us) will in fact give an infinite loop (never returning to original caller), but it's KINDA on the right track

@@ -298,7 +299,7 @@ void processInputCommandString(const char *inputCommandString)
    else
    {
        //TODOreq: blink pin 13 rapidly to indicate an error. longer term should request the command is re-sent. note: even if the checksum succeeds we still might get an invalid command (checksums aren't perfect), we we'd STILL want to request the command is re-sent. if however 50 invalid commands are received IN A ROW, then we would want to go into blink-13-error-mode as that indicates a bug
        fatalErrorBlinkPin13();fatalErrorBlinkPin13(3);
    }
}
int messageSize_OrZeroIfStillReadingHeader;
@@ -335,7 +336,7 @@ void business()
    //at this point we know that a message header was just read from Serial, and messageSize_OrZeroIfStillReadingHeader contains it's message size (but that doesn't mean that many bytes are available on Serial.available())
    if((messageSize_OrZeroIfStillReadingHeader + 1 /*plus 1 for null term we add on below*/) > MAX_MESSAGE_SIZE)
    {
        fatalErrorBlinkPin13();fatalErrorBlinkPin13(4);
    }
    int numBytesOfMessageLeft = messageSize_OrZeroIfStillReadingHeader - numBytesOfMessageReadSoFar;
    int numBytesToRead = min(numBytesOfMessageLeft, Serial.available());
@@ -356,7 +357,7 @@ void business()
    else
    {
        //TODOmb: start looking for SYNC again right after the SYNC we just saw to get us here? how it currently works is we start looking for SYNC after the [just-confirmed-malformed] message has already been read in
        fatalErrorBlinkPin13();fatalErrorBlinkPin13(5);
    }
    searchingForHeader = true;
}
diff --git a/Projects/wasdf/src/lib/wasdfarduino.cpp b/Projects/wasdf/src/lib/wasdfarduino.cpp
index 695e955..7a5ae27 100644
--- a/Projects/wasdf/src/lib/wasdfarduino.cpp
+++ b/Projects/wasdf/src/lib/wasdfarduino.cpp
@@ -43,14 +43,40 @@ void WasdfArduino::openSerialPortIfNotOpen()
}
QByteArray WasdfArduino::checksum(const QByteArray &input)
{
    return QCryptographicHash::hash(input, QCryptographicHash::Md5); //MD5 is overkill for checksum, but underkill for cyrpto.crypto. 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)
{
    //send SYNC, then checksumOfSize,checksumOfSizeOfData, then sizeOfData, then checksumOfData, then commandToSendToArduino, which should (will TODOreq) be a json document in string form
    //m_SerialPortTextStreamstatic const QString delim(","); //TODOreq: in shared headers

    //send SYNC
    m_SerialPortTextStream << "SYNC";
    //m_SerialPortTextStreamm_SerialPortTextStream << checksumOfData;
    //^this isn't like QDataStream, I'm sending the ASCII representation of numbers when I dodelim;

    //send checksumOfSizeOfData
    QString sizeofDataAsString = QString::number(commandToSendToArduino.size());
    QByteArray sizeOfCommandAsByteArray(sizeofDataAsString.toLatin1());
    QByteArray checksumOfSizeOfCommand = checksum(sizeOfCommandAsByteArray);
    QString checksumOfSizeOfCommandAsString = QString(checksumOfSizeOfCommand);
    m_SerialPortTextStream << checksumOfSizeOfCommandAsString; //TODOreq: s/Command/Data/Message (idc which, but keep it like this. so maybeuniform mother fucker (eh "command" makes sense from wasdf business logic, but "message" and "data" make sense from "message header reader" perspective))
    m_SerialPortTextStream << delim;

    //send sizeOfData
    m_SerialPortTextStream << sizeofDataAsString;
    m_SerialPortTextStream << delim;

    //send checksumOfData
    QByteArray commandToSendToArduinoAsLatin1(commandToSendToArduino.toLatin1());
    QByteArray checksumOfCommand = checksum(commandToSendToArduinoAsLatin1);
    QString checksumOfCommandAsString = QString(checksumOfCommand);
    m_SerialPortTextStream << checksumOfCommandAsString;
    m_SerialPortTextStream << delim;

    //send commandToSendToArduino
    m_SerialPortTextStream << commandToSendToArduino;

#if 0 //turns out I should NOT use a textStream so my commands are binary? the problem, then, becomes portability. I'm pretty damn sure Arduinodo need to send things over as ASCII. arduino uses a stable integer size, so if I use qint32 (etc) then2-byte int size wtf??? I shouldcan't be ablefucked. I'm going to always work with arduinochecksum (hash) the STRING representation of shit instead of the raw bytes
    QByteArray sync("SYNC"); //TODOoptimization: make this a member and it's initialization in construction phasemmandToSendToArduino.toLatin1());
    QByteArray commandToSendToArduinoAsLatin1(commandToSendToArduino.toLatin1());
    qint32 sizeOfCommand = commandToSendToArduino.size();
@@ -64,6 +90,7 @@ void WasdfArduino::sendCommandToArduino(const QString &commandToSendToArduino)
    m_SerialPort->write(sizeOfCommandAsByteArray); //fixed size
    m_SerialPort->write(checksumOfCommand); //fixed size
    m_SerialPort->write(commandToSendToArduinoAsLatin1); //variable size
#endif

    //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()
@@ -161,6 +188,7 @@ void WasdfArduino::handleSerialPortReadyReadCalibrationMode()
    while(m_SerialPort->canReadLine())
    {
        QString line = m_SerialPortTextStream.readLine();
        emit e("raw line read from serial: " + line); //TODOreq: this is only here for testing
        //line is simply: "[pinId]:[sensorValue]"
        QStringList lineSplitAtColon = line.split(":");
        if(lineSplitAtColon.size() != 2)