mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现启动splash画面,实现天历史数据的处理和数据库存贮
This commit is contained in:
@@ -5,6 +5,13 @@
|
||||
#include "protocol/CommEntity.h"
|
||||
#include "common/JsonN.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
static std::unordered_set<int> g_setCacheDeviceType = {3, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110};
|
||||
static bool CheckCacheType(int type)
|
||||
{
|
||||
return g_setCacheDeviceType.find(type) != g_setCacheDeviceType.end();
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
{
|
||||
@@ -40,15 +47,15 @@ std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
}
|
||||
}
|
||||
|
||||
int step = 600;
|
||||
for (int i = 0; i*600<86400; ++i)
|
||||
{
|
||||
double voltage = double(Utils::random(20000, 30000))*0.01;
|
||||
double current = double(Utils::random(1000, 2000))*0.01;
|
||||
device->mapCacheVoltage[i*step] = voltage;
|
||||
device->mapCacheCurrent[i*step] = current;
|
||||
device->mapCachePower[i*step] = voltage * current;
|
||||
}
|
||||
//int step = 600;
|
||||
//for (int i = 0; i*600<86400; ++i)
|
||||
//{
|
||||
// double voltage = double(Utils::random(20000, 30000))*0.01;
|
||||
// double current = double(Utils::random(1000, 2000))*0.01;
|
||||
// device->mapCacheVoltage[i*step] = voltage;
|
||||
// device->mapCacheCurrent[i*step] = current;
|
||||
// device->mapCachePower[i*step] = voltage * current;
|
||||
//}
|
||||
|
||||
// 启动通讯,该函数中会自动判断isOpen状态,选择是否进行通讯连接
|
||||
//device->startComm();
|
||||
@@ -117,6 +124,64 @@ void Device::getCachePower(std::vector<std::string>& vec)
|
||||
}
|
||||
}
|
||||
|
||||
int64_t GetCurrentTimePos(int step)
|
||||
{
|
||||
auto tp = chrono::system_clock::now();
|
||||
int64_t tTime = chrono::time_point_cast<chrono::seconds>(tp).time_since_epoch().count();
|
||||
std::time_t t = chrono::system_clock::to_time_t(tp);
|
||||
std::tm* tmlocal = localtime(&t);
|
||||
tmlocal->tm_hour = 0;
|
||||
tmlocal->tm_min = 0;
|
||||
tmlocal->tm_sec = 0;
|
||||
int64_t tDate = chrono::time_point_cast<chrono::seconds>(chrono::system_clock::from_time_t(mktime(tmlocal))).time_since_epoch().count();
|
||||
return (tTime - tDate) / step;
|
||||
}
|
||||
|
||||
void Device::setCache(int datatype, std::vector<double>& vec)
|
||||
{
|
||||
std::map<int, double>* mapptr = NULL;
|
||||
if (datatype == 1) { mapptr = &mapCacheVoltage; }
|
||||
else if (datatype == 2) { mapptr = &mapCacheCurrent; }
|
||||
else if (datatype == 3) { mapptr = &mapCachePower; }
|
||||
|
||||
if (mapptr)
|
||||
{
|
||||
const int step = 600;
|
||||
const int N = 86400/step;
|
||||
|
||||
int n = GetCurrentTimePos(step);
|
||||
for (int i = 0; i<N; ++i)
|
||||
{
|
||||
if (i < vec.size()) { (*mapptr)[i] = vec[i]; }
|
||||
else if (i <= n) { (*mapptr)[i] = 0; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Device::cache(int npos)
|
||||
{
|
||||
if (!CheckCacheType(this->type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (npos == 0)
|
||||
{
|
||||
mapCacheVoltage.clear();
|
||||
mapCacheCurrent.clear();
|
||||
mapCachePower.clear();
|
||||
}
|
||||
// 根据设备类型从参数(寄存器地址)中读取实时数据进行保存
|
||||
mapCacheVoltage[npos] = Utils::random(100, 200);
|
||||
mapCacheCurrent[npos] = Utils::random(100, 200);
|
||||
mapCachePower[npos] = Utils::random(100, 200);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Device::storeDB(int npos)
|
||||
{
|
||||
}
|
||||
|
||||
void Device::setParam(std::string k, std::string v)
|
||||
{
|
||||
mapParams[k] = v;
|
||||
|
||||
Reference in New Issue
Block a user