diff --git a/src/Makefile.cross b/src/Makefile.cross index b9bda56..8c04a8d 100644 --- a/src/Makefile.cross +++ b/src/Makefile.cross @@ -21,9 +21,9 @@ else DEMO_INS_PATH := $(DIR) endif -.PHONY : mqtt_proxy +.PHONY : mqtt_proxy enice -all: mqtt_proxy +all: mqtt_proxy enice 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 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 + diff --git a/src/build/Makefile.enice.cross b/src/build/Makefile.enice.cross new file mode 100644 index 0000000..c474d63 --- /dev/null +++ b/src/build/Makefile.enice.cross @@ -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 diff --git a/src/tools/enice_send.c b/src/tools/enice_send.c new file mode 100644 index 0000000..af976f7 --- /dev/null +++ b/src/tools/enice_send.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include + +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; +}