Skip to content

Commit 2953cd6

Browse files
committed
add license
1 parent 6a08602 commit 2953cd6

File tree

5 files changed

+155
-37
lines changed

5 files changed

+155
-37
lines changed

examples/Uno_and_above/Uno_and_above.ino

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
1+
/*
2+
This example demonstrates how the Sqlite Micro Logger library
3+
can be used to write Analog data into Sqlite database.
4+
Works on any Arduino compatible microcontroller with SD Card attachment
5+
having 2kb RAM or more (such as Arduino Uno).
6+
7+
How Sqlite Micro Logger works:
8+
https://github.com/siara-in/sqlite_micro_logger
9+
10+
Copyright 2019 Arundale Ramanathan, Siara Logics (in)
11+
12+
Licensed under the Apache License, Version 2.0 (the "License");
13+
you may not use this file except in compliance with the License.
14+
You may obtain a copy of the License at
15+
16+
http://www.apache.org/licenses/LICENSE-2.0
17+
18+
Unless required by applicable law or agreed to in writing, software
19+
distributed under the License is distributed on an "AS IS" BASIS,
20+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
See the License for the specific language governing permissions and
22+
limitations under the License.
23+
*/
124
#include "ulog_sqlite.h"
225
#include <SPI.h>
326
#include <SD.h>
4-
//#include <SdFat.h>
527

6-
//SdFat SD;
728
File myFile;
829

