wangzhengquan
2020-06-10 bf17db04a093ca277c421ea7d24fe2a050963dca
version 1
2个文件已删除
11个文件已添加
11 文件已重命名
10个文件已修改
1100 ■■■■ 已修改文件
Makefile 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/login.dat 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/Makefile 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/hcnetdisk.c 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/include/hcnetdisk.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/include/logintable.h 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/include/netdisk.h 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/netdisk.c 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
device/test 补丁 | 查看 | 原始文档 | blame | 历史
device/test.c 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
message_define.md 159 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/Makefile 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/client 补丁 | 查看 | 原始文档 | blame | 历史
service/client.c 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/core 补丁 | 查看 | 原始文档 | blame | 历史
service/netdisk_service 补丁 | 查看 | 原始文档 | blame | 历史
service/netdisk_service.c 245 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/test 补丁 | 查看 | 原始文档 | blame | 历史
service/test.c 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/Makefile 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/bus 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/bus.c 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/pair 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/pair.c 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/pipeline 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/pipeline.c 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/pubsub 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/pubsub.c 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/reqrep 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/reqrep.c 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/survey 补丁 | 查看 | 原始文档 | blame | 历史
test/nanomsg/survey.c 补丁 | 查看 | 原始文档 | blame | 历史
test/nng/reqrep 补丁 | 查看 | 原始文档 | blame | 历史
test/nng/reqrep.c 211 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Makefile
@@ -1,4 +1,4 @@
DIRS = common netdisk
DIRS = common device service
all:
    for i in $(DIRS); do \
