51 {
52 std::string appName = "ccsds_encoder";
53
54 std::unordered_map<std::string, std::string> allowed;
55 allowed.insert({"h", "help"});
56 allowed.insert({"v", "verbose"});
57 allowed.insert({"i", "input"});
58 allowed.insert({"o", "output"});
59 allowed.insert({"c", "config"});
60
61 const std::set<std::string> booleanArgs{"verbose", "help"};
62
63 std::unordered_map<std::string, std::string> args;
64 args.insert({"verbose", "false"});
65 args.insert({"help", "false"});
66
67 const auto start = std::chrono::high_resolution_clock::now();
69 std::cerr << "[ Error " << res.error().code() << " ]: "<< res.error().message() << std::endl ;
70 return res.error().code();
71 }
72
73
74
75
76 if (args["help"] == "true") {
78 return 0;
79 }
80 bool verbose{args["verbose"] == "true"};
81
82 if (args.find("input") == args.end()) {
83 std::cerr <<
"[ Error " <<
ARG_PARSE_ERROR <<
" ]: " <<
"Input file must be specified" << std::endl;
86 }
87
89 std::cerr <<
"[ Error " <<
ARG_PARSE_ERROR <<
" ]: " <<
"Input \"" << args[
"input"] <<
"\" does not exist" << std::endl;
91 }
92 const std::string input{args["input"]};
93 const std::string output{args["output"]};
94
95 if (output.empty()) {
96 std::cerr <<
"[ Error " <<
ARG_PARSE_ERROR <<
" ]: " <<
"Output file must be specified" << std::endl;
99 }
100
101 if (args.find("config") == args.end()) {
102 std::cerr <<
"[ Error " <<
ARG_PARSE_ERROR <<
" ]: " <<
"Config file must be specified" << std::endl;
105 }
106
108 std::cerr <<
"[ Error " <<
ARG_PARSE_ERROR <<
" ]: " <<
"Config \"" << args[
"config"] <<
"\" does not exist" << std::endl;
110 }
111 const std::string configFile{args["config"]};
112
113
114 customConsole(appName,
"reading CCSDS configuration file: " + configFile);
116 {
117 if (
auto res = cfg.
load(configFile); !res.has_value()) {
118 std::cerr << "[ Error " << res.error().code() << " ]: "<< res.error().message() << std::endl ;
119 return res.error().code();
120 }
121 }
122
124
125 if (cfg.
isKey(
"data_field_size")) {
126 std::uint16_t dataFieldSize;
129 }
130
131 if (cfg.
isKey(
"sync_pattern_enable")) {
132 bool syncPatternEnable;
135 if (syncPatternEnable && cfg.
isKey(
"sync_pattern")) {
136 std::uint32_t syncPattern;
139 }
140 }
141
143
145 std::cerr << "[ Error " << res.error().code() << " ]: "<< res.error().message() << std::endl ;
146 return res.error().code();
147 }
148
149 std::vector<std::uint8_t> inputBytes;
151
153 std::cerr << "[ Error " << res.error().code() << " ]: "<< res.error().message() << std::endl ;
154 return res.error().code();
155 }else {
156 inputBytes = res.value();
158 std::cerr <<
"[ Error " <<
INVALID_INPUT_DATA <<
" ]: "<<
"Input data is too big for unsegmented packets, data "
159 << inputBytes.size() <<
" must be less than defined data packet length of " << manager.
getDataFieldSize() << std::endl ;
161 }
162 }
163
164 customConsole(appName,
"generating CCSDS packets using input data");
166 std::cerr << "[ Error " << res.error().code() << " ]: "<< res.error().message() << std::endl ;
167 return res.error().code();
168 }
169 if (verbose)
customConsole(appName,
"printing data to screen:");
171
176 std::cerr << "[ Error " << res.error().code() << " ]: "<< res.error().message() << std::endl ;
177 return res.error().code();
178 }
179
180 const auto end = std::chrono::high_resolution_clock::now();
181 const auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
182 customConsole(appName,
"execution time: " + std::to_string(duration.count()) +
" [us]");
184 return 0;
185}
#define ASSIGN_OR_PRINT(var, result)
Macro to assign a result value or print an error message.
bool fileExists(const std::string &fileName)
filesystem check fore file existence prepared for both windows and linux.
CCSDS::ResultBuffer readBinaryFile(const std::string &filename)
Read a specified binary file and return its contents as a buffer.
CCSDS::ResultBool writeBinaryFile(const std::vector< std::uint8_t > &data, const std::string &filename)
This function takes in a buffer of data and a file name.
void printPackets(CCSDS::Manager &manager)
Prints to console a series of CCSDS Packets contained in the manager.
Manages CCSDS packets and their templates.
void setSyncPatternEnable(bool enable)
enable sync pattern utilization both in serialization, deserialization, read and write.
std::uint16_t getDataFieldSize() const
retrieves the set data field size (this includes the secondary header if present)
void setSyncPattern(std::uint32_t syncPattern)
set sync pattern that should indicate the start of a CCSDS packet.
Packet getTemplate()
Retrieves the packet template.
ResultBool loadTemplateConfig(const Config &cfg)
Loads a template packet from a configuration object.
std::vector< std::uint8_t > getPacketsBuffer() const
Retrieves a buffer containing all the stored packets sequentially.
void setDataFieldSize(std::uint16_t size)
Sets the size of the data field.
ResultBool setApplicationData(const std::vector< std::uint8_t > &data)
Sets the application data for the packet.
Header & getPrimaryHeader()
returns the CCSDS packet's Primary Header.
bool has_value() const
Checks if the result contains a valid value.
Parses and stores config values from custom file format.
bool isKey(const std::string &key) const
CCSDS::ResultBool load(const std::string &filename)
Load config file.
CCSDS::Result< T > get(const std::string &key) const
Get value by key and type.
void printHelp()
This is the source file that holds the execution logic of ccsds_encoder binary file.
void customConsole(const std::string &appName, const std::string &message, const std::string &logLevel="INFO")
Prints log to console adding various information about.
CCSDS::ResultBool parseArguments(int argc, char *argv[], std::unordered_map< std::string, std::string > &allowedMap, std::unordered_map< std::string, std::string > &outArgs, const std::set< std::string > &booleanArgs)
Parses the input arguments with defined values returns an unordered map with given keys and input val...
@ ARG_PARSE_ERROR
Error Parsing argument.
@ UNSEGMENTED
11 Complete packet in a single frame.