9-
int32_t read_fn(struct uls_write_context *ctx, void *buf, size_t len) {
30+
#define SD_CS_PIN 8
31+
32+
int32_t read_fn(struct uls_write_context *ctx, void *buf, long pos, size_t len) {
33+
myFile.seek(pos);
1034
size_t ret = myFile.read((byte *)buf, len);
1135
if (ret != len)
1236
return ULS_RES_READ_ERR;
1337
return ret;
1438
}
1539

16-
int seek_fn(struct uls_write_context *ctx, long pos) {
40+
int32_t write_fn(struct uls_write_context *ctx, void *buf, long pos, size_t len) {
1741
myFile.seek(pos);
18-
return ULS_RES_OK;
19-
}
20-
21-
int32_t write_fn(struct uls_write_context *ctx, void *buf, size_t len) {
2242
size_t ret = myFile.write((byte *)buf, len);
2343
if (ret != len)
2444
return ULS_RES_ERR;
@@ -66,7 +86,6 @@ int input_num() {
6686
return ret;
6787
}
6888

69-
#define SD_CS_PIN 8
7089
bool isInited = false;
7190
void setup() {
7291
// Open serial communications and wait for port to open:
@@ -99,13 +118,11 @@ void loop() {
99118
Serial.print(F("\nSqlite uLogger\n"));
100119
Serial.print(F("DB name: "));
101120
input_string(filename, sizeof(filename));
102-
Serial.print(F("\nEntry count: "));
121+
Serial.print(F("\nRecord count: "));
103122
num_entries = input_num();
104123
Serial.print(F("\nDelay(ms): "));
105124
dly = input_num();
106125

107-
//buf = (byte *) SD.file()->cacheClear();
108-
109126
// open the file. note that only one file can be open at a time,
110127
// so you have to close this one before opening another.
111128
myFile = SD.open(filename, FILE_WRITE);
@@ -118,7 +135,6 @@ void loop() {
118135
ctx.page_size_exp = 9;
119136
ctx.max_pages_exp = 0;
120137
ctx.read_fn = read_fn;
121-
ctx.seek_fn = seek_fn;
122138
ctx.flush_fn = flush_fn;
123139
ctx.write_fn = write_fn;
124140
int res = uls_write_init(&ctx);
@@ -131,7 +147,7 @@ void loop() {
131147
break;
132148
}
133149
if (num_entries) {
134-
res = uls_create_new_row(&ctx);
150+
res = uls_append_new_row(&ctx);
135151
if (res)
136152
break;
137153
delay(dly);

examples/Uno_and_above_Binary_Search/Uno_and_above_Binary_Search.ino

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
1+
/*
2+
This example demonstrates how the Sqlite Micro Logger library
3+
can be used to write Analog data into Sqlite database.
4+
Works on any Arduino compatible microcontroller with SD Card attachment
5+
having 2kb RAM or more (such as Arduino Uno).
6+
7+
How Sqlite Micro Logger works:
8+
https://github.com/siara-in/sqlite_micro_logger
9+
10+
Copyright 2019 Arundale Ramanathan, Siara Logics (in)
11+
12+
Licensed under the Apache License, Version 2.0 (the "License");
13+
you may not use this file except in compliance with the License.
14+
You may obtain a copy of the License at
15+
16+
http://www.apache.org/licenses/LICENSE-2.0
17+
18+
Unless required by applicable law or agreed to in writing, software
19+
distributed under the License is distributed on an "AS IS" BASIS,
20+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
See the License for the specific language governing permissions and
22+
limitations under the License.
23+
*/
124
#include "ulog_sqlite.h"
225
#include <SPI.h>
326
#include <SD.h>
427

528
File myFile;
629

7-
int32_t read_fn(struct uls_write_context *ctx, void *buf, size_t len) {
30+
#define SD_CS_PIN 8
31+
32+
int32_t read_fn(struct uls_write_context *ctx, void *buf, long pos, size_t len) {
33+
myFile.seek(pos);
834
size_t ret = myFile.read((byte *)buf, len);
935
if (ret != len)
1036
return ULS_RES_READ_ERR;
1137
return ret;
1238
}
1339

14-
int seek_fn(struct uls_write_context *ctx, long pos) {
40+
int32_t write_fn(struct uls_write_context *ctx, void *buf, long pos, size_t len) {
1541
myFile.seek(pos);
16-
return ULS_RES_OK;
17-
}
18-
19-
int32_t write_fn(struct uls_write_context *ctx, void *buf, size_t len) {
2042
size_t ret = myFile.write((byte *)buf, len);
2143
if (ret != len)
2244
return ULS_RES_ERR;
@@ -64,7 +86,6 @@ int input_num() {
6486
return ret;
6587
}
6688

67-
#define SD_CS_PIN 8
6889
bool isInited = false;
6990
void setup() {
7091
// Open serial communications and wait for port to open:
@@ -97,13 +118,11 @@ void loop() {
97118
Serial.print(F("\nSqlite uLogger\n"));
98119
Serial.print(F("DB name: "));
99120
input_string(filename, sizeof(filename));
100-
Serial.print(F("\nEntry count: "));
121+
Serial.print(F("\nRecord count: "));
101122
num_entries = input_num();
102123
Serial.print(F("\nDelay(ms): "));
103124
dly = input_num();
104125

105-
//buf = (byte *) SD.file()->cacheClear();
106-
107126
// open the file. note that only one file can be open at a time,
108127
// so you have to close this one before opening another.
109128
myFile = SD.open(filename, FILE_WRITE);
@@ -116,7 +135,6 @@ void loop() {
116135
ctx.page_size_exp = 9;
117136
ctx.max_pages_exp = 0;
118137
ctx.read_fn = read_fn;
119-
ctx.seek_fn = seek_fn;
120138
ctx.flush_fn = flush_fn;
121139
ctx.write_fn = write_fn;
122140
int res = uls_write_init(&ctx);
@@ -129,7 +147,7 @@ void loop() {
129147
break;
130148
}
131149
if (num_entries) {
132-
res = uls_create_new_row(&ctx);
150+
res = uls_append_new_row(&ctx);
133151
if (res)
134152
break;
135153
delay(dly);

src/test_ulog_sqlite.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/*
2+
Testing program for Sqlite Micro Logger
3+
4+
Sqlite Micro Logger is a Fast, Lean and Mean
5+
Sqlite database logger targetting low memory systems such as Microcontrollers.
6+
7+
This Library can work on systems that have as little as 2kb,
8+
such as the ATMega328 MCU. It is available for the Arduino platform.
9+
10+
https://github.com/siara-in/sqlite_micro_logger
11+
12+
Copyright 2019 Arundale Ramanathan, Siara Logics (in)
13+
14+
Licensed under the Apache License, Version 2.0 (the "License");
15+
you may not use this file except in compliance with the License.
16+
You may obtain a copy of the License at
17+
18+
http://www.apache.org/licenses/LICENSE-2.0
19+
20+
Unless required by applicable law or agreed to in writing, software
21+
distributed under the License is distributed on an "AS IS" BASIS,
22+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
See the License for the specific language governing permissions and
24+
limitations under the License.
25+
*/
26+
127
#ifndef ARDUINO
228

329
#include "ulog_sqlite.h"
@@ -121,7 +147,7 @@ int test_multilevel(char *filename) {
121147
txt[j] = 'a' + (char)(rand() % 26);
122148
uls_set_col_val(&ctx, 4, ULS_TYPE_TEXT, txt, txt_len);
123149
if (i < max_rows - 1)
124-
uls_create_new_row(&ctx);
150+
uls_append_new_row(&ctx);
125151
}
126152
if (uls_finalize(&ctx)) {
127153
printf("Error during finalize\n");
@@ -156,7 +182,7 @@ int test_basic(char *filename) {
156182
uls_set_col_val(&ctx, 2, ULS_TYPE_TEXT, "How", 3);
157183
uls_set_col_val(&ctx, 3, ULS_TYPE_TEXT, "Are", 3);
158184
uls_set_col_val(&ctx, 4, ULS_TYPE_TEXT, "You", 3);
159-
uls_create_new_row(&ctx);
185+
uls_append_new_row(&ctx);
160186
uls_set_col_val(&ctx, 0, ULS_TYPE_TEXT, "I", 1);
161187
uls_set_col_val(&ctx, 1, ULS_TYPE_TEXT, "am", 2);
162188
uls_set_col_val(&ctx, 2, ULS_TYPE_TEXT, "fine", 4);
@@ -190,7 +216,7 @@ void print_usage() {
190216
printf(" Searches <db_name.db> for given row_id and prints result\n\n");
191217
printf("test_ulog_sqlite -b <db_name.db> <col_idx> <value>\n");
192218
printf(" Searches <db_name.db> and column for given value using\n");
193-
printf(" binary search and prints result\n\n");
219+
printf(" binary search and prints result. col_idx starts from 0.\n\n");
194220
printf("test_ulog_sqlite -n\n");
195221
printf(" Runs pre-defined tests and creates databases (verified manually)\n\n");
196222
}
@@ -264,7 +290,7 @@ int append_records(int argc, char *argv[], struct uls_write_context *ctx) {
264290
return -4;
265291
}
266292
if (i < argc - 1) {
267-
if (uls_create_new_row(ctx)) {
293+
if (uls_append_new_row(ctx)) {
268294
printf("Error during add col\n");
269295
return -5;
270296
}

src/ulog_sqlite.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/*
2+
Sqlite Micro Logger
3+
4+
Fast, Lean and Mean Sqlite database logger targetting
5+
low memory systems such as Microcontrollers.
6+
7+
This Library can work on systems that have as little as 2kb,
8+
such as the ATMega328 MCU. It is available for the Arduino platform.
9+
10+
https://github.com/siara-in/sqlite_micro_logger
11+
12+
Copyright 2019 Arundale Ramanathan, Siara Logics (in)
13+
14+
Licensed under the Apache License, Version 2.0 (the "License");
15+
you may not use this file except in compliance with the License.
16+
You may obtain a copy of the License at
17+
18+
http://www.apache.org/licenses/LICENSE-2.0
19+
20+
Unless required by applicable law or agreed to in writing, software
21+
distributed under the License is distributed on an "AS IS" BASIS,
22+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
See the License for the specific language governing permissions and
24+
limitations under the License.
25+
*/
26+
127
#include "ulog_sqlite.h"
228

329
#include <stdlib.h>
@@ -160,7 +186,7 @@ int32_t get_pagesize(byte page_size_exp) {
160186
uint16_t acquire_last_pos(struct uls_write_context *wctx, byte *ptr) {
161187
uint16_t last_pos = read_uint16(ptr + 5);
162188
if (last_pos == 0) {
163-
uls_create_new_row(wctx);
189+
uls_append_new_row(wctx);
164190
last_pos = read_uint16(ptr + 5);
165191
}
166192
return last_pos;
@@ -437,7 +463,7 @@ int form_page1(struct uls_write_context *wctx, char *table_name, char *table_scr
437463
int orig_col_count = wctx->col_count;
438464
wctx->cur_write_page = 0;
439465
wctx->col_count = 5;
440-
uls_create_new_row(wctx);
466+
uls_append_new_row(wctx);
441467
uls_set_col_val(wctx, 0, ULS_TYPE_TEXT, "table", 5);
442468
if (table_name == NULL)
443469
table_name = default_table_name;
@@ -479,7 +505,6 @@ int form_page1(struct uls_write_context *wctx, char *table_name, char *table_scr
479505
wctx->cur_write_page = 1;
480506
wctx->cur_write_rowid = 0;
481507
init_bt_tbl_leaf(wctx->buf);
482-
uls_create_new_row(wctx);
483508

484509
return ULS_RES_OK;
485510

@@ -550,7 +575,7 @@ int uls_write_init(struct uls_write_context *wctx) {
550575
}
551576

552577
// See .h file for API description
553-
int uls_create_new_row(struct uls_write_context *wctx) {
578+
int uls_append_new_row(struct uls_write_context *wctx) {
554579

555580
wctx->cur_write_rowid++;
556581
byte *ptr = wctx->buf + (wctx->buf[0] == 13 ? 0 : 100);
@@ -821,7 +846,7 @@ int uls_init_for_append(struct uls_write_context *wctx) {
821846
res = read_bytes_wctx(wctx, wctx->buf, wctx->cur_write_page * page_size, page_size);
822847
if (res)
823848
return res;
824-
res = uls_create_new_row(wctx);
849+
res = uls_append_new_row(wctx);
825850
if (res)
826851
return res;
827852
return ULS_RES_OK;

src/ulog_sqlite.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/*
2+
Sqlite Micro Logger
3+
4+
Fast, Lean and Mean Sqlite database logger targetting
5+
low memory systems such as Microcontrollers.
6+
7+
This Library can work on systems that have as little as 2kb,
8+
such as the ATMega328 MCU. It is available for the Arduino platform.
9+
10+
https://github.com/siara-in/sqlite_micro_logger
11+
12+
Copyright 2019 Arundale Ramanathan, Siara Logics (in)
13+
14+
Licensed under the Apache License, Version 2.0 (the "License");
15+
you may not use this file except in compliance with the License.
16+
You may obtain a copy of the License at
17+
18+
http://www.apache.org/licenses/LICENSE-2.0
19+
20+
Unless required by applicable law or agreed to in writing, software
21+
distributed under the License is distributed on an "AS IS" BASIS,
22+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
See the License for the specific language governing permissions and
24+
limitations under the License.
25+
*/
26+
127
#ifndef __ULOG_SQLITE__
228
#define __ULOG_SQLITE__
329

@@ -62,7 +88,13 @@ int uls_init_for_append(struct uls_write_context *wctx);
6288
// Creates new record with all columns null
6389
// If no more space in page, writes it to disk
6490
// creates new page, and creates a new record
65-
int uls_create_new_row(struct uls_write_context *wctx);
91+
int uls_append_new_row(struct uls_write_context *wctx);
92+
93+
// Creates new record with given column values
94+
// If no more space in page, writes it to disk
95+
// creates new page, and creates a new record
96+
int uls_append_new_row_with_values(struct uls_write_context *wctx,
97+
uint8_t types[], const void *values[], uint16_t lengths[]);
6698

6799
// Sets value of column in the current record for the given column index
68100
// If no more space in page, writes it to disk
@@ -144,7 +176,8 @@ int uls_srch_row_by_id(struct uls_read_context *rctx, uint32_t rowid);
144176

145177
// Performs binary search on the inserted records
146178
// using the given Value and positions at the record found
147-
// Does not change position if record not found
179+
// Changes current position to closest match, if record not found
180+
// is_rowid = 1 is used to do Binary Search by RowId
148181
int uls_bin_srch_row_by_val(struct uls_read_context *rctx, int col_idx,
149182
int val_type, void *val, uint16_t len, byte is_rowid);
150183

0 commit comments

Comments
 (0)