Tutorials/k0SDR/Tutorial05: sq3_parse.cpp

File sq3_parse.cpp, 2.0 KB (added by nilanjan, 8 years ago)
Line 
1// Compile:
2// > gcc sq3_parse.cpp -o sq3_parse -lsqlite3
3//
4// Run:
5// > ./sq3_parse spectrum.grid.sq3
6//
7
8#include <stdio.h>
9#include <sqlite3.h>
10#include <string.h>
11
12static int callback1(void *NotUsed, int argc, char **argv, char **azColName){
13 int i;
14
15 /*
16 for(i=0; i<argc; i++)
17 printf("%s,", azColName[i]);
18 printf("\n");
19 */
20
21 for(i=0; i<argc; i++){
22 if (strcmp("FFTNum",azColName[i]) == 0)
23 continue;
24
25 if (strcmp("FFTBins",azColName[i]) != 0)
26 printf("%s,", argv[i] ? argv[i] : "NULL");
27 else
28 {
29 float *pFFTBins = (float*)argv[i];
30 for (int j=0; j<128; j++)
31 {
32 printf("%f,", *pFFTBins++);
33 }
34 printf("\n");
35
36 }
37
38 }
39
40 return 0;
41
42}
43
44static int callback2(void *NotUsed, int argc, char **argv, char **azColName){
45 int i;
46
47 for(i=0; i<argc; i++){
48
49 //printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
50
51 float *pFFTBins = (float*)argv[i];
52 for (int j=0; j<128; j++)
53 {
54 printf("%f, ", *pFFTBins++);
55 }
56
57 }
58 printf("\n");
59 return 0;
60}
61
62int main(int argc, char **argv){
63 sqlite3 *db;
64 char *zErrMsg = 0;
65 int rc;
66 sqlite3_int64 last_row_id;
67
68 if( argc!=2 ){
69 fprintf(stderr, "Usage: %s DATABASE\n", argv[0]);
70 return(1);
71 }
72 rc = sqlite3_open(argv[1], &db);
73 if( rc ){
74 fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
75 sqlite3_close(db);
76 return(1);
77 }
78
79 rc = sqlite3_exec(db, "select * from spectrum_data where oml_sender_id=1", callback1, 0, &zErrMsg);
80 if( rc!=SQLITE_OK ){
81 fprintf(stderr, "SQL error: %s\n", zErrMsg);
82 sqlite3_free(zErrMsg);
83 }
84
85 /*
86 rc = sqlite3_exec(db, "select FFTBins from spectrum_data where rowid=9", callback2, 0, &zErrMsg);
87 if( rc!=SQLITE_OK ){
88 fprintf(stderr, "SQL error: %s\n", zErrMsg);
89 sqlite3_free(zErrMsg);
90 }
91 */
92
93 //fprintf(stdout, "Last row id: %lld\n", sqlite3_last_insert_rowid(db));
94
95 sqlite3_close(db);
96 return 0;
97}