Procházet zdrojové kódy

接口定义完成;

Jeff před 5 roky
rodič
revize
2d45c509c9

+ 26 - 19
scbc.tools/scbc.tools/DataImpl.cpp

@@ -8,6 +8,7 @@
 
 CDataImpl::CDataImpl(void):m_psqlite3(NULL),m_pszErrmsg(NULL)
 {
+	//sqlite3_threadsafe();
 }
 
 CDataImpl::~CDataImpl(void)
@@ -31,22 +32,23 @@ BOOL CDataImpl::Open()
 		return FALSE;
 
 	// ´´½¨±í;
+	char* psqlite_error = NULL;
 	if ( !QueryTable("mid"))
 	{
-		sqlite3_exec(m_psqlite3, _CREATE_MID_TABLE_, NULL, NULL, &m_pszErrmsg);
-		FREE_MSG
+		sqlite3_exec(m_psqlite3, _CREATE_MID_TABLE_, NULL, NULL, &psqlite_error);
+		FREE_MSG2
 	}
 
 	if ( !QueryTable("keys"))
 	{
-		sqlite3_exec(m_psqlite3, _CREATE_KEYS_TABLE_, NULL, NULL, &m_pszErrmsg);
-		FREE_MSG
+		sqlite3_exec(m_psqlite3, _CREATE_KEYS_TABLE_, NULL, NULL, &psqlite_error);
+		FREE_MSG2
 	}
 
 	if ( !QueryTable("log"))
 	{
-		sqlite3_exec(m_psqlite3, _CREATE_LOG_TABLE_, NULL, NULL, &m_pszErrmsg);
-		FREE_MSG
+		sqlite3_exec(m_psqlite3, _CREATE_LOG_TABLE_, NULL, NULL, &psqlite_error);
+		FREE_MSG2
 	}
 
 	return TRUE;
@@ -101,13 +103,14 @@ BOOL CDataImpl::QueryTable(std::string table)
 	INT nCol = 0;
 
 	char** pazResult = NULL;
+	char* psqlite_error = NULL;
 	char szSql[MAX_PATH] = {0};
 	_stprintf_s(szSql, _T("select * from sqlite_master where type = 'table' and name = '%s'"), table.c_str());
-	int sqlite_error = sqlite3_get_table(m_psqlite3, szSql, &pazResult, &nRow, &nCol, &m_pszErrmsg);
+	int sqlite_error = sqlite3_get_table(m_psqlite3, szSql, &pazResult, &nRow, &nCol, &psqlite_error);
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsType:%s"), m_pszErrmsg);
-		FREE_MSG
+		FREE_MSG2
 		return FALSE;
 	}
 
@@ -126,15 +129,16 @@ INT CDataImpl::QueryMidInfo(std::string order, STMid &data)
 	INT nCol = 0;
 
 	char** pazResult = NULL;
+	char* psqlite_error = NULL;
 	std::string strSql = _SELECT_MID_TABLE_;
 	strSql.append(" WHERE bid = '");
 	strSql.append(order);
 	strSql.append("';");
-	int sqlite_error = sqlite3_get_table(m_psqlite3, strSql.c_str(), &pazResult, &nRow, &nCol, &m_pszErrmsg);
+	int sqlite_error = sqlite3_get_table(m_psqlite3, strSql.c_str(), &pazResult, &nRow, &nCol, &psqlite_error);
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsType:%s"), m_pszErrmsg);
-		FREE_MSG
+		FREE_MSG2
 		return -1;
 	}
 
@@ -184,15 +188,16 @@ INT CDataImpl::QueryKeyInfo(std::string sn, STKeys &data)
 	INT nCol = 0;
 
 	char** pazResult = NULL;
+	char* psqlite_error = NULL;
 	std::string strSql = _SELECT_KEYS_TABLE_;
 	strSql.append(" WHERE sn = '");
 	strSql.append(sn);
 	strSql.append("';");
-	int sqlite_error = sqlite3_get_table(m_psqlite3, strSql.c_str(), &pazResult, &nRow, &nCol, &m_pszErrmsg);
+	int sqlite_error = sqlite3_get_table(m_psqlite3, strSql.c_str(), &pazResult, &nRow, &nCol, &psqlite_error);
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsInfo:%s"), m_pszErrmsg);
-		FREE_MSG
+		FREE_MSG2
 		return -1;
 	}
 
@@ -230,12 +235,13 @@ INT CDataImpl::QueryUnReportKeyInfo(std::vector<STKeys> &vtdata)
 	INT nCol = 0;
 
 	char** pazResult = NULL;
+	char* psqlite_error = NULL;
 	std::string strSql = "SELECT sn,copy_date FROM keys WHERE copy_date <> '' and report_status in(0,-1)";
