Add enice upload message test code

This commit is contained in:
HuangXin 2019-01-10 10:39:12 +08:00
parent 72c72d8e1c
commit 685e7a9f05
3 changed files with 104 additions and 2 deletions

View File

@ -21,9 +21,9 @@ else
DEMO_INS_PATH := $(DIR) DEMO_INS_PATH := $(DIR)
endif endif
.PHONY : mqtt_proxy .PHONY : mqtt_proxy enice
all: mqtt_proxy all: mqtt_proxy enice
mqtt_proxy: mqtt_proxy:
@ -35,3 +35,12 @@ else
@make all $(MAKE_FLAGS) -C build -f Makefile.app.cross DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=mqtt_proxy @make all $(MAKE_FLAGS) -C build -f Makefile.app.cross DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=mqtt_proxy
endif endif
enice:
ifeq ($(OPT), clean)
@make $(MAKE_FLAGS) -C build -f Makefile.enice.cross cleanall MAKE_TARGET=enice_send
else ifeq ($(OPT), install)
@make $(MAKE_FLAGS) -C build -f Makefile.enice.cross install DIR=$(DIR) MAKE_TARGET=enice_send
else
@make all $(MAKE_FLAGS) -C build -f Makefile.enice.cross DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=enice_send
endif

View File

@ -0,0 +1,47 @@
# target name, the target name must have the same name of c source file
TARGET_NAME=enice
# target
# for linux module driver: KO
# for application: EXE
# for dynamic library: DLL
TARGET_TYPE = EXE
# target object
# for application: APP
# for device driver: DRV
TARGET_OBJ = APP
TARGET_BOX =
#debug mode or release mode
DEBUG = TRUE
PLAT_R16 ?= TRUE
PLAT_R311 ?= FALSE
PLAT_LINUX ?= FALSE
PLAT_WIN32 ?= FALSE
PLAT_WIN64 ?= FALSE
VPATH = ../tools
# source code
# set the source file, don't used .o because of ...
# MRS Board Source Files
PLAT_R16_SRCS = enice_send.c
# gcc CFLAGS
PLAT_R16_CFLAGS := -I./ -I../include -DCURRENT_VERSION=\"1.0.0\"
R16_LIBS := -lpthread -lmosquitto -lcurl -lcrypto -lnghttp2 -lssl -lcares
# this line must be at below of thus, because of...
include /opt/common/Makefile.cross
ifeq ($(MAKECMDGOALS), )
$(shell find ./ -name $(TARGET)-*.exe -delete)
else
ifeq ($(MAKECMDGOALS), all)
$(shell find ./ -name "$(TARGET)-*.exe" -delete)
endif
endif

46
src/tools/enice_send.c Normal file
View File

@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <sys/socket.h>
#include <arpa/inet.h>
int main(int argc, char* argv[])
{
int ret;
int sockFd;
struct sockaddr_in addr;
const char* pMsg = "{\"id\": 0, \"msg\": \"hello world\"}";
int msgSize = strlen(pMsg);
sockFd = socket(AF_INET, SOCK_DGRAM, 0);
if(sockFd == -1)
{
fprintf(stderr, "Create UDP socket error\n");
return 0;
}
setsockopt(sockFd, SOL_SOCKET, SO_REUSEADDR, &ret, sizeof(ret));
memset(&addr, 0, sizeof(addr));
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(10086);
addr.sin_family = AF_INET;
ret = sendto(sockFd, pMsg, msgSize, 0, (struct sockaddr*)&addr, sizeof(addr));
if(ret != msgSize)
{
fprintf(stdout, "Send Messsage Error: Need send %d bytes, ret = %d\n", msgSize, ret);
}
while(1)
{
usleep(1000);
}
return 0;
}