aqhome: added lib for hexfiles and flash records.
This commit is contained in:
106
aqhome/libtest.c
106
aqhome/libtest.c
@@ -19,6 +19,8 @@
|
||||
#include "aqhome/mqtt/msg_mqtt_publish.h"
|
||||
#include "aqhome/mqtt/msg_mqtt_pubresponse.h"
|
||||
#include "aqhome/msgmanager.h"
|
||||
#include "aqhome/hexfile/hexfile.h"
|
||||
#include "aqhome/hexfile/flashrecord.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
|
||||
@@ -342,6 +344,105 @@ int testIpcConnection()
|
||||
|
||||
|
||||
|
||||
int testHexfile(int argc, char **argv)
|
||||
{
|
||||
const char *inFilename;
|
||||
const char *outFilename;
|
||||
AQH_HEXFILE *h;
|
||||
int rv;
|
||||
|
||||
if (argc<3) {
|
||||
fprintf(stderr, "Missing filenames (in, out)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rv=AQH_Init();
|
||||
if (rv<0) {
|
||||
}
|
||||
|
||||
inFilename=argv[1];
|
||||
outFilename=argv[2];
|
||||
h=AQH_Hexfile_fromFile(inFilename);
|
||||
if (h==NULL) {
|
||||
fprintf(stderr, "Error reading hexfile \"%s\".\n", inFilename);
|
||||
return 2;
|
||||
}
|
||||
else {
|
||||
AQH_HEXFILERECORD_LIST *recordList;
|
||||
GWEN_BUFFER *buffer;
|
||||
|
||||
recordList=AQH_Hexfile_GetRecordList(h);
|
||||
fprintf(stdout, "INTEL Hexfile read with %d records\n", AQH_HexfileRecord_List_GetCount(recordList));
|
||||
|
||||
buffer=GWEN_Buffer_new(0, 1024, 0, 1);
|
||||
AQH_Hexfile_toBuffer(h, buffer);
|
||||
rv=GWEN_SyncIo_Helper_WriteFile(outFilename, (const uint8_t*) GWEN_Buffer_GetStart(buffer), GWEN_Buffer_GetUsedBytes(buffer));
|
||||
GWEN_Buffer_free(buffer);
|
||||
if (rv<0) {
|
||||
fprintf(stderr, "ERROR writing outfile \"%s\": %d", outFilename, rv);
|
||||
AQH_Hexfile_free(h);
|
||||
return 3;
|
||||
}
|
||||
AQH_Hexfile_free(h);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int testFlashRecords(int argc, char **argv)
|
||||
{
|
||||
const char *inFilename;
|
||||
AQH_HEXFILE *h;
|
||||
int rv;
|
||||
|
||||
if (argc<2) {
|
||||
fprintf(stderr, "Missing filename\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rv=AQH_Init();
|
||||
if (rv<0) {
|
||||
}
|
||||
|
||||
inFilename=argv[1];
|
||||
h=AQH_Hexfile_fromFile(inFilename);
|
||||
if (h==NULL) {
|
||||
fprintf(stderr, "Error reading hexfile \"%s\".\n", inFilename);
|
||||
return 2;
|
||||
}
|
||||
else {
|
||||
AQH_HEXFILERECORD_LIST *recordList;
|
||||
AQH_FLASHRECORD_LIST *flashRecordList;
|
||||
|
||||
recordList=AQH_Hexfile_GetRecordList(h);
|
||||
fprintf(stdout, "INTEL Hexfile read with %d records\n", AQH_HexfileRecord_List_GetCount(recordList));
|
||||
|
||||
flashRecordList=AQH_FlashRecord_fromHexfileRecords(recordList);
|
||||
if (flashRecordList==NULL) {
|
||||
fprintf(stderr, "ERROR creating flash record list\n");
|
||||
AQH_Hexfile_free(h);
|
||||
return 3;
|
||||
}
|
||||
else {
|
||||
AQH_FLASHRECORD *fr;
|
||||
|
||||
fprintf(stdout, "Flash record list created with %d records\n", AQH_FlashRecord_List_GetCount(flashRecordList));
|
||||
fr=AQH_FlashRecord_List_First(flashRecordList);
|
||||
while(fr) {
|
||||
fprintf(stdout, "- %08x (%d bytes)\n", AQH_FlashRecord_GetAddress(fr), AQH_FlashRecord_GetDataLength(fr));
|
||||
fr=AQH_FlashRecord_List_Next(fr);
|
||||
}
|
||||
}
|
||||
|
||||
AQH_Hexfile_free(h);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -349,7 +450,10 @@ int main(int argc, char **argv)
|
||||
//return testEndpoints();
|
||||
//return testMsgMqttConnect();
|
||||
//return testMqttConnection();
|
||||
return testIpcConnection();
|
||||
|
||||
//return testIpcConnection();
|
||||
//return testHexfile(argc, argv);
|
||||
return testFlashRecords(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user