GrpcPrint/PrintS/log/AxisLog.cpp
2024-03-19 17:45:12 +08:00

139 lines
4.3 KiB
C++

#include "AxisLog.h"
AxisLog::AxisLog()
: m_PreMoldPos(0.0f)
, m_PreLinearEncoderPos(0.0f)
,m_PreLoadPos(0.0f)
,m_PreArmPos(0.0f)
,m_PreSupplyPos(0.0f)
,m_AftMoldPos(0.0f)
, m_AftLinearEncoderPos(0.0f)
, m_AftLoadPos(0.0f)
, m_AftArmPos(0.0f)
, m_AftSupplyPos(0.0f)
,m_MoldDataCount(0)
, m_MoldData(NULL)
, m_LoadDataCount(0)
, m_LoadData(NULL)
, m_ArmDataCount(0)
, m_ArmData(NULL)
, m_SupplyDataCount(0)
, m_SupplyData(NULL)
{
}
AxisLog::~AxisLog()
{
if (m_MoldData)delete[] m_MoldData;
if (m_LoadData) delete[] m_LoadData;
if (m_ArmData)delete[] m_ArmData;
if (m_SupplyData)delete[] m_SupplyData;
}
AxisLog::AxisLog(int64_t jobid, int64_t layerindex, int ct)
:m_JobId(jobid)
,m_LayerIndex(layerindex)
,m_CoverType(ct)
, m_PreMoldPos(0.0f)
, m_PreLinearEncoderPos(0.0f)
, m_PreLoadPos(0.0f)
, m_PreArmPos(0.0f)
, m_PreSupplyPos(0.0f)
, m_AftMoldPos(0.0f)
, m_AftLinearEncoderPos(0.0f)
, m_AftLoadPos(0.0f)
, m_AftArmPos(0.0f)
, m_AftSupplyPos(0.0f)
,m_MoldDataCount(0)
,m_MoldData(NULL)
,m_LoadDataCount(0)
,m_LoadData(NULL)
,m_ArmDataCount(0)
,m_ArmData(NULL)
,m_SupplyDataCount(0)
,m_SupplyData(NULL)
{
}
void AxisLog::CreateIfNoExist(SQLite::Database* db)
{
if (db == nullptr)return;
char buffer[2048];
if (db->tableExists(AL_TABLE_NAME)) {
sprintf_s(buffer, sizeof(buffer), "SELECT * FROM %s LIMIT 0", AL_TABLE_NAME.c_str());
SQLite::Statement query(*db, buffer);
//if (query.executeStep()) {
try {
query.getColumnIndex(AL_FIELD_PRE_MOLD_POS.c_str());
}
catch (SQLite::Exception&) {
sprintf_s(buffer, "DROP TABLE %s ", AL_TABLE_NAME.c_str());
db->exec(buffer);
}
}
string createsql = "CREATE TABLE IF NOT EXISTS %s(%s INTEGER PRIMARY KEY AUTOINCREMENT,%s INTEGER,%s INTEGER,%s INTEGER,\
%s REAL,%s REAL,%s REAL,%s REAL,%s REAL,%s REAL,%s REAL,%s REAL,%s REAL,%s REAL, %s INTEGER,%s INTEGER,%s INTEGER,%s INTEGER,%s BLOB, %s BLOB, %s BLOB,%s BLOB)";
sprintf_s(buffer, sizeof(buffer), createsql.c_str(),
AL_TABLE_NAME.c_str(),
AL_FIELD_ID.c_str(),
AL_FIELD_JOB_ID.c_str(),
AL_FIELD_LAYER_INDEX.c_str(),
AL_FIELD_COVER_TYPE.c_str(),
AL_FIELD_PRE_MOLD_POS.c_str(),
AL_FIELD_PRE_LINEAR_ENCODER_POS.c_str(),
AL_FIELD_PRE_LOAD_POS.c_str(),
AL_FIELD_PRE_ARM_POS.c_str(),
AL_FIELD_PRE_SUPPLY_POS.c_str(),
AL_FIELD_AFT_MOLD_POS.c_str(),
AL_FIELD_AFT_LINEAR_ENCODER_POS.c_str(),
AL_FIELD_AFT_LOAD_POS.c_str(),
AL_FIELD_AFT_ARM_POS.c_str(),
AL_FIELD_AFT_SUPPLY_POS.c_str(),
AL_FIELD_MOLD_DATA_COUNT.c_str(),
AL_FIELD_LOAD_DATA_COUNT.c_str(),
AL_FIELD_ARM_DATA_COUNT.c_str(),
AL_FIELD_SUPPLY_DATA_COUNT.c_str(),
AL_FIELD_MOLD_DATA.c_str(),
AL_FIELD_LOAD_DATA.c_str(),
AL_FIELD_ARM_DATA.c_str(),
AL_FIELD_SUPPLY_DATA.c_str()
);
db->exec(buffer);
sprintf_s(buffer, sizeof(buffer), "CREATE INDEX IF NOT EXISTS idx_%s_%s ON %s (%s)",
AL_TABLE_NAME.c_str(),
AL_FIELD_JOB_ID.c_str(),
AL_TABLE_NAME.c_str(),
AL_FIELD_JOB_ID.c_str()
);
db->exec(buffer);
}
const string AxisLog::AL_TABLE_NAME="AxisLog";
const string AxisLog::AL_FIELD_ID="id";
const string AxisLog::AL_FIELD_JOB_ID="job_id";
const string AxisLog::AL_FIELD_LAYER_INDEX="layer_index";
const string AxisLog::AL_FIELD_COVER_TYPE = "cover_type";
const string AxisLog::AL_FIELD_PRE_MOLD_POS = "pre_mold_pos";
const string AxisLog::AL_FIELD_PRE_LINEAR_ENCODER_POS = "pre_linear_encoder_pos";
const string AxisLog::AL_FIELD_PRE_LOAD_POS = "pre_load_pos";
const string AxisLog::AL_FIELD_PRE_ARM_POS = "pre_arm_pos";
const string AxisLog::AL_FIELD_PRE_SUPPLY_POS = "pre_supply_pos";
const string AxisLog::AL_FIELD_AFT_MOLD_POS = "aft_mold_pos";
const string AxisLog::AL_FIELD_AFT_LINEAR_ENCODER_POS = "aft_linear_encoder_pos";
const string AxisLog::AL_FIELD_AFT_LOAD_POS = "aft_load_pos";
const string AxisLog::AL_FIELD_AFT_ARM_POS = "aft_arm_pos";
const string AxisLog::AL_FIELD_AFT_SUPPLY_POS = "aft_supply_pos";
const string AxisLog::AL_FIELD_MOLD_DATA_COUNT="mold_data_count";
const string AxisLog::AL_FIELD_LOAD_DATA_COUNT="load_data_count";
const string AxisLog::AL_FIELD_ARM_DATA_COUNT="arm_data_count";
const string AxisLog::AL_FIELD_SUPPLY_DATA_COUNT = "supply_data_count";
const string AxisLog::AL_FIELD_MOLD_DATA="mold_data";
const string AxisLog::AL_FIELD_LOAD_DATA="load_data";
const string AxisLog::AL_FIELD_ARM_DATA="arm_data";
const string AxisLog::AL_FIELD_SUPPLY_DATA = "supply_data";