예제 #1
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);
    }
}
예제 #2
0
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);
    }
}
예제 #3
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);
}