Program Listing for File ref_serial_transmitter.hpp

Return to documentation for file (src/tap/communication/serial/ref_serial_transmitter.hpp)

/*
 * Copyright (c) 2022 Advanced Robotics at the University of Washington <robomstr@uw.edu>
 *
 * This file is part of Taproot.
 *
 * Taproot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Taproot is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Taproot.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef TAPROOT_REF_SERIAL_TRANSMITTER_HPP_
#define TAPROOT_REF_SERIAL_TRANSMITTER_HPP_

#include "tap/architecture/timeout.hpp"
#include "tap/communication/serial/ref_serial_constants.hpp"
#include "tap/util_macros.hpp"

#include "modm/processing/resumable.hpp"

#include "dji_serial.hpp"
#include "ref_serial_data.hpp"

namespace tap
{
class Drivers;
}

namespace tap::communication::serial
{
class RefSerialTransmitter : public RefSerialData, public modm::Resumable<8>
{
public:
    RefSerialTransmitter(Drivers* drivers);

    static void configGraphicGenerics(
        Tx::GraphicData* graphicData,
        const uint8_t* name,
        Tx::GraphicOperation operation,
        uint8_t layer,
        Tx::GraphicColor color);
    static void configLine(
        uint16_t width,
        uint16_t startX,
        uint16_t startY,
        uint16_t endX,
        uint16_t endY,
        Tx::GraphicData* sharedData);
    static void configRectangle(
        uint16_t width,
        uint16_t startX,
        uint16_t startY,
        uint16_t endX,
        uint16_t endY,
        Tx::GraphicData* sharedData);
    static void configCircle(
        uint16_t width,
        uint16_t centerX,
        uint16_t centerY,
        uint16_t radius,
        Tx::GraphicData* sharedData);
    static void configEllipse(
        uint16_t width,
        uint16_t centerX,
        uint16_t centerY,
        uint16_t xLen,
        uint16_t yLen,
        Tx::GraphicData* sharedData);
    static void configArc(
        uint16_t startAngle,
        uint16_t endAngle,
        uint16_t width,
        uint16_t centerX,
        uint16_t centerY,
        uint16_t xLen,
        uint16_t yLen,
        Tx::GraphicData* sharedData);
    static void configFloatingNumber(
        uint16_t fontSize,
        uint16_t decimalPrecision,
        uint16_t width,
        uint16_t startX,
        uint16_t startY,
        float value,
        Tx::GraphicData* sharedData);
    static void configInteger(
        uint16_t fontSize,
        uint16_t width,
        uint16_t startX,
        uint16_t startY,
        int32_t value,
        Tx::GraphicData* sharedData);
    static void configCharacterMsg(
        uint16_t fontSize,
        uint16_t width,
        uint16_t startX,
        uint16_t startY,
        const char* dataToPrint,
        Tx::GraphicCharacterMessage* sharedData);

    static void configFrameHeader(DJISerial::FrameHeader* header, uint16_t msgLen);
    static void configInteractiveHeader(
        Tx::InteractiveHeader* header,
        uint16_t cmdId,
        RobotId senderId,
        uint16_t receiverId);

    mockable modm::ResumableResult<void> deleteGraphicLayer(
        Tx::DeleteGraphicOperation graphicOperation,
        uint8_t graphicLayer);

    mockable modm::ResumableResult<void> sendGraphic(
        Tx::Graphic1Message* graphicMsg,
        bool configMsgHeader = true,
        bool sendMsg = true);
    mockable modm::ResumableResult<void> sendGraphic(
        Tx::Graphic2Message* graphicMsg,
        bool configMsgHeader = true,
        bool sendMsg = true);
    mockable modm::ResumableResult<void> sendGraphic(
        Tx::Graphic5Message* graphicMsg,
        bool configMsgHeader = true,
        bool sendMsg = true);
    mockable modm::ResumableResult<void> sendGraphic(
        Tx::Graphic7Message* graphicMsg,
        bool configMsgHeader = true,
        bool sendMsg = true);
    mockable modm::ResumableResult<void> sendGraphic(
        Tx::GraphicCharacterMessage* graphicMsg,
        bool configMsgHeader = true,
        bool sendMsg = true);

    mockable modm::ResumableResult<void> sendRobotToRobotMsg(
        Tx::RobotToRobotMessage* robotToRobotMsg,
        uint16_t msgId,
        RobotId receiverId,
        uint16_t msgLen);

private:
    tap::Drivers* drivers;
    Tx::DeleteGraphicLayerMessage deleteGraphicLayerMessage;

    template <typename GRAPHIC>
    modm::ResumableResult<void> sendGraphic_(
        GRAPHIC* graphicMsg,
        uint16_t messageId,
        bool configMsgHeader,
        bool sendMsg,
        RobotId robotId,
        tap::Drivers* drivers,
        uint8_t extraDataLength);
};
}  // namespace tap::communication::serial

#endif  // TAPROOT_REF_SERIAL_TRANSMITTER_HPP_