wangzhengquan
2020-06-30 04ca103d9c561e62bbb557c5db30771c17a7bdbf
update
1个文件已添加
14个文件已修改
107 ■■■■ 已修改文件
data/config.txt 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/login.dat 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/Makefile 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/hcnetdisk.c 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/include/hcnetdisk.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/libnetdisk.a 补丁 | 查看 | 原始文档 | blame | 历史
device/libnetdisk.so 补丁 | 查看 | 原始文档 | blame | 历史
device/test 补丁 | 查看 | 原始文档 | blame | 历史
device/test.c 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/netdisk_service 补丁 | 查看 | 原始文档 | blame | 历史
service/netdisk_service.c 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/request_handler.c 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/test_client 补丁 | 查看 | 原始文档 | blame | 历史
service/test_client.c 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
消息体定义.md 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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
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",
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
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);
//停止下载
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:
device/libnetdisk.a
Binary files differ
device/libnetdisk.so
Binary files differ
device/test
Binary files differ
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();
service/netdisk_service
Binary files differ
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());
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内部会释放buf
  rv = nng_send(sock, strdup(str.c_str()), str.length(), NNG_FLAG_ALLOC);
  //free(buf);
service/test_client
Binary files differ
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;
ÏûÏ¢Ì嶨Òå.md
@@ -1,5 +1,10 @@
# è§†é¢‘服务的地址
tcp://192.168.20.104:8801
# æ¶ˆæ¯ä½“定义
通信消息体采用json的数据格式。
## 1. ç™»å½•