data/login.dat
File was renamed from device/data/login.dat
@@ -1,5 +1,6 @@
{
   "1" : {
      "deviceType" : "HC",
      "host" : "192.168.20.11",
      "loginUUID" : "1",
      "password" : "a1234567",
@@ -7,6 +8,7 @@
      "username" : "admin"
   },
   "2" : {
      "deviceType" : "HC",
      "host" : "192.168.20.11",
      "loginUUID" : "2",
      "password" : "a1234567",
device/Makefile
@@ -3,7 +3,7 @@
#
ROOT=..
LDLIBS+=-Wl,-rpath=../hclib:../hclib/HCNetSDKCom:../common
LDDIR += -L$(ROOT)/hcnetdisk_wrapper -L../hclib -L../hclib/HCNetSDKCom
LDDIR += -L../hclib -L../hclib/HCNetSDKCom
LDLIBS += -lhcnetsdk -lhpr -lHCCore
LDLIBS += -lpthread  -ljsoncpp
LIB_NETDISK = libnetdisk.a
@@ -17,7 +17,7 @@
all: $(LIB_NETDISK) $(DLIB_NETDISK)
test: hcnetdisk.c netdisk.c
test: hcnetdisk.c
#static lib
$(LIB_NETDISK): $(OBJS)
device/hcnetdisk.c
@@ -36,8 +36,8 @@
HCNetdisk::HCNetdisk(const std::string &_devicename):Netdisk(_devicename){
HCNetdisk::HCNetdisk(): Netdisk(){
  deviceType="HC";
}
int HCNetdisk::_login(Netdisk_LoginInfo &loginInfo) {
@@ -55,6 +55,7 @@
  NET_DVR_DEVICEINFO_V40 struDeviceInfo = {0};
  //lUserID = 0;
  lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfo);
  printf("lUserID = %d\n", lUserID);
  if (lUserID < 0)
  {
    printf("Login error, %d\n", NET_DVR_GetLastError());
@@ -62,7 +63,8 @@
    return -1;
  }
  printf("lUserID = %ld\n", lUserID);
  loginInfo.userid = std::to_string(lUserID);
  userid = lUserID;
  username = loginInfo.username;
  password = loginInfo.password;
@@ -72,8 +74,6 @@
  startChannel = struDeviceInfo.struDeviceV30.byStartDChan;
  maxChannels = struDeviceInfo.struDeviceV30.byIPChanNum + struDeviceInfo.struDeviceV30.byHighDChanNum * 256;
  return 0;
}
@@ -81,16 +81,14 @@
int HCNetdisk::login(Netdisk_LoginInfo &loginInfo) {
   
  //_login(loginInfo);
  Netdisk::addLoginInfo(loginInfo);
  return _login(loginInfo);
  //Netdisk::addLoginInfo(loginInfo);
  return 0;
}
int HCNetdisk::logout() {
    //注销用户
    NET_DVR_Logout(userid);
    userid = -1;
    return 0;
}
@@ -99,8 +97,8 @@
    char destfile[1024];
    int i = 0;
    Netdisk_LoginInfo loginInfo = Netdisk::getLoginInfo(request.loginUUID);
    _login(loginInfo);
    // Netdisk_LoginInfo loginInfo = Netdisk::getLoginInfo(request.loginUUID);
    // _login(loginInfo);
    
    start = request.start;
@@ -117,12 +115,12 @@
        // printf("end   = %s", asctime(&end));
        sprintf(destfile, "%s/%s-%d-%ld-%d", 
             request.destpath.c_str(), 
            devicename.c_str(),
            deviceType.c_str(),
             request.channel, 
             mktime(&start), 
             i);
        // printf("%s\n", destfile);
        downloadByTime_wrapper(userid, request.channel, &start, &end, destfile);
        // downloadByTime_wrapper(userid, request.channel, &start, &end, destfile);
        if(files != NULL) {
            files->push_back(destfile);
        }
device/include/hcnetdisk.h
@@ -18,7 +18,7 @@
    int _login(Netdisk_LoginInfo &loginInfo);
public:
    static bool envInited ;
    HCNetdisk(const std::string &_devicename = "HC");
    HCNetdisk();
    virtual ~HCNetdisk();
device/include/logintable.h
File was deleted
device/include/netdisk.h
@@ -10,6 +10,8 @@
typedef struct Netdisk_LoginInfo {
    std::string loginUUID;
    std::string deviceType;
    std::string userid;
    std::string username;
    std::string password;
    std::string host;
@@ -34,27 +36,26 @@
    std::string loginDataFile;
protected:
    std::string devicename; //设备名称
    int startChannel;       //起始通道号
    int maxChannels;        //最大通道数
    long userid;            //用户id
    std::string deviceType; //设备类型
    std::string loginUUID;
    std::string username;   //用户名
    std::string password;   //密码
    std::string host;       //ip
    int port;               //端口
    long userid;            //用户id
    //Json::FastWriter jsonwriter;
    Json::Value loginData;
    Netdisk_LoginInfo  getLoginInfo(std::string uuid);
    // Netdisk_LoginInfo  getLoginInfo(std::string uuid);
    int addLoginInfo(Netdisk_LoginInfo &loginInfo);
    // int addLoginInfo(Netdisk_LoginInfo &loginInfo);
public:
    Netdisk(const std::string &_devicename="");
    Netdisk(){};
    virtual ~Netdisk() {}
    
@@ -65,7 +66,6 @@
    virtual int downloadByTime(Netdisk_DownloadRequest &request, std::vector<std::string> *files) = 0;
    void saveLoginInfo();
    int getStartChannel() {return startChannel;}
device/netdisk.c
File was deleted
device/test
Binary files differ
device/test.c
@@ -7,11 +7,12 @@
void test1() {
     
    Netdisk *netdisk = new HCNetdisk("海康");
    Netdisk *netdisk = new HCNetdisk();
    //登录
    Netdisk_LoginInfo loginInfo;
    loginInfo.loginUUID="1";
    loginInfo.deviceType="HC";
    loginInfo.host = "192.168.20.11";
    loginInfo.port = 8000;
    loginInfo.username = "admin";
@@ -53,24 +54,7 @@
    netdisk->logout();
}
void test2() {
    HCNetdisk netdisk("海康");
    //Netdisk *netdisk = dhnetdisk_new();
    //登录
    Netdisk_LoginInfo loginInfo;
    loginInfo.host = "192.168.20.11";
    loginInfo.port = 8000;
    loginInfo.username = "admin";
    loginInfo.password = "a1234567";
    netdisk.login(loginInfo);
    std::cout << "起始通道:" << netdisk.getStartChannel() << ", 最大通道号:" << netdisk.getMaxChannels() << std::endl;
}
int main() {
message_define.md
New file
@@ -0,0 +1,159 @@
# 消息体定义
通信消息体采用json的数据格式。
## 1. 登录
请求体
```
{
    method: "login",
    arguments: {
        //设备类型(HC:海康)
        deviceType: "HC",
        loginUUID: "11111",
        //用户名
        username: "admin",
        //密码
        password: "a1234567",
        // ip地址
        host:  "192.168.20.11",
        // 端口号
        port: 8000
    }
}
```
响应体
```
{
    code: 0, // 0表示成功,其他值代表相应的错误码
    payload: {
        loginUUID: "11111"
    }
}
```
## 2、下载
请求体
```
{
    method: "downloadByTime",
    arguments: {
        loginUUID:  "11111",
        //通道号
        channel: 1,
        //开始时间
        start: {
                year: 2020,
                mon: 4,
                day: 10,
                hour: 14,
                min: 20,
                sec: 0
         },
         //结束时间
         end:  {
                year: 2020,
                mon: 4,
                day: 10,
                hour: 15,
                min: 20,
                sec: 0
        },
        //下载文件存储路径
        destpath: "/Downloads"
    }
}
```
响应体
```
{
    code: 0, // 0表示成功,其他值代表相应的错误码
    payload: {
        //完成下载的文件的列表
        filelist: [
            "/Downloads/1.mp3",
            "/Downloads/2.mp3",
            "/Downloads/3.mp3"
        ]
    }
}
```
## 3. 登出
请求体
```
{
    method: "logout",
    arguments: {
        loginUUID: "1"
    }
}
```
响应体
```
{
    code: 0 // 0表示成功,其他值代表相应的错误码
}
```
## 4. 获取起始通道号
请求体
```
{
    method: "getStartChannel",
    arguments: {
        loginUUID: "1"
    }
}
```
响应体
```
{
    code: 0, // 0表示成功,其他值代表相应的错误码
    payload: {
        startChanel: 1
    }
}
```
## 5. 获取最大通道号
请求体
```
{
    method: "getMaxChannels",
    arguments: {
        loginUUID: "1"
    }
}
```
响应体
```
{
    code: 0, // 0表示成功,其他值代表相应的错误码
    payload: {
        maxChanel: 64
    }
}
```
service/Makefile
New file
@@ -0,0 +1,27 @@
#
# Makefile for common library.
#
ROOT=..
LDLIBS+=-Wl,-rpath=$(ROOT)/hclib:$(ROOT)/hclib/HCNetSDKCom:$(ROOT)/common:$(ROOT)/device
LDDIR += -L$(ROOT)/device -L$(ROOT)/hclib -L$(ROOT)/hclib/HCNetSDKCom
LDLIBS += -lnetdisk
LDLIBS +=  -lhcnetsdk -lhpr -lHCCore
LDLIBS += -ljsoncpp  -lnng  -lpthread
INCLUDE += -I$(ROOT)/device/include
LIB_NETDISK = $(ROOT)/libnetdisk.a
DLIB_NETDISK = $(ROOT)/libnetdisk.so
PLATFORM=$(shell $(ROOT)/systype.sh)
include $(ROOT)/Make.defines.$(PLATFORM)
all: netdisk_service client test
netdisk_service: $(ROOT)/device/hcnetdisk.c
test: $(ROOT)/device/hcnetdisk.c
clean:
    rm -f test *.o a.out core temp.* *.a *.so
include $(ROOT)/Make.common.inc
service/client
Binary files differ
service/client.c
New file
@@ -0,0 +1,132 @@
#include "usg_common.h"
#include "netdisk.h"
#include "hcnetdisk.h"
#include <jsoncpp/json/json.h>
#include <nng/nng.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
const char *url = "tcp://127.0.0.1:8899";
void
fatal(const char *func, int rv)
{
  fprintf(stderr, "%s: %s\n", func, nng_strerror(rv));
  exit(1);
}
void doLogin(nng_socket sock) {
    char *     buf = NULL;
    int        rv;
    size_t     sz;
    Json::Value request;
    Json::Value arguments;
    arguments["loginUUID"] = "1";
    arguments["deviceType"] = "HC";
    arguments["username"] = "admin";
    arguments["password"] = "a1234567";
    arguments["host"] = "192.168.20.11";
    arguments["port"] = 8000;
    request["method"] = "login";
    request["arguments"]= arguments;
    std::string str = request.toStyledString();
    if ((rv = nng_send(sock, strdupa(str.c_str()), str.length(), 0)) != 0) {
        fatal("nng_send", rv);
    }
    if ((rv = nng_recv(sock, &buf, &sz, NNG_FLAG_ALLOC)) != 0) {
        fatal("nng_recv", rv);
    }
    std::cout << buf;
    nng_free(buf, sz);
}
void doDownloadByTime(nng_socket sock) {
    char *     buf = NULL;
    int        rv;
    size_t     sz;
    Json::Value request;
    Json::Value arguments;
    arguments["loginUUID"] = "1";
    Json::Value start;
    start["year"] = 2020;
    start["mon"] = 4;
    start["day"] = 10;
    start["hour"] = 14;
    start["min"] = 20;
    start["sec"] = 0;
    arguments["start"] = start;
    Json::Value end;
    end["year"] = 2020;
    end["mon"] = 4;
    end["day"] = 10;
    end["hour"] = 15;
    end["min"] = 20;
    end["sec"] = 0;
    arguments["end"] = end;
    arguments["channel"] = 1;
    arguments["destpath"] = "/home/basic/data/Downloads/test";
    arguments["host"] = "192.168.20.11";
    arguments["port"] = 8000;
    request["method"] = "downloadByTime";
    request["arguments"]= arguments;
    std::string str = request.toStyledString();
    if ((rv = nng_send(sock, strdup(str.c_str()), str.length(), 0)) != 0) {
        fatal("nng_send", rv);
    }
    if ((rv = nng_recv(sock, &buf, &sz, NNG_FLAG_ALLOC)) != 0) {
        fatal("nng_recv", rv);
    }
    std::cout << buf << std::endl;
    // Json::Reader jsonreader;
    // Json::Value response;
    // jsonreader.parse(buf, response);
    // std::cout << response["payload"]["filelist"][3];
    nng_free(buf, sz);
}
int
client(const char *method)
{
    nng_socket sock;
    int        rv;
    if ((rv = nng_req0_open(&sock)) != 0) {
        fatal("nng_socket", rv);
    }
    if ((rv = nng_dial(sock, url, NULL, 0)) != 0) {
        fatal("nng_dial", rv);
    }
    printf("CLIENT: SENDING DATE REQUEST\n");
    if (strcmp(method, "login") == 0) {
        doLogin(sock);
    } else if (strcmp(method, "download") == 0) {
        doDownloadByTime(sock);
    } else {
        printf("Don't surpport %s \n", method);
    }
    nng_close(sock);
    return (0);
}
int
main(const int argc, const char **argv)
{
    if ((argc > 1))
        return (client(argv[1]));
    // std::string str("123");
    // char *str2="123";
    // printf("str length  %d, %d\n", str.length(), strlen(str2));
    fprintf(stderr, "Usage: client  <method> ...\n");
    return (1);
}
service/core
Binary files differ
service/netdisk_service
Binary files differ
service/netdisk_service.c
New file
@@ -0,0 +1,245 @@
#include "usg_common.h"
#include "netdisk.h"
#include "hcnetdisk.h"
#include <jsoncpp/json/json.h>
#include <nng/nng.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
using namespace std;
const char *url = "tcp://127.0.0.1:8899";
Json::Value loginData;
std::map<std::string, Netdisk *> *userDeviceMap;
std::string login_data_file = "../data/login.dat";
int saveLoginInfo(Netdisk_LoginInfo &loginInfo) {
    Json::Value item;
    item["loginUUID"] = loginInfo.loginUUID;
    item["deviceType"] = loginInfo.deviceType;
    item["username"] = loginInfo.username;
    item["password"] = loginInfo.password;
    item["host"] = loginInfo.host;
    item["port"] = loginInfo.port;
    loginData[loginInfo.loginUUID] = item;
    auto str = loginData.toStyledString();
    // std::cout << str << std::endl;
    std::ofstream fout(login_data_file);
    fout << str;
    fout.close();
    return 0;
}
Netdisk_LoginInfo  getLoginInfo(std::string uuid) {
 Json::Value item = loginData[uuid];
 Netdisk_LoginInfo loginInfo;
 loginInfo.loginUUID = item["loginUUID"].asString();
 loginInfo.deviceType = item["deviceType"].asString();
 loginInfo.username = item["username"].asString();
 loginInfo.password = item["password"].asString();
 loginInfo.host = item["host"].asString();
 loginInfo.port = item["port"].asInt();
 return loginInfo;
}
void
fatal(const char *func, int rv)
{
  fprintf(stderr, "%s: %s\n", func, nng_strerror(rv));
  exit(1);
}
int handleLogin(nng_socket sock, Json::Value request) {
  int rv, code;
  // char *buf;
  Netdisk *netdisk = NULL;
  Json::Value arguments = request["arguments"];
  //登录
  Netdisk_LoginInfo loginInfo;
  loginInfo.loginUUID=arguments["loginUUID"].asString();
  loginInfo.deviceType = arguments["deviceType"].asString();
  loginInfo.host = arguments["host"].asString();
  loginInfo.port = arguments["port"].asInt();
  loginInfo.username = arguments["username"].asString();
  loginInfo.password = arguments["password"].asString();
  std::map<std::string, Netdisk *>::iterator userDeviceIter = userDeviceMap->find(loginInfo.loginUUID);
  if( userDeviceIter != userDeviceMap->end() ) {
     netdisk = userDeviceIter->second;
  }
  if (netdisk == NULL) {
    printf("=========null\n");
    if(loginInfo.deviceType == "HC") {
      // std::cout << "new HCNetdisk" << std::endl;
      netdisk = new HCNetdisk();
      userDeviceMap->insert({loginInfo.loginUUID, netdisk});
    } else {
      err_msg(0, "无法识别的设备类型: %s", loginInfo.deviceType.c_str());
    }
  }
  code = netdisk->login(loginInfo);
  if (code == 0) {
    saveLoginInfo(loginInfo);
    std::cout << "起始通道:" << netdisk->getStartChannel() << ", 最大通道号:" << netdisk->getMaxChannels() << std::endl;
  }
  Json::Value response;
  Json::Value payload;
  payload["loginUUID"] = loginInfo.loginUUID;
  response["code"] = code;
  response["payload"]  = payload;
  const std::string str = response.toStyledString();
  // nng内部会释放buf
  rv = nng_send(sock, strdup(str.c_str()), str.length(), NNG_FLAG_ALLOC);
  //free(buf);
  if (rv != 0) {
    fatal("nng_send", rv);
    return rv;
  }
  return 0;
}
int handleDownloadByTime(nng_socket sock, Json::Value request) {
  int rv, code;
  // char *buf;
  Netdisk *netdisk = NULL;
  Json::Value arguments = request["arguments"];
  Netdisk_DownloadRequest drequest;
  drequest.loginUUID = arguments["loginUUID"].asString();
  Json::Value start = arguments["start"];
  drequest.start.tm_year = start["year"].asInt()-1900; // 这个时间类型从1900开始算作第一年
  drequest.start.tm_mon = start["mon"].asInt()-1; // 0是第一个月
  drequest.start.tm_mday = start["day"].asInt();
  drequest.start.tm_hour = start["hour"].asInt();
  drequest.start.tm_min = start["min"].asInt();
  drequest.start.tm_sec = start["sec"].asInt();
  Json::Value end = arguments["end"];
  drequest.end.tm_year = end["year"].asInt()-1900; // 这个时间类型从1900开始算作第一年
  drequest.end.tm_mon = end["mon"].asInt()-1; // 0是第一个月
  drequest.end.tm_mday = end["day"].asInt();
  drequest.end.tm_hour = end["hour"].asInt();
  drequest.end.tm_min = end["min"].asInt();
  drequest.end.tm_sec = end["sec"].asInt();
  drequest.channel = arguments["channel"].asInt();
  drequest.destpath = arguments["destpath"].asString();
  std::map<string, Netdisk *>::iterator userDeviceIter = userDeviceMap->find( drequest.loginUUID);
  if( userDeviceIter != userDeviceMap->end() ) {
     netdisk = userDeviceIter->second;
  }
  Netdisk_LoginInfo loginInfo = getLoginInfo(drequest.loginUUID);
  if (netdisk == NULL) {
    if(loginInfo.deviceType == "HC") {
      // std::cout << "new HCNetdisk" << std::endl;
      netdisk = new HCNetdisk();
      userDeviceMap->insert({loginInfo.loginUUID, netdisk});
    } else {
      err_msg(0, "无法识别的设备类型: %s", loginInfo.deviceType.c_str());
    }
  }
  if ( (code = netdisk->login(loginInfo)) != 0 ) {
    printf("下载登录失败\n");
  }
  std::vector<std::string> files;
  if ( (code = netdisk->downloadByTime(drequest, &files) ) != 0) {
    printf("下载失败\n");
  }
  Json::Value response;
  Json::Value payload;
  response["code"] = code;
  Json::Value filelist;
  for(std::string f : files) {
    filelist.append(f);
  }
  payload["filelist"] = filelist;
  response["payload"] = payload;
  std::string str = response.toStyledString();
  std::cout << str << std::endl;
  rv = nng_send(sock, strdup(str.c_str()), str.length(), NNG_FLAG_ALLOC);
  if (rv != 0) {
    fatal("nng_send", rv);
    return rv;
  }
  return 0;
}
int
server()
{
  Json::Reader jsonreader;
  Json::Value request;
  nng_socket sock;
  int rv;
  if ((rv = nng_rep0_open(&sock)) != 0) {
    fatal("nng_rep0_open", rv);
  }
  if ((rv = nng_listen(sock, url, NULL, 0)) != 0) {
    fatal("nng_listen", rv);
  }
  for (;;) {
    char *   buf = NULL;
    size_t   sz;
    if ((rv = nng_recv(sock, &buf, &sz, NNG_FLAG_ALLOC)) != 0) {
      fatal("nng_recv", rv);
    }
    jsonreader.parse(buf, request);
    std::string method = request["method"].asString();
    if (method == "login") {
      handleLogin(sock, request);
    } else if (method == "downloadByTime") {
      handleDownloadByTime(sock, request);
    } else {
      std::cerr << "Don't support " << method << std::endl;
    }
    // Unrecognized command, so toss the buffer.
    nng_free(buf, sz);
  }
}
int main()
{
  Netdisk_EnvConfig config;
  config.libpath = "../hclib/";
  HCNetdisk::netdisk_init(&config);
  Json::Reader jsonreader;
  ifstream fin(login_data_file);
  jsonreader.parse(fin, loginData);
  fin.close();
  userDeviceMap = new std::map<std::string, Netdisk *>();
  server();
  HCNetdisk::netdisk_deinit();
}
service/test
Binary files differ
service/test.c
New file
@@ -0,0 +1,70 @@
#include "usg_common.h"
#include "netdisk.h"
#include "hcnetdisk.h"
void test1() {
    Netdisk *netdisk = new HCNetdisk();
    //登录
    Netdisk_LoginInfo loginInfo;
    loginInfo.loginUUID="1";
    loginInfo.deviceType="HC";
    loginInfo.host = "192.168.20.11";
    loginInfo.port = 8000;
    loginInfo.username = "admin";
    loginInfo.password = "a1234567";
    netdisk->login(loginInfo);
    std::cout << "起始通道:" << netdisk->getStartChannel() << ", 最大通道号:" << netdisk->getMaxChannels() << std::endl;
    //下载
    Netdisk_DownloadRequest request;
    request.loginUUID = "1";
    request.start.tm_year = 2020-1900; // 这个时间类型从1900开始算作第一年
    request.start.tm_mon = 4-1; // 0是第一个月
    request.start.tm_mday = 10;
    request.start.tm_hour = 14;
    request.start.tm_min = 20;
    request.start.tm_sec = 0;
    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_sec = 0;
    request.channel = 1;
    request.destpath = "/home/basic/data/Downloads/test";
    std::vector<std::string> files;
    if (netdisk->downloadByTime(request, &files) != 0) {
        printf("下载失败\n");
    } else {
         for(auto f : files) {
            std::cout << f << '\n';
        }
    }
    netdisk->logout();
}
int main() {
    Netdisk_EnvConfig config;
    config.libpath = "../hclib/";
    HCNetdisk::netdisk_init(&config);
    test1();
    // test2();
    HCNetdisk::netdisk_deinit();
}
test/Makefile
@@ -5,7 +5,7 @@
LDLIBS+=-Wl,-rpath=../hclib:../hclib/HCNetSDKCom:../common
LDDIR += -L$(ROOT)/hcnetdisk_wrapper -L../hclib -L../hclib/HCNetSDKCom
LDLIBS +=  -lhcnetsdk -lhpr -lHCCore 
LDLIBS += -lpthread  -ljsoncpp -lnanomsg
LDLIBS +=   -ljsoncpp  -lnng  -lpthread
LIB_NETDISK = libnetdisk.a
DLIB_NETDISK = libnetdisk.so
PLATFORM=$(shell $(ROOT)/systype.sh)
@@ -13,9 +13,8 @@
 
all: download1 test_file test_io profile test_json
all: nng/reqrep
test_file: test_file.c
clean:
    rm -f test *.o a.out core temp.* *.a *.so
test/nanomsg/bus
Binary files differ
test/nanomsg/bus.c
test/nanomsg/pair
Binary files differ
test/nanomsg/pair.c
test/nanomsg/pipeline
Binary files differ
test/nanomsg/pipeline.c
test/nanomsg/pubsub
Binary files differ
test/nanomsg/pubsub.c
test/nanomsg/reqrep
Binary files differ
test/nanomsg/reqrep.c
New file
@@ -0,0 +1,106 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <nanomsg/nn.h>
#include <nanomsg/reqrep.h>
#define NODE0 "node0"
#define NODE1 "node1"
#define DATE "DATE"
void
fatal(const char *func)
{
        fprintf(stderr, "%s: %s\n", func, nn_strerror(nn_errno()));
        exit(1);
}
char *
date(void)
{
        time_t now = time(&now);
        struct tm *info = localtime(&now);
        char *text = asctime(info);
        text[strlen(text)-1] = '\0'; // remove '\n'
        return (text);
}
int
node0(const char *url)
{
        int sz_date = strlen(DATE) + 1; // '\0' too
        int sock;
        int rv;
        if ((sock = nn_socket(AF_SP, NN_REP)) < 0) {
                fatal("nn_socket");
        }
          if ((rv = nn_bind(sock, url)) < 0) {
                fatal("nn_bind");
        }
        for (;;) {
                char *buf = NULL;
                int bytes;
                if ((bytes = nn_recv(sock, &buf, NN_MSG, 0)) < 0) {
                        fatal("nn_recv");
                }
                if ((bytes == (strlen(DATE) + 1)) && (strcmp(DATE, buf) == 0)) {
                        printf("NODE0: RECEIVED DATE REQUEST\n");
                        char *d = date();
                        int sz_d = strlen(d) + 1; // '\0' too
                        printf("NODE0: SENDING DATE %s\n", d);
                        if ((bytes = nn_send(sock, d, sz_d, 0)) < 0) {
                                fatal("nn_send");
                        }
                }
                nn_freemsg(buf);
        }
}
int
node1(const char *url)
{
        int sz_date = strlen(DATE) + 1; // '\0' too
        char *buf = NULL;
        int bytes = -1;
        int sock;
        int rv;
        if ((sock = nn_socket(AF_SP, NN_REQ)) < 0) {
                fatal("nn_socket");
        }
        if ((rv = nn_connect (sock, url)) < 0) {
                fatal("nn_connect");
        }
        printf("NODE1: SENDING DATE REQUEST %s\n", DATE);
        if ((bytes = nn_send(sock, DATE, sz_date, 0)) < 0) {
                fatal("nn_send");
        }
        if ((bytes = nn_recv(sock, &buf, NN_MSG, 0)) < 0) {
                fatal("nn_recv");
        }
        printf("NODE1: RECEIVED DATE %s\n", buf);
        nn_freemsg(buf);
        return (nn_shutdown(sock, 0));
}
int
main(const int argc, const char **argv)
{
        if ((argc > 1) && (strcmp(NODE0, argv[1]) == 0))
                return (node0(argv[2]));
        if ((argc > 1) && (strcmp(NODE1, argv[1]) == 0))
                return (node1(argv[2]));
      fprintf(stderr, "Usage: reqrep %s|%s <URL> ...\n", NODE0, NODE1);
      return (1);
}
/*
./reqrep node0 ipc:///tmp/reqrep.ipc & node0=$! && sleep 1
./reqrep node1 ipc:///tmp/reqrep.ipc
kill $node0
*/
test/nanomsg/survey
Binary files differ
test/nanomsg/survey.c
test/nng/reqrep
Binary files differ
test/nng/reqrep.c
@@ -1,106 +1,161 @@
#include <stdlib.h>
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
//
// This is just a simple REQ/REP demonstration application.  It is derived
// from the legacy nanomsg demonstration program of the same name, written
// by Tim Dysinger, but updated for nng.  I've also updated it to pass simpler
// binary data rather than strings over the network.
//
// The program implements a simple RPC style service, which just returns
// the date in UNIX time (seconds since 1970).
//
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <nanomsg/nn.h>
#include <nanomsg/reqrep.h>
#define NODE0 "node0"
#define NODE1 "node1"
#define DATE "DATE"
#include <nng/nng.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
#define CLIENT "client"
#define SERVER "server"
#define DATECMD 1
#define PUT64(ptr, u)                                        \
    do {                                                 \
        (ptr)[0] = (uint8_t)(((uint64_t)(u)) >> 56); \
        (ptr)[1] = (uint8_t)(((uint64_t)(u)) >> 48); \
        (ptr)[2] = (uint8_t)(((uint64_t)(u)) >> 40); \
        (ptr)[3] = (uint8_t)(((uint64_t)(u)) >> 32); \
        (ptr)[4] = (uint8_t)(((uint64_t)(u)) >> 24); \
        (ptr)[5] = (uint8_t)(((uint64_t)(u)) >> 16); \
        (ptr)[6] = (uint8_t)(((uint64_t)(u)) >> 8);  \
        (ptr)[7] = (uint8_t)((uint64_t)(u));         \
    } while (0)
#define GET64(ptr, v)                                 \
    v = (((uint64_t)((uint8_t)(ptr)[0])) << 56) + \
        (((uint64_t)((uint8_t)(ptr)[1])) << 48) + \
        (((uint64_t)((uint8_t)(ptr)[2])) << 40) + \
        (((uint64_t)((uint8_t)(ptr)[3])) << 32) + \
        (((uint64_t)((uint8_t)(ptr)[4])) << 24) + \
        (((uint64_t)((uint8_t)(ptr)[5])) << 16) + \
        (((uint64_t)((uint8_t)(ptr)[6])) << 8) +  \
        (((uint64_t)(uint8_t)(ptr)[7]))
void
fatal(const char *func)
fatal(const char *func, int rv)
{
        fprintf(stderr, "%s: %s\n", func, nn_strerror(nn_errno()));
        exit(1);
    fprintf(stderr, "%s: %s\n", func, nng_strerror(rv));
    exit(1);
}
char *
date(void)
void
showdate(time_t now)
{
        time_t now = time(&now);
        struct tm *info = localtime(&now);
        char *text = asctime(info);
        text[strlen(text)-1] = '\0'; // remove '\n'
        return (text);
    struct tm *info = localtime(&now);
    printf("%s", asctime(info));
}
int
node0(const char *url)
server(const char *url)
{
        int sz_date = strlen(DATE) + 1; // '\0' too
        int sock;
        int rv;
    nng_socket sock;
    int        rv;
        if ((sock = nn_socket(AF_SP, NN_REP)) < 0) {
                fatal("nn_socket");
        }
          if ((rv = nn_bind(sock, url)) < 0) {
                fatal("nn_bind");
        }
        for (;;) {
                char *buf = NULL;
                int bytes;
                if ((bytes = nn_recv(sock, &buf, NN_MSG, 0)) < 0) {
                        fatal("nn_recv");
                }
                if ((bytes == (strlen(DATE) + 1)) && (strcmp(DATE, buf) == 0)) {
                        printf("NODE0: RECEIVED DATE REQUEST\n");
                        char *d = date();
                        int sz_d = strlen(d) + 1; // '\0' too
                        printf("NODE0: SENDING DATE %s\n", d);
                        if ((bytes = nn_send(sock, d, sz_d, 0)) < 0) {
                                fatal("nn_send");
                        }
                }
                nn_freemsg(buf);
        }
    if ((rv = nng_rep0_open(&sock)) != 0) {
        fatal("nng_rep0_open", rv);
    }
    if ((rv = nng_listen(sock, url, NULL, 0)) != 0) {
        fatal("nng_listen", rv);
    }
    for (;;) {
        char *   buf = NULL;
        size_t   sz;
        uint64_t val;
        if ((rv = nng_recv(sock, &buf, &sz, NNG_FLAG_ALLOC)) != 0) {
            fatal("nng_recv", rv);
        }
        if ((sz == sizeof(uint64_t)) &&
            ((GET64(buf, val)) == DATECMD)) {
            time_t now;
            printf("SERVER: RECEIVED DATE REQUEST\n");
            now = time(&now);
            printf("SERVER: SENDING DATE: ");
            showdate(now);
            // Reuse the buffer.  We know it is big enough.
            PUT64(buf, (uint64_t) now);
            rv = nng_send(sock, buf, sz, NNG_FLAG_ALLOC);
            if (rv != 0) {
                fatal("nng_send", rv);
            }
            continue;
        }
        // Unrecognized command, so toss the buffer.
        nng_free(buf, sz);
    }
}
int
node1(const char *url)
client(const char *url)
{
        int sz_date = strlen(DATE) + 1; // '\0' too
        char *buf = NULL;
        int bytes = -1;
        int sock;
        int rv;
    nng_socket sock;
    int        rv;
    size_t     sz;
    char *     buf = NULL;
    uint8_t    cmd[sizeof(uint64_t)];
        if ((sock = nn_socket(AF_SP, NN_REQ)) < 0) {
                fatal("nn_socket");
        }
        if ((rv = nn_connect (sock, url)) < 0) {
                fatal("nn_connect");
        }
        printf("NODE1: SENDING DATE REQUEST %s\n", DATE);
        if ((bytes = nn_send(sock, DATE, sz_date, 0)) < 0) {
                fatal("nn_send");
        }
        if ((bytes = nn_recv(sock, &buf, NN_MSG, 0)) < 0) {
                fatal("nn_recv");
        }
        printf("NODE1: RECEIVED DATE %s\n", buf);
        nn_freemsg(buf);
        return (nn_shutdown(sock, 0));
    PUT64(cmd, DATECMD);
    if ((rv = nng_req0_open(&sock)) != 0) {
        fatal("nng_socket", rv);
    }
    if ((rv = nng_dial(sock, url, NULL, 0)) != 0) {
        fatal("nng_dial", rv);
    }
    printf("CLIENT: SENDING DATE REQUEST\n");
    if ((rv = nng_send(sock, cmd, sizeof(cmd), 0)) != 0) {
        fatal("nng_send", rv);
    }
    if ((rv = nng_recv(sock, &buf, &sz, NNG_FLAG_ALLOC)) != 0) {
        fatal("nng_recv", rv);
    }
    if (sz == sizeof(uint64_t)) {
        uint64_t now;
        GET64(buf, now);
        printf("CLIENT: RECEIVED DATE: ");
        showdate((time_t) now);
    } else {
        printf("CLIENT: GOT WRONG SIZE!\n");
    }
    // This assumes that buf is ASCIIZ (zero terminated).
    nng_free(buf, sz);
    nng_close(sock);
    return (0);
}
int
main(const int argc, const char **argv)
{
        if ((argc > 1) && (strcmp(NODE0, argv[1]) == 0))
                return (node0(argv[2]));
    if ((argc > 1) && (strcmp(CLIENT, argv[1]) == 0))
        return (client(argv[2]));
        if ((argc > 1) && (strcmp(NODE1, argv[1]) == 0))
                return (node1(argv[2]));
    if ((argc > 1) && (strcmp(SERVER, argv[1]) == 0))
        return (server(argv[2]));
      fprintf(stderr, "Usage: reqrep %s|%s <URL> ...\n", NODE0, NODE1);
      return (1);
    fprintf(stderr, "Usage: reqrep %s|%s <URL> ...\n", CLIENT, SERVER);
    return (1);
}
/*
./reqrep node0 ipc:///tmp/reqrep.ipc & node0=$! && sleep 1
./reqrep node1 ipc:///tmp/reqrep.ipc
kill $node0
*/