Select Git revision
rdcu_pkt_to_file.c
rdcu_pkt_to_file.c 10.72 KiB
/**
* @file rdcu_pkt_to_file.c
* @author Dominik Loidolt (dominik.loidolt@univie.ac.at)
* @date 2020
*
* @copyright GPLv2
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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.
*
* @brief RDCU packets to file library
*
* This library provided a rmap_rx and rmap_tx function for the rdcu_rmap
* library to write generated packets into text files.
* @warning this part of the software is not intended to run on-board on the ICU.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <sys/stat.h>
#include <cmp_support.h>
#include <rdcu_pkt_to_file.h>
#include <cmp_rdcu.h>
#include <rdcu_rmap.h>
#include <rdcu_ctrl.h>
#include <rdcu_cmd.h>
#include <cmp_rdcu_testing.h>
/* Name of directory were the RMAP packages are stored */
static char tc_folder_dir[MAX_TC_FOLDER_DIR_LEN] = "TC_FILES";
/**
* @brief set the directory name were the RMAP packages are stored
*
* @param dir_name Name of directory were the RMAP packages are stored
*/
void set_tc_folder_dir(const char *dir_name)
{
if (!dir_name)
return;
strncpy(tc_folder_dir, dir_name, sizeof(tc_folder_dir));
/* Ensure null-termination. */
tc_folder_dir[sizeof(tc_folder_dir) - 1] = '\0';
}
/**
* @brief return a file to write with the name format dir_name/XXX.tc, where XXX
* is n_tc in decimal representation
*
* @param dir_name name of directory were the RMAP packages are stored
* @param n_tc number of TC commands
*
* @return pointer to the new file stream
* @see https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/
*/