コード例 #1
0
ファイル: hott.c プロジェクト: 180jacob/cleanflight
static void hottSendTelemetryData(void) {
    if (!hottIsSending) {
        hottIsSending = true;
        // FIXME temorary workaround for HoTT not working on Hardware serial ports due to hardware/softserial serial port initialisation differences
        if ((portConfig->identifier == SERIAL_PORT_UART1) || (portConfig->identifier == SERIAL_PORT_UART2) || (portConfig->identifier == SERIAL_PORT_UART3))
        	workAroundForHottTelemetryOnUsart(hottPort, MODE_TX);
        else
        	serialSetMode(hottPort, MODE_TX);
        hottMsgCrc = 0;
        return;
    }

    if (hottMsgRemainingBytesToSendCount == 0) {
        hottMsg = NULL;
        hottIsSending = false;
        // FIXME temorary workaround for HoTT not working on Hardware serial ports due to hardware/softserial serial port initialisation differences
        if ((portConfig->identifier == SERIAL_PORT_UART1) || (portConfig->identifier == SERIAL_PORT_UART2) || (portConfig->identifier == SERIAL_PORT_UART3))
        	workAroundForHottTelemetryOnUsart(hottPort, MODE_RX);
        else
        	serialSetMode(hottPort, MODE_RX);
        flushHottRxBuffer();
        return;
    }

    --hottMsgRemainingBytesToSendCount;
    if(hottMsgRemainingBytesToSendCount == 0) {
        hottSerialWrite(hottMsgCrc++);
        return;
    }

    hottMsgCrc += *hottMsg;
    hottSerialWrite(*hottMsg++);
}
コード例 #2
0
ファイル: hott.c プロジェクト: Hwurzburg/cleanflight
static void hottSendTelemetryData(void) {
    if (!hottIsSending) {
        hottIsSending = true;
        serialSetMode(hottPort, MODE_TX);
        hottMsgCrc = 0;
        return;
    }

    if (hottMsgRemainingBytesToSendCount == 0) {
        hottMsg = NULL;
        hottIsSending = false;

        serialSetMode(hottPort, MODE_RX);
        flushHottRxBuffer();
        return;
    }

    --hottMsgRemainingBytesToSendCount;
    if(hottMsgRemainingBytesToSendCount == 0) {
        hottSerialWrite(hottMsgCrc++);
        return;
    }

    hottMsgCrc += *hottMsg;
    hottSerialWrite(*hottMsg++);
}
コード例 #3
0
ファイル: hott.c プロジェクト: Aeroprobing/Cleanflight
static void hottSendTelemetryData(void) {
    if (!hottIsSending) {
        hottIsSending = true;
        // FIXME temorary workaround for HoTT not working on Hardware serial ports due to hardware/softserial serial port initialisation differences
        //serialSetMode(hottPort, MODE_TX);
        closeSerialPort(hottPort);
        hottPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_HOTT, NULL, HOTT_BAUDRATE, MODE_TX, SERIAL_NOT_INVERTED);
        hottMsgCrc = 0;
        return;
    }

    if (hottMsgRemainingBytesToSendCount == 0) {
        hottMsg = NULL;
        hottIsSending = false;

        // FIXME temorary workaround for HoTT not working on Hardware serial ports due to hardware/softserial serial port initialisation differences
        //serialSetMode(hottPort, MODE_RX);
        closeSerialPort(hottPort);
        hottPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_HOTT, NULL, HOTT_BAUDRATE, MODE_RX, SERIAL_NOT_INVERTED);
        flushHottRxBuffer();
        return;
    }

    --hottMsgRemainingBytesToSendCount;
    if(hottMsgRemainingBytesToSendCount == 0) {
        hottSerialWrite(hottMsgCrc++);
        return;
    }

    hottMsgCrc += *hottMsg;
    hottSerialWrite(*hottMsg++);
}
コード例 #4
0
ファイル: hott.c プロジェクト: 180jacob/cleanflight
static void hottCheckSerialData(uint32_t currentMicros)
{
    static bool lookingForRequest = true;

    uint8_t bytesWaiting = serialRxBytesWaiting(hottPort);

    if (bytesWaiting <= 1) {
        return;
    }

    if (bytesWaiting != 2) {
        flushHottRxBuffer();
        lookingForRequest = true;
        return;
    }

    if (lookingForRequest) {
        lastHoTTRequestCheckAt = currentMicros;
        lookingForRequest = false;
        return;
    } else {
        bool enoughTimePassed = currentMicros - lastHoTTRequestCheckAt >= HOTT_RX_SCHEDULE;

        if (!enoughTimePassed) {
            return;
        }
        lookingForRequest = true;
    }

    uint8_t requestId = serialRead(hottPort);
    uint8_t address = serialRead(hottPort);

    if ((requestId == 0) || (requestId == HOTT_BINARY_MODE_REQUEST_ID) || (address == HOTT_TELEMETRY_NO_SENSOR_ID)) {
    /*
     * FIXME the first byte of the HoTT request frame is ONLY either 0x80 (binary mode) or 0x7F (text mode).
     * The binary mode is read as 0x00 (error reading the upper bit) while the text mode is correctly decoded.
     * The (requestId == 0) test is a workaround for detecting the binary mode with no ambiguity as there is only
     * one other valid value (0x7F) for text mode.
     * The error reading for the upper bit should nevertheless be fixed
     */
        processBinaryModeRequest(address);
    }
}
コード例 #5
0
ファイル: hott.c プロジェクト: Hwurzburg/cleanflight
static void hottCheckSerialData(uint32_t currentMicros)
{
    static bool lookingForRequest = true;

    uint8_t bytesWaiting = serialTotalBytesWaiting(hottPort);

    if (bytesWaiting <= 1) {
        return;
    }

    if (bytesWaiting != 2) {
        flushHottRxBuffer();
        lookingForRequest = true;
        return;
    }

    if (lookingForRequest) {
        lastHoTTRequestCheckAt = currentMicros;
        lookingForRequest = false;
        return;
    } else {
        bool enoughTimePassed = currentMicros - lastHoTTRequestCheckAt >= HOTT_RX_SCHEDULE;

        if (!enoughTimePassed) {
            return;
        }
        lookingForRequest = true;
    }

    uint8_t requestId = serialRead(hottPort);
    uint8_t address = serialRead(hottPort);

    if ((requestId == 0) || (requestId == HOTT_BINARY_MODE_REQUEST_ID) || (address == HOTT_TELEMETRY_NO_SENSOR_ID)) {
        processBinaryModeRequest(address);
    }
}
コード例 #6
0
ファイル: hott.c プロジェクト: raul-ortega/iNav
void handleHoTTTelemetry(timeUs_t currentTimeUs)
{
    static uint8_t hottRequestBuffer[2];
    static int hottRequestBufferPtr = 0;

    if (!hottTelemetryEnabled) {
        return;
    }

    bool reprocessState;
    do {
        reprocessState = false;

        switch (hottState) {
        case HOTT_WAITING_FOR_REQUEST:
            if (serialRxBytesWaiting(hottPort)) {
                hottRequestBufferPtr = 0;
                hottSwitchState(HOTT_RECEIVING_REQUEST, currentTimeUs);
                reprocessState = true;
            }
            break;

        case HOTT_RECEIVING_REQUEST:
            if ((currentTimeUs - hottStateChangeUs) >= HOTT_RX_SCHEDULE) {
                // Waiting for too long - resync
                flushHottRxBuffer();
                hottSwitchState(HOTT_WAITING_FOR_REQUEST, currentTimeUs);
            }
            else {
                while (serialRxBytesWaiting(hottPort) && hottRequestBufferPtr < 2) {
                    hottRequestBuffer[hottRequestBufferPtr++] = serialRead(hottPort);
                }

                if (hottRequestBufferPtr >= 2) {
                    if ((hottRequestBuffer[0] == 0) || (hottRequestBuffer[0] == HOTT_BINARY_MODE_REQUEST_ID)) {
                        /*
                         * FIXME the first byte of the HoTT request frame is ONLY either 0x80 (binary mode) or 0x7F (text mode).
                         * The binary mode is read as 0x00 (error reading the upper bit) while the text mode is correctly decoded.
                         * The (requestId == 0) test is a workaround for detecting the binary mode with no ambiguity as there is only
                         * one other valid value (0x7F) for text mode.
                         * The error reading for the upper bit should nevertheless be fixed
                         */
                        if (processBinaryModeRequest(hottRequestBuffer[1])) {
                            hottSwitchState(HOTT_WAITING_FOR_TX_WINDOW, currentTimeUs);
                        }
                        else {
                            hottSwitchState(HOTT_WAITING_FOR_REQUEST, currentTimeUs);
                        }
                    }
                    else if (hottRequestBuffer[0] == HOTT_TEXT_MODE_REQUEST_ID) {
                        // FIXME Text mode
                        hottSwitchState(HOTT_WAITING_FOR_REQUEST, currentTimeUs);
                    }
                    else {
                        // Received garbage - resync
                        flushHottRxBuffer();
                        hottSwitchState(HOTT_WAITING_FOR_REQUEST, currentTimeUs);
                    }

                    reprocessState = true;
                }
            }
            break;

        case HOTT_WAITING_FOR_TX_WINDOW:
            if ((currentTimeUs - hottStateChangeUs) >= HOTT_TX_SCHEDULE) {
                hottTxMsgCrc = 0;
                hottSwitchState(HOTT_TRANSMITTING, currentTimeUs);
            }
            break;

        case HOTT_TRANSMITTING:
            if (hottSendTelemetryDataByte(currentTimeUs)) {
                hottSwitchState(HOTT_ENDING_TRANSMISSION, currentTimeUs);
            }
            break;

        case HOTT_ENDING_TRANSMISSION:
            if ((currentTimeUs - hottStateChangeUs) >= HOTT_TX_DELAY_US) {
                flushHottRxBuffer();
                hottSwitchState(HOTT_WAITING_FOR_REQUEST, currentTimeUs);
                reprocessState = true;
            }
            break;
        };
    } while (reprocessState);
}