Added bitwise not and modulus division to the list of operations you

can do with modifiers in the custom frame window
This commit is contained in:
Collin Kidder
2015-11-23 09:19:47 -05:00
parent 79fc69040d
commit 3ed0ac4880
4 changed files with 46 additions and 20 deletions
+2 -1
View File
@@ -30,6 +30,7 @@ public:
int ID; int ID;
int bus; int bus;
int databyte; int databyte;
bool notOper; //should a bitwise NOT be applied to this prior to doing the actual calculation?
}; };
//list of operations that can be done between the two operands //list of operations that can be done between the two operands
@@ -42,7 +43,7 @@ enum ModifierOperationType
AND, AND,
OR, OR,
XOR, XOR,
NOT MOD
}; };
//A single modifier operation //A single modifier operation
+2 -2
View File
@@ -1,12 +1,12 @@
#ifndef CONFIG #ifndef CONFIG
#define CONFIG #define CONFIG
#define VERSION 138 #define VERSION 139
//try to keep this in sync. //try to keep this in sync.
//SavvyCAN will complain if you connect a GVRET board with a revision //SavvyCAN will complain if you connect a GVRET board with a revision
//less than this number. //less than this number.
#define CURRENT_GVRET_VER 325 #define CURRENT_GVRET_VER 325 //330 is the newest but it is WIP
#endif // CONFIG #endif // CONFIG
+33 -11
View File
@@ -412,9 +412,8 @@ void FrameSenderWindow::doModifiers(int idx)
case XOR: case XOR:
shadowReg = first ^ second; shadowReg = first ^ second;
break; break;
case NOT: case MOD:
shadowReg = !shadowReg; shadowReg = first % second;
break;
} }
} }
//Finally, drop the result into the proper data byte //Finally, drop the result into the proper data byte
@@ -427,18 +426,21 @@ int FrameSenderWindow::fetchOperand(int idx, ModifierOperand op)
CANFrame *tempFrame = NULL; CANFrame *tempFrame = NULL;
if (op.ID == 0) //numeric constant if (op.ID == 0) //numeric constant
{ {
return op.databyte; if (op.notOper) return ~op.databyte;
else return op.databyte;
} }
else if (op.ID == -2) else if (op.ID == -2)
{ {
return sendingData.at(idx).data[op.databyte]; if (op.notOper) return ~sendingData.at(idx).data[op.databyte];
else return sendingData.at(idx).data[op.databyte];
} }
else //look up external data byte else //look up external data byte
{ {
tempFrame = lookupFrame(op.ID, op.bus); tempFrame = lookupFrame(op.ID, op.bus);
if (tempFrame != NULL) if (tempFrame != NULL)
{ {
return tempFrame->data[op.databyte]; if (op.notOper) return ~tempFrame->data[op.databyte];
else return tempFrame->data[op.databyte];
} }
else return 0; else return 0;
} }
@@ -497,15 +499,30 @@ void FrameSenderWindow::processModifierText(int line)
thisMod.destByte = leftSide.right(1).toInt(); thisMod.destByte = leftSide.right(1).toInt();
thisMod.operations.clear(); thisMod.operations.clear();
} }
else continue; else
if (!(Utility::grabOperation(mods[i]) == "=")) continue; {
qDebug() << "Something wrong with lefthand val";
continue;
}
if (!(Utility::grabOperation(mods[i]) == "="))
{
qDebug() << "Err: No = after lefthand val";
continue;
}
abort = false; abort = false;
while (!abort) while (!abort)
{ {
QString token = Utility::grabAlphaNumeric(mods[i]); QString token = Utility::grabAlphaNumeric(mods[i]);
ModifierOp thisOp; ModifierOp thisOp;
if (firstOp) if (firstOp)
{ {
if (token[0] == '~')
{
thisOp.first.notOper = true;
token = token.remove(0, 1); //remove the ~ character
}
else thisOp.first.notOper = false;
parseOperandString(token.split(":"), thisOp.first); parseOperandString(token.split(":"), thisOp.first);
firstOp = false; firstOp = false;
} }
@@ -519,6 +536,7 @@ void FrameSenderWindow::processModifierText(int line)
thisOp.operation = ADDITION; thisOp.operation = ADDITION;
thisOp.second.ID = 0; thisOp.second.ID = 0;
thisOp.second.databyte = 0; thisOp.second.databyte = 0;
thisOp.second.notOper = false;
thisMod.operations.append(thisOp); thisMod.operations.append(thisOp);
} }
else //otherwise try to grab them else //otherwise try to grab them
@@ -532,6 +550,12 @@ void FrameSenderWindow::processModifierText(int line)
{ {
thisOp.operation = parseOperation(operation); thisOp.operation = parseOperation(operation);
QString secondOp = Utility::grabAlphaNumeric(mods[i]); QString secondOp = Utility::grabAlphaNumeric(mods[i]);
if (mods[i][0] == '~')
{
thisOp.second.notOper = true;
mods[i] = mods[i].remove(0, 1); //remove the ~ character
}
else thisOp.second.notOper = false;
thisOp.second.bus = sendingData[line].bus; thisOp.second.bus = sendingData[line].bus;
thisOp.second.ID = sendingData[line].ID; thisOp.second.ID = sendingData[line].ID;
parseOperandString(secondOp.split(":"), thisOp.second); parseOperandString(secondOp.split(":"), thisOp.second);
@@ -661,11 +685,9 @@ ModifierOperationType FrameSenderWindow::parseOperation(QString op)
if (op == "*") return MULTIPLICATION; if (op == "*") return MULTIPLICATION;
if (op == "/") return DIVISION; if (op == "/") return DIVISION;
if (op == "&") return AND; if (op == "&") return AND;
if (op == "AND") return AND;
if (op == "|") return OR; if (op == "|") return OR;
if (op == "OR") return OR;
if (op == "^") return XOR; if (op == "^") return XOR;
if (op == "XOR") return XOR; if (op == "%") return MOD;
return ADDITION; return ADDITION;
} }
+8 -5
View File
@@ -5,8 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include <QByteArray> #include <QByteArray>
#include <QDateTime> #include <QDateTime>
#include <QDebug>
class Utility class Utility
{ {
@@ -82,13 +81,17 @@ public:
for (int i = 0; i < input.length(); i++) for (int i = 0; i < input.length(); i++)
{ {
thisChar = input[i]; thisChar = input[i];
if (thisChar.isLetterOrNumber() || thisChar == ':') builder.append(input[i]); if (thisChar.isLetterOrNumber() || thisChar == ':' || thisChar == '~') builder.append(input[i]);
else else
{ {
input = input.right(input.length() - i); //qDebug() << "i: "<< i << " len: " << input.length();
if (i < (input.length() - 1)) input = input.right(input.length() - i);
else input = "";
return builder; return builder;
} }
} }
//qDebug() << "Reached end of string in grabAlphaNumeric";
input = "";
return builder; return builder;
} }
@@ -97,7 +100,7 @@ public:
QString builder; QString builder;
QChar thisChar = input[0]; QChar thisChar = input[0];
if (thisChar == '+' || thisChar == '-' || thisChar == '*' || thisChar == '/' || thisChar == '^' || thisChar == '&' || thisChar == '|' || thisChar == '=') if (thisChar == '+' || thisChar == '-' || thisChar == '*' || thisChar == '/' || thisChar == '^' || thisChar == '&' || thisChar == '|' || thisChar == '=' || thisChar == '%')
{ {
input = input.right(input.length() - 1); input = input.right(input.length() - 1);
builder = thisChar; builder = thisChar;