commit 5f9b051e4244afabc3fc6301bcd40fc0b870f551
Author: d3fault <>
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
@@ -70,6 +70,7 @@ Documents/minddump/2017/5/1496022570-LhX790.txt:1496022707
@@ -4105,7 +4106,7 @@ Projects/LossyDirectoryCopier/src/main.cpp:1386648220
@@ -5923,8 +5924,8 @@ Projects/libAvGraphicsItem3/src/main.cpp:1327003410
@@ -5932,17 +5933,17 @@ Projects/wasdf/design/checksummed.message.protocol.txt:1496025143
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);
        digitalWrite(13, HIGH);
        digitalWrite(13, LOW);
bool newSensorValueHasChangedEnoughThatWeWantToReportIt(int oldSensorValue, int newSensorValue)
@@ -82,7 +83,7 @@ public:
            //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(?)...
            return 0;
        Serial.readBytes((char*)m_ChecksumOfData, SizeOfaChecksum);
@@ -124,7 +125,7 @@ private:

            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)
        //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
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)
    int numBytesOfMessageLeft = messageSize_OrZeroIfStillReadingHeader - numBytesOfMessageReadSoFar;
    int numBytesToRead = min(numBytesOfMessageLeft, Serial.available());
@@ -356,7 +357,7 @@ void business()
        //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
    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

    //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()
        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)