// SPDX-License-Identifier: GPL-2.0-only
/*
 * Digital Voice Modem - Common Library
 * GPLv2 Open Source. Use is subject to license terms.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 *  Copyright (C) 2022,2024 Bryan Biedenkapp, N2PLL
 *
 */
#include "Defines.h"
#include "p25/lc/tdulc/LC_CONV_FALLBACK.h"

using namespace p25;
using namespace p25::defines;
using namespace p25::lc;
using namespace p25::lc::tdulc;

#include <cassert>

// ---------------------------------------------------------------------------
//  Public Class Members
// ---------------------------------------------------------------------------

/* Initializes a new instance of the LC_CONV_FALLBACK class. */

LC_CONV_FALLBACK::LC_CONV_FALLBACK() : TDULC()
{
    m_lco = LCO::CONV_FALLBACK;
}

/* Decode a terminator data unit w/ link control. */

bool LC_CONV_FALLBACK::decode(const uint8_t* data)
{
    assert(data != nullptr);

    /* stub */

    return true;
}

/* Encode a terminator data unit w/ link control. */

void LC_CONV_FALLBACK::encode(uint8_t* data)
{
    assert(data != nullptr);

    ulong64_t rsValue = 0U;

    rsValue = (rsValue << 48) + s_siteData.channelId();                             // Channel ID 6
    rsValue = (rsValue << 40) + s_siteData.channelId();                             // Channel ID 5
    rsValue = (rsValue << 32) + s_siteData.channelId();                             // Channel ID 4
    rsValue = (rsValue << 24) + s_siteData.channelId();                             // Channel ID 3
    rsValue = (rsValue << 16) + s_siteData.channelId();                             // Channel ID 2
    rsValue = (rsValue << 8) + s_siteData.channelId();                              // Channel ID 1

    std::unique_ptr<uint8_t[]> rs = TDULC::fromValue(rsValue);
    TDULC::encode(data, rs.get());
}
