Browse Source

update

master
zhaohe 2 years ago
parent
commit
87aa3936e6
  1. 18
      .vscode/c_cpp_properties.json
  2. 6
      CMakeLists.txt
  3. 18
      README.md
  4. 2
      iflytoplinuxsdk
  5. 28
      init.sh
  6. 27
      src/configs/gconfig.hpp
  7. 10
      src/configs/project_setting.hpp
  8. 61
      src/main.cpp
  9. 51
      src/main.hpp
  10. 42
      src/main_control_service.cpp
  11. 74
      src/main_control_service.hpp
  12. 0
      src/service/front_end_service.cpp
  13. 41
      src/service/front_end_service.hpp
  14. 2
      src/version.hpp
  15. 8
      src/zservice_container/zservice_container.cpp
  16. 200
      src/zservice_container/zservice_container.hpp

18
.vscode/c_cpp_properties.json

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/src",
"${workspaceFolder}/iflytoplinuxsdk/src/",
],
"compilerPath": "/usr/bin/g++",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}

6
CMakeLists.txt

@ -50,18 +50,20 @@ file(
)
message("VAR_APP_SOURCE: ${VAR_APP_SOURCE}")
zadd_executable(
TARGET
app.out #
SRC
${VAR_APP_SOURCE}
LINK_DIRECTORIES
libs/libixwebsocket/lib
LINK_LIBRARIES
pthread
libixwebsocket.a
#
INCLUDE_DIRECTORIES
src
iflytoplinuxsdk/src/iflytop/core/spdlog/include/
iflytoplinuxsdk/src/
libs/libixwebsocket/include
./)

18
README.md

@ -0,0 +1,18 @@
# README
```
1. 功能点
FrontEndService
MainCtrlService
UnixCan
IflytopCmdServer
SqlService
UsrDB
SensorDataDB
DisinfectionRecordDB
DeviceConfigDB
```

2
iflytoplinuxsdk

@ -1 +1 @@
Subproject commit 3edbad7ca097f108cef97f9e89e80da1310263e5
Subproject commit 9fbd8473108b10c6d0e69ed663fa27fee5d4dfa0

28
init.sh

@ -0,0 +1,28 @@
#!/bin/bash
LIBSDIR=$(pwd)/libs/
mkdir -p ${LIBSDIR}
function prepare_ifytop_librelease_libs() {
cd ${IFLYBUILD_TARGET_LIBS_DIR}
libname=$1
linklibs=$2
url=$3
wget -c $3
tarname=$(basename $3)
# unpackname=tarname 去掉.tar.gz, 例如iflytopv1.3.0.tar.gz -> iflytopv1.3.0
unpackname=${tarname%.tar.gz}
tar -xvf $tarname >/dev/null
rm -rf ${LIBSDIR}/$libname
mv $unpackname ${LIBSDIR}/$libname
LINK_DIRECTORIES="${LINK_DIRECTORIES};${LIBSDIR}/$libname/lib"
INCLUDE_DIRECTORIES="${INCLUDE_DIRECTORIES};${LIBSDIR}/$libname/include"
LINK_LIBS="${LINK_LIBS};$linklibs"
}
prepare_ifytop_librelease_libs libixwebsocket "ixwebsocket" "http://192.168.1.2:8021/zlibrelease/libixwebsocket/libixwebsocket_v11.4.3_aarch64_static_ubuntu18.04_0.tar.gz"
echo "$LINK_DIRECTORIES"
echo "$INCLUDE_DIRECTORIES"
echo "$LINK_LIBS"

27
src/configs/gconfig.hpp

@ -0,0 +1,27 @@
#pragma once
#include <exception>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include "iflytop/core/components/config_template/config_template.hpp"
#define ConfigELEMENT_LIST(marco) \
marco(string /* */, deviceId, "") /*设备ID*/ \
marco(string /* */, iflytopSubDeviceCanIFName, "can0") /*子设备Can设备名称*/ \
marco(int32_t /* */, iflytopSubDeviceCanBitrate, 500000) /*子设备Can设备波特率*/ \
marco(string /* */, pipettingRobotCanIFName, "can1") /*移液臂Can设备名称*/ \
marco(int32_t /* */, pipettingRobotCanBitrate, 500000) /*移液臂Can设备波特率*/
configTemplateDEFILE_CONFIG_SERVICE2( //
GConfig, //
ConfigELEMENT_LIST, //
"./configs/config.json", {});

10
src/configs/project_setting.hpp

@ -0,0 +1,10 @@
#pragma once
#define LINUX_HARDWARE_ID (0x02)
/*******************************************************************************
* LINUX_HARDWARE_REG *
*******************************************************************************/
#define REG_REBOOT_FLAG 0x0000 // 重启标识
#define REG_DEVICE_ID 0x0001 // 重启标识
#define REG_EXCEPTION_FLAG 0x0100 // 异常标志位