-	int sqlite_error = sqlite3_get_table(m_psqlite3, strSql.c_str(), &pazResult, &nRow, &nCol, &m_pszErrmsg);
+	int sqlite_error = sqlite3_get_table(m_psqlite3, strSql.c_str(), &pazResult, &nRow, &nCol, &psqlite_error);
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsInfo:%s"), m_pszErrmsg);
-		FREE_MSG
+		FREE_MSG2
 		return -1;
 	}
 
@@ -261,11 +267,12 @@ INT CDataImpl::QueryLogInfo(std::string sn, STLog &data)
 	INT nCol = 0;
 
 	char** pazResult = NULL;
-	int sqlite_error = sqlite3_get_table(m_psqlite3, _SELECT_LOG_TABLE_, &pazResult, &nRow, &nCol, &m_pszErrmsg);
+	char* psqlite_error = NULL;
+	int sqlite_error = sqlite3_get_table(m_psqlite3, _SELECT_LOG_TABLE_, &pazResult, &nRow, &nCol, &psqlite_error);
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryTaskInfo:%s"), m_pszErrmsg);
-		FREE_MSG
+		FREE_MSG2
 		return -1;
 	}
 
@@ -301,12 +308,13 @@ INT CDataImpl::QueryUnReportLogInfo(std::vector<STLog> &vtdata)
 	INT nCol = 0;
 
 	char** pazResult = NULL;
+	char* psqlite_error = NULL;
 	std::string strSql = "SELECT type, sn, content, gdate FROM log WHERE report_status in(0,-1)";
-	int sqlite_error = sqlite3_get_table(m_psqlite3, strSql.c_str(), &pazResult, &nRow, &nCol, &m_pszErrmsg);
+	int sqlite_error = sqlite3_get_table(m_psqlite3, strSql.c_str(), &pazResult, &nRow, &nCol, &psqlite_error);
 	if ( sqlite_error != SQLITE_OK)
 	{
 		//Global::WriteTextLog(_T("QueryContactsInfo:%s"), m_pszErrmsg);
-		FREE_MSG
+		FREE_MSG2
 		return -1;
 	}
 
@@ -437,7 +445,6 @@ INT CDataImpl::BatchInsertKeyInfo(std::vector<STKeys> &vtdata)
 	nRet = sqlite3_finalize(stmt); 
 	if ( nRet != SQLITE_OK )
 	{
-		FREE_MSG2
 		return -1;
 	}
 

+ 0 - 40
scbc.tools/scbc.tools/Global.h

