Przeglądaj źródła

解决rtthread数据库接口数据类型不匹配的bug

guohui 1 rok temu
rodzic
commit
9555e6d21f

+ 17 - 11
f407/applications/db.c

@@ -343,7 +343,8 @@ typedef struct {
 #ifdef USE_STMTS
     tab_stmt_t   stmts[DB_TAB_MAX];
 #endif
-    
+    char         *buf;
+    int          buflen;
     uint8_t      inited;
 }db_handle_t;
 static db_handle_t dbHandle={0};
@@ -478,18 +479,17 @@ static sqlite3_stmt* get_stmt(db_handle_t *h, int tab_id, int cmd)
 static int tab_cmd(db_handle_t *h, int tab_id, int cmd_id, handle_t list)
 {
     int r=-1;
-    char sql[512];
     sqlite3_stmt *stmt;
     sqlite3 *db=get_db(h,tab_id);
 
     if(cmd_id>=CMD_CREATE) {
-        snprintf(sql, sizeof(sql), tab_info[tab_id].sql[cmd_id], tab_info[tab_id].sql[cmd_id]);
+        snprintf(h->buf, h->buflen, tab_info[tab_id].sql[cmd_id-CMD_CREATE], tab_info[tab_id].tab);
     }
     else {
-        snprintf(sql, sizeof(sql), common_cmd[cmd_id], tab_info[tab_id].tab);
+        snprintf(h->buf, h->buflen, common_cmd[cmd_id], tab_info[tab_id].tab);
     }
     
-    r = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
+    r = sqlite3_prepare_v2(db, h->buf, -1, &stmt, NULL);
     if (r == SQLITE_OK) {
         
         if(cmd_id>=CMD_CREATE) {
@@ -517,7 +517,6 @@ static int tab_cmd(db_handle_t *h, int tab_id, int cmd_id, handle_t list)
 static int stmt_init(db_handle_t *h)
 {
     int i,j,r;
-    char temp[512];
     sqlite3 *db=NULL;
     node_t node;
     list_cfg_t lc={0,0,10};
@@ -530,15 +529,15 @@ static int stmt_init(db_handle_t *h)
 #ifdef USE_STMTS
             for(j=0; j<CMD_MAX; j++) {
                 if(j>=CMD_CREATE) {
-                    snprintf(temp, sizeof(temp), common_cmd[j-CMD_CREATE], tab_info[i].tab);
+                    snprintf(h->buf, h->buflen, common_cmd[j-CMD_CREATE], tab_info[i].tab);
                 }
                 else {
-                    snprintf(temp, sizeof(temp), tab_info[i].sql[j], tab_info[i].tab);
+                    snprintf(h->buf, h->buflen, tab_info[i].sql[j], tab_info[i].tab);
                 }
                 
-                r = sqlite3_prepare_v2(db, temp, -1, &h->stmts[i].stmt[j], 0);
+                r = sqlite3_prepare_v2(db, h->buf, -1, &h->stmts[i].stmt[j], 0);
                 if (r != SQLITE_OK) {
-                    LOGE("sqlite3_prepare_v2 failed, sql: %s, %s\n", temp, sqlite3_errmsg(db));
+                    LOGE("sqlite3_prepare_v2 failed, sql: %s, %s\n", h->buf, sqlite3_errmsg(db));
                 }
             }
 #endif
@@ -940,12 +939,19 @@ int db_init(void)
     char *ext[DB_MAX]={"cfg","rec"};
     
     memset(h, 0, sizeof(db_handle_t));
+    h->buflen = (1024*2);
+    h->buf = (char*)malloc(h->buflen);
+    if(!h->buf) {
+        LOGE("___db buf malloc failed!\n");
+        return -1;
+    }
+    
     sqlite3_initialize();
     for(i=0; i<DB_MAX; i++) {
         sprintf(path, "%s/%s_%s.db", DB_PATH, DB_NAME, ext[i]);
         r = sqlite3_open(path, &h->db[i]);
         if(r != SQLITE_OK) {
-            LOGE("___%s open failed\n", path);
+            LOGE("___%s open failed, %s\n", path, sqlite3_errstr(r));
             return -1 ;
         }
         sqlite3_exec(h->db[i], "PRAGMA cache_size=0;" , NULL, NULL, NULL);

+ 0 - 2
f407/applications/fs.c

@@ -69,7 +69,6 @@ static int nor_mount(void)
     
     fal_init();
     
-    //dev = fal_mtd_nor_device_create(NOR_DEV);
     dev = fal_blk_device_create(NOR_DEV);
     if(!dev) {
         LOGE("Can't create a mtd device on nor partition\n");
@@ -235,7 +234,6 @@ int fs_mkdir(char *path)
 int fs_init(void)
 {
     dfs_mount(NULL, "/", "rom", 0, &(romfs_root));
-    
     sd_mount();
     nor_mount();
     return 0;

+ 0 - 2
f407/applications/main.c

@@ -7,7 +7,6 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <unistd.h>
-#include "db.h"
 #include "web.h"
 #include "sys.h"
 #include "power.h"
@@ -100,7 +99,6 @@ static int user_init(void)
     modbus_data_t *cas=&p->cas;
     
     //power_init();
-    db_init();
     //cascade_init(cas->mode, cas->addr, cas->baud);
     
     //web_init();

+ 3 - 3
f407/applications/packages/sqlite-v3.19.3/rtthread_io_methods.c

@@ -7,8 +7,8 @@ static int _rtthread_io_read(sqlite3_file *file_id, void *pbuf, int cnt, sqlite3
     assert(file_id);
     assert(offset >= 0);
     assert(cnt > 0);
-
-    new_offset = lseek(file->fd, offset, SEEK_SET);
+    
+    new_offset = lseek(file->fd, (off_t)offset, SEEK_SET);
     
     if (new_offset!=offset)
     {
@@ -58,7 +58,7 @@ static int _rtthread_io_write(sqlite3_file* file_id, const void *pbuf, int cnt,
     assert(file_id);
     assert(cnt > 0);
 
-    new_offset = lseek(file->fd, offset, SEEK_SET);
+    new_offset = lseek(file->fd, (off_t)offset, SEEK_SET);
 
     if (new_offset!=offset)
     {

+ 3 - 4
f407/applications/rtconfig.h

@@ -75,7 +75,7 @@
 //RT-Thread Components
 #define RT_USING_COMPONENTS_INIT
 #define RT_USING_USER_MAIN
-#define RT_MAIN_THREAD_STACK_SIZE (1024*4)
+#define RT_MAIN_THREAD_STACK_SIZE (1024*10)
 #define RT_MAIN_THREAD_PRIORITY 10
 
 #define RT_USING_MSH
@@ -110,12 +110,11 @@
 #define RT_SYSTEM_WORKQUEUE_STACKSIZE 2048
 #define RT_SYSTEM_WORKQUEUE_PRIORITY 23
 #define RT_USING_SERIAL
-//#define RT_USING_SERIAL_V1
 #define RT_USING_SERIAL_V2
 #define RT_SERIAL_USING_DMA
 #define RT_SERIAL_RB_BUFSZ 64
 #define RT_USING_SDIO
-#define SDIO_MAX_FREQ 20*1000000
+#define SDIO_MAX_FREQ 40*1000000
 #define RT_MMCSD_STACK_SIZE (1024*2)
 #define RT_MMCSD_THREAD_PREORITY 22
 #define RT_MMCSD_MAX_PARTITION 16
@@ -124,7 +123,7 @@
 #define RT_USING_SFUD
 #define RT_SFUD_USING_SFDP
 #define RT_SFUD_USING_FLASH_INFO_TABLE
-#//define RT_SFUD_SPI_MAX_HZ (40*1000000)
+#define RT_SFUD_SPI_MAX_HZ (40*1000000)
 #define RT_USING_I2C
 #define RT_USING_I2C_BITOPS
 #define RT_USING_PIN

+ 2 - 0
f407/applications/sys.c

@@ -13,6 +13,7 @@
 #include "fs.h"
 #include "ui.h"
 #include "mb.h"
+#include "db.h"
 #include "sensor.h"
 #include "breaker.h"
 #include "thread.h"
@@ -180,6 +181,7 @@ static void poll_thread(void *arg)
 int sys_init(void)
 {
     fs_init();
+    //db_init();
     paras_init();
     ui_init();
     

+ 2 - 2
f407/drivers/drv/stm32f4xx_hal_msp.c

@@ -386,9 +386,9 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
     GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
+      
     /* SPI1 interrupt Init */
-    HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
+    HAL_NVIC_SetPriority(SPI1_IRQn, 6, 0);
     HAL_NVIC_EnableIRQ(SPI1_IRQn);
   /* USER CODE BEGIN SPI1_MspInit 1 */
 

Plik diff jest za duży
+ 395 - 418
f407/project/app/app.uvoptx


+ 0 - 56
f407/project/app/app.uvprojx

@@ -675,62 +675,6 @@
         <Group>
           <GroupName>packages/db</GroupName>
           <Files>
-            <File>
-              <FileName>dbhelper.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\..\applications\packages\sqlite-v3.19.3\dbhelper.c</FilePath>
-              <FileOption>
-                <CommonProperty>
-                  <UseCPPCompiler>2</UseCPPCompiler>
-                  <RVCTCodeConst>0</RVCTCodeConst>
-                  <RVCTZI>0</RVCTZI>
-                  <RVCTOtherData>0</RVCTOtherData>
-                  <ModuleSelection>0</ModuleSelection>
-                  <IncludeInBuild>0</IncludeInBuild>
-                  <AlwaysBuild>2</AlwaysBuild>
-                  <GenerateAssemblyFile>2</GenerateAssemblyFile>
-                  <AssembleAssemblyFile>2</AssembleAssemblyFile>
-                  <PublicsOnly>2</PublicsOnly>
-                  <StopOnExitCode>11</StopOnExitCode>
-                  <CustomArgument></CustomArgument>
-                  <IncludeLibraryModules></IncludeLibraryModules>
-                  <ComprImg>1</ComprImg>
-                </CommonProperty>
-                <FileArmAds>
-                  <Cads>
-                    <interw>2</interw>
-                    <Optim>0</Optim>
-                    <oTime>2</oTime>
-                    <SplitLS>2</SplitLS>
-                    <OneElfS>2</OneElfS>
-                    <Strict>2</Strict>
-                    <EnumInt>2</EnumInt>
-                    <PlainCh>2</PlainCh>
-                    <Ropi>2</Ropi>
-                    <Rwpi>2</Rwpi>
-                    <wLevel>0</wLevel>
-                    <uThumb>2</uThumb>
-                    <uSurpInc>2</uSurpInc>
-                    <uC99>2</uC99>
-                    <uGnu>2</uGnu>
-                    <useXO>2</useXO>
-                    <v6Lang>0</v6Lang>
-                    <v6LangP>0</v6LangP>
-                    <vShortEn>2</vShortEn>
-                    <vShortWch>2</vShortWch>
-                    <v6Lto>2</v6Lto>
-                    <v6WtE>2</v6WtE>
-                    <v6Rtti>2</v6Rtti>
-                    <VariousControls>
-                      <MiscControls></MiscControls>
-                      <Define></Define>
-                      <Undefine></Undefine>
-                      <IncludePath></IncludePath>
-                    </VariousControls>
-                  </Cads>
-                </FileArmAds>
-              </FileOption>
-            </File>
             <File>
               <FileName>sqlite3.c</FileName>
               <FileType>1</FileType>