61
src/main.cpp

@ -1,5 +1,58 @@
int main(int argc, char const *argv[])
{
return 0;
#include "main.hpp"
#include <signal.h>
using namespace iflytop;
using namespace core;
using namespace std;
/*******************************************************************************
* MAIN => MAIN *
*******************************************************************************/
Main *Main::g_main;
int main(int argc, char *argv[]) {
Main main;
Main::g_main = &main;
main.run(argc, argv);
}
void Main::onsignal(int signo) { exit(0); }
void Main::run(int argc, char *argv[]) {
// ::signal(SIGINT, Main::_onsignal);
thread.reset(new Thread("main", [&]() { exit(main(argc, argv)); }));
while (true) sleep(1000);
}
int Main::main(int argc, char *argv[]) {
/**
* @brief
*/
// string device_id;
// auto cli = ((required("-device_id") & value("device_id", device_id)).doc("device_id"));
// if (!parse(argc, argv, cli)) {
// cout << make_man_page(cli, argv[0]);
// exit(-1);
// }
/**
* @brief
*/
logger->info("system setup start.");
spdlog::flush_on(spdlog::level::debug);
logger->info("#");
logger->info("# company:{}", "ifytop");
logger->info("# version:{}", VERSION);
logger->info("#");
logger->info("build {}.....", "Config");
// 构造GConfig
BUILD_AND_REG_SERRVICE(GConfig);
GET_SERVICE(GConfig)->initialize();
/**
* @brief
*/
// if (!device_id.empty()) GET_SERVICE(GConfig)->set_deviceId(device_id);
auto config = GET_SERVICE(GConfig);
// 构造MainControlService
BUILD_AND_REG_SERRVICE(MainControlService);
GET_SERVICE(MainControlService)->initialize();
logger->info("system setup end.");
while (true) sleep(1000);
}

51
src/main.hpp

@ -0,0 +1,51 @@
// #include <curl/curl.h>
#pragma once
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
//
#include "configs/gconfig.hpp"
#include "iflytop/core/spdlogfactory/logger.hpp"
#include "iflytop/core/thread/thread.hpp"
#include "version.hpp"
#include "zservice_container/zservice_container.hpp"
#include "iflytop/components/zclicpp/clipp.h"
//
#include "main_control_service.hpp"
namespace iflytop {
using namespace iflytop;
using namespace core;
using namespace std;
using namespace clipp;
class Main {
ENABLE_LOGGER(Main);
private:
unique_ptr<Thread> thread;
private:
int main(int argc, char *argv[]);
public:
static Main *g_main;
static void _onsignal(int signo) { g_main->onsignal(signo); }
void onsignal(int signo);
public:
Main(/* args */) {}
~Main() {}
void run(int argc, char *argv[]);
void dosystem(string order, bool dump) {
if (dump) logger->info("{}", order);
system(order.c_str());
}
};
} // namespace iflytop

42
src/main_control_service.cpp

@ -0,0 +1,42 @@
#include "main_control_service.hpp"
#include "configs/project_setting.hpp"
#include "iflytop/core/components/stringutils.hpp"
#include "version.hpp"
using namespace iflytop;
using namespace core;
using namespace std;
#define BIND
void MainControlService::initialize() {
GET_TO_SERVICE(m_zconfig);
// m_iflytopCanProtocolControler.reset(new IflytopCanProtocolControler());
// m_iflytopCanProtocolControler->initialize(m_zconfig->get_iflytopSubDeviceCanIFName(), m_zconfig->get_iflytopSubDeviceCanBitrate(), false);
// m_iflytopCanProtocolControler->start();
m_restfulServer.reset(new RestfulServer());
m_restfulServer->regAPI("/hello_world", RESTFUL_SERVER_BIND(MainControlService::hello_world));
m_restfulServer->regAPI("/api1/script_processer/doscript", RESTFUL_SERVER_BIND(MainControlService::doscript));
m_restfulServer->regAPI("/api1/script_processer/stopscript", RESTFUL_SERVER_BIND(MainControlService::stopscript));
m_restfulServer->start(20000, 20001, "0.0.0.0");
};
HttpResponsePtr MainControlService::hello_world( //
HttpRequestPtr request, shared_ptr<RestfulServer::Context> context, std::shared_ptr<ConnectionState>) {
return std::make_shared<HttpResponse>(200, "OK", HttpErrorCode::Ok, WebSocketHttpHeaders(), "hello_world");
}
HttpResponsePtr MainControlService::doscript(HttpRequestPtr httpreq, shared_ptr<RestfulServer::Context> context, std::shared_ptr<ConnectionState> conn) {
// logger->info("do\n{}", httpreq->body);
// if (m_a8000_script_processer->isWorking()) {
// return std::make_shared<HttpResponse>(200, "FAIL", HttpErrorCode::Ok, WebSocketHttpHeaders(), "do script fail, script processer is running");
// }
// m_a8000_script_processer->executeScript(httpreq->body);
return std::make_shared<HttpResponse>(200, "OK", HttpErrorCode::Ok, WebSocketHttpHeaders(), "do script success");
}
HttpResponsePtr MainControlService::stopscript(HttpRequestPtr, shared_ptr<RestfulServer::Context>, std::shared_ptr<ConnectionState>) {
// m_a8000_script_processer->stopScript();
return std::make_shared<HttpResponse>(200, "OK", HttpErrorCode::Ok, WebSocketHttpHeaders(), "stop script success");
}

74
src/main_control_service.hpp

@ -0,0 +1,74 @@
//
// Created by zwsd
//
#pragma once
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include "iflytop/core/spdlogfactory/logger.hpp"
#include "iflytop/components/restful_server/restful_server.hpp"
//
#include "configs/gconfig.hpp"
#include "zservice_container/zservice_container.hpp"
//
#include "configs/gconfig.hpp"
#include "iflytop/core/components/jobs/work_queue.hpp"
#include "iflytop/core/components/timer/simple_timer.hpp"
// #include "zlinuxcomponents/iflytop_can_protocol_stack/basic/iflytop_virtual_can_slave.hpp"
// #include "zlinuxcomponents/iflytop_can_protocol_stack/iflytop_can_protocol_controler.hpp"
//
/**
* @brief
*
* service: MainControlService
*
* :
* :
* :
* :
*
*/
namespace iflytop {
using namespace std;
using namespace core;
class MainControlService : public enable_shared_from_this<MainControlService> {
ENABLE_LOGGER(MainControlService);
shared_ptr<GConfig> m_zconfig;
shared_ptr<RestfulServer> m_restfulServer;
public:
MainControlService(){};
void initialize();
private:
void dosystem(string order, bool dump) {
if (dump) logger->info("do:{}", order);
system(order.c_str());
}
private:
HttpResponsePtr reactionConfigCardInfo_read(HttpRequestPtr, shared_ptr<RestfulServer::Context>, std::shared_ptr<ConnectionState>);
HttpResponsePtr reactionConfigCardInfo_trigger_once_report(HttpRequestPtr, shared_ptr<RestfulServer::Context>, std::shared_ptr<ConnectionState>);
HttpResponsePtr reactionConfigCardInfo_read_state(HttpRequestPtr, shared_ptr<RestfulServer::Context>, std::shared_ptr<ConnectionState>);
HttpResponsePtr hello_world(HttpRequestPtr, shared_ptr<RestfulServer::Context>, std::shared_ptr<ConnectionState>);
//
HttpResponsePtr doscript(HttpRequestPtr, shared_ptr<RestfulServer::Context>, std::shared_ptr<ConnectionState>);
HttpResponsePtr doscriptblock(HttpRequestPtr, shared_ptr<RestfulServer::Context>, std::shared_ptr<ConnectionState>);
HttpResponsePtr stopscript(HttpRequestPtr, shared_ptr<RestfulServer::Context>, std::shared_ptr<ConnectionState>);
void createReactionConfigCardInfoReportAndSend();
};
} // namespace iflytop

0
deplib/.mark → src/service/front_end_service.cpp

41
src/service/front_end_service.hpp

@ -0,0 +1,41 @@
//
// Created by zwsd
//
#pragma once
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include "iflytop/core/spdlogfactory/logger.hpp"
#include "iflytop/core/thread/thread.hpp"
/**
* @brief
*
* service: FrontEndService
*
* :
* :
* :
* :
*
*/
namespace iflytop {
using namespace std;
using namespace core;
class FrontEndService : public enable_shared_from_this<FrontEndService> {
ENABLE_LOGGER(FrontEndService);
public:
FrontEndService(){};
void initialize(){};
};
} // namespace iflytop

2
src/version.hpp

@ -0,0 +1,2 @@
#pragma once
#define VERSION "0.1"

8
src/zservice_container/zservice_container.cpp

@ -0,0 +1,8 @@
#include "zservice_container.hpp"
using namespace iflytop;
using namespace std;
ServiceContrainer& ServiceContrainer::get() {
static ServiceContrainer serviceContrainer;
return serviceContrainer;
}

200
src/zservice_container/zservice_container.hpp

@ -0,0 +1,200 @@
//
// Created by zwsd
//
#pragma once
#include <algorithm>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>
/**
* @brief
*
* service: ServiceContrainer
*
* :
* :
* :
* :
*
*/
// std::shared_ptr<Buffer> buf(new Buffer());
// ZserviceContainerAny any(buf);
// std::shared_ptr<Buffer> b = any.Get<std::shared_ptr<Buffer>>();
// assert(buf.get() == b.get());
namespace iflytop {
using namespace std;
class ZserviceContainerAny {
public:
ZserviceContainerAny() : content_(nullptr) {}
~ZserviceContainerAny() { delete content_; }
template <typename ValueType>
explicit ZserviceContainerAny(const ValueType& value) : content_(new Holder<ValueType>(value)) {}
ZserviceContainerAny(const ZserviceContainerAny& other)
: content_(other.content_ ? other.content_->clone() : nullptr) {}
public:
ZserviceContainerAny& swap(ZserviceContainerAny& rhs) {
std::swap(content_, rhs.content_);
return *this;
}
template <typename ValueType>
ZserviceContainerAny& operator=(const ValueType& rhs) {
ZserviceContainerAny(rhs).swap(*this);
return *this;
}
ZserviceContainerAny& operator=(const ZserviceContainerAny& rhs) {
ZserviceContainerAny(rhs).swap(*this);
return *this;
}
bool IsEmpty() const { return !content_; }
const std::type_info& GetType() const { return content_ ? content_->GetType() : typeid(void); }
template <typename ValueType>
ValueType operator()() const {
return Get<ValueType>();
}
template <typename ValueType>
ValueType Get() const {
if (GetType() == typeid(ValueType)) {
return static_cast<ZserviceContainerAny::Holder<ValueType>*>(content_)->held_;
} else {
return ValueType();
}
}
protected:
class ZPlaceHolder {
public:
virtual ~ZPlaceHolder() {}
public:
virtual const std::type_info& GetType() const = 0;
virtual ZPlaceHolder* clone() const = 0;
};
template <typename ValueType>
class Holder : public ZPlaceHolder {
public:
Holder(const ValueType& value) : held_(value) {}
virtual const std::type_info& GetType() const { return typeid(ValueType); }
virtual ZPlaceHolder* clone() const { return new Holder(held_); }
ValueType held_;
};
protected:
ZPlaceHolder* content_;
template <typename ValueType>
friend ValueType* zany_cast(ZserviceContainerAny*);
};
template <typename ValueType>
ValueType* zany_cast(ZserviceContainerAny* any) {
if (any && any->GetType() == typeid(ValueType)) {
return &(static_cast<ZserviceContainerAny::Holder<ValueType>*>(any->content_)->held_);
}
return nullptr;
}
template <typename ValueType>
const ValueType* zany_cast(const ZserviceContainerAny* any) {
return zany_cast<ValueType>(const_cast<ZserviceContainerAny*>(any));
}
template <typename ValueType>
ValueType zany_cast(const ZserviceContainerAny& any) {
const ValueType* result = zany_cast<ValueType>(&any);
assert(result);
if (!result) {
return ValueType();
}
return *result;
}
class ServiceContrainer {
map<type_index, ZserviceContainerAny> services;
ServiceContrainer(){};
public:
static ServiceContrainer& get();
template <typename T>
void regAndInitializeService(shared_ptr<T> object) {
if (object == nullptr) {
return;
}
object->initialize();
type_index index = typeid(T);
services[index] = ZserviceContainerAny(object);
};
template <typename T>
void regService(shared_ptr<T> object) {
if (object == nullptr) {
return;
}
type_index index = typeid(T);
services[index] = ZserviceContainerAny(object);
};
template <typename T>
shared_ptr<T> getService() {
type_index index = typeid(T);
auto result = services.find(index);
if (result == services.end()) {
return nullptr;
}
return result->second.Get<std::shared_ptr<T>>();
};
template <typename T>
void getToService(shared_ptr<T>& service) {
type_index index = typeid(T);
auto result = services.find(index);
if (result == services.end()) {
service = nullptr;
}
service = result->second.Get<std::shared_ptr<T>>();
};
};
#define GET_SERVICE(type) (ServiceContrainer::get().getService<type>())
#define GET_TO_SERVICE(value) \
ServiceContrainer::get().getToService(value); \
if (value == nullptr) { \
logger->error("[{}:{}]GET_TO_SERVICE({}) fail", __FILE__, __LINE__, #value); \
exit(-1); \
};
#define BUILD_AND_REG_SERRVICE(type, ...) \
logger->info("build {}.....", #type); \
shared_ptr<type> type##_val(new type(__VA_ARGS__)); \
ServiceContrainer::get().regService(type##_val);
#define BUILD_AND_REG_MOCK_SERRVICE(type, mocktype, ...) \
logger->info("build {}.....", #type); \
shared_ptr<type> type##_val(new mocktype(__VA_ARGS__)); \
ServiceContrainer::get().regService(type##_val);
} // namespace iflytop
Loading…
Cancel
Save