40 #include "Impinj/impinjinternal_ltkcpp.h"
46 #define MAX_PATH_LEN (256)
54 static char * g_errMsgStr =
"<ERROR_MESSAGE MessageID=\"0\" Version=\"0\"\n" \
55 " xmlns:llrp=\'http://www.llrp.org/ltk/schema/core/encoding/xml/1.0\'\n" \
56 " xmlns=\'http://www.llrp.org/ltk/schema/core/encoding/xml/1.0\'>\n" \
58 " <StatusCode>M_Success</StatusCode>\n" \
59 " <ErrorDescription></ErrorDescription>\n" \
64 char pathSeparator =
'\\';
66 char pathSeparator =
'/';
84 unsigned char *binbuf;
93 if(fopen_s(&infp, ifile,
"rb"))
95 infp = fopen(ifile,
"r");
103 fseek(infp,0,SEEK_END);
105 fseek(infp,0,SEEK_SET);
106 binbuf=(
unsigned char *)malloc(len);
108 fread(binbuf,len,1,infp);
112 perror(
"Could not malloc buffer for binary packet");
118 if(fopen_s(&outfp, ofile,
"w")) {
120 outfp = fopen(ofile,
"w");
123 fprintf(stderr,
"Could not open output file %s for writing", ofile);
132 CFrameDecoder MyFrameDecoder(pTypeRegistry,
140 pMessage = MyFrameDecoder.decodeMessage();
151 pError = &MyFrameDecoder.m_ErrorDetails;
153 fprintf(stderr,
"ERROR: Decoder error, result=%d\n",
157 fprintf(stderr,
"ERROR ... refType=%s\n",
162 fprintf(stderr,
"ERROR ... refField=%s\n",
166 fprintf(outfp,
"%s\n", g_errMsgStr);
167 }
else if ((xmlbuf = (
char*) malloc(xmlLen)) == NULL) {
168 fprintf(stderr,
"Could not allocate output buffer for XML file size %u\n", xmlLen);
169 fprintf(outfp,
"%s\n", g_errMsgStr);
171 CXMLTextEncoder MyXMLEncoder(xmlbuf, xmlLen);
172 MyXMLEncoder.encodeElement(pMessage);
173 if(!MyXMLEncoder.m_bOverflow)
175 fprintf(outfp,
"%s", xmlbuf);
179 fprintf(stderr,
"<!-- Buffer overflow -->\n");
180 fprintf(outfp,
"%s\n", g_errMsgStr);
189 void convertDirEntry(
char *idir,
char *odir,
struct dirent *ep) {
190 char vector[MAX_PATH_LEN];
191 char iBuf[MAX_PATH_LEN];
192 char oBuf[MAX_PATH_LEN];
197 perror(
"Invalid file endpoint from dirent");
201 len = (int) strlen(ep->d_name);
209 if(strncmp(&ep->d_name[len-4],
".bin", 4) != 0) {
214 memset(vector, 0x00,
sizeof(vector));
216 strncpy_s(vector, ep->d_name, len-4);
217 sprintf_s(iBuf,
"%s%s.bin", idir, vector);
218 sprintf_s(oBuf,
"%s%s.xml", odir, vector);
220 strncpy(vector, ep->d_name, len-4);
221 sprintf(iBuf,
"%s%s.bin", idir, vector);
222 sprintf(oBuf,
"%s%s.xml", odir, vector);
228 main (
int ac,
char *av[])
232 char idir[MAX_PATH_LEN];
233 char odir[MAX_PATH_LEN];
242 fprintf(stderr,
"ERROR: Bad usage\nusage: %s INPUTDIR OUTPUTDIR\n", av[0]);
246 dpin = opendir (av[1]);
249 fprintf(stderr,
"ERROR: Could not stat input directory %s\n", av[1]);
255 strcpy_s(idir, av[1]);
260 len = (int) strlen(idir);
261 if(idir[len-1] != pathSeparator) {
262 idir[len] = pathSeparator;
267 dpout = opendir (av[1]);
270 fprintf(stderr,
"ERROR: Could not stat output directory %s\n", av[2]);
276 strcpy_s(odir, av[2]);
280 len = (int) strlen(odir);
281 if(odir[len-1] != pathSeparator) {
282 odir[len] = pathSeparator;
289 pTypeRegistry = getTheTypeRegistry();
292 enrollImpinjInternalTypesIntoRegistry(pTypeRegistry);
295 while((ep=readdir(dpin))) {
296 convertDirEntry(idir, odir, ep);
299 (void) closedir(dpin);
300 (void) closedir(dpout);
305 delete pTypeRegistry;
void enrollImpinjTypesIntoRegistry(CTypeRegistry *pTypeRegistry)
Enrolls the types for Impinj into the LTKCPP registry.
char * m_pName
String name of field (e.g. "ROSpecID")
const CFieldDescriptor * m_pRefField
If non-NULL this is the field descriptors for the errored field.
const CTypeDescriptor * m_pRefType
If non-NULL this is the type descriptors for the errored type.
EResultCode m_eResultCode
Result code from operation.
A collection of pointers to CTypeDescriptors.
File that includes all Impinj Custom extension classes and types.
Class to return error details in LTKCPP operations.
char * m_pName
String name of parameter/message type (e.g. "ROSpec")
void convertFile(char *ifile, char *ofile)
File that includes all LLRP classes and types.
Base Class for All LLRP LTK Messages.
int main(int ac, char *av[])
Command main routine.