/firmware/src/Motherboard/Tool.hh

http://github.com/makerbot/G3Firmware · C++ Header · 107 lines · 21 code · 21 blank · 65 comment · 0 complexity · 00d32ea7ee4987fcd585d4243b8c249e MD5 · raw file

  1. /*
  2. * Copyright 2010 by Adam Mayer <adam@makerbot.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>
  16. */
  17. #ifndef TOOL_HH_
  18. #define TOOL_HH_
  19. #include "Packet.hh"
  20. // TODO: Make this into a class.
  21. /// There are three fundamental ways to initiate a tool interaction. They are:
  22. /// <ul>
  23. /// <li> Passthrough queries. These are initiated by the host. The controller passes
  24. /// the query along to the tool, and the response is copied back to the host.</li>
  25. /// <li> Controller queries. These are initiated by the controller. They generally
  26. /// are not directly returned to the host.</li>
  27. /// <li> Queued commands. The responses from these queries are generally discarded.
  28. /// At this time, the command thread blocks until these commands return.</li>
  29. /// </ul>
  30. ///
  31. /// Because the tool can only process one transaction at a time, and we don't
  32. /// want to block on tool transactions, the tool lock must be acquired before using
  33. /// the tool interface. Once the lock is acquired, it must be explicitly released by
  34. /// the holder.
  35. namespace tool {
  36. /// Run the tool maintenance timeslice. Checks for tool command timeouts, etc.
  37. void runToolSlice();
  38. /// Get the tool interaction lock.
  39. /// \return True if the lock has been successfully acquired, false otherwise.
  40. bool getLock();
  41. /// Release the tool interaction lock, letting some other part of the system
  42. /// interact with the toolheads.
  43. void releaseLock();
  44. /// Start a transaction. Assumes that the caller has acquired the lock and
  45. /// filled the output packet.
  46. void startTransaction();
  47. /// Check if the transaction is completed.
  48. /// \return True if the transaction is complete.
  49. bool isTransactionDone();
  50. /// Get the output packet
  51. /// \return Reference to the output packet, which the host should fill with a query
  52. /// to send to the tool.
  53. OutPacket& getOutPacket();
  54. /// Get the input packet
  55. /// \return Reference to the input packet, which should contain a query respose from
  56. /// the tool, which the host should then inspect.
  57. InPacket& getInPacket();
  58. /// Get the total number of packets that were attempted to be sent to a tool. This can
  59. /// be used to assess communication quality with the tool.
  60. /// \return Total number of packets sent over the rs485 line to the tool
  61. uint32_t getSentPacketCount();
  62. /// Get the total number of packets that failed to get a response from a tool. This can
  63. /// be used to assess communication quality with the tool.
  64. /// \return Total number of packets sent to the tool, that failed to generate a response.
  65. uint32_t getPacketFailureCount();
  66. /// Get the total packet retries attempted. The host will attempt to retry a packet 5 times
  67. /// before giving up, so this number will increase by 5 for every failed packet.
  68. /// \return Total number of packet retries attempted.
  69. uint32_t getRetryCount();
  70. /// Get the total number of received bytes that were discarded as noise.
  71. /// \return Total number of noise bytes received.
  72. uint32_t getNoiseByteCount();
  73. /// Attempt to reset the tool by sending it a reset packet
  74. /// \return True if the extruder responded to the reset request.
  75. bool reset();
  76. /// Attempt to test the tool by sending it a series of pings
  77. /// \return True if the test succeeded; false otherwise.
  78. bool test();
  79. /// Set the toolhead index
  80. /// \param index Index (0-127) of the toolhead to communicate with
  81. void setCurrentToolheadIndex(uint8_t index);
  82. /// Get the current toolhead index
  83. /// \return Index of the current toolhead.
  84. uint8_t getCurrentToolheadIndex();
  85. }
  86. #endif // TOOL_HH_