|
|
|
@ -36,6 +36,7 @@ static void return_timeout(struct db_command *cmd); |
|
|
|
static void return_disabled(struct db_command *cmd); |
|
|
|
static void handle_db_command(struct db_command *cmd); |
|
|
|
static int callback(void *result_str, int argc, char **argv, char **azColName); |
|
|
|
extern int sqlite3_init_with_sdram_heap(void); |
|
|
|
static const char *sql_upgrade_workorder_steps = |
|
|
|
"CREATE TABLE WorkorderSteps (WorkOrder VARCHAR,DYELOT VARCHAR,ProgramID VARCHAR,Program VARCHAR,ReDye INT DEFAULT (0)," |
|
|
|
"Mode VARCHAR,Step INT,StepID VARCHAR,StepName VARCHAR,ParameterName VARCHAR,P1 DOUBLE,P2 DOUBLE,P3 DOUBLE," |
|
|
|
@ -179,6 +180,10 @@ void close_db_immediately(void) { |
|
|
|
void db_sqlite_init_full(void) |
|
|
|
{ |
|
|
|
LOG_D("[DataBase] Init SQLite"); |
|
|
|
if (sqlite3_init_with_sdram_heap() != 0) |
|
|
|
{ |
|
|
|
LOG_E("Failed to set memory"); |
|
|
|
}else{ LOG_D("set memory");} |
|
|
|
sqlite3_initialize(); |
|
|
|
|
|
|
|
if (access(DB_NAME, F_OK) != 0) |
|
|
|
@ -190,9 +195,7 @@ void db_sqlite_init_full(void) |
|
|
|
{ |
|
|
|
sqlite3_close(g_db); |
|
|
|
//限制缓存大小 (100KB)
|
|
|
|
sqlite3_exec(g_db, "PRAGMA cache_size = -50;", 0, 0, 0); |
|
|
|
//设置临时存储为文件模式 (节省内存)
|
|
|
|
sqlite3_exec(g_db, "PRAGMA temp_store = FILE;", 0, 0, 0); |
|
|
|
sqlite3_exec(g_db, "PRAGMA cache_size = 50;", 0, 0, 0); |
|
|
|
g_db = RT_NULL; |
|
|
|
} |
|
|
|
return; //
|
|
|
|
@ -235,15 +238,15 @@ void db_sqlite_init_full(void) |
|
|
|
} |
|
|
|
|
|
|
|
LOG_D("[DataBase] New database created. Creating tables Name (%s)",DB_NAME); |
|
|
|
sqlite3_close(g_db); |
|
|
|
g_db=RT_NULL; |
|
|
|
} |
|
|
|
}else { |
|
|
|
if (sqlite3_open(DB_NAME, &g_db) == SQLITE_OK) |
|
|
|
{ |
|
|
|
//限制缓存大小 (100KB)
|
|
|
|
sqlite3_exec(g_db, "PRAGMA cache_size = -50;", 0, 0, 0); |
|
|
|
//设置临时存储为文件模式 (节省内存)
|
|
|
|
sqlite3_exec(g_db, "PRAGMA temp_store = FILE;", 0, 0, 0); |
|
|
|
LOG_D("[DataBase] NAME (%s)",DB_NAME); |
|
|
|
sqlite3_close(g_db); |
|
|
|
g_db=RT_NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -276,12 +279,21 @@ static void db_sqlite(void *parameter) { |
|
|
|
|
|
|
|
// 默认启用数据库
|
|
|
|
db_enabled = RT_TRUE; |
|
|
|
|
|
|
|
static rt_bool_t first_wait_done = RT_FALSE; |
|
|
|
while (1) |
|
|
|
{ |
|
|
|
// 接收命令
|
|
|
|
if (rt_mq_recv(db_mq, &cmd, sizeof(struct db_command), RT_WAITING_FOREVER) <= RT_EOK) |
|
|
|
if (rt_mq_recv(db_mq, &cmd, sizeof(struct db_command), 500) <= RT_EOK) |
|
|
|
{ |
|
|
|
if (first_wait_done) |
|
|
|
{ |
|
|
|
first_wait_done = RT_FALSE; |
|
|
|
//sqlite3_exec(g_db, "PRAGMA shrink_memory;", 0, 0, 0);
|
|
|
|
sqlite3_close(g_db); |
|
|
|
g_db=RT_NULL; |
|
|
|
} |
|
|
|
continue; |
|
|
|
}else{first_wait_done = RT_TRUE;} |
|
|
|
|
|
|
|
//检查排队超时
|
|
|
|
rt_tick_t now = rt_tick_get(); |
|
|
|
@ -321,10 +333,10 @@ static void db_sqlite(void *parameter) { |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
//限制缓存大小 (100KB)
|
|
|
|
sqlite3_exec(g_db, "PRAGMA cache_size = -50;", 0, 0, 0); |
|
|
|
//sqlite3_exec(g_db, "PRAGMA cache_size = -50;", 0, 0, 0);
|
|
|
|
//设置临时存储为文件模式 (节省内存)
|
|
|
|
sqlite3_exec(g_db, "PRAGMA temp_store = FILE;", 0, 0, 0); |
|
|
|
rt_kprintf("Opened database: %s\n", DB_NAME); |
|
|
|
//sqlite3_exec(g_db, "PRAGMA temp_store = FILE;", 0, 0, 0);
|
|
|
|
//rt_kprintf("Opened database: %s\n", DB_NAME);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -422,12 +434,12 @@ void thread_DB_SQLite(void) |
|
|
|
db_err = rt_thread_init(&dat_sqlite_thread, "db_sql", db_sqlite, RT_NULL,dat_sqlite_stack, 1024*16, 15, 10); |
|
|
|
if(db_err != RT_EOK) |
|
|
|
{ |
|
|
|
LOG_D("Failed to create SQLite thread!\n"); |
|
|
|
LOG_D("Failed to create SQLite thread!"); |
|
|
|
} |
|
|
|
rt_thread_startup(&dat_sqlite_thread); |
|
|
|
|
|
|
|
/*rt_thread_t tid;
|
|
|
|
tid = rt_thread_create("db_sql", db_sqlite, RT_NULL, 1024 *14, 18, 10); |
|
|
|
tid = rt_thread_create("db_sql", db_sqlite, RT_NULL, 1024 *16, 18, 10); |
|
|
|
|
|
|
|
if (tid != RT_NULL) |
|
|
|
{ |
|
|
|
|