Browse Source

init proj

storage-in-realtime
zhaohe 12 months ago
parent
commit
426b289831
  1. 6
      .gitmodules
  2. 14
      CMakeLists.txt
  3. 26
      app_protocols/apperrorcode/apperrorcode.hpp
  4. 45
      app_protocols/appexception/zexception.hpp
  5. 1
      app_protocols/transmit_disfection_protocol
  6. 1
      app_protocols/zscanprotocol
  7. 0
      src/app/app_components/app_errorcode_mgr.cpp
  8. 0
      src/app/app_components/app_errorcode_mgr.hpp
  9. 56
      src/components/simple_udp/simple_udp.cpp
  10. 58
      src/components/simple_udp/simple_udp.hpp
  11. 2
      src/components/sqlite_orm/README.md
  12. 18253
      src/components/sqlite_orm/sqlite_orm.hpp
  13. 28
      src/components/uart_printer/uart_printer.cpp
  14. 37
      src/components/uart_printer/uart_printer.hpp
  15. 41
      src/components/ziconv.cpp
  16. 24
      src/components/ziconv.hpp

6
.gitmodules

@ -0,0 +1,6 @@
[submodule "app_protocols/transmit_disfection_protocol"]
path = app_protocols/transmit_disfection_protocol
url = zwsd@192.168.1.3:p_transmit_disinfection_v3/transmit_disfection_protocol.git
[submodule "app_protocols/zscanprotocol"]
path = app_protocols/zscanprotocol
url = zwsd@192.168.1.3:zprotocols/zscanprotocol.git

14
CMakeLists.txt

