summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuxueli <[email protected]>2020-10-19 13:59:35 +0800
committerliuxueli <[email protected]>2020-10-19 13:59:35 +0800
commit34b0d3bc0b5aa6767b0ba8848255f47137dab0dc (patch)
tree26fa9c6f86eac43d52c65c0f17460935fc749e24
parent46322d01502e4ff20a0fe34f2ae153fe9f193cc9 (diff)
从hostname中读取设备在据点内偏移
-rw-r--r--src/tsg_entry.cpp22
-rw-r--r--src/tsg_entry.h4
2 files changed, 23 insertions, 3 deletions
diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp
index 0a3c1e0..d38c8e4 100644
--- a/src/tsg_entry.cpp
+++ b/src/tsg_entry.cpp
@@ -111,6 +111,21 @@ static int tsg_get_sn(char *filename, char *device_sn, int device_sn_len)
return flags;
}
+static int get_device_id(char *command, int entrance_id)
+{
+ FILE *fp=NULL;
+ char buffer[128]={0};
+
+ fp=popen(command, "r");
+ if(fp)
+ {
+ fgets(buffer,sizeof(buffer),fp);
+ pclose(fp);
+ }
+
+ return (entrance_id<<7)+(atoi(buffer)%128);
+}
+
static int tsg_proto_name2flag(char *proto_list, int *flag)
{
int i=0;
@@ -1153,9 +1168,12 @@ extern "C" int TSG_MASTER_INIT()
MESA_load_profile_string_def(tsg_conffile, "SYSTEM", "IDENTIFY_PROTO_NAME", identify_proto_name, sizeof(identify_proto_name), "HTTP;SSL;DNS;FTP;BGP;SIP;MAIL;STREAMING_MEDIA;QUIC;");
tsg_proto_name2flag(identify_proto_name, &g_tsg_para.proto_flag);
- MESA_load_profile_int_def(tsg_conffile, "SYSTEM", "DEVICE_ID", &g_tsg_para.device_id, 0);
+ MESA_load_profile_int_def(tsg_conffile, "SYSTEM", "ENTRANCE_ID", &g_tsg_para.entrance_id, 0);
MESA_load_profile_short_def(tsg_conffile, "SYSTEM", "TIMEOUT", (short *)&g_tsg_para.timeout, 300);
-
+
+ MESA_load_profile_string_def(tsg_conffile, "SYSTEM", "DEVICE_ID_COMMAND", g_tsg_para.device_id_command, sizeof(g_tsg_para.device_id_command), NULL);
+ g_tsg_para.device_id=get_device_id(g_tsg_para.device_id_command, g_tsg_para.entrance_id);
+
MESA_load_profile_string_def(tsg_conffile, "SYSTEM", "DEVICE_SN_FILENAME", device_sn_filename, sizeof(device_sn_filename), "/opt/tsg/etc/tsg_sn.json");
ret=tsg_get_sn(device_sn_filename, g_tsg_para.device_sn, sizeof(g_tsg_para.device_sn));
if(ret==0)
diff --git a/src/tsg_entry.h b/src/tsg_entry.h
index d03fb88..1459c51 100644
--- a/src/tsg_entry.h
+++ b/src/tsg_entry.h
@@ -101,7 +101,8 @@ typedef struct _tsg_para
int level;
unsigned short timeout;
int app_id_table_type;
- int device_id;
+ int device_id;
+ int entrance_id;
int table_id[TABLE_MAX];
int dyn_subscribe_ip_table_id; //TSG_DYN_SUBSCRIBER_IP
int priority_project_id;
@@ -110,6 +111,7 @@ typedef struct _tsg_para
int fs2_field_id[TSG_FS2_MAX];
char device_sn[MAX_DOAMIN_LEN/8];
char log_path[MAX_DOAMIN_LEN/8];
+ char device_id_command[MAX_DOAMIN_LEN/8];
char data_center[_MAX_TABLE_NAME_LEN];
char table_name[TABLE_MAX][_MAX_TABLE_NAME_LEN];
void *logger;