@@ -16,16 +16,6 @@
 namespace Global
 {
 	//////////////////////////////////////////////////////////////////////////
-	// 升级包请求体;
-	typedef struct
-	{
-		std::string appid;
-		std::string devicemodel;
-		std::string dnum;
-		std::string ver;
-		std::string type;
-	} __update_post__;
-
 	// 升级包返回体;
 	typedef struct
 	{
@@ -55,36 +45,6 @@ namespace Global
 		__upcontent__ upcontent;
 	} __update_result__;
 
-	// 烧录数据请求体;
-	typedef struct
-	{
-		std::string clienttype;
-		//std::string	projectid;
-		std::string version;
-		std::string bid; //批次号;
-		std::string mac; // mac地址;
-	} __burndata_post__;
-
-	typedef struct
-	{
-		std::string name;
-		std::string type;
-	} __burndata__;
-
-	typedef struct
-	{
-		std::string message;
-		std::string code;
-		std::string factoryname;
-		std::string factoryip;
-		std::string factoryNum;
-		std::string version;
-		std::string projectid;
-		std::string clienttype;
-		std::string host;
-		std::vector<__burndata__> obj;
-	} __burndata_result__;
-
 	typedef struct CHASSIS
 	{
 		bool IsCopyDID;

+ 11 - 0
scbc.tools/scbc.tools/SDK.cpp

@@ -0,0 +1,11 @@
+#include "StdAfx.h"
+#include "SDK.h"
+#include "CritSection.h"
+
+CSDK::CSDK(void)
+{
+}
+
+CSDK::~CSDK(void)
+{
+}

+ 13 - 0
scbc.tools/scbc.tools/SDK.h

@@ -0,0 +1,13 @@
+#ifndef __SDK_HEADER__
+#define __SDK_HEADER__
+
+#pragma once
+
+class CSDK
+{
+public:
+	CSDK(void);
+	~CSDK(void);
+};
+
+#endif

+ 72 - 1
scbc.tools/scbc.tools/scbc.tools.cpp

@@ -6,12 +6,13 @@
 #include "CurlClient.h"
 #include "DataImpl.h"
 #include "Global.h"
+#include "SDK.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
 #endif
 
-
+#ifdef TEST_MODE
 // 唯一的应用程序对象
 
 CWinApp theApp;
@@ -149,3 +150,73 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 
 	return nRetCode;
 }
+
+#else
+// 全局数据库对象;
+CDataImpl g_db;
+
+int QueryMidInfo(const char* lpOrder)
+{
+	if ( lpOrder == NULL || lpOrder[0] == '\0' )
+		return -1;
+
+	CDataImpl db;
+	if ( !db.Open() )
+		return -2;
+	
+	STMid mid;
+	int nRow = db.QueryMidInfo(lpOrder, mid);
+	if ( nRow == -1)
+		return -3;
+
+	if ( nRow == 0 )
+		return 0;
+
+	if ( nRow == 1)
+	{
+		if ( _tcsicmp(mid.status.c_str(), "0") == 0 )
+			return 1;
+		else if ( _tcsicmp(mid.status.c_str(), "1") == 0 )
+			return 2;
+		else if ( _tcsicmp(mid.status.c_str(), "1") == -1 )
+			return 3;
+	}
+
+	return -4;
+}
+
+int DownloadMidData(const char* lpOrder)
+{
+	if ( lpOrder == NULL || lpOrder[0] == '\0' )
+		return -1;
+	
+	// 1、直接http请求数据mid data;
+
+	// 2、查询数据库是否有该批次,有则更新,无则插入;
+
+	// 3、key文件包是否存在,存在判断md5值,相同则下载成功;否则启动后台线程开始下载;
+
+	return 0;
+}
+
+int QueryKeyInfo(const char* lpSN)
+{
+	return 0;
+}
+
+int UpdateKeyCopyStatus(const char* lpSN)
+{
+	return 0;
+}
+
+int UpdateKeyReportStatus(const char* lpSN)
+{
+	return 0;
+}
+
+int ReportKeyCopyResults(const char* lpSN)
+{
+	return 0;
+}
+
+#endif

+ 55 - 12
scbc.tools/scbc.tools/scbc.tools.h

@@ -10,18 +10,61 @@
 #define SCBCTOOLS_API __declspec(dllimport)
 #endif
 
-// 此类是从 scbc.tools.dll 导出的
-class SCBCTOOLS_API Cscbctools {
-public:
-	Cscbctools(void);
-	// TODO: 在此添加您的方法。
-};
+#ifdef  __cplusplus  
+extern "C" {  
+#endif
+	/*
+	函数:查询指定批次MID信息。
+		一般用于DownloadMidData调用后,查询是否下载成功;或者下载前,查询该批次是否已经在下载中;
+	参数:lpOrder 批次号;
+	返回:
+		0=表示该批次未下载过,不存在数据库中;
+		1=表示该批次下载中;
+		2=表示该批次已完成下载;
+		3=表示该批次下载失败;
+		-1=表示lpOrder参数空;
+		-2=表示打开db失败;
+		-3=表示查询出错;
+		-4=表示数据异常;
+	*/
+	extern SCBCTOOLS_API int QueryMidInfo(const char* lpOrder);
+
+	/*
+	函数:下载指定批次MID数据;(后台线程下载)
+	参数:lpOrder 批次号;
+	返回:None
+	*/
+	extern SCBCTOOLS_API int DownloadMidData(const char* lpOrder);
+
+	/*
+	函数:查询SN对应的Keys;
+	参数:lpSN 条码;
+	返回:
+	*/
+	extern SCBCTOOLS_API int QueryKeyInfo(const char* lpSN);
+
+	/*
+	函数:更新抄写状态;
+	参数:lpSN 条码;
+	返回:
+	*/
+	extern SCBCTOOLS_API int UpdateKeyCopyStatus(const char* lpSN);
 
-extern SCBCTOOLS_API int nscbctools;
+	/*
+	函数:更新上报状态;
+	参数:lpSN 条码;
+	返回:
 
-SCBCTOOLS_API int fnscbctools(void);
+	*/
+	extern SCBCTOOLS_API int UpdateKeyReportStatus(const char* lpSN);
 
-// 判断mid数据是否已下载;
-extern "C" bool is_data_down();
-// 下载批次MID数据;
-extern "C" int get_mid_data(const char* lpOrder);
+	/*
+	函数:上报抄写结果;
+	参数:lpSN 条码; lpSN = NULL时,上报所有抄写成功且未上报的抄写结果;
+	返回:0=表示上报失败、1=表示上报成功;
+		上报成功后,调用UpdateKeyReportStatus更新上报状态;
+	*/
+	extern SCBCTOOLS_API int ReportKeyCopyResults(const char* lpSN);
+#ifdef  __cplusplus  
+}
+#endif

+ 8 - 0
scbc.tools/scbc.tools/scbc.tools.vcproj

@@ -261,6 +261,10 @@
 				RelativePath=".\scbc.tools.cpp"
 				>
 			</File>
+			<File
+				RelativePath=".\SDK.cpp"
+				>
+			</File>
 			<File
 				RelativePath=".\stdafx.cpp"
 				>
@@ -311,6 +315,10 @@
 				RelativePath=".\scbc.tools.h"
 				>
 			</File>
+			<File
+				RelativePath=".\SDK.h"
+				>
+			</File>
 			<File
 				RelativePath=".\stdafx.h"
 				>