17 #include <sys/types.h> 34 #ifdef USE_IS_INTERNAL 35 # include "../../libs/IS_internal.h" 54 for (map_name_to_info_t::const_iterator offset = offsetMap->begin(); offset != offsetMap->end(); offset++)
57 header += offset->first;
60 fputs(header.c_str(), pFile);
61 return (
int)header.length();
67 #if PLATFORM_IS_EMBEDDED 82 stringstream stream(line);
84 columnHeaders.clear();
87 getline(stream, columnHeader,
',');
88 while (columnHeader.length() > 0 && (columnHeader[columnHeader.size() - 1] ==
'\r' || columnHeader[columnHeader.size() - 1] ==
'\n'))
90 columnHeader.resize(columnHeader.size() - 1);
92 if (columnHeader.length() == 0)
94 columnHeader =
"UNKNOWN";
96 if (columnHeader ==
"_ID_")
98 columnHeaders.push_back({ 0xFFFFFFFF, 0xFFFFFFFF,
DataTypeInt64,
"_ID_" });
102 map_name_to_info_t::const_iterator offset = offsetMap->find(columnHeader);
103 if (offset == offsetMap->end())
105 columnHeaders.push_back({ 0xFFFFFFFF, 0xFFFFFFFF,
DataTypeBinary, columnHeader });
109 columnHeaders.push_back(offset->second);
130 SNPRINTF(tmp, 64,
"%llu", (
long long unsigned int)orderId);
133 fputs(s.c_str(), pFile);
136 return (
int)s.length() + 1 + (int)strnlen(tmp,
sizeof(tmp));
146 while (s.length() > 0 && (s[s.size() - 1] ==
'\r' || s[s.size() - 1] ==
'\n'))
148 s.resize(s.size() - 1);
153 string::const_iterator
start = s.begin();
157 bool inQuotes =
false;
158 uint32_t foundQuotes = 0;
159 memset(buf, 0, hdr.
size);
160 for (string::const_iterator i = start; i < s.end() && index < columnHeaders.size(); i++)
162 if (*i ==
',' && !inQuotes)
165 columnData = string(start + foundQuotes, i - foundQuotes);
176 inQuotes = !inQuotes;
177 foundQuotes |= (uint32_t)inQuotes;
194 const uint8_t* bufPtr = buf;
200 memset(tmpBuffer, 0, hdr.
offset);
201 memcpy(tmpBuffer + hdr.
offset, buf, hdr.
size);
203 memset(tmpBuffer + dataEnd, 0, size - dataEnd);
212 for (map_name_to_info_t::const_iterator offset = offsetMap->begin(); offset != offsetMap->end(); offset++)
215 if (csv.length() != 0)
static const map_name_to_info_t * GetMapInfo(uint32_t dataId)
int WriteHeaderToFile(FILE *pFile, uint32_t id)
CDCHeaderDescriptor header
bool StringCSVToData(string &s, p_data_hdr_t &hdr, uint8_t *buf, uint32_t bufSize, const vector< data_info_t > &columnHeaders)
bool DataToStringCSV(const p_data_hdr_t &hdr, const uint8_t *buf, string &csv)
static bool StringToData(const char *stringBuffer, int stringLength, const p_data_hdr_t *hdr, uint8_t *dataBuffer, const data_info_t &info, int radix=10, bool json=false)
#define _ARRAY_BYTE_COUNT(a)
static uint32_t GetSize(uint32_t dataId)
#define IS_DATA_MAPPING_MAX_STRING_LENGTH
USBInterfaceDescriptor data
static bool DataToString(const data_info_t &info, const p_data_hdr_t *hdr, const uint8_t *dataBuffer, data_mapping_string_t stringBuffer, bool json=false)
int WriteDataToFile(uint64_t orderId, FILE *pFile, const p_data_hdr_t &dataHdr, const uint8_t *dataBuf)
map< string, data_info_t, sCaseInsensitiveCompare > map_name_to_info_t
int ReadHeaderFromFile(FILE *pFile, uint32_t id, vector< data_info_t > &columnHeaders)