From 04ca103d9c561e62bbb557c5db30771c17a7bdbf Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期二, 30 六月 2020 17:03:47 +0800 Subject: [PATCH] update --- data/config.txt | 10 +++- 消息体定义.md | 5 ++ device/libnetdisk.so | 0 service/netdisk_service | 0 device/hcnetdisk.c | 15 ++++--- device/include/hcnetdisk.h | 4 +- service/request_handler.c | 2 + service/netdisk_service.c | 48 ++++++++++++++++++++++- device/test | 0 service/test_client | 0 data/login.dat | 8 ++++ device/libnetdisk.a | 0 device/test.c | 6 +- device/Makefile | 3 + service/test_client.c | 6 +- 15 files changed, 85 insertions(+), 22 deletions(-) diff --git a/data/config.txt b/data/config.txt index 6fa76c2..67a95b4 100644 --- a/data/config.txt +++ b/data/config.txt @@ -1,8 +1,12 @@ # nng鏈湴鏈嶅姟鍦板潃 -server_url=tcp://127.0.0.1:8801 - +# server_url=tcp://192.168.20.104:8801 +server_url=tcp://192.168.20.104:7701 # nng杩滅▼璋冪敤鍦板潃鍦板潃 -client_url=tcp://127.0.0.1:7701 +client_url=tcp://192.168.20.104:7702 +# client_url=tcp://192.168.20.10:8802 + +# 蹇冭烦鏈嶅姟鍣� +heart_server=tcp://192.168.20.10:5006 # 璐熻矗涓嬭浇浠诲姟鐨勭嚎绋嬫睜鐨勬暟閲� workers=4 \ No newline at end of file diff --git a/data/login.dat b/data/login.dat index cfdd39a..eb74f4b 100644 --- a/data/login.dat +++ b/data/login.dat @@ -7,6 +7,14 @@ "port" : 8000, "username" : "admin" }, + "11111" : { + "deviceType" : "HC", + "host" : "192.168.20.11", + "loginUUID" : "11111", + "password" : "a1234567", + "port" : 8000, + "username" : "admin" + }, "2" : { "deviceType" : "HC", "host" : "192.168.20.11", diff --git a/device/Makefile b/device/Makefile index 957beba..bcb84e6 100644 --- a/device/Makefile +++ b/device/Makefile @@ -2,8 +2,9 @@ # Makefile for common library. # ROOT=.. -LDLIBS+=-Wl,-rpath=$(ROOT)/lib/hc:$(ROOT)/lib/hc/HCNetSDKCom:$(ROOT)/common +LDLIBS+=-Wl,-rpath=$(ROOT)/lib/hc:$(ROOT)/lib/hc/HCNetSDKCom:$(ROOT)/common:$(ROOT)/lib/jsoncpp LDDIR += -L$(ROOT)/lib/hc -L$(ROOT)/lib/hc/HCNetSDKCom +LDDIR += -L$(ROOT)/lib/jsoncpp -L$(ROOT)/lib/nng LDLIBS += -lhcnetsdk -lhpr -lHCCore LDLIBS += -lpthread -ljsoncpp LIB_NETDISK = libnetdisk.a diff --git a/device/hcnetdisk.c b/device/hcnetdisk.c index a99f339..dfc0e4c 100644 --- a/device/hcnetdisk.c +++ b/device/hcnetdisk.c @@ -118,12 +118,15 @@ request.channel, mktime(&start), i); - - if(downloadByTime_wrapper(userid, request.channel, &start, &end, destfile) != -1) { + std::cout << "destfile:" << destfile << std::endl; + char *destfiledup = strdup(destfile); + if(downloadByTime_wrapper(userid, request.channel, &start, &end, destfiledup) != -1) { if(files != NULL) { + // std::cout << "push destfile:" << destfile << std::endl; files->push_back(destfile); } } + free(destfiledup); start = end; i++; @@ -137,7 +140,7 @@ /** * @return success: 0, failture : -1 */ -int HCNetdisk::downloadByTime_wrapper(long userid, int channel, struct tm *start, struct tm *end, char *destfile) { +int HCNetdisk::downloadByTime_wrapper(const long userid, const int channel, const struct tm *start, const struct tm *end, const char *destfile) { NET_DVR_FILECOND_V40 struFileCond = {0}; struFileCond.dwFileType = 0xFF; @@ -219,9 +222,8 @@ -int HCNetdisk::saveRecordFile(int userId, char * srcfile, char * destfile) +int HCNetdisk::saveRecordFile( int userId, char * srcfile, char * destfile) { - printf("destfile=%s\n", destfile); int bRes = 1; int hPlayback = 0; //鎸夋枃浠跺悕涓嬭浇褰曞儚 @@ -239,12 +241,11 @@ return bRes; } int nPos = 0; + //涓嬭浇杩涘害 for (nPos = 0; nPos < 100 && nPos >= 0; nPos = NET_DVR_GetDownloadPos(hPlayback)) { printf("Be downloading...%d %%\n", nPos); sleep(1); -//涓嬭浇杩涘害 -//millisecond } printf("have got %d\n", nPos); //鍋滄涓嬭浇 diff --git a/device/include/hcnetdisk.h b/device/include/hcnetdisk.h index eeee33d..d7be63a 100644 --- a/device/include/hcnetdisk.h +++ b/device/include/hcnetdisk.h @@ -11,8 +11,8 @@ private: - int downloadByTime_wrapper(long userid, int channel, struct tm *start, struct tm *end, char *destfile); - int saveRecordFile(int userId, char * srcfile, char * destfile); + int downloadByTime_wrapper(const long userid, const int channel, const struct tm *start, const struct tm *end, const char *destfile); + int saveRecordFile( int userId, char * srcfile, char * destfile); int _login(Netdisk_LoginInfo &loginInfo); public: diff --git a/device/libnetdisk.a b/device/libnetdisk.a index 7488ddc..26feba9 100644 --- a/device/libnetdisk.a +++ b/device/libnetdisk.a Binary files differ diff --git a/device/libnetdisk.so b/device/libnetdisk.so index 59d1974..c92a81a 100755 --- a/device/libnetdisk.so +++ b/device/libnetdisk.so Binary files differ diff --git a/device/test b/device/test new file mode 100755 index 0000000..7d2c177 --- /dev/null +++ b/device/test Binary files differ diff --git a/device/test.c b/device/test.c index fe1e655..7fca9ae 100644 --- a/device/test.c +++ b/device/test.c @@ -35,8 +35,8 @@ request.end.tm_year = 2020-1900; // 杩欎釜鏃堕棿绫诲瀷浠�1900寮�濮嬬畻浣滅涓�骞� request.end.tm_mon = 4-1; // 0鏄涓�涓湀 request.end.tm_mday = 10; - request.end.tm_hour = 15; - request.end.tm_min = 20; + request.end.tm_hour = 14; + request.end.tm_min = 21; request.end.tm_sec = 0; request.channel = 1; @@ -58,7 +58,7 @@ int main() { Netdisk_EnvConfig config; - config.libpath = "../hclib/"; + config.libpath = "../lib/hc"; HCNetdisk::netdisk_init(&config); test1(); diff --git a/service/netdisk_service b/service/netdisk_service index 37aa2b8..2bcdf1d 100755 --- a/service/netdisk_service +++ b/service/netdisk_service Binary files differ diff --git a/service/netdisk_service.c b/service/netdisk_service.c index 1f55786..8daa2b8 100644 --- a/service/netdisk_service.c +++ b/service/netdisk_service.c @@ -9,6 +9,8 @@ #include <nng/nng.h> #include <nng/protocol/reqrep0/rep.h> #include <nng/protocol/reqrep0/req.h> +#include <nng/protocol/survey0/survey.h> +#include <nng/protocol/survey0/respond.h> using namespace std; @@ -162,7 +164,7 @@ if ((rv = nng_recv(sock, &buf, &sz, NNG_FLAG_ALLOC)) != 0) { fatal("nng_recv", rv); } - +printf("RECEIVED RPC REQUEST:\n %s", buf); jsonreader.parse(buf, request); nng_free(buf, sz); std::string method = request["method"].asString(); @@ -196,6 +198,47 @@ pthread_create(&tid, NULL, worker, NULL); } + +void heartBeat(const char *url, const char *name) +{ + nng_socket sock; + int rv; + + if ((rv = nng_respondent0_open(&sock)) != 0) { + fatal("nng_respondent0_open", rv); + } + if ((rv = nng_dial(sock, url, NULL, NNG_FLAG_NONBLOCK)) != 0) { + fatal("nng_dial", rv); + } + for (;;) { + char *buf = NULL; + size_t sz; + if ((rv = nng_recv(sock, &buf, &sz, NNG_FLAG_ALLOC)) == 0) { +printf("CLIENT (%s): RECEIVED \"%s\" SURVEY REQUEST\n", name, buf); + nng_free(buf, sz); + char response[1024]; + sprintf(response, "%s-%d", name, getpid()); +printf("CLIENT (%s): SENDING SURVEY RESPONSE:%s\n", name, response); + if ((rv = nng_send(sock, response, strlen(response) + 1, 0)) != 0) { + fatal("nng_send", rv); + } + } + } +} + +void *heart(void *vargp) +{ + pthread_detach(pthread_self()); + heartBeat(config.get("heart_server").c_str(), "netdisk"); + return NULL; +} + +// 蹇冭烦鍙戦�佽繘绋� +void initHeart() { + pthread_t tid; + pthread_create(&tid, NULL, heart, NULL); +} + int main() { //鐜鍙橀噺鍒濆鍖� @@ -207,11 +250,10 @@ hcEnvConfig.libpath = "../lib/hc"; HCNetdisk::netdisk_init(&hcEnvConfig); - - registRequestHandleFun(); initThreadPool(); + initHeart(); startServer(config.get("server_url").c_str()); diff --git a/service/request_handler.c b/service/request_handler.c index 2428a39..af4d9e7 100644 --- a/service/request_handler.c +++ b/service/request_handler.c @@ -63,6 +63,8 @@ response["msg"] = rmsg; response["payload"] = payload; const std::string str = response.toStyledString(); + +err_msg(0, "login send back:\n %s", str.c_str()); // nng鍐呴儴浼氶噴鏀綽uf rv = nng_send(sock, strdup(str.c_str()), str.length(), NNG_FLAG_ALLOC); //free(buf); diff --git a/service/test_client b/service/test_client index 580b0c5..3777195 100755 --- a/service/test_client +++ b/service/test_client Binary files differ diff --git a/service/test_client.c b/service/test_client.c index b204c11..0a90fb3 100644 --- a/service/test_client.c +++ b/service/test_client.c @@ -112,13 +112,13 @@ end["year"] = 2020; end["mon"] = 4; end["day"] = 10; - end["hour"] = 15; - end["min"] = 20; + end["hour"] = 14; + end["min"] = 30; end["sec"] = 0; arguments["end"] = end; arguments["channel"] = 1; - arguments["destpath"] = "/home/basic/data/Downloads/test"; + arguments["destpath"] = "/home/basic/data/Downloads"; arguments["host"] = "192.168.20.11"; arguments["port"] = 8000; diff --git "a/\346\266\210\346\201\257\344\275\223\345\256\232\344\271\211.md" "b/\346\266\210\346\201\257\344\275\223\345\256\232\344\271\211.md" index 8281a03..871f2be 100644 --- "a/\346\266\210\346\201\257\344\275\223\345\256\232\344\271\211.md" +++ "b/\346\266\210\346\201\257\344\275\223\345\256\232\344\271\211.md" @@ -1,5 +1,10 @@ +# 瑙嗛鏈嶅姟鐨勫湴鍧� + +tcp://192.168.20.104:8801 + # 娑堟伅浣撳畾涔� + 閫氫俊娑堟伅浣撻噰鐢╦son鐨勬暟鎹牸寮忋�� ## 1. 鐧诲綍 -- Gitblit v1.8.0