147 lines
3.0 KiB
C
147 lines
3.0 KiB
C
|
|
#ifdef HAVE_CONFIG_H
|
|
# include <config.h>
|
|
#endif
|
|
|
|
#include "aqhome/msg/msg_ping.h"
|
|
#include "aqhome/msg/endpointmgr.h"
|
|
#include "aqhome/msg/endpoint_node.h"
|
|
#include "aqhome/msg/endpoint_log.h"
|
|
#include "aqhome/msg/endpoint_tty.h"
|
|
#include "aqhome/ipc/endpoint_node_ipc_tcp.h"
|
|
#include "aqhome/msgmanager.h"
|
|
|
|
#include "aqhome/aqhome.h"
|
|
|
|
#include <gwenhywfar/debug.h>
|
|
#include <gwenhywfar/text.h>
|
|
#include <gwenhywfar/gwentime.h>
|
|
#include <gwenhywfar/buffer.h>
|
|
#include <gwenhywfar/endpoint_ipc_tcp.h>
|
|
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
|
|
|
|
|
|
GWEN_MSG *createPingMsg(uint8_t destAddr, uint8_t srcAddr)
|
|
{
|
|
GWEN_MSG *msg;
|
|
int rv;
|
|
|
|
msg=GWEN_Msg_new(AQH_MAXMSGSIZE);
|
|
rv=GWEN_Msg_AddByte(msg, destAddr);
|
|
if (rv<0) {
|
|
fprintf(stderr, "ERROR1: %d\n", rv);
|
|
GWEN_Msg_free(msg);
|
|
return NULL;
|
|
}
|
|
rv=GWEN_Msg_AddByte(msg, 6); /* msglen */
|
|
if (rv<0) {
|
|
fprintf(stderr, "ERROR2: %d\n", rv);
|
|
GWEN_Msg_free(msg);
|
|
return NULL;
|
|
}
|
|
rv=GWEN_Msg_AddByte(msg, AQH_MSG_TYPE_PING); /* ping */
|
|
if (rv<0) {
|
|
fprintf(stderr, "ERROR3: %d\n", rv);
|
|
GWEN_Msg_free(msg);
|
|
return NULL;
|
|
}
|
|
rv=GWEN_Msg_AddByte(msg, srcAddr); /* src addr */
|
|
if (rv<0) {
|
|
fprintf(stderr, "ERROR4: %d\n", rv);
|
|
GWEN_Msg_free(msg);
|
|
return NULL;
|
|
}
|
|
|
|
rv=GWEN_Msg_AddByte(msg, 0); /* timestamp */
|
|
if (rv<0) {
|
|
fprintf(stderr, "ERROR5: %d\n", rv);
|
|
GWEN_Msg_free(msg);
|
|
return NULL;
|
|
}
|
|
rv=GWEN_Msg_AddByte(msg, 0); /* timestamp */
|
|
if (rv<0) {
|
|
fprintf(stderr, "ERROR6: %d\n", rv);
|
|
GWEN_Msg_free(msg);
|
|
return NULL;
|
|
}
|
|
rv=GWEN_Msg_AddByte(msg, 0); /* timestamp */
|
|
if (rv<0) {
|
|
fprintf(stderr, "ERROR7: %d\n", rv);
|
|
GWEN_Msg_free(msg);
|
|
return NULL;
|
|
}
|
|
rv=GWEN_Msg_AddByte(msg, 0); /* timestamp */
|
|
if (rv<0) {
|
|
fprintf(stderr, "ERROR8: %d\n", rv);
|
|
GWEN_Msg_free(msg);
|
|
return NULL;
|
|
}
|
|
|
|
|
|
rv=AQH_NodeMsg_AddChecksum(msg);
|
|
if (rv<0) {
|
|
fprintf(stderr, "ERROR9: %d\n", rv);
|
|
GWEN_Msg_free(msg);
|
|
return NULL;
|
|
}
|
|
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
int testEndpoints()
|
|
{
|
|
int rv;
|
|
GWEN_MSG_ENDPOINT_MGR *emgr;
|
|
GWEN_MSG_ENDPOINT *epTty;
|
|
GWEN_MSG_ENDPOINT *epLog;
|
|
GWEN_MSG_ENDPOINT *epTcp;
|
|
|
|
rv=AQH_Init();
|
|
if (rv<0) {
|
|
}
|
|
|
|
emgr=AQH_MsgManager_new(0xc0);
|
|
epTty=AQH_TtyNodeEndpoint_new("/dev/ttyUSB0", AQH_MSGMGR_ENDPOINTGROUP_NODE);
|
|
if (epTty==NULL) {
|
|
DBG_ERROR(NULL, "Error creating endpoint TTY");
|
|
return 2;
|
|
}
|
|
GWEN_MsgEndpointMgr_AddEndpoint(emgr, epTty);
|
|
|
|
epLog=AQH_LogEndpoint_new("endpoints.log", AQH_MSGMGR_ENDPOINTGROUP_NODE);
|
|
if (epLog==NULL) {
|
|
DBG_ERROR(AQH_LOGDOMAIN, "Error creating endpoint LOG");
|
|
return 2;
|
|
}
|
|
GWEN_MsgEndpointMgr_AddEndpoint(emgr, epLog);
|
|
|
|
epTcp=AQH_TcpIpcNodeEndpoint_new(NULL, "127.0.0.1", 45454, AQH_MSGMGR_ENDPOINTGROUP_IPC);
|
|
if (epTcp==NULL) {
|
|
DBG_ERROR(AQH_LOGDOMAIN, "Error creating endpoint TCP");
|
|
return 2;
|
|
}
|
|
GWEN_MsgEndpointMgr_AddEndpoint(emgr, epTcp);
|
|
|
|
for (;;) {
|
|
DBG_DEBUG(AQH_LOGDOMAIN, "Next loop");
|
|
AQH_MsgManager_LoopOnce(emgr);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return testEndpoints();
|
|
}
|
|
|
|
|