Browse Source

fix come bug

storage-in-realtime
zhaohe 12 months ago
parent
commit
5eae7d8575
  1. 7
      CMakeLists.txt
  2. 0
      app_protocols/apperrorcode/app_errorcode_mgr.hpp
  3. 5
      app_protocols/appexception/appexception.hpp
  4. 2
      appdep/iflytop/core/thread/thread.cpp
  5. BIN
      appdep/libs/libixwebsocket/aarch64/libixwebsocket.a
  6. BIN
      appdep/libs/libixwebsocket/aarch64/libixwebsocket.bak.a
  7. 68
      appdep/libs/libixwebsocket/include/ixwebsocket/IXSocketOpenSSL.h
  8. 1
      appsrc/appbase/appbasedep.hpp
  9. 0
      appsrc/appcomponents/canchannel/com/canerrorcode_dumper.hpp
  10. 106
      appsrc/appcomponents/canchannel/com/socket_can.cpp
  11. 1
      appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp
  12. 1
      appsrc/appcomponents/canchannel/transmit_disinfection_can_master.cpp
  13. 1
      appsrc/baseservice/baseservice.hpp
  14. 1
      appsrc/baseservice/front_msg_processer/front_msg_processer.cpp
  15. 4
      appsrc/baseservice/iflytop_front_end_service/iflytop_front_end_service.cpp
  16. 1
      appsrc/main.cpp
  17. 5
      appsrc/service/hardware/device_ctrl_service.cpp
  18. 16
      appsrc/service/hardware/disinfectant_weight_update_service.cpp
  19. 36
      appsrc/service/hardware/warning_light_controler.cpp
  20. 5
      appsrc/service/hardware/warning_light_controler.hpp
  21. 1
      appsrc/service/main_control_service.cpp
  22. 2
      buildpc.sh

7
CMakeLists.txt

@ -41,6 +41,10 @@ message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message("PROJECT_NAME: ${PROJECT_NAME}")
message("ARCH: ${ARCH}")
if(${ARCH} STREQUAL "amd64")
add_definitions(-DBUILD_ON_PC)
endif()
file(
GLOB_RECURSE
APP_SRC #
@ -88,6 +92,9 @@ zadd_executable(
pthread
ixwebsocket
z
crypto
ssl
dl
sqlite3
#
# LINK_DIRECTORIES

0
appsrc/appcomponents/app_errorcode_mgr/app_errorcode_mgr.hpp → app_protocols/apperrorcode/app_errorcode_mgr.hpp

5
app_protocols/appexception/appexception.hpp

@ -18,6 +18,7 @@
#include <vector>
#include "app_protocols/apperrorcode/apperrorcode.hpp"
#include "app_protocols/apperrorcode/app_errorcode_mgr.hpp"
#include "iflytop/core/thisclass/thisclass.hpp"
namespace iflytop {
using namespace std;
@ -30,10 +31,10 @@ class appexception : public std::exception {
int32_t m_ecode;
appexception(ThisClass &thisclass, string func, int32_t ecode, const string &description) {
thisclass.logger->error("appexception: {} {} ", func, description);
this->description = description;
this->m_ecode = ecode;
this->whatstr = description;
thisclass.logger->error("[{}:{}] throw exception: {} {}", thisclass.className, func, ecode2str(ecode), description);
}
appexception(ThisClass &thisclass, string func, int32_t ecode, const char *fmt, ...) {
@ -45,7 +46,7 @@ class appexception : public std::exception {
this->description = buffer;
this->m_ecode = ecode;
this->whatstr = buffer;
thisclass.logger->error("appexception: {} {} ", func, description);
thisclass.logger->error("[{}:{}] throw exception: {} {}", thisclass.className, func, ecode2str(ecode), buffer);
}
virtual ~appexception() {}

2
appdep/iflytop/core/thread/thread.cpp

@ -71,7 +71,7 @@ void Thread::join() {
};
Thread::~Thread() {
if (!hasJointd) {
logger->error(fmt::format("thread {} unjoin ", name));
logger->error(fmt::format("fatal error,thread {} unjoin ", name));
exit(-1);
}
}

BIN
appdep/libs/libixwebsocket/aarch64/libixwebsocket.a

BIN
appdep/libs/libixwebsocket/aarch64/libixwebsocket.bak.a

68
appdep/libs/libixwebsocket/include/ixwebsocket/IXSocketOpenSSL.h

@ -0,0 +1,68 @@
/*
* IXSocketOpenSSL.h
* Author: Benjamin Sergeant, Matt DeBoer
* Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved.
*/
#ifdef IXWEBSOCKET_USE_OPEN_SSL
#pragma once
#include "IXCancellationRequest.h"
#include "IXSocket.h"
#include "IXSocketTLSOptions.h"
#include <mutex>
#include <openssl/bio.h>
#include <openssl/conf.h>
#include <openssl/err.h>
#include <openssl/hmac.h>
#include <openssl/ssl.h>
namespace ix
{
class SocketOpenSSL final : public Socket
{
public:
SocketOpenSSL(const SocketTLSOptions& tlsOptions, int fd = -1);
~SocketOpenSSL();
virtual bool accept(std::string& errMsg) final;
virtual bool connect(const std::string& host,
int port,
std::string& errMsg,
const CancellationRequest& isCancellationRequested) final;
virtual void close() final;
virtual ssize_t send(char* buffer, size_t length) final;
virtual ssize_t recv(void* buffer, size_t length) final;
private:
void openSSLInitialize();
std::string getSSLError(int ret);
SSL_CTX* openSSLCreateContext(std::string& errMsg);
bool openSSLAddCARootsFromString(const std::string roots);
bool openSSLClientHandshake(const std::string& hostname,
std::string& errMsg,
const CancellationRequest& isCancellationRequested);
bool openSSLCheckServerCert(SSL* ssl, const std::string& hostname, std::string& errMsg);
bool checkHost(const std::string& host, const char* pattern);
bool handleTLSOptions(std::string& errMsg);
bool openSSLServerHandshake(std::string& errMsg);
// Required for OpenSSL < 1.1
static void openSSLLockingCallback(int mode, int type, const char* /*file*/, int /*line*/);
SSL* _ssl_connection;
SSL_CTX* _ssl_context;
const SSL_METHOD* _ssl_method;
SocketTLSOptions _tlsOptions;
mutable std::mutex _mutex; // OpenSSL routines are not thread-safe
static std::once_flag _openSSLInitFlag;
static std::atomic<bool> _openSSLInitializationSuccessful;
};
} // namespace ix
#endif // IXWEBSOCKET_USE_OPEN_SSL

1
appsrc/appbase/appbasedep.hpp

@ -9,6 +9,7 @@
#include "app_protocols/apperrorcode/apperrorcode.hpp"
#include "app_protocols/appexception/appexception.hpp"
#include "app_protocols/transmit_disfection_protocol/transmit_disfection_protocol.hpp"
#include "app_protocols/apperrorcode/app_errorcode_mgr.hpp"
//
#include "components/sqlite_orm/sqlite_orm.hpp"

0
appsrc/appcomponents/canchannel/com/canerrorcode_dumper.hpp

106
appsrc/appcomponents/canchannel/com/socket_can.cpp

@ -1,7 +1,101 @@
#include "socket_can.hpp"
#include "linux/can/error.h"
using namespace iflytop;
static bool isInPc() {
#if (defined BUILD_ON_PC) // x86平台
return true;
#else
return false;
#endif
}
string dumpcanerror(canfd_frame_t *frame) {
uint32_t canid = frame->can_id;
uint8_t *data = frame->data;
string error;
error = "Error:[ ";
if (canid & CAN_ERR_TX_TIMEOUT) error += "CAN_ERR_TX_TIMEOUT,";
if (canid & CAN_ERR_LOSTARB) error += "CAN_ERR_LOSTARB,";
if (canid & CAN_ERR_CRTL) error += "CAN_ERR_CRTL,";
if (canid & CAN_ERR_PROT) error += "CAN_ERR_PROT,";
if (canid & CAN_ERR_TRX) error += "CAN_ERR_TRX,";
if (canid & CAN_ERR_ACK) error += "CAN_ERR_ACK,";
if (canid & CAN_ERR_BUSOFF) error += "CAN_ERR_BUSOFF,";
if (canid & CAN_ERR_BUSERROR) error += "CAN_ERR_BUSERROR,";
if (canid & CAN_ERR_RESTARTED) error += "CAN_ERR_RESTARTED,";
error += " ]";
error += ",";
if (data[1] != 0) {
string suberror;
if (data[1] == CAN_ERR_CRTL_RX_OVERFLOW) suberror = "RX buffer overflow";
if (data[1] == CAN_ERR_CRTL_TX_OVERFLOW) suberror = "TX buffer overflow";
if (data[1] == CAN_ERR_CRTL_RX_WARNING) suberror = "reached warning level for RX errors";
if (data[1] == CAN_ERR_CRTL_TX_WARNING) suberror = "reached warning level for TX errors";
if (data[1] == CAN_ERR_CRTL_RX_PASSIVE) suberror = "reached error passive status RX";
if (data[1] == CAN_ERR_CRTL_TX_PASSIVE) suberror = "reached error passive status TX";
if (data[1] == CAN_ERR_CRTL_ACTIVE) suberror = "recovered to error active state";
error += fmt::format("CAN-controller e:(0x{:x}),{}", data[1], suberror);
}
if (data[2] != 0) {
string suberror;
if (data[2] == CAN_ERR_PROT_BIT) suberror = "single bit error";
if (data[2] == CAN_ERR_PROT_FORM) suberror = "frame format error";
if (data[2] == CAN_ERR_PROT_STUFF) suberror = "bit stuffing error";
if (data[2] == CAN_ERR_PROT_BIT0) suberror = "unable to send dominant bit";
if (data[2] == CAN_ERR_PROT_BIT1) suberror = "unable to send recessive bit";
if (data[2] == CAN_ERR_PROT_OVERLOAD) suberror = "bus overload";
if (data[2] == CAN_ERR_PROT_ACTIVE) suberror = "active error announcement";
if (data[2] == CAN_ERR_PROT_TX) suberror = "error occurred on transmission";
error += fmt::format("CAN-proto e:(0x{:x}),{}", data[2], suberror);
}
if (data[3] != 0) {
string suberror;
/* error in CAN protocol (location) / data[3] */
if (data[3] == CAN_ERR_PROT_LOC_UNSPEC) suberror = "unspecified ";
if (data[3] == CAN_ERR_PROT_LOC_SOF) suberror = "start of frame ";
if (data[3] == CAN_ERR_PROT_LOC_ID28_21) suberror = "ID bits 28 - 21 (SFF: 10 - 3) ";
if (data[3] == CAN_ERR_PROT_LOC_ID20_18) suberror = "ID bits 20 - 18 (SFF: 2 - 0 )";
if (data[3] == CAN_ERR_PROT_LOC_SRTR) suberror = "substitute RTR (SFF: RTR) ";
if (data[3] == CAN_ERR_PROT_LOC_IDE) suberror = "identifier extension ";
if (data[3] == CAN_ERR_PROT_LOC_ID17_13) suberror = "ID bits 17-13 ";
if (data[3] == CAN_ERR_PROT_LOC_ID12_05) suberror = "ID bits 12-5 ";
if (data[3] == CAN_ERR_PROT_LOC_ID04_00) suberror = "ID bits 4-0 ";
if (data[3] == CAN_ERR_PROT_LOC_RTR) suberror = "RTR ";
if (data[3] == CAN_ERR_PROT_LOC_RES1) suberror = "reserved bit 1 ";
if (data[3] == CAN_ERR_PROT_LOC_RES0) suberror = "reserved bit 0 ";
if (data[3] == CAN_ERR_PROT_LOC_DLC) suberror = "data length code ";
if (data[3] == CAN_ERR_PROT_LOC_DATA) suberror = "data section ";
if (data[3] == CAN_ERR_PROT_LOC_CRC_SEQ) suberror = "CRC sequence ";
if (data[3] == CAN_ERR_PROT_LOC_CRC_DEL) suberror = "CRC delimiter ";
if (data[3] == CAN_ERR_PROT_LOC_ACK) suberror = "ACK slot ";
if (data[3] == CAN_ERR_PROT_LOC_ACK_DEL) suberror = "ACK delimiter ";
if (data[3] == CAN_ERR_PROT_LOC_EOF) suberror = "end of frame ";
if (data[3] == CAN_ERR_PROT_LOC_INTERM) suberror = "intermission ";
error += fmt::format("CAN-proto l:{:x},{}", data[3], suberror);
}
if (data[4] != 0) {
string suberror;
if (data[4] == CAN_ERR_TRX_UNSPEC) suberror = "unspecified ";
if (data[4] == CAN_ERR_TRX_CANH_NO_WIRE) suberror = "CANH no wire ";
if (data[4] == CAN_ERR_TRX_CANH_SHORT_TO_BAT) suberror = "CANH short to battery ";
if (data[4] == CAN_ERR_TRX_CANH_SHORT_TO_VCC) suberror = "CANH short to VCC ";
if (data[4] == CAN_ERR_TRX_CANH_SHORT_TO_GND) suberror = "CANH short to GND ";
if (data[4] == CAN_ERR_TRX_CANL_NO_WIRE) suberror = "CANL no wire ";
if (data[4] == CAN_ERR_TRX_CANL_SHORT_TO_BAT) suberror = "CANL short to battery ";
if (data[4] == CAN_ERR_TRX_CANL_SHORT_TO_VCC) suberror = "CANL short to VCC ";
if (data[4] == CAN_ERR_TRX_CANL_SHORT_TO_GND) suberror = "CANL short to GND ";
if (data[4] == CAN_ERR_TRX_CANL_SHORT_TO_CANH) suberror = "CANL short to CANH ";
error += fmt::format("CAN-trx e:(0x{:x}),{}", data[4], suberror);
}
return error;
}
/*******************************************************************************
* UTILS *
*******************************************************************************/
@ -64,6 +158,11 @@ bool SocketCan::isTxFrame(const canfd_frame_t &frame) {
*******************************************************************************/
void SocketCan::initialize(const char *canname, int baudrate, bool enableLoopBack) {
if (isInPc()) {
logger->info("in pc, skip initialize can bus");
return;
}
m_canname = canname;
m_baudrate = baudrate;
m_enableLoopBack = enableLoopBack;
@ -72,6 +171,9 @@ void SocketCan::initialize(const char *canname, int baudrate, bool enableLoopBac
}
bool SocketCan::sendFrame(CANUSB_FRAME frametype, uint32_t id, unsigned char data[], int data_length_code, int32_t overtime) {
if (isInPc()) {
return true;
}
tp_steady start = tu_steady().now();
while (tu_steady().elapsedTimeMs(start) < overtime && !m_canBusIsReady) {
@ -105,6 +207,9 @@ bool SocketCan::sendFrame(CANUSB_FRAME frametype, uint32_t id, unsigned char dat
}
bool SocketCan::sendFrame(canfd_frame_t &frame, int32_t overtime) {
if (isInPc()) {
return true;
}
if (!m_canBusIsReady) {
logger->error("can bus is not ready");
return false;
@ -250,6 +355,7 @@ void SocketCan::socketCanReadThreadLoop() {
// /usr/include/linux/can/error.h
// x can-bus error event 20000004,0004000000000086
logger->error("rx can-bus error event {:x},{}", canframe.can_id, StringUtils().bytesToString(canframe.data, canframe.len));
logger->error("can error:{}", dumpcanerror(&canframe));
unsetTxStateToTxing();
break;
} else {

1
appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp

@ -2,7 +2,6 @@
#include <stdarg.h>
#include "appcomponents/app_errorcode_mgr/app_errorcode_mgr.hpp"
#include "app_protocols/appexception/appexception.hpp"
using namespace iflytop;

1
appsrc/appcomponents/canchannel/transmit_disinfection_can_master.cpp

@ -1,6 +1,5 @@
#include "transmit_disinfection_can_master.hpp"
#include "appcomponents/app_errorcode_mgr/app_errorcode_mgr.hpp"
using namespace iflytop;
using namespace zscanprotocol;
using namespace transmit_disfection_protocol;

1
appsrc/baseservice/baseservice.hpp

@ -2,7 +2,6 @@
#include "appbase/appbase.hpp"
#include "appsetting/appsetting.hpp"
//
#include "appcomponents/app_errorcode_mgr/app_errorcode_mgr.hpp"
#include "appcomponents/canchannel/transmit_disinfection_can_master.hpp"
#include "db/db_service.hpp"
#include "devicestate/device_state_service.hpp"

1
appsrc/baseservice/front_msg_processer/front_msg_processer.cpp

@ -1,6 +1,5 @@
#include "front_msg_processer.hpp"
#include "appcomponents/app_errorcode_mgr/app_errorcode_mgr.hpp"
#include "iflytop/core/error/error_code.hpp"
using namespace iflytop;

4
appsrc/baseservice/iflytop_front_end_service/iflytop_front_end_service.cpp

@ -1,6 +1,5 @@
#include "iflytop_front_end_service.hpp"
#include "appcomponents/app_errorcode_mgr/app_errorcode_mgr.hpp"
using namespace nlohmann;
using namespace iflytop;
using namespace std;
@ -15,6 +14,9 @@ void IflytopFrontEndService::initialize(string ip) {
m_workQueue->startWork();
m_server.reset(new WebSocketServer(19001, ip));
SocketTLSOptions tlsOptions;
// tlsOptions.tls = true;
m_server->setTLSOptions(tlsOptions);
m_server->setOnConnectionCallback([this](weak_ptr<WebSocket> webSocket, shared_ptr<ConnectionState> connectionState) {
logger->info("Remote ip: {}", connectionState->getRemoteIp());
auto ws = webSocket.lock();

1
appsrc/main.cpp

@ -85,7 +85,6 @@ int Main::main(int argc, char *argv[]) {
// 构造MainControlService
BUILD_AND_REG_SERRVICE(MainControlService);
GET_SERVICE(MainControlService)->initialize();
logger->info("system setup end.");
while (true) sleep(1000);
}

5
appsrc/service/hardware/device_ctrl_service.cpp

@ -16,8 +16,8 @@ using namespace core;
*
*/
bool isInPc() {
#if (defined __i386__) || (defined __x86_64__) // x86平台
static bool isInPc() {
#if (defined BUILD_ON_PC) // x86平台
return true;
#else
return false;
@ -39,6 +39,7 @@ void DeviceIoControlService::initialize() {
if (isInPc()) {
logger->warn("run in pc, skip initialize device io control service");
return;
} else {
}
TransmitDisinfectionCanMaster::ins()->initialize(m_config->get_canIF().c_str(), m_config->get_canBitrate(), false);

16
appsrc/service/hardware/disinfectant_weight_update_service.cpp

@ -6,7 +6,9 @@ using namespace std;
void DisinfectantWeightUpdateService::initialize() { //
GET_TO_SERVICE(deviceIoControlService);
updateThread.reset(new Thread("DisinfectantWeightUpdateService", [this]() { updateWeightThread(); }));
updateThread.reset(new Thread("DisinfectantWeightUpdateService", [this]() { //
updateWeightThread();
}));
}
float DisinfectantWeightUpdateService::getWeight() { //
@ -14,9 +16,13 @@ float DisinfectantWeightUpdateService::getWeight() { //
}
void DisinfectantWeightUpdateService::updateWeightThread() {
while (true) {
float weightCache = deviceIoControlService->DisinfectantVolume_readVal();
weightCache = filter.filter(weightCache);
logger->info("weight {}", weightCache);
sleep(1000);
try {
float weightCache = deviceIoControlService->DisinfectantVolume_readVal();
weightCache = filter.filter(weightCache);
logger->info("weight {} g", weightCache);
} catch (const std::exception& e) {
logger->error("updateWeightThread error: {}", e.what());
}
sleep(1);
}
}

36
appsrc/service/hardware/warning_light_controler.cpp

@ -24,6 +24,7 @@ void WarningLightControler::workThread() {
void WarningLightControler::initialize() {
GET_TO_SERVICE(dcs);
logger->warn("WarningLightControler initialize");
m_thread.reset(new Thread("LightCtrlServiceThread", std::bind(&WarningLightControler::workThread, this)));
}
@ -31,7 +32,7 @@ void WarningLightControler::beepCtrl(lightState_t state) {
switch (state) {
case kstate_warning:
m_beepState = !m_beepState;
dcs->WarningLight_setState(255, 0, 0, m_beepState ? 255 : 0);
ctrlLightNoEx(255, 0, 0, m_beepState ? 255 : 0);
break;
default:
break;
@ -44,38 +45,19 @@ void WarningLightControler::changeLightState(lightState_t state) {
switch (m_nowState) {
case kstate_idle:
// 绿色
dcs->WarningLight_setState(0, 255, 0, 0);
ctrlLightNoEx(0, 255, 0, 0);
break;
case kstate_work:
// 黄色
dcs->WarningLight_setState(0, 0, 255, 0);
ctrlLightNoEx(0, 0, 255, 0);
break;
case kstate_warning:
// 红色
dcs->WarningLight_setState(255, 0, 0, 0);
ctrlLightNoEx(255, 0, 0, 0);
break;
default:
break;
}
// #if (defined PROJECT_TYPE_PIPE_DISINFECTION)
// switch (m_nowState) {
// case kstate_idle:
// // 绿色
// m_deviceIoControlService->warningLightCtrl(0, 255, 0, 0);
// break;
// case kstate_work:
// // 黄色
// m_deviceIoControlService->warningLightCtrl(255, 255, 0, 0);
// break;
// case kstate_warning:
// // 红色
// m_deviceIoControlService->warningLightCtrl(255, 0, 0, 0);
// break;
// default:
// break;
// }
// #endif
}
WarningLightControler::lightState_t WarningLightControler::inferTheCurrentLightingState() {
@ -87,3 +69,11 @@ WarningLightControler::lightState_t WarningLightControler::inferTheCurrentLighti
}
return kstate_idle;
}
void WarningLightControler::ctrlLightNoEx(int r, int g, int b, int warning) {
try {
dcs->WarningLight_setState(r, g, b, warning);
} catch (const std::exception& e) {
logger->error("do WarningLight_setState error: {}", e.what());
}
}

5
appsrc/service/hardware/warning_light_controler.hpp

@ -45,7 +45,7 @@ class WarningLightControler : public enable_shared_from_this<WarningLightControl
private:
shared_ptr<DeviceIoControlService> dcs;
unique_ptr<Thread> m_thread;
unique_ptr<Thread> m_thread;
bool m_workFlag = false;
bool m_warningFlag = false;
@ -63,6 +63,9 @@ class WarningLightControler : public enable_shared_from_this<WarningLightControl
lightState_t inferTheCurrentLightingState();
void changeLightState(lightState_t state);
void beepCtrl(lightState_t state);
private:
void ctrlLightNoEx(int r, int g, int b, int warning);
};
}; // namespace iflytop

1
appsrc/service/main_control_service.cpp

@ -74,4 +74,5 @@ void MainControlService::initialize() {
cmd = cxt->cmd;
receipt = cxt->receipt;
});
};

2
buildpc.sh

@ -9,7 +9,7 @@
# PROJECT_TYPE_DRAW_BAR_BOX
#
mkdir -p build
mkdir -p build && rm -rf build && mkdir build
inittestdata.sh
cd build

Loading…
Cancel
Save