PageRenderTime 17ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

C++ Header | 107 lines | 21 code | 21 blank | 65 comment | 0 complexity | 00d32ea7ee4987fcd585d4243b8c249e MD5 | raw file
  2 * Copyright 2010 by Adam Mayer	 <>
  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
 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 <>
 16 */
 18#ifndef TOOL_HH_
 19#define TOOL_HH_
 21#include "Packet.hh"
 23// TODO: Make this into a class.
 25/// There are three fundamental ways to initiate a tool interaction.  They are:
 26/// <ul>
 27/// <li> Passthrough queries.  These are initiated by the host.  The controller passes
 28///      the query along to the tool, and the response is copied back to the host.</li>
 29/// <li> Controller queries.  These are initiated by the controller.  They generally
 30///      are not directly returned to the host.</li>
 31/// <li> Queued commands.  The responses from these queries are generally discarded.
 32///     At this time, the command thread blocks until these commands return.</li>
 33/// </ul>
 35/// Because the tool can only process one transaction at a time, and we don't
 36/// want to block on tool transactions, the tool lock must be acquired before using
 37/// the tool interface. Once the lock is acquired, it must be explicitly released by
 38/// the holder.
 39namespace tool {
 41/// Run the tool maintenance timeslice.  Checks for tool command timeouts, etc.
 42void runToolSlice();
 44/// Get the tool interaction lock.
 45/// \return True if the lock has been successfully acquired, false otherwise.
 46bool getLock();
 48/// Release the tool interaction lock, letting some other part of the system
 49/// interact with the toolheads.
 50void releaseLock();
 52/// Start a transaction.  Assumes that the caller has acquired the lock and
 53/// filled the output packet.
 54void startTransaction();
 56/// Check if the transaction is completed.
 57/// \return True if the transaction is complete.
 58bool isTransactionDone();
 60/// Get the output packet
 61/// \return Reference to the output packet, which the host should fill with a query
 62///         to send to the tool.
 63OutPacket& getOutPacket();
 65/// Get the input packet
 66/// \return Reference to the input packet, which should contain a query respose from
 67///         the tool, which the host should then inspect.
 68InPacket& getInPacket();
 70/// Get the total number of packets that were attempted to be sent to a tool. This can
 71/// be used to assess communication quality with the tool.
 72/// \return Total number of packets sent over the rs485 line to the tool
 73uint32_t getSentPacketCount();
 75/// Get the total number of packets that failed to get a response from a tool. This can
 76/// be used to assess communication quality with the tool.
 77/// \return Total number of packets sent to the tool, that failed to generate a response.
 78uint32_t getPacketFailureCount();
 80/// Get the total packet retries attempted. The host will attempt to retry a packet 5 times
 81/// before giving up, so this number will increase by 5 for every failed packet.
 82/// \return Total number of packet retries attempted.
 83uint32_t getRetryCount();
 85/// Get the total number of received bytes that were discarded as noise.
 86/// \return Total number of noise bytes received.
 87uint32_t getNoiseByteCount();
 89/// Attempt to reset the tool by sending it a reset packet
 90/// \return True if the extruder responded to the reset request.
 91bool reset();
 93/// Attempt to test the tool by sending it a series of pings
 94/// \return True if the test succeeded; false otherwise.
 95bool test();
 97/// Set the toolhead index
 98/// \param index Index (0-127) of the toolhead to communicate with
 99void setCurrentToolheadIndex(uint8_t index);
101/// Get the current toolhead index
102/// \return Index of the current toolhead.
103uint8_t getCurrentToolheadIndex();
107#endif // TOOL_HH_