Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Ken_CAN_test.cpp
- Revision:
- 8:6f096b45ca15
- Parent:
- 7:a9150dc1e481
- Child:
- 9:7c27efe30a77
--- a/Ken_CAN_test.cpp Tue Jun 21 08:44:17 2022 +0000
+++ b/Ken_CAN_test.cpp Wed Jun 22 16:04:06 2022 +0000
@@ -8,7 +8,6 @@
#include <ctype.h> //For 'is digit' condition
#include <sstream> //This is used to convert an integer to hex
#include <time.h> //To measure how long a process took? Includes clock_t and CLOCKS_PER_SEC
-//#include <list> //To let me make lists of CAN IDs
RawSerial pc(USBTX, USBRX); // USB UART Terminal, tx, rx. Is needed for 'pc.printf' functions to work.
@@ -23,12 +22,14 @@
//Set messageOutText to a default message so it's defined.
string messageOutText = "";
string messageOutTextWithSpaces = "";
+string buttonPressMessageOutText = "";
string part = "";
int partincrement = 0;
__int64 incrementer = 0;
int CANCount = 0;
int spamon = 0;
int idspamon = 0;
+int idscheckedcount = 0;
int spamcount = 0;
int totalspamsever = 0;
int spamstarttime = 0;
@@ -46,14 +47,40 @@
unsigned char expected8 = 0;
unsigned char expected9 = 0;
unsigned char expected10 = 0;
+int expectationwasfulfilled = -1;
+int expectationresolved = 1;
+int expectationtimer = 0;
+int shouldntcomein = 0;
+
int failsthistest = 0;
+int noreplyfailsthistest = 0;
+int mismatchfailsthistest = 0;
int addnewlinetonextmessage = 0;
+int checklaterbytes = 0;
+int aspamisgoing = 0;
+int CANpassthrough = 1;
+
+//Array of IDs to translate can be overwritten with the 'copyarray'.
+//It's arranged in columns of IDs that are translated to the ID in the next column.
+//NOTE: Array must be a large enough size to contain all ID translations.
+int idsarray[2][8] = {};
+int arrayx = 2;
+int arrayy = 8;
+
+//A function to handle when CAN-expectations are not fulfilled
+void expectationwasnotfulfilled(void)
+ {
+ //pc.printf("Expectation was not fulfilled for that message!\r\n");
+ }
//A function to clear all test-related variables
void resettest(void)
{
pc.printf("Resetting test.\r\n");
failsthistest = 0;
+ noreplyfailsthistest = 0;
+ mismatchfailsthistest = 0;
+ idscheckedcount = 0;
}
//A function to add a carriage return in the output if the system has been writing out the CAN messages it sends.
@@ -70,13 +97,14 @@
//A function to end a test and report on findings.
void endtest()
{
+ expectationresolved = 1;
if (failsthistest == 0)
{
pc.printf("\033[1;32mTest complete. %d failures found.\033[0m\r\n", failsthistest);
}
if (failsthistest > 0)
{
- pc.printf("\033[1;31mTest complete. %d failures found.\033[0m\r\n", failsthistest);
+ pc.printf("\033[1;31mTest complete. %d failures found. %d were mismatch failures. %d were 'no reply' failures.\033[0m\r\n", failsthistest, mismatchfailsthistest, noreplyfailsthistest);
}
addnewlineifneeded();
pc.printf("-------------------------------------\r\n");
@@ -88,7 +116,15 @@
{
CanBus.write(messageOut1);
//addnewlineifneeded();
- pc.printf("\033[1;33m%s\033[0m\r", messageOutTextWithSpaces);
+ pc.printf("\033[1;33mSending out: %s \033[0m", messageOutTextWithSpaces);
+ if (aspamisgoing == 0)
+ {
+ //pc.printf("\r\n");
+ }
+ expectationresolved = 0;
+ //pc.printf("Expectationresolved now is %d.", expectationresolved);
+ addnewlineifneeded();
+ expectationtimer = 0;
//addnewlinetonextmessage = 1;
}
@@ -152,6 +188,29 @@
{
messageOut1.id = hextotal;
expected1 = hextotal;
+ //For IDs, check if the ID is represented in the idsarray.
+ int idwasfound = 0;
+ idwasfound = 0;
+ shouldntcomein = 0;
+ if (CANpassthrough == 0)
+ {
+ for(int i = 0; i <=arrayy-1; i++)
+ {
+ if(idsarray[0][i] == expected1)
+ {
+ idwasfound = 1;
+ int originalexpectedvalue = expected1;
+ expected1 = idsarray[1][i];
+ pc.printf("\r\nFound message ID %d at 0,%d in idsarray! Will adjust expected value to %d.\r\n", originalexpectedvalue, i, expected1);
+ }
+ }
+ if (idwasfound == 0 and CANpassthrough == 0)
+ {
+ //pc.printf("ID of %d was never found, expecting it NOT to come in.\r\n", expected1);
+ //pc.printf("CANpassthrough is %d.\r\n", CANpassthrough);
+ shouldntcomein = 1;
+ }
+ }
}
if (partincrement == 2)
{
@@ -207,6 +266,16 @@
//pc.printf("After removing spaces, messageOutText is '%s'\r\n", messageOutText);
string startofstring = messageOutText.substr(0,20); //Take the first 20 characters of the newly-formed string to get a spaceless CAN message.
//pc.printf("String to parse is '%s'.\r\n", startofstring);
+ expectationresolved = 0;
+ if (expectationwasfulfilled == 0)
+ {
+ expectationwasnotfulfilled();
+ }
+ if (expectationwasfulfilled == -1)
+ {
+ expectationwasfulfilled = 0;
+ }
+ expectationwasfulfilled = 0;
partincrement = 0;
part = startofstring.substr(0,3);
dealwithpart();
@@ -254,9 +323,9 @@
void printMessageIn (void)
{
- //This function will print out whatever the CAN bus is receiving and keep it in messagetocheck.
- //messagetocheck = ("%03X %01X %02X %02X %02X %02X %02X %02X %02X %02X", messageIn.id,messageIn.len,messageIn.data[0],messageIn.data[1],messageIn.data[2],messageIn.data[3],messageIn.data[4],messageIn.data[5],messageIn.data[6],messageIn.data[7]);
- //pc.printf("Message IN: %03X %01X %02X %02X %02X %02X %02X %02X %02X %02X\r\n",messageIn.id,messageIn.len,messageIn.data[0],messageIn.data[1],messageIn.data[2],messageIn.data[3],messageIn.data[4],messageIn.data[5],messageIn.data[6],messageIn.data[7]);
+ //This function will print out whatever the CAN bus is receiving.
+ //addnewlineifneeded();
+ //pc.printf("\033[0;36mMessage IN: %03X %01X %02X %02X %02X %02X %02X %02X %02X %02X\033[0m\r\n",messageIn.id,messageIn.len,messageIn.data[0],messageIn.data[1],messageIn.data[2],messageIn.data[3],messageIn.data[4],messageIn.data[5],messageIn.data[6],messageIn.data[7]);
}
//The 'main' function will run as soon as the program starts.
@@ -268,11 +337,11 @@
CanBus.reset(); // clear any bus errors
CanBus2.reset(); // clear any bus errors
//NOTE: Print messages must be below this line to work.
- pc.printf("------------------------------------------\r\n");
+ pc.printf("\033[0m------------------------------------------\r\n");
pc.printf("Welcome to Ken CAN test.\r\n");
pc.printf("Setting CAN bus to 500k.\r\n");
pc.printf("Setting serial port to baud rate 115200.\r\n");
- pc.printf("Using pins 9 and 10 for CANBus 1 and 30 and 29 for CANBus 2.\r\n");
+ pc.printf("Using pins 9 and 10 for CANBus 1 (out) and 30 and 29 for CANBus 2 (in).\r\n");
pc.printf("Version %d.%d\r\n",kMajorVersion,kMinorVersion);
pc.printf("Build date %s %s\r\n",__DATE__,__TIME__);
pc.printf("------------------------------------------\r\n");
@@ -287,6 +356,46 @@
//Check for button presses
while (1)
{
+ if (expectationtimer < 100 and expectationresolved == 0)
+ {
+ if (expectationresolved == 0)
+ {
+ //pc.printf("It's real!\r\n");
+ if (expectationtimer == 0)
+ {
+ //pc.printf("Expectation timer is %d\r\n", expectationtimer);
+ }
+ expectationtimer++;
+ //pc.printf("Expectation timer is now %d!\r\n", expectationtimer);
+ if (expectationtimer >= 5)
+ {
+ if (shouldntcomein == 0)
+ {
+ expectationwasfulfilled = 0;
+ failsthistest++;
+ noreplyfailsthistest++;
+ if (aspamisgoing == 0)
+ {
+ pc.printf("\r\n");
+ }
+ pc.printf("\033[38;5;220mNo reply message detected from ID %d. Ensure that CAN is connected to port 2. 'No reply' fails this test are now %d.\033[0m\r", expected1, noreplyfailsthistest);
+ }
+ if (shouldntcomein == 1)
+ {
+ expectationwasfulfilled = 1;
+ //pc.printf("\rIt didn't come in! Good.\r\n", shouldntcomein);
+ }
+ expectationresolved = 1;
+ //pc.printf("Expectation timer reached %d!\r\n", expectationtimer);
+ expectationtimer = 0;
+ if (idspamon == 1)
+ {
+ idscheckedcount++;
+ }
+ }
+ wait(0.01);
+ }
+ }
if (pc.readable())
{
c = pc.getc();
@@ -295,65 +404,57 @@
//When the a key is pressed, define a CAN message and send it.
//pc.printf("A key was pressed! (%c)\r\n", c);
messageOutText = "";
+ buttonPressMessageOutText = "";
if (c == '1')
{
- addnewlineifneeded();
- messageOutText = "301 8 01 01 01 01 01 01 01 01";
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "301 8 01 01 01 01 01 01 01 01";
}
if (c == '2')
{
- addnewlineifneeded();
- messageOutText = "302 8 02 02 02 02 02 02 02 02";
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "302 8 02 02 02 02 02 02 02 02";
}
if (c == '3')
{
- addnewlineifneeded();
- messageOutText = "303 8 00 00 00 00 00 00 00 33";
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "303 8 00 00 00 00 00 00 00 33";
}
if (c == '4')
{
- addnewlineifneeded();
- messageOutText = "304 8 04 04 04 04 04 04 04 04";
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "304 8 04 04 04 04 04 04 04 04";
}
if (c == '5')
{
- addnewlineifneeded();
- messageOutText = "305 8 05 05 05 05 05 05 05 05";
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "305 8 05 05 05 05 05 05 05 05";
}
if (c == '6')
{
- addnewlineifneeded();
- messageOutText = "306 8 06 06 06 06 06 06 06 06";
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "306 8 06 06 06 06 06 06 06 06";
}
if (c == '7')
{
- addnewlineifneeded();
- messageOutText = "307 8 07 07 07 07 07 07 07 07";
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "307 8 07 07 07 07 07 07 07 07";
}
if (c == '8')
{
- addnewlineifneeded();
- messageOutText = "308 8 08 08 08 08 08 08 08 08";
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "308 8 08 08 08 08 08 08 08 08";
}
if (c == '9')
{
- addnewlineifneeded();
- messageOutText = "309 8 09 09 09 09 09 09 09 09";
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "309 8 09 09 09 09 09 09 09 09";
}
if (c == 'f')
{
- addnewlineifneeded();
- messageOutText = "7FF 8 FF FF FF FF FF FF FF FF";//NOTE: CAN IDs only go p to 7FF, not FFF.
- addnewlinetonextmessage = 1;
+ buttonPressMessageOutText = "7FF 8 FF FF FF FF FF FF FF FF";//NOTE: CAN IDs only go p to 7FF, not FFF.
+ }
+ if (buttonPressMessageOutText != "")//Centralized 'button press MessageOut' routine that applies to all button presses.
+ {
+ if (aspamisgoing == 0)
+ {
+ addnewlineifneeded();
+ messageOutText = buttonPressMessageOutText;
+ addnewlinetonextmessage = 1;
+ checklaterbytes = 1;//Check all bytes for button-press messages.
+ }
+ buttonPressMessageOutText = "";
}
if (c == 'q')
{
@@ -379,17 +480,46 @@
CanBus.frequency(1000 * 1000); // CAN bus at 1000k
CanBus2.frequency(1000 * 1000); // CAN bus at 1000k
}
+ if (c == 'm')
+ {
+ pc.printf("Will try to make an array.\r\n");
+ //Making a two-dimensional array with 301-309 in the first column, then 401-409 in the second column.
+ int copyarray[2][8] = {{769, 770, 771, 772, 773, 774, 776, 777}, {1025, 1026, 1027, 1028, 1029, 1030, 1032, 1033}};
+ //int copyarray[2][1] = {{2047}, {1025}};
+ memcpy(idsarray, copyarray, sizeof(copyarray)); //Copy the new array over the old 'idsarray'.
+ arrayx = 2;
+ arrayy = 8;
+ pc.printf("Array is %dx%d.\r\n", arrayx, arrayy);
+ pc.printf("1st column of IDs array says %d, %d, %d, %d, %d, %d, %d, %d\r\n", idsarray[0][0], idsarray[0][1], idsarray[0][2], idsarray[0][3], idsarray[0][4], idsarray[0][5], idsarray[0][6], idsarray[0][7]);
+ pc.printf("2nd column of IDs array says %d, %d, %d, %d, %d, %d, %d, %d\r\n", idsarray[1][0], idsarray[1][1], idsarray[1][2], idsarray[1][3], idsarray[1][4], idsarray[1][5], idsarray[1][6], idsarray[1][7]);
+ //pc.printf("1st column of IDs array says %d.\r\n", idsarray[0][0]);
+ //pc.printf("2nd column of IDs array says %d.\r\n", idsarray[1][0]);
+ CANpassthrough = 0;
+ pc.printf("CANpassthrough is now set to %d.\r\n", CANpassthrough);
+ /*
+ pc.printf("Will search for '305' in row 1.\r\n");
+ //Search for '305' in the array.
+ for(int i = 0; i <=arrayy; i++)
+ {
+ if(idsarray[0][i] == 305)
+ {
+ pc.printf("Element is found at 0,%d.\r\n", i);
+ }
+ }
+ */
+ //pc.printf("It got here.\r\n"); //To check if it got stuck at this point.
+ }
//if (c == 's')
// {
// pc.printf("Sending authentic sats message.\r\n");
// messageOutText = "301 8 06 3F B2 29 12 97 67 37";
// }
- if (c == 'o')
+ if (c == 'o' and idspamon == 0 and spamon == 1)
{
incrementer = (incrementer * 16);
pc.printf("Multiplied Incrementer by 16. It's now now %d.\r\n", incrementer);
}
- if (c == 'i')
+ if (c == 'i' and idspamon == 1)
{
incrementer = incrementer + 16;
std::stringstream sstream;
@@ -406,11 +536,13 @@
//pc.printf("Will try to send '%s'.\r\n", messageOutText);
}
messageOut1.format = CANStandard;
- if (c == 'z' and spamon == 0)
+ if (c == 'z' and aspamisgoing == 0)
{
resettest();
- pc.printf("Starting spam sequence for ID %s. Press 'x' to end. \r\n", spampreamble);
+ pc.printf("Starting spam sequence for ID %s. Press 'x' to end. Press 'o' to increase incrementer.\r\n", spampreamble);
spamon = 1;
+ aspamisgoing = 1;
+ checklaterbytes = 1;
incrementer = 0;
spamcount = 0;
spamstarttime = clock();
@@ -418,14 +550,15 @@
//Pressing 'x' switches off spam mode
if (c == 'x' and spamon == 1)
{
- //spamcount = 9999999;
- spamon = 0;
+ spamon = 2;
+ aspamisgoing = 0;
int spamendtime = 0;
spamendtime = clock();
int spamtime = 0;
spamtime = spamendtime - spamstarttime;
int spamtimeseconds = 0;
spamtimeseconds = (spamtime / CLOCKS_PER_SEC);
+ addnewlinetonextmessage = 1;
addnewlineifneeded();
pc.printf("Ending spam mode. Spammed %d times for %d ticks (%d seconds) at %d ticks per second.\r\n", spamcount, spamtime, spamtimeseconds, CLOCKS_PER_SEC);
//pc.printf("Clock right now is %d.\r\n", (spamtime));
@@ -443,12 +576,18 @@
endtest();
//pc.printf("-------------------------\r\n");
}
- if (c == 'v' and idspamon == 0)
+ if (c == 'v' and aspamisgoing == 0)
{
resettest();
idspamon = 1; //Set the 'idspamon' integer to 1 so ID spam happens.
+ aspamisgoing = 1;
+ checklaterbytes = 0;
idlistincrementer = 0;
pc.printf("Beginning spam of all possible CAN IDs (000 - 7FF).\r\n");
+ if (checklaterbytes == 0)
+ {
+ pc.printf("Will only check CAN IDs, not later bytes.\r\n");
+ }
}
if (messageOutText != "")
{
@@ -467,7 +606,7 @@
//If spam mode is on, spam an incrementing CAN message
- if (spamon == 1)
+ if (spamon == 1 and expectationresolved == 1)
{
spamcount ++;
totalspamsever ++;
@@ -485,7 +624,17 @@
//CanBus2.write(messageOut1);
wait(0.01);
}
- if (idspamon == 1)
+ if (idspamon == 1 and idlistincrementer >= 2048 and expectationresolved == 1) //If the spam value gets to 2048 (7FF), end the spam sequence. RL only go up to 7FF.
+ {
+ idspamon = 0;
+ aspamisgoing = 0;
+ addnewlinetonextmessage = 1;
+ addnewlineifneeded();
+ pc.printf("Ending ID spam sequence. %d IDs checked total.\r\n", idscheckedcount);
+ idlistincrementer = 0;
+ endtest();
+ }
+ if (idspamon == 1 and expectationresolved == 1)
{
std::stringstream sstream;
sstream << std::hex << idlistincrementer;
@@ -510,91 +659,147 @@
//CanBus2.write(messageOut1);
idlistincrementer++; //Only add 1 to the idlist incrementer at the end so the first ID it sends is '000'.
//pc.printf("ID list incrementer is now %d\r\n", idlistincrementer);
- if (idlistincrementer >= 2048) //If the spam value gets to 2048 (7FF), end the spam sequence. RL only go up to 7FF.
- {
- idspamon = 0;
- addnewlineifneeded();
- pc.printf("Ending ID spam sequence.\r\n");
- idlistincrementer = 0;
- endtest();
- }
+
wait(0.01);//ID spam at 100Hz
}
//Check for CAN messages coming in
- if (CanBus.read(messageIn))
- {
- //CANCount ++;
- //printMessageIn();
- }
if (CanBus2.read(messageIn))
{
+ if (idspamon == 1)
+ {
+ idscheckedcount++;
+ }
CANCount ++;
printMessageIn();
if (1 == 1)
{
- //string messagetocheck = "";
- //string messageintext = ("%03X %01X %d %d %d %d %d %d %d %d", messageIn.id, messageIn.len, messageIn.data[0], messageIn.data[1], messageIn.data[2], messageIn.data[3],messageIn.data[4],messageIn.data[5],messageIn.data[6],messageIn.data[7]);
- //messagetocheck = ("%03X %01X %02X %02X %02X %02X %02X %02X %02X %02X", messageIn.id, messageIn.len, messageIn.data[0], messageIn.data[1], messageIn.data[2], messageIn.data[3],messageIn.data[4],messageIn.data[5],messageIn.data[6],messageIn.data[7]);
- //pc.printf("Expectation is %d %d %d %d %d %d %d %d %d %d\r\n", expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8, expected9, expected10);
int itsamatch = 1;
- addnewlineifneeded();
+ //addnewlineifneeded();
+ pc.printf("Message received was: ");
if (expected1 != messageIn.id)
{
- pc.printf("ID of %d does NOT match %d.\r\n", messageIn.id, expected1);
+ if (CANpassthrough == 1)
+ {
+ //pc.printf("\r\nID of %d does NOT match %d.\r\n", messageIn.id, expected1);
+ pc.printf("\033[1;31m%03X\033[0m ", messageIn.id);
+ }
+ itsamatch = 0;
+ }
+ else
+ {
+ pc.printf("%03X ", messageIn.id);
+ }
+ if (expected2 != messageIn.len and checklaterbytes >= 1)
+ {
+ //pc.printf("Length of %d does NOT match %d.\r\n", messageIn.len, expected2);
+ pc.printf("\033[1;31m%01X\033[0m ", messageIn.len);
itsamatch = 0;
}
- if (expected2 != messageIn.len)
+ else
{
- pc.printf("Length of %d does NOT match %d.\r\n", messageIn.len, expected2);
+ pc.printf("%01X ", messageIn.len);
+ }
+ if (expected3 != messageIn.data[0] and checklaterbytes >= 1)
+ {
+ //pc.printf("Data 0 of %d does NOT match %d.\r\n", messageIn.data[0], expected3);
+ pc.printf("\033[1;31m%02X\033[0m ", messageIn.data[0]);
itsamatch = 0;
}
- if (expected3 != messageIn.data[0])
+ else
{
- pc.printf("Data 0 of %d does NOT match %d.\r\n", messageIn.data[0], expected3);
+ pc.printf("%02X ", messageIn.data[0]);
+ }
+ if (expected4 != messageIn.data[1] and checklaterbytes >= 1)
+ {
+ //pc.printf("Data 1 of %d does NOT match %d.\r\n", messageIn.data[1], expected4);
+ pc.printf("\033[1;31m%02X\033[0m ", messageIn.data[1]);
itsamatch = 0;
}
- if (expected4 != messageIn.data[1])
+ else
{
- pc.printf("Data 1 of %d does NOT match %d.\r\n", messageIn.data[1], expected4);
+ pc.printf("%02X ", messageIn.data[1]);
+ }
+ if (expected5 != messageIn.data[2] and checklaterbytes >= 1)
+ {
+ //pc.printf("Data 2 of %d does NOT match %d.\r\n", messageIn.data[2], expected5);
+ pc.printf("\033[1;31m%02X\033[0m ", messageIn.data[2]);
itsamatch = 0;
}
- if (expected5 != messageIn.data[2])
+ else
{
- pc.printf("Data 2 of %d does NOT match %d.\r\n", messageIn.data[2], expected5);
- itsamatch = 0;
- }
- if (expected6 != messageIn.data[3])
+ pc.printf("%02X ", messageIn.data[2]);
+ }
+ if (expected6 != messageIn.data[3] and checklaterbytes >= 1)
{
- pc.printf("Data 3 of %d does NOT match %d.\r\n", messageIn.data[3], expected6);
+ //pc.printf("Data 3 of %d does NOT match %d.\r\n", messageIn.data[3], expected6);
+ pc.printf("\033[1;31m%02X\033[0m ", messageIn.data[3]);
itsamatch = 0;
}
- if (expected7 != messageIn.data[4])
+
+ else
+ {
+ pc.printf("%02X ", messageIn.data[3]);
+ }
+ if (expected7 != messageIn.data[4] and checklaterbytes >= 1)
{
- pc.printf("Data 4 of %d does NOT match %d.\r\n", messageIn.data[4], expected7);
+ //pc.printf("Data 4 of %d does NOT match %d.\r\n", messageIn.data[4], expected7);
+ pc.printf("\033[1;31m%02X\033[0m ", messageIn.data[4]);
+ itsamatch = 0;
+ }
+ else
+ {
+ pc.printf("%02X ", messageIn.data[4]);
+ }
+ if (expected8 != messageIn.data[5] and checklaterbytes >= 1)
+ {
+ //pc.printf("Data 5 of %d does NOT match %d.\r\n", messageIn.data[5], expected8);
+ pc.printf("\033[1;31m%02X\033[0m ", messageIn.data[5]);
itsamatch = 0;
}
- if (expected8 != messageIn.data[5])
+ else
{
- pc.printf("Data 5 of %d does NOT match %d.\r\n", messageIn.data[5], expected8);
- itsamatch = 0;
+ pc.printf("%02X ", messageIn.data[5]);
}
- if (expected9 != messageIn.data[6])
+ if (expected9 != messageIn.data[6] and checklaterbytes >= 1)
{
- pc.printf("Data 6 of %d does NOT match %d.\r\n", messageIn.data[6], expected9);
+ //pc.printf("Data 6 of %d does NOT match %d.\r\n", messageIn.data[6], expected9);
+ pc.printf("\033[1;31m%02X\033[0m ", messageIn.data[6]);
itsamatch = 0;
}
- if (expected10 != messageIn.data[7])
+ else
{
- pc.printf("Data 7 of %d does NOT match %d.\r\n", messageIn.data[7], expected10);
+ pc.printf("%02X ", messageIn.data[6]);
+ }
+ if (expected10 != messageIn.data[7] and checklaterbytes >= 1)
+ {
+ //pc.printf("Data 7 of %d does NOT match %d.\r\n", messageIn.data[7], expected10);
+ pc.printf("\033[1;31m%02X\033[0m ", messageIn.data[7]);
itsamatch = 0;
}
+ else
+ {
+ pc.printf("%02X ", messageIn.data[7]);
+ }
+ //pc.printf("\r\n");
if (itsamatch == 0)
{
- pc.printf("Message received was: %03X %01X %02X %02X %02X %02X %02X %02X %02X %02X\r\n",messageIn.id,messageIn.len,messageIn.data[0],messageIn.data[1],messageIn.data[2],messageIn.data[3],messageIn.data[4],messageIn.data[5],messageIn.data[6],messageIn.data[7]);
- pc.printf("That does NOT match expectation! (%03X %01X %02X %02X %02X %02X %02X %02X %02X %02X)\r\n", expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8, expected9, expected10);
+ mismatchfailsthistest++;
+ pc.printf("\r\nDoes NOT match : %03X %01X %02X %02X %02X %02X %02X %02X %02X %02X\r\n", expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8, expected9, expected10);
failsthistest++; //Add 1 to failsthistest to mark the fail
+ expectationwasfulfilled = 0;
+ expectationresolved = 1;
+ }
+ if (itsamatch == 1)
+ {
+ expectationwasfulfilled = 1;
+ expectationresolved = 1;
+ //pc.printf("It's a match. Expectation fulfilled.\r\n");
}
}
}
- }
+ //if (expected1 != -1) //If CANBus does not read a message in
+ //{
+//
+ //}
+ }
}
\ No newline at end of file