hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <ctype.h>
#include <inttypes.h>
 
#include <glib.h>
 
#include <pthread.h>
#include <gdbus.h>
 
#include "json-c/json.h"
#include "rkdb.h"
#include "common.h"
 
#define TABLE_PERIPHERALS_RELAY               "PeripheralsRelay"
#define TABLE_PERIPHERALS_WEIGEN              "PeripheralsWeigen"
#define TABLE_PERIPHERALS_FILL_LIGHT          "PeripheralsFillLight"
#define TABLE_PERIPHERALS_VERSION             "PeripheralsVersion"
 
#define PERIPHERALS_VERSION             "1.0.0"
 
int peripherals_dbus_register(DBusConnection *dbus_conn)
{
    g_dbus_register_interface(dbus_conn, "/",
                              DB_PERIPHERALS_INTERFACE,
                              methods,
                              signals, NULL, DB_PERIPHERALS_INTERFACE, NULL);
 
    return 0;
}
 
void peripherals_init(void)
{
    char *col_para;
 
    if (equal_version(TABLE_PERIPHERALS_VERSION, PERIPHERALS_VERSION))
        return;
 
    g_free(rkdb_drop(TABLE_PERIPHERALS_RELAY));
    g_free(rkdb_drop(TABLE_PERIPHERALS_WEIGEN));
    g_free(rkdb_drop(TABLE_PERIPHERALS_FILL_LIGHT));
    g_free(rkdb_drop(TABLE_PERIPHERALS_VERSION));
 
    creat_version_table(TABLE_PERIPHERALS_VERSION, PERIPHERALS_VERSION);
 
    col_para = "id INTEGER PRIMARY KEY AUTOINCREMENT," \
               "iIOIndex INT," \
               "iEnable INT DEFAULT 0," \
               "iValidLevel INT DEFAULT 1," \
               "iDuration INT DEFAULT 500";
    g_free(rkdb_create(TABLE_PERIPHERALS_RELAY, col_para));
    g_free(rkdb_insert(TABLE_PERIPHERALS_RELAY, "id, iIOIndex", "0, 0"));
 
    
    col_para = "id INTEGER PRIMARY KEY AUTOINCREMENT," \
               "iEnable INT DEFAULT 0," \
               "iWiegandBit INT DEFAULT 26," \
               "iDuration INT DEFAULT 0";
    g_free(rkdb_create(TABLE_PERIPHERALS_WEIGEN, col_para));
    g_free(rkdb_insert(TABLE_PERIPHERALS_WEIGEN, "id", "0"));
 
    col_para = "id INTEGER PRIMARY KEY AUTOINCREMENT," \
               "iSaveEnergyEnable INT DEFAULT 0," \
               "iSaveEnergyBrightness INT DEFAULT 50," \
               "iNormalBrightness INT DEFAULT 50";
    g_free(rkdb_create(TABLE_PERIPHERALS_FILL_LIGHT, col_para));
    g_free(rkdb_insert(TABLE_PERIPHERALS_FILL_LIGHT, "id", "0"));
}