/**
 * @file mfcc_tc_tm_sample.c
 *
 * @brief This file contains functions that provides demonstration of
 *        usage of TC TM Library APIs
 *
 * The functions provided in the file provides demonstration on
 * usage of TC TM library APIs
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*********************************************************************/
#include "mfcc_tc_tm_sample.h"
#include <stdio.h>

/*****************************************************************************/
/******************* TeleCommand Encode Functions ****************************/
/*****************************************************************************/

/*!
 * @brief This API encodes the Interface Control Messsage for
 * Target point request
 */
int8 tc_trgt_point_req_enc(uint8 *data, tctm_trgt_pt_req_s *tpr)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data, &tpr->lat, 4);
    data += 4;
    os_memcpy(data, &tpr->longit, 4);
    data += 4;
    os_memcpy(data, &tpr->alt, 4);
    data += 4;
    *data = tpr->pld_hw_id;
    data += 1;
    *data = tpr->act_tmr_min;
    data += 1;
    *data = tpr->act_tmr_sec;
    data += 1;
    os_memcpy(data, &tpr->act_tmr_ms, 2);

    status = TCTM_OK;

    return status;
}

/****************************************************************************/
/******************* TeleMetry Decode Functions *****************************/
/****************************************************************************/

/*!
 * @brief This API decodes the TM for GNNS location
 * sharing information
 */
int8 tm_gnss_loc_info_dec(uint8 *data, tctm_gnss_loc_info_s *gli)
{
    int8 status;

    /* Decode data parameters */
    gli->status = *data;
    data += 1;
    os_memcpy(&gli->lat, data, 4);
    data += 4;
    os_memcpy(&gli->longit, data, 4);
    data += 4;
    os_memcpy(&gli->alt, data, 4);
    if(!gli->status)
    {
        DEBUG_CPRINT(("GNSS Location Information Received Successfully\n"));
    }
    else
    {
        DEBUG_CPRINT(("GNSS Location Information Receiption Failure \n"));
    }

    status = TCTM_OK;
    return status;
}
