aqhome: Added test for sending packets to MCU.
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
#include <gwenhywfar/gwentime.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
int testRecv()
|
||||
@@ -55,9 +57,53 @@ int testRecv()
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
int testSend()
|
||||
{
|
||||
return testRecv();
|
||||
AQH_SERIAL *sr;
|
||||
int rv;
|
||||
int i;
|
||||
GWEN_BUFFER *dbuf;
|
||||
uint8_t sendBuf[5]={0x01, 0x02, 0xdb, 0x00, 0xd8 };
|
||||
uint8_t sendBuf2[2]={0x02, 0xdb };
|
||||
|
||||
fprintf(stdout, "Opening device...\n");
|
||||
sr=AQH_Serial_new("/dev/ttyUSB0", 240);
|
||||
rv=AQH_Serial_Open(sr);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "ERROR opening device (%d)", rv);
|
||||
AQH_Serial_free(sr);
|
||||
return 2;
|
||||
}
|
||||
fprintf(stdout, "Device open, waiting for packets\n");
|
||||
|
||||
dbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
for (i=0; ; i++) {
|
||||
GWEN_TIME *ti;
|
||||
|
||||
//rv=AQH_Serial_Send(sr, sendBuf, sizeof(sendBuf));
|
||||
rv=AQH_Serial_SendPacket(sr, 1, sendBuf2, sizeof(sendBuf2));
|
||||
if (rv<0)
|
||||
break;
|
||||
ti=GWEN_CurrentTime();
|
||||
GWEN_Time_toString(ti, "YYYY-MM-DD hh:mm:ss", dbuf);
|
||||
fprintf(stdout, "%s: Packet %d sent.\n", GWEN_Buffer_GetStart(dbuf), i);
|
||||
GWEN_Time_free(ti);
|
||||
GWEN_Buffer_Reset(dbuf);
|
||||
sleep(3);
|
||||
}
|
||||
GWEN_Buffer_free(dbuf);
|
||||
|
||||
AQH_Serial_Close(sr);
|
||||
AQH_Serial_free(sr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//return testRecv();
|
||||
return testSend();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user