📄 mdb.c
字号:
/*The Chinese Characters which used in comments are encoded as UNICODE-utf8 mode*/
/*Please DO NOT change UNICODE mode */
/**********************************************************************************
Copyright (c),2000-2007, Obtelecom Tech.Co.Ltd.
FileName: MDB.c
Module:Matrix Database
Author: David Ding Date:2007-7-19
Description: Create Database for Matrix
Version: 1.00
Function List:
1.
History:
<author> <time> <version> <description>
David 07/7/19 1.00 build this module
*************************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <db.h>
#include "../include/mdbcom.h"
#include "../include/common.h"
#include "../include/config.h"
#include "../include/vardef.h"
#include "../include/db.h"
/*********************************************************************************
Function: main()
Descripton: create 4 matrix database,get data from all device through 485s
Calls: MDBcreate(DB *)
Table Accessed: table table name varies NO
1 EquInfo 6
Table Updated:
**********************************************************************************/
int main()
{
/*create 4 MDBs header,
"equip.Info","route.Info","work.Sta","device.Sta"
which located in /mnt/*/
EqupInfo_tableCreate();
RouteInfo_tableCreate();
DeviceStatus_tableCreate();
}
/*********************************************************************************
Function: EqupInfo_tableCreate(DB * )
Descripton: create table equipment count ,set default datas to MDB
Calls: 1,check_equip(struct Get_EquInfo *)
2,EqupBox_tableCreate(int , DB *)
EqupCard_tableCreate(int,DB *)
EqupPort_tableCreate(int,DB *)
EqupChannel_tableCreate(int, DB *)
Called By: main()
Table Accessed:table equpCount,table equBox,table equpCard,
table equpPort,table equpChannel
Table Updated:
Input: -
Output: -
Return: -
Others: -
**********************************************************************************/
void EqupInfo_tableCreate()
{
DB *dbp;
DBT key,data;
int ret;
struct Get_EquInfo eqinfo;
int i;
/*check equip infomations from equip through 485 bus*/
// check_equip(&eqinfo);
if ((ret = db_create(&dbp, NULL, 0)) != 0) {
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit (1);
}
if ((ret = dbp->open(dbp,NULL,"EQUPDB", NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
dbp->err(dbp, ret, "%s", "EQUPDB");
exit (1);
}
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = "matr_version1";
key.size = sizeof("matr_version1");
data.data = eqinfo.Version1;
data.size = sizeof(WORD);
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, ret, "DB->put");
key.data = "matr_version2";
key.size = sizeof("matr_version2");
data.data = eqinfo.Version2;
data.size = sizeof(WORD);
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, ret, "DB->put");
key.data = "matr_version3";
key.size = sizeof("matr_version3");
data.data = eqinfo.Version3;
data.size = sizeof(WORD);
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, ret, "DB->put");
key.data = "matr_code";
key.size = sizeof("matr_code");
data.data = eqinfo.MatrixCode;
data.size = sizeof(DWORD);
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, ret, "DB->put");
key.data = "box_count";
key.size = sizeof("box_count");
data.data = eqinfo.BoxCount;
data.size = sizeof(BYTE);
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, ret, "DB->put");
key.data = "card_count";
key.size = sizeof("card_count");
data.data = eqinfo.CardCount;
data.size = sizeof(BYTE);
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, ret, "DB->put");
key.data = "port_count";
key.size = sizeof("port_count");
data.data = eqinfo.PortCount;
data.size = sizeof(WORD);
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, ret, "DB->put");
key.data = "channel_count";
key.size = sizeof("channel_count");
data.data = eqinfo.ChannelCount;
data.size = sizeof(WORD);
if ((ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, ret, "DB->put");
for(i=0;i<eqinfo.BoxCount;i++)
equpBox_tableCreate(i,dbp);
for(i=0;i<eqinfo.CardCount;i++)
equpCard_tableCreate(i,dbp);
for(i=0;i<eqinfo.PortCount;i++)
equpPort_tableCreate(i,dbp);
for(i=0;i<eqinfo.ChannelCount;i++)
equpChannel_tableCreate(i,dbp);
}
/*********************************************************************************
Function: equpBox_tableCreate(int, DB * )
Descripton: create table box infomation ,set default datas to MDB
Calls:
Called By: EqupCount_tableCreate()
Table Accessed:
Table Updated:
Input: box i
Output:
Return:
Others:
**********************************************************************************/
void equpBox_tableCreate(int i,DB *dbp)
{
DB *dbp;
DBT key,data;
int db_ret;
int t_ret;
int boxcode,boxtype;
char str1[10];
char strtmp;
struct Equ_BOX eqbox;
/*check box infomations from equip through 485 bus*/
//check_eqbox(i,&eqbox);
/*open matrix database file which located at /mnt/equp.info*/
if ((db_ret = db_create(&dbp, NULL, 0)) != 0)
{
fprintf(stderr, "db_create: %s\n", db_strerror(db_ret));
exit (1);
}
if ((db_ret = dbp->open(dbp,NULL,"EQUPDB", NULL, DB_BTREE, DB_CREATE, 0664)) != 0)
{
dbp->err(dbp, db_ret, "%s", "EQUPDB");
exit (1);
}
boxcode = (int) (eqbox.BoxCode);
boxtype = (int) (eqbox.BoxTypeID);
/*card code ASCII encode: eg. 1box,2card,15channel ->keyword as b01c02ch15cc*/
strcat(str1,"boxcode");
strtmp =(char)((boxcode/10)+48);
strcat(str1,&strtmp);
strtmp =(char)((boxcode%10)+48);
strcat(str1,&strtmp);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = str1;
key.size = sizeof("boxcodeii");
data.data = eqbox.BoxCode;
data.size = sizeof(BYTE);
if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, db_ret, "DB->put");
strcat(str1,"boxtype");
strtmp =(char)((boxtype/10)+48);
strcat(str1,&strtmp);
strtmp =(char)((boxtype%10)+48);
strcat(str1,&strtmp);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = str1;
key.size = sizeof("boxtypeii");
data.data = eqbox.BoxTypeID;
data.size = sizeof(WORD);
if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, db_ret, "DB->put");
}
/*********************************************************************************
Function: equpCard_tableCreate(int, DB * )
Descripton: create table card infomation ,set default datas to MDB
Calls:
Called By: EqupCount_tableCreate()
Table Accessed:
Table Updated:
Input: card i
Output:
Return:
Others:
**********************************************************************************/
void equpCard_tableCreate(int i,DB *dbp)
{
DB *dbp;
DBT key,data;
int db_ret;
int t_ret;
int cardcode,boxcode,slotcode,cardtype,cardsoft;
char str1[10];
char strtmp;
struct Equ_CARD eqcard;
/*check box infomations from equip through 485 bus*/
//check_eqbox(i,&eqbox);
/*open matrix database file which located at /mnt/equp.info*/
if ((db_ret = db_create(&dbp, NULL, 0)) != 0)
{
fprintf(stderr, "db_create: %s\n", db_strerror(db_ret));
exit (1);
}
if ((db_ret = dbp->open(dbp,NULL,"EQUPDB", NULL, DB_BTREE, DB_CREATE, 0664)) != 0)
{
dbp->err(dbp, db_ret, "%s", "EQUPDB");
exit (1);
}
cardcode = (int) (eqcard.CardCode);
boxcode = (int) (eqcard.BoxCode);
slotcode = (int) (eqcard.SlotCode);
cardtype = (int) (eqcard.CardTypeID);
cardsoft = (int) (eqcard.CardSoftVer);
/*card code ASCII encode: eg. 1box,2card,15channel ->keyword as b01c02ch15cc*/
strcat(str1," cardcode");
strtmp =(char)(( cardcode/10)+48);
strcat(str1,&strtmp);
strtmp =(char)(( cardcode%10)+48);
strcat(str1,&strtmp);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = str1;
key.size = sizeof(" cardcodeii");
data.data = eqcard.CardCode;
data.size = sizeof(DWORD);
if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
printf("db: %s: key stored.\n", (char *)key.data);
else dbp->err(dbp, db_ret, "DB->put");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -