Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include "Pkt_Def.h"
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. MotorBody DriveCmd;
  10. DriveCmd.Direction = FORWARD;
  11. DriveCmd.Duration = 20;
  12.  
  13. PktDef TestPkt;
  14. char *ptr;
  15.  
  16. //Testing the PktDef creation interface based on user input
  17. TestPkt.SetCmd(DRIVE);
  18. TestPkt.SetBodyData((char *)&DriveCmd, 2);
  19. TestPkt.SetPktCount(1);
  20. TestPkt.CalcCRC();
  21. ptr = TestPkt.GenPacket();
  22.  
  23.  
  24. TestPkt.printHeaderContents();
  25. TestPkt.printDeserializedPacket(ptr);
  26.  
  27.  
  28. //cout << showbase
  29. // << internal
  30. // << setfill('0');
  31.  
  32. //for (int x = 0; x < (int)TestPkt.GetLength(); x++)
  33. // cout << hex << setw(4) << (unsigned int)*(ptr++) << ", ";
  34.  
  35. cout << endl;
  36. TestPkt.SetCmd(ACK);
  37. TestPkt.CalcCRC();
  38. ptr = TestPkt.GenPacket();
  39.  
  40.  
  41. TestPkt.printHeaderContents();
  42. TestPkt.printDeserializedPacket(ptr);
  43.  
  44.  
  45. //for (int x = 0; x < (int)TestPkt.GetLength(); x++)
  46. // cout << hex << setw(4) << (unsigned int)*(ptr++) << ", ";
  47.  
  48. // cout << endl << noshowbase << dec;
  49.  
  50. //Testing the PktDef creation interface based on an RxBuffer of RAW Data
  51. char buffer[9] = { 0x02, 0x00, 0x00, 0x00, 0x02, 0x09, 0x11, 0x24, 0x08 };
  52. PktDef RxPkt(buffer);
  53. cout << "CommandID: " << RxPkt.GetCmd() << endl;
  54. cout << "PktCount: " << RxPkt.GetPktCount() << endl;
  55. cout << "Pkt Length: " << RxPkt.GetLength() << endl;
  56. cout << "Body Data: " << endl;
  57.  
  58. ptr = RxPkt.GetBodyData();
  59. cout << showbase << hex;
  60. cout << "Byte 1 " << (int)*ptr++ << endl;
  61. cout << "Byte 2 " << (int)*ptr << endl;
  62.  
  63. //Testing the PktDef CRC Calculation
  64.  
  65. //Test #1 -- Validation of a Correct CRC Calculation
  66. char CRCGoodTest[9] = { 0x02, 0x00, 0x00, 0x00, 0x02, 0x09, 0x11, 0x24, 0x08 };
  67. bool Result = RxPkt.CheckCRC(CRCGoodTest, 9);
  68. if (Result)
  69. cout << "CRC Test #1 -- PASSED" << endl;
  70. else
  71. cout << "CRC Test #1 -- FAILED" << endl;
  72.  
  73. //Test #2 -- Validation of an Incorrect CRC Calculation
  74. char CRCBadTest[9] = { 0x02, 0x00, 0x00, 0x00, 0x02, 0x09, 0x11, 0x24, 0x17 };
  75. Result = RxPkt.CheckCRC(CRCBadTest, 9);
  76. if (Result)
  77. cout << "CRC Test #1 -- FAILED" << endl;
  78. else
  79. cout << "CRC Test #1 -- PASSED" << endl;
  80.  
  81. return 1;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement