V20260324

This commit is contained in:
qingjiao 2026-03-24 18:14:23 +08:00
parent 3f12dc6ee0
commit 7cf8c5c6fc
10 changed files with 145 additions and 45 deletions

View File

@ -386,7 +386,7 @@ endif()
if(CMAKE_HOST_UNIX)
target_link_libraries(CC_API PUBLIC
nlohmann_json
libcppp-reiconv.shared
libcppp-reiconv.static
crypto ssl
)
if (AUDIO_IO)
@ -395,7 +395,7 @@ if(CMAKE_HOST_UNIX)
elseif(CMAKE_HOST_WIN32)
target_link_libraries(CC_API PUBLIC
nlohmann_json
libcppp-reiconv.shared
libcppp-reiconv.static
crypto ssl
)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "OHOS" AND NOT W_T_L_Arm)

View File

@ -278,7 +278,7 @@ namespace CTL {
template<typename T>
void Conversion(T* str, const ByteHander size) {
const auto c_str = reinterpret_cast<const char*>(str);
bytes.assign(c_str, c_str + size);
bytes.assign(&c_str[0], &c_str[0] + size);
}
/**
*

View File

@ -233,7 +233,7 @@ void CTL::Application::StartDaemon(int argc, char **argv) {
Sh += String::format(" {} Daemon_Start &\n", AppNamePathSh.c_str());
Sh += String::format(" echo $! > {}.pid\n", AppName.c_str());
Sh += String::format(" echo \"Start {}\"\n", AppNamePathSh.c_str());
Sh += " sleep 1\n";
Sh += " sleep 3\n";
Sh += "fi\n";
Sh += String::format("sleep {}\n", DaemonTime);
Sh += "done\n";

View File

@ -33,6 +33,9 @@ target_link_libraries(Distribution_Service PUBLIC CC_API)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm|ARM|Armv[0-9]+")
target_link_libraries(Distribution_Service PUBLIC stdc++fs)
# set_target_properties(Distribution_Service PROPERTIES
# LINK_FLAGS "-static-libgcc -static-libstdc++"
# )
endif ()
target_include_directories(Distribution_Service PUBLIC

View File

@ -13,9 +13,9 @@ std::shared_mutex Config::m_mutex_udp_tool;
void Config::Save() {
const auto Setting = getConfig();
try {
const CTL::JSONObject Json = *Setting;
const JSON Json(*Setting);
const auto Path = GetSettingDB();
CTL::FileOutStream::WriteFile(Path,Json.to_String());
CTL::FileOutStream::WriteFile(Path,Json.dump());
}
catch (CCException& e) {
BS_Log::Error("Config::Save Error: {}",e.what());
@ -43,12 +43,28 @@ void Config::Init() {
Setting->WorkingMode = Json["WorkingMode"];
Setting->TermNumber = Json["TermNumber"];
Setting->DHCPFlag = Json["DHCPFlag"];
Setting->TermIPGw = Json["TermIPGw"];
Setting->TermIPNm = Json["TermIPNm"];
}
}
catch (CCException& e) {
BS_Log::Error("Config::Init Error: {}",e.what());
}
#ifdef IS_ARM32
if (Setting->IP.empty())
{
try {
Setting->MacAddr = CTL::System::GetMac();
}
catch (...){}
Setting->IP = "192.168.1.108";
Setting->TermIPNm = "255.255.255.0";
Setting->TermIPGw = "192.168.1.1";
}
SetNetWorkInfo(Setting->IP,Setting->TermIPGw,Setting->TermIPNm);
#else
Setting->IP = GetIP();
#endif
BS_Log::Log("Local IP: {}",Setting->IP.c_str());
BS_Log::Log("Local ID: {}",Setting->ID);
}
@ -86,31 +102,70 @@ CTL::String Config::GetIP() {
ConfigTerm * Config::getThisInfo() {
const auto Setting = getConfig();
const auto Data = new ConfigTerm;
std::strcpy(Data->termIDnVerStr,Setting->Ver.c_str());
std::strcpy(Data->macStr,Setting->MacAddr.c_str());
std::strcpy(Data->macChkStr,Setting->MacAddr.c_str());
std::strcpy(Data->servIPAddrStr,Setting->ServerIP.c_str());
std::strcpy(Data->termIPAddrStr,Setting->IP.c_str());
std::strcpy(Data->termIPGwStr,Setting->TermIPGw.c_str());
std::strcpy(Data->termIPNmStr,Setting->TermIPNm.c_str());
std::strcpy(Data->termCmdPortStr,CC::to_String(Setting->OrderPort).c_str());
std::strcpy(Data->servCmdPortStr,CC::to_String(Setting->ServerPort).c_str());
std::strcpy(Data->termStmPortStr,CC::to_String(Setting->StreamPort).c_str());
// const auto workModeStrS = APPTool::GetBytes(Setting->WorkingMode);
// std::strcpy(Data->workModeStr,CC::to_String(Setting->WorkingMode).c_str());
// Data->workModeStr[0] = workModeStrS[0];
// Data->workModeStr[1] = workModeStrS[1];
std::memset(Data, 0, sizeof(ConfigTerm));
#define SAFE_STRNCPY(dest, src, size) do { \
const auto& s = (src); \
if (!s.empty()) { \
std::strncpy((dest), s.c_str(), (size) - 1); \
(dest)[(size) - 1] = '\0'; \
} \
} while(0)
try {
SAFE_STRNCPY(Data->termIDnVerStr, Setting->Ver, sizeof(Data->termIDnVerStr));
SAFE_STRNCPY(Data->macStr, Setting->MacAddr, sizeof(Data->macStr));
SAFE_STRNCPY(Data->macChkStr, Setting->MacAddr, sizeof(Data->macChkStr));
SAFE_STRNCPY(Data->servIPAddrStr, Setting->ServerIP, sizeof(Data->servIPAddrStr));
SAFE_STRNCPY(Data->termIPAddrStr, Setting->IP, sizeof(Data->termIPAddrStr));
SAFE_STRNCPY(Data->termIPGwStr, Setting->TermIPGw, sizeof(Data->termIPGwStr));
SAFE_STRNCPY(Data->termIPNmStr, Setting->TermIPNm, sizeof(Data->termIPNmStr));
const auto termCmdPortStr = CC::to_String(Setting->OrderPort);
SAFE_STRNCPY(Data->termCmdPortStr, termCmdPortStr, sizeof(Data->termCmdPortStr));
const auto servCmdPortStr = CC::to_String(Setting->ServerPort);
SAFE_STRNCPY(Data->servCmdPortStr, servCmdPortStr, sizeof(Data->servCmdPortStr));
const auto termStmPortStr = CC::to_String(Setting->StreamPort);
SAFE_STRNCPY(Data->termStmPortStr, termStmPortStr, sizeof(Data->termStmPortStr));
Data->workModeStr[0] = getTermWorkInfo(Setting->WorkingMode);
Data->workModeStr[1] = '\0';
std::strcpy(Data->btNameStr,"");
std::strcpy(Data->dhcpFlagStr,CC::to_String(Setting->DHCPFlag).c_str());
std::strcpy(Data->btPwdStr,"");
std::strcpy(Data->termTypeStr,CC::to_String(Setting->TermNumber).c_str());
std::strcpy(Data->sipUsrNameStr,"");
std::strcpy(Data->sipUsrPwdStr,"");
std::strcpy(Data->sipProxyRealmStr,"");
std::strcpy(Data->cmdFlagByteStr,CC::to_String("").c_str());
std::strcpy(Data->onlineFlagStr,CC::to_String(Setting->isConnect).c_str());
std::strncpy(Data->btNameStr, "", sizeof(Data->btNameStr) - 1);
Data->btNameStr[sizeof(Data->btNameStr) - 1] = '\0';
const auto dhcpFlagStr = CC::to_String(Setting->DHCPFlag);
SAFE_STRNCPY(Data->dhcpFlagStr, dhcpFlagStr, sizeof(Data->dhcpFlagStr));
std::strncpy(Data->btPwdStr, "", sizeof(Data->btPwdStr) - 1);
Data->btPwdStr[sizeof(Data->btPwdStr) - 1] = '\0';
const auto termTypeStr = CC::to_String(Setting->TermNumber);
SAFE_STRNCPY(Data->termTypeStr, termTypeStr, sizeof(Data->termTypeStr));
std::strncpy(Data->sipUsrNameStr, "", sizeof(Data->sipUsrNameStr) - 1);
Data->sipUsrNameStr[sizeof(Data->sipUsrNameStr) - 1] = '\0';
std::strncpy(Data->sipUsrPwdStr, "", sizeof(Data->sipUsrPwdStr) - 1);
Data->sipUsrPwdStr[sizeof(Data->sipUsrPwdStr) - 1] = '\0';
std::strncpy(Data->sipProxyRealmStr, "", sizeof(Data->sipProxyRealmStr) - 1);
Data->sipProxyRealmStr[sizeof(Data->sipProxyRealmStr) - 1] = '\0';
std::strncpy(Data->cmdFlagByteStr, "", sizeof(Data->cmdFlagByteStr) - 1);
Data->cmdFlagByteStr[sizeof(Data->cmdFlagByteStr) - 1] = '\0';
const auto onlineFlagStr = CC::to_String(Setting->isConnect);
SAFE_STRNCPY(Data->onlineFlagStr, onlineFlagStr, sizeof(Data->onlineFlagStr));
} catch (...) {
BS_Log::Error("getThisInfo: String copy exception");
delete Data;
return nullptr;
}
#undef SAFE_STRNCPY
return Data;
}
@ -126,6 +181,24 @@ void Config::groupBroadcast(const CTL::ByteArray &data, int port) {
}
void Config::SetNetWorkInfo(const CTL::String& IP,const CTL::String& GW,const CTL::String& Mask) {
#ifdef IS_ARM32
try{
CTL::String str = CTL::String::format("ifconfig eth0 down");
CTL::System::Execute(str);
CTL::Thread::SleepMS(5);
str = CTL::String::format("ifconfig eth0 up");
CTL::System::Execute(str);
CTL::Thread::SleepMS(5);
str = CTL::String::format("ifconfig eth0 {} netmask {}",IP.c_str(),Mask.c_str());
CTL::System::Execute(str);
CTL::Thread::SleepMS(5);
str = CTL::String::format("route add default gw {}",GW.c_str());
CTL::System::Execute(str);
}
catch (CCException& e){
BS_Log::Error("[fun-configure|MainConfigure] NetInit Error: {}",e.what());
}
#elif IS_ARM
try{
//获取当前网络名称
const CTL::String GetNetName = ("nmcli -t -f NAME,TYPE,DEVICE,STATE con show --active");
@ -154,6 +227,7 @@ void Config::SetNetWorkInfo(const CTL::String& IP,const CTL::String& GW,const CT
catch (CCException& e){
BS_Log::Error("[fun-configure|MainConfigure] NetInit Error: {}",e.what());
}
#endif
}
void Config::CloseService() {

View File

@ -31,13 +31,13 @@ struct ConfigTerm{
class Config {
JSON_TYPE_INTRUSIVE(Config,IP,OrderPort,StreamPort,HttpPort,Flag,ServerID,ServerIP,ServerPort,ID
,Name,WorkingMode,TermNumber,DHCPFlag);
,Name,WorkingMode,TermNumber,DHCPFlag,TermIPGw,TermIPNm);
public:
int ServerID = 2;
int ID = 1;
CTL::String Name = "Distribution 1";
int ONLINEVol = 1;
CTL::String IP = "0.0.0.0";
CTL::String IP = "";
CTL::String ServerIP = "192.168.2.208"; // 目标主服务器IP
int ServerPort = 10060; // 目标主服务器端口
int OrderPort = 10050; // 10060

View File

@ -104,11 +104,14 @@ public:
}
static void Function_0xF4(const DataPacket& packet){
const auto Setting = Config::getConfig();
ConfigTerm* t = CTL::ByteArray::Conversion<ConfigTerm>(packet.AdditionalData);
const auto t = CTL::ByteArray::Conversion<ConfigTerm>(packet.AdditionalData);
CTL::AutoDestruct<ConfigTerm> autoDestruct(t);
if (t) {
const auto TMac = CTL::String(t->macChkStr);
if (TMac == Setting->MacAddr) {
const auto IP_t = Setting->IP;
const auto GW_t = Setting->TermIPGw;
const auto Nm_t = Setting->TermIPNm;
const auto IDS = CTL::String(t->termIDnVerStr);
if (!IDS.empty()) {
const int ID = IDS.to_int();
@ -156,12 +159,20 @@ public:
Setting->TermIPNm = NM;
}
// -----------------------------------------------------------------
#if IS_ARM
Config::SetNetWorkInfo(IP,Setting->TermIPGw,Setting->TermIPNm);
#endif
BS_Log::Log("Config::Save...");
Config::Save();
#if IS_ARM
if (IP_t != Setting->IP || GW_t != Setting->TermIPGw || Nm_t != Setting->TermIPNm){
BS_Log::Log("Config::SetNetWorkInfo IP:{} IPGw:{} IPNm: {}",IP.c_str(),
Setting->TermIPGw.c_str(),Setting->TermIPNm.c_str());
Config::SetNetWorkInfo(IP,Setting->TermIPGw,Setting->TermIPNm);
}
#endif
BS_Log::Log("Config::CloseService...");
Config::CloseService();
BS_Log::Log("CTL::Application::ReleaseLock...");
CTL::Application::ReleaseLock();
BS_Log::Log("std::terminate...");
CTL::Thread::SleepMS(1000);
std::terminate();
}

View File

@ -22,7 +22,7 @@ class TaskExecutor{
public:
//------------------------------------------------------------------------------------------------------------------
static void InitPool() {
thread_pool_t.InitStart(100,1024,1000 * 5);
thread_pool_t.InitStart(100,100,1000 * 5);
}
static void ReleasePool() {
thread_pool_t.Stop();

View File

@ -131,7 +131,9 @@ public:
BS_Log::Init();
Config::Init();
TaskExecutor::InitPool();
TaskInfo::thread_pool.InitStart(255, 1024, 1000);
TaskInfo::thread_pool.InitStart(40, 255, 1000);
try
{
ConnectionService::init();
CC::SetCloseFun(CloseFun);
m_threadPool.AddTask(&ThreadMain::orderRun,this);
@ -139,6 +141,11 @@ public:
m_threadPool.AddTask(ThreadMain::ConnectService);
m_threadPool.AddTask(TaskInfo::InitSocket);
}
catch (CCException& e)
{
BS_Log::Error("ThreadMain init: {}",e.what());
}
}
};
#endif

5
gk7205-mount Normal file
View File

@ -0,0 +1,5 @@
mount -t nfs -o nolock,tcp 192.168.2.208:/home/qingjiao/tarns /mnt
ifconfig eth0 up
ifconfig eth0 192.168.2.36 netmask 255.255.255.0
route add default gw 192.168.2.254