@ -40,9 +40,17 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message("PROJECT_NAME: ${PROJECT_NAME}")
file(GLOB_RECURSE APP_SRC #
src/*.cpp #
src/*.c #
file(
GLOB_RECURSE
APP_SRC #
src/*.cpp #
src/*.c #
src/*.hpp #
src/*.h #
app_protocols/*.cpp #
app_protocols/*.c #
app_protocols/*.hpp #
app_protocols/*.h #
)
zadd_executable(

26
app_protocols/apperrorcode/apperrorcode.hpp

@ -0,0 +1,26 @@
#pragma once
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
namespace iflytop {
using namespace std;
typedef enum {
ksucc = 0,
kappe_disinfectant_insufficient = 1, // 消毒液不足
kappe_the_bottom_of_the_device_has_water = 2, // 设备底部有水
kappe_the_evaporation_bin_has_water = 3, // 蒸发仓有水
kappe_the_sensor_is_prehearting = 4, // 传感器正在预热
} apperror_t;
} // namespace iflytop

45
app_protocols/appexception/zexception.hpp

@ -0,0 +1,45 @@
//
// Created by zhaohe on 19-5-21.
//
#pragma once
#include <stdarg.h>
#include <exception>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
namespace iflytop {
using namespace std;
class app_exception : public std::exception {
public:
string description;
string whatstr;
int32_t ecode;
app_exception(int32_t ecode, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
char buffer[1024];
vsnprintf(buffer, sizeof(buffer), fmt, args);
this->description = buffer;
this->description = description;
this->ecode = ecode;
this->whatstr = buffer;
}
virtual ~app_exception() {}
const char *what() const _GLIBCXX_USE_NOEXCEPT { return whatstr.c_str(); }
};
} // namespace iflytop

1
app_protocols/transmit_disfection_protocol

@ -0,0 +1 @@
Subproject commit 9836b9c4356e8cf635be9ab8394d75c8fb301dfe

1
app_protocols/zscanprotocol

@ -0,0 +1 @@
Subproject commit 94c49f650f508e64b9e30e733dbb161c72ae2559

0
src/app/app_components/app_errorcode_mgr.cpp

0
src/app/app_components/app_errorcode_mgr.hpp

56
src/components/simple_udp/simple_udp.cpp

@ -0,0 +1,56 @@
#include "simple_udp.hpp"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
using namespace std;
using namespace iflytop;
using namespace core;
void SimpleUDP::initialize(int port) {
// 建立一个UDP的socket
m_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (m_socket == -1) {
logger->error("socket failed");
return;
}
// 绑定地址信息
struct sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(port);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(m_socket, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
logger->error("bind {} failed,", port);
return;
}
logger->info("bind {} success", port);
m_thread.reset(new Thread("udpThread", [this]() { //
struct sockaddr_in peeraddr;
socklen_t peerlen;
while (true) {
memset(m_rxbuf, 0, sizeof(m_rxbuf));
memset(&peeraddr, 0, sizeof(sockaddr_in));
peerlen = sizeof(sockaddr_in);
int ret = recvfrom(m_socket, m_rxbuf, sizeof(m_rxbuf), 0, (struct sockaddr *)&peeraddr, &peerlen);
logger->debug("Recv msg {} from IP:{} Port:{}\n", m_rxbuf, inet_ntoa(peeraddr.sin_addr), ntohs(peeraddr.sin_port));
// int wret = ::sendto(m_socket, "Hello World!", strlen("Hello World!"), 0, (sockaddr *)&peeraddr, peerlen);
// logger->debug("sendto ret:{}", wret);
// perror("sendto");
if (ret < 0) {
logger->error("recvfrom failed, {}", strerror(errno));
continue;
}
if (m_on_recv) {
m_on_recv(&peeraddr, m_rxbuf, ret);
}
}
}));
return;
};

58
src/components/simple_udp/simple_udp.hpp

@ -0,0 +1,58 @@
//
// Created by zwsd
//
#pragma once
#include <errno.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h> /* See NOTES */
#include <sys/types.h>
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include "iflytop/core/core.hpp"
/**
* @brief
*
* service: SimpleUDP
*
* :
* :
* :
* :
*
*/
namespace iflytop {
using namespace std;
using namespace core;
class SimpleUDP : public enable_shared_from_this<SimpleUDP> {
ENABLE_LOGGER(SimpleUDP);
int m_socket = -1;
unique_ptr<Thread> m_thread;
char m_rxbuf[1024];
typedef function<void(struct sockaddr_in* from, char* data, size_t len)> on_recv_t;
on_recv_t m_on_recv;
public:
SimpleUDP(){};
void initialize(int port);
void set_on_recv(on_recv_t on_recv) { m_on_recv = on_recv; }
void sendto(struct sockaddr_in* from, const char* data, size_t len) { ::sendto(m_socket, data, len, 0, (struct sockaddr*)from, sizeof(struct sockaddr_in)); }
};
} // namespace iflytop

2
src/components/sqlite_orm/README.md

@ -0,0 +1,2 @@
v1.8.2
https://github.com/fnc12/sqlite_orm

18253
src/components/sqlite_orm/sqlite_orm.hpp
File diff suppressed because it is too large
View File

28
src/components/uart_printer/uart_printer.cpp

@ -0,0 +1,28 @@
#include "uart_printer.hpp"
using namespace iflytop;
using namespace core;
UartPrinter::UartPrinter() {}
UartPrinter::~UartPrinter() {}
void UartPrinter::initialize(string path, string rate) {
logger->info("initialize uart printer {} {}", path, rate);
m_path = path;
m_rate = rate;
m_uart = make_shared<Uart>();
int ret = m_uart->open(path, rate);
if (ret != 0) {
logger->error("open uart {} failed", path);
m_isopen = false;
return;
}
m_isopen = true;
return;
}
void UartPrinter::print(string str) {
if (!m_isopen) {
logger->error("uart {} is not open", m_path);
return;
}
m_uart->send((char *)str.c_str(), str.size());
return;
}

37
src/components/uart_printer/uart_printer.hpp

@ -0,0 +1,37 @@
#pragma once
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include "iflytop/core/components/uart/uart.hpp"
#include "iflytop/core/spdlogfactory/logger.hpp"
namespace iflytop {
namespace core {
using namespace std;
class UartPrinter {
ENABLE_LOGGER(UartPrinter);
private:
shared_ptr<Uart> m_uart;
string m_path;
string m_rate;
bool m_isopen = false;
public:
UartPrinter();
~UartPrinter();
void initialize(string path, string rate);
void print(string str);
};
} // namespace core
} // namespace iflytop

41
src/components/ziconv.cpp

@ -0,0 +1,41 @@
#include <iconv.h>
#include "ziconv.hpp"
using namespace iflytop;
string ZIconv::utf8_to_gb2312(const std::string& utf8_str) {
// 打开转换描述符
iconv_t cd = iconv_open("GB2312", "UTF-8");
if (cd == (iconv_t)-1) {
perror("iconv_open failed");
exit(EXIT_FAILURE);
}
// 输入字符串
const char* in_str = utf8_str.c_str();
size_t in_size = utf8_str.size();
// 输出缓冲区
size_t out_size = in_size * 2; // 假设输出的字节数不会超过输入的两倍
char* out_buf = new char[out_size];
char* out_str = out_buf;
// 进行转换
if (iconv(cd, const_cast<char**>(&in_str), &in_size, &out_str, &out_size) == (size_t)-1) {
perror("iconv failed");
iconv_close(cd);
delete[] out_buf;
exit(EXIT_FAILURE);
}
// 关闭转换描述符
iconv_close(cd);
// 获取转换后的字符串
std::string gb2312_str(out_buf, out_str - out_buf);
// 释放内存
delete[] out_buf;
return gb2312_str;
}

24
src/components/ziconv.hpp

@ -0,0 +1,24 @@
#pragma once
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
namespace iflytop {
using namespace std;
class ZIconv {
private:
/* data */
public:
static string utf8_to_gb2312(const string& utf8_str);
static string toGB2312(const string& utf8_str) { return utf8_to_gb2312(utf8_str); }
static string noChange(const string& utf8_str) { return utf8_str; }
};
} // namespace iflytop
Loading…
Cancel
Save