40 #include "Impinj/impinjinternal_ltkcpp.h"
43 #include "libxml/parser.h"
47 #define MAX_PATH_LEN (256)
56 unsigned char errMsgBinary[18] = {0x04, 0x64, 0x00, 0x00,
57 0x00, 0x12, 0x00, 0x00,
58 0x00, 0x00, 0x01, 0x1F,
59 0x00, 0x08, 0x00, 0x00,
63 char pathSeparator =
'\\';
65 char pathSeparator =
'/';
81 CXMLTextDecoder * pDecoder;
84 unsigned char *binbuf;
93 if(fopen_s(&infp, ifile,
"r"))
95 infp = fopen(ifile,
"r");
104 fseek(infp,0,SEEK_END);
106 fseek(infp,0,SEEK_SET);
107 xmlbuf=(
char *) malloc(xmlLen);
109 fread(xmlbuf,xmlLen,1,infp);
113 perror(
"Could not malloc buffer for LTK-XML message");
120 if(fopen_s(&outfp, ofile,
"wb")) {
122 outfp = fopen(ofile,
"w");
125 fprintf(stderr,
"Could not open output file %s for writing", ofile);
134 pDecoder =
new CXMLTextDecoder(pTypeRegistry, xmlbuf, xmlLen);
140 pMessage = pDecoder->decodeMessage();
150 fwrite(errMsgBinary, 1,
sizeof(errMsgBinary), outfp);
152 pError = &pDecoder->m_ErrorDetails;
154 #ifdef XML2LLRP_DEBUG
155 fprintf(stderr,
"ERROR: Decoder error, result=%d\n",
158 if(NULL != pMessageIDStr)
160 fprintf(stderr,
"ERROR ... MessageID=%s\n",
165 fprintf(stderr,
"ERROR ... refType=%s\n",
170 fprintf(stderr,
"ERROR ... refField=%s\n",
175 fprintf(stderr,
"ERROR ... whatStr=%s\n",
178 if(0 != pError->m_OtherDetail)
180 fprintf(stderr,
"ERROR ... XML line number %d\n",
181 pError->m_OtherDetail);
192 CFrameEncoder * pEncoder;
200 binbuf = (
unsigned char *) malloc(xmlLen);
202 perror(
"Could not malloc buffer for LLRP Binary packet");
207 memset(binbuf, 0, xmlLen);
208 pEncoder =
new CFrameEncoder(binbuf, xmlLen);
214 pEncoder->encodeElement(pMessage);
218 binLen = pEncoder->getLength();
222 if(
RC_OK != pEncoder->m_ErrorDetails.m_eResultCode)
225 pError = &pEncoder->m_ErrorDetails;
228 fwrite(errMsgBinary,1,
sizeof(errMsgBinary), outfp);
230 #ifdef XML2LLRP_DEBUG
231 fprintf(stderr,
"Failed to Encode XML message\n");
232 fprintf(stderr,
"ERROR: Encoder error, status=%d\n",
236 fprintf(stderr,
"ERROR ... refType=%s\n",
241 fprintf(stderr,
"ERROR ... refField=%s\n",
248 fwrite(binbuf, 1, binLen, outfp);
264 void convertDirEntry(
char *idir,
char *odir,
struct dirent *ep) {
265 char vector[MAX_PATH_LEN];
266 char iBuf[MAX_PATH_LEN];
267 char oBuf[MAX_PATH_LEN];
272 perror(
"Invalid file endpoint from dirent");
276 len = (int) strlen(ep->d_name);
284 if(strncmp(&ep->d_name[len-4],
".xml", 4) != 0) {
289 memset(vector, 0x00,
sizeof(vector));
291 strncpy_s(vector, ep->d_name, len-4);
292 sprintf_s(iBuf,
"%s%s.xml", idir, vector);
293 sprintf_s(oBuf,
"%s%s.bin", odir, vector);
295 strncpy(vector, ep->d_name, len-4);
296 sprintf(iBuf,
"%s%s.xml", idir, vector);
297 sprintf(oBuf,
"%s%s.bin", odir, vector);
303 main (
int ac,
char *av[])
307 char idir[MAX_PATH_LEN];
308 char odir[MAX_PATH_LEN];
317 fprintf(stderr,
"ERROR: Bad usage\nusage: %s INPUTDIR OUTPUTDIR\n", av[0]);
321 dpin = opendir (av[1]);
324 fprintf(stderr,
"ERROR: Could not stat input directory %s\n", av[1]);
330 strcpy_s(idir, av[1]);
335 len = (int) strlen(idir);
336 if(idir[len-1] != pathSeparator) {
337 idir[len] = pathSeparator;
342 dpout = opendir (av[1]);
345 fprintf(stderr,
"ERROR: Could not stat output directory %s\n", av[2]);
351 strcpy_s(odir, av[2]);
355 len = (int) strlen(odir);
356 if(odir[len-1] != pathSeparator) {
357 odir[len] = pathSeparator;
364 pTypeRegistry = getTheTypeRegistry();
367 enrollImpinjInternalTypesIntoRegistry(pTypeRegistry);
370 while((ep=readdir(dpin))) {
371 convertDirEntry(idir, odir, ep);
374 (void) closedir(dpin);
375 (void) closedir(dpout);
380 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.
const char * m_pWhatStr
Descriptive printable error string.
A collection of pointers to CTypeDescriptors.
File that includes all Impinj Custom extension classes and types.
void convertFile(char *ifile, char *ofile)
Class to return error details in LTKCPP operations.
char * m_pName
String name of parameter/message type (e.g. "ROSpec")
File that includes all LLRP classes and types.
Base Class for All LLRP LTK Messages.
int main(int ac, char *av[])
Command main routine.