/firmware/src/Extruder/DebugPacketProcessor.cc

http://github.com/makerbot/G3Firmware · C++ · 82 lines · 61 code · 6 blank · 15 comment · 17 complexity · 814166ad5d48c435adf8916b30515111 MD5 · raw file

  1. /*
  2. * DebugPacketProcessor.cc
  3. *
  4. * Created on: Dec 9, 2009
  5. * Author: phooky
  6. */
  7. #include "DebugPacketProcessor.hh"
  8. #include "UART.hh"
  9. #include "Timeout.hh"
  10. #include "Configuration.hh"
  11. #if HAS_SLAVE_UART
  12. #include "Motherboard.hh"
  13. #include "Errors.hh"
  14. #include "Tool.hh"
  15. #endif
  16. #if HAS_COMMAND_QUEUE
  17. #include "Command.hh"
  18. #endif // HAS_COMMAND_QUEUE
  19. namespace CommandCode {
  20. enum {
  21. DEBUG_ECHO = 0x70,
  22. DEBUG_GENERATE_BAD_PACKET = 0x71,
  23. DEBUG_SIMULATE_BAD_PACKET = 0x72,
  24. DEBUG_SLAVE_PASSTHRU = 0x73,
  25. DEBUG_CLEAR_COMMAND_QUEUE = 0x74,
  26. DEBUG_COMMAND_QUEUE_FILLER = 0xF0
  27. };
  28. }
  29. namespace BadReceptionCode {
  30. enum {
  31. RECEIVED_NOISE = 1,
  32. BAD_PACKET_LENGTH = 2,
  33. BAD_CRC = 3,
  34. TIMEOUT = 4
  35. };
  36. }
  37. namespace BadResponseCode {
  38. enum {
  39. NO_RESPONSE = 1,
  40. SKIP_START_BYTE = 2,
  41. BAD_PACKET_LENGTH = 3,
  42. BAD_CRC = 4,
  43. TIMEOUT = 5
  44. };
  45. }
  46. /// Identify a debug packet, and process it. If the packet is a debug
  47. /// packet, return true, indicating that no further processing should
  48. /// be done. Otherwise, processing of this packet should drop through
  49. /// to the next processing level.
  50. bool processDebugPacket(const InPacket& from_host, OutPacket& to_host) {
  51. if (from_host.getLength() == 0) {
  52. return false;
  53. } // drop through on a nop packet
  54. uint8_t command = from_host.read8(0);
  55. if ((command & 0x70) == 0x70) {
  56. // This is a debug packet
  57. if (command == CommandCode::DEBUG_ECHO) {
  58. // We start from 1 so we can skip the debug command byte.
  59. to_host.reset();
  60. for (int i = 1; i < from_host.getLength(); i++) {
  61. to_host.append8(from_host.read8(i));
  62. }
  63. return true;
  64. } else if (command == CommandCode::DEBUG_GENERATE_BAD_PACKET) {
  65. // TODO
  66. } else if (command == CommandCode::DEBUG_SIMULATE_BAD_PACKET) {
  67. // TODO
  68. } else if (command == CommandCode::DEBUG_SLAVE_PASSTHRU) {
  69. return true;
  70. }
  71. return false;
  72. } else {
  73. // This is not a debug packet
  74. return false;
  75. }
  76. }