소스 검색

1、ini接口ok
2、将结构体内的_global_device_info指针改为静态

guohui 2 년 전
부모
커밋
f1b6e170e6

+ 6 - 1
pro/CMakeLists.txt

@@ -12,7 +12,9 @@ project (pdu_ctrl_app)
 
 add_definitions(-DSHELL_CFG_USER="shell_cfg_user.h")
 
-include_directories (${PROJECT_SOURCE_DIR}/modbus/inc ${PROJECT_SOURCE_DIR}/sqlite/inc)
+include_directories (${PROJECT_SOURCE_DIR}/modbus/inc 
+                     ${PROJECT_SOURCE_DIR}/ini
+                     ${PROJECT_SOURCE_DIR}/sqlite/inc)
 
 include_directories (${PROJECT_SOURCE_DIR}/easylogger/os/inc)
 include_directories (${PROJECT_SOURCE_DIR}/easylogger/inc)
@@ -50,6 +52,9 @@ set(PDU_SRC_LIST
 	${PROJECT_SOURCE_DIR}/easylogger/src/elog_buf.c	
 	${PROJECT_SOURCE_DIR}/easylogger/src/elog_utils.c
 
+    ${PROJECT_SOURCE_DIR}/ini/dictionary.c
+	${PROJECT_SOURCE_DIR}/ini/iniparser.c
+
 	${PROJECT_SOURCE_DIR}/mongoose/mongoose.c
 	${PROJECT_SOURCE_DIR}/src/websocket_handle.c
 

+ 383 - 0
pro/ini/dictionary.c

@@ -0,0 +1,383 @@
+/*-------------------------------------------------------------------------*/
+/**
+   @file    dictionary.c
+   @author  N. Devillard
+   @brief   Implements a dictionary for string variables.
+
+   This module implements a simple dictionary object, i.e. a list
+   of string/string associations. This object is useful to store e.g.
+   informations retrieved from a configuration file (ini files).
+*/
+/*--------------------------------------------------------------------------*/
+
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+#include "dictionary.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/** Minimal allocated number of entries in a dictionary */
+#define DICTMINSZ   128
+
+/*---------------------------------------------------------------------------
+                            Private functions
+ ---------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Duplicate a string
+  @param    s String to duplicate
+  @return   Pointer to a newly allocated string, to be freed with free()
+
+  This is a replacement for strdup(). This implementation is provided
+  for systems that do not have it.
+ */
+/*--------------------------------------------------------------------------*/
+static char * xstrdup(const char * s)
+{
+    char * t ;
+    size_t len ;
+    if (!s)
+        return NULL ;
+
+    len = strlen(s) + 1 ;
+    t = (char*) malloc(len) ;
+    if (t) {
+        memcpy(t, s, len) ;
+    }
+    return t ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Double the size of the dictionary
+  @param    d Dictionary to grow
+  @return   This function returns non-zero in case of failure
+ */
+/*--------------------------------------------------------------------------*/
+static int dictionary_grow(dictionary * d)
+{
+    char        ** new_val ;
+    char        ** new_key ;
+    unsigned     * new_hash ;
+
+    new_val  = (char**) calloc(d->size * 2, sizeof *d->val);
+    new_key  = (char**) calloc(d->size * 2, sizeof *d->key);
+    new_hash = (unsigned*) calloc(d->size * 2, sizeof *d->hash);
+    if (!new_val || !new_key || !new_hash) {
+        /* An allocation failed, leave the dictionary unchanged */
+        if (new_val)
+            free(new_val);
+        if (new_key)
+            free(new_key);
+        if (new_hash)
+            free(new_hash);
+        return -1 ;
+    }
+    /* Initialize the newly allocated space */
+    memcpy(new_val, d->val, d->size * sizeof(char *));
+    memcpy(new_key, d->key, d->size * sizeof(char *));
+    memcpy(new_hash, d->hash, d->size * sizeof(unsigned));
+    /* Delete previous data */
+    free(d->val);
+    free(d->key);
+    free(d->hash);
+    /* Actually update the dictionary */
+    d->size *= 2 ;
+    d->val = new_val;
+    d->key = new_key;
+    d->hash = new_hash;
+    return 0 ;
+}
+
+/*---------------------------------------------------------------------------
+                            Function codes
+ ---------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Compute the hash key for a string.
+  @param    key     Character string to use for key.
+  @return   1 unsigned int on at least 32 bits.
+
+  This hash function has been taken from an Article in Dr Dobbs Journal.
+  This is normally a collision-free function, distributing keys evenly.
+  The key is stored anyway in the struct so that collision can be avoided
+  by comparing the key itself in last resort.
+ */
+/*--------------------------------------------------------------------------*/
+unsigned dictionary_hash(const char * key)
+{
+    size_t      len ;
+    unsigned    hash ;
+    size_t      i ;
+
+    if (!key)
+        return 0 ;
+
+    len = strlen(key);
+    for (hash=0, i=0 ; i<len ; i++) {
+        hash += (unsigned)key[i] ;
+        hash += (hash<<10);
+        hash ^= (hash>>6) ;
+    }
+    hash += (hash <<3);
+    hash ^= (hash >>11);
+    hash += (hash <<15);
+    return hash ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Create a new dictionary object.
+  @param    size    Optional initial size of the dictionary.
+  @return   1 newly allocated dictionary object.
+
+  This function allocates a new dictionary object of given size and returns
+  it. If you do not know in advance (roughly) the number of entries in the
+  dictionary, give size=0.
+ */
+/*-------------------------------------------------------------------------*/
+dictionary * dictionary_new(size_t size)
+{
+    dictionary  *   d ;
+
+    /* If no size was specified, allocate space for DICTMINSZ */
+    if (size<DICTMINSZ) size=DICTMINSZ ;
+
+    d = (dictionary*) calloc(1, sizeof *d) ;
+
+    if (d) {
+        d->size = size ;
+        d->val  = (char**) calloc(size, sizeof *d->val);
+        d->key  = (char**) calloc(size, sizeof *d->key);
+        d->hash = (unsigned*) calloc(size, sizeof *d->hash);
+        if (!d->size || !d->val || !d->hash) {
+            free((void *) d->size);
+            free((void *) d->val);
+            free((void *) d->hash);
+            free(d);
+            d = NULL;
+        }
+    }
+    return d ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Delete a dictionary object
+  @param    d   dictionary object to deallocate.
+  @return   void
+
+  Deallocate a dictionary object and all memory associated to it.
+ */
+/*--------------------------------------------------------------------------*/
+void dictionary_del(dictionary * d)
+{
+    size_t  i ;
+
+    if (d==NULL) return ;
+    for (i=0 ; i<d->size ; i++) {
+        if (d->key[i]!=NULL)
+            free(d->key[i]);
+        if (d->val[i]!=NULL)
+            free(d->val[i]);
+    }
+    free(d->val);
+    free(d->key);
+    free(d->hash);
+    free(d);
+    return ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get a value from a dictionary.
+  @param    d       dictionary object to search.
+  @param    key     Key to look for in the dictionary.
+  @param    def     Default value to return if key not found.
+  @return   1 pointer to internally allocated character string.
+
+  This function locates a key in a dictionary and returns a pointer to its
+  value, or the passed 'def' pointer if no such key can be found in
+  dictionary. The returned character pointer points to data internal to the
+  dictionary object, you should not try to free it or modify it.
+ */
+/*--------------------------------------------------------------------------*/
+const char * dictionary_get(const dictionary * d, const char * key, const char * def)
+{
+    unsigned    hash ;
+    size_t      i ;
+
+    if(d == NULL || key == NULL)
+       return def ;
+
+    hash = dictionary_hash(key);
+    for (i=0 ; i<d->size ; i++) {
+        if (d->key[i]==NULL)
+            continue ;
+        /* Compare hash */
+        if (hash==d->hash[i]) {
+            /* Compare string, to avoid hash collisions */
+            if (!strcmp(key, d->key[i])) {
+                return d->val[i] ;
+            }
+        }
+    }
+    return def ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Set a value in a dictionary.
+  @param    d       dictionary object to modify.
+  @param    key     Key to modify or add.
+  @param    val     Value to add.
+  @return   int     0 if Ok, anything else otherwise
+
+  If the given key is found in the dictionary, the associated value is
+  replaced by the provided one. If the key cannot be found in the
+  dictionary, it is added to it.
+
+  It is Ok to provide a NULL value for val, but NULL values for the dictionary
+  or the key are considered as errors: the function will return immediately
+  in such a case.
+
+  Notice that if you dictionary_set a variable to NULL, a call to
+  dictionary_get will return a NULL value: the variable will be found, and
+  its value (NULL) is returned. In other words, setting the variable
+  content to NULL is equivalent to deleting the variable from the
+  dictionary. It is not possible (in this implementation) to have a key in
+  the dictionary without value.
+
+  This function returns non-zero in case of failure.
+ */
+/*--------------------------------------------------------------------------*/
+int dictionary_set(dictionary * d, const char * key, const char * val)
+{
+    size_t         i ;
+    unsigned       hash ;
+
+    if (d==NULL || key==NULL) return -1 ;
+
+    /* Compute hash for this key */
+    hash = dictionary_hash(key) ;
+    /* Find if value is already in dictionary */
+    if (d->n>0) {
+        for (i=0 ; i<d->size ; i++) {
+            if (d->key[i]==NULL)
+                continue ;
+            if (hash==d->hash[i]) { /* Same hash value */
+                if (!strcmp(key, d->key[i])) {   /* Same key */
+                    /* Found a value: modify and return */
+                    if (d->val[i]!=NULL)
+                        free(d->val[i]);
+                    d->val[i] = (val ? xstrdup(val) : NULL);
+                    /* Value has been modified: return */
+                    return 0 ;
+                }
+            }
+        }
+    }
+    /* Add a new value */
+    /* See if dictionary needs to grow */
+    if (d->n==d->size) {
+        /* Reached maximum size: reallocate dictionary */
+        if (dictionary_grow(d) != 0)
+            return -1;
+    }
+
+    /* Insert key in the first empty slot. Start at d->n and wrap at
+       d->size. Because d->n < d->size this will necessarily
+       terminate. */
+    for (i=d->n ; d->key[i] ; ) {
+        if(++i == d->size) i = 0;
+    }
+    /* Copy key */
+    d->key[i]  = xstrdup(key);
+    d->val[i]  = (val ? xstrdup(val) : NULL) ;
+    d->hash[i] = hash;
+    d->n ++ ;
+    return 0 ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Delete a key in a dictionary
+  @param    d       dictionary object to modify.
+  @param    key     Key to remove.
+  @return   void
+
+  This function deletes a key in a dictionary. Nothing is done if the
+  key cannot be found.
+ */
+/*--------------------------------------------------------------------------*/
+void dictionary_unset(dictionary * d, const char * key)
+{
+    unsigned    hash ;
+    size_t      i ;
+
+    if (key == NULL || d == NULL) {
+        return;
+    }
+
+    hash = dictionary_hash(key);
+    for (i=0 ; i<d->size ; i++) {
+        if (d->key[i]==NULL)
+            continue ;
+        /* Compare hash */
+        if (hash==d->hash[i]) {
+            /* Compare string, to avoid hash collisions */
+            if (!strcmp(key, d->key[i])) {
+                /* Found key */
+                break ;
+            }
+        }
+    }
+    if (i>=d->size)
+        /* Key not found */
+        return ;
+
+    free(d->key[i]);
+    d->key[i] = NULL ;
+    if (d->val[i]!=NULL) {
+        free(d->val[i]);
+        d->val[i] = NULL ;
+    }
+    d->hash[i] = 0 ;
+    d->n -- ;
+    return ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Dump a dictionary to an opened file pointer.
+  @param    d   Dictionary to dump
+  @param    f   Opened file pointer.
+  @return   void
+
+  Dumps a dictionary onto an opened file pointer. Key pairs are printed out
+  as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as
+  output file pointers.
+ */
+/*--------------------------------------------------------------------------*/
+void dictionary_dump(const dictionary * d, FILE * out)
+{
+    size_t  i ;
+
+    if (d==NULL || out==NULL) return ;
+    if (d->n<1) {
+        fprintf(out, "empty dictionary\n");
+        return ;
+    }
+    for (i=0 ; i<d->size ; i++) {
+        if (d->key[i]) {
+            fprintf(out, "%20s\t[%s]\n",
+                    d->key[i],
+                    d->val[i] ? d->val[i] : "UNDEF");
+        }
+    }
+    return ;
+}

+ 170 - 0
pro/ini/dictionary.h

@@ -0,0 +1,170 @@
+
+/*-------------------------------------------------------------------------*/
+/**
+   @file    dictionary.h
+   @author  N. Devillard
+   @brief   Implements a dictionary for string variables.
+
+   This module implements a simple dictionary object, i.e. a list
+   of string/string associations. This object is useful to store e.g.
+   informations retrieved from a configuration file (ini files).
+*/
+/*--------------------------------------------------------------------------*/
+
+#ifndef _DICTIONARY_H_
+#define _DICTIONARY_H_
+
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*---------------------------------------------------------------------------
+                                New types
+ ---------------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Dictionary object
+
+  This object contains a list of string/string associations. Each
+  association is identified by a unique string key. Looking up values
+  in the dictionary is speeded up by the use of a (hopefully collision-free)
+  hash function.
+ */
+/*-------------------------------------------------------------------------*/
+typedef struct _dictionary_ {
+    unsigned        n ;     /** Number of entries in dictionary */
+    size_t          size ;  /** Storage size */
+    char        **  val ;   /** List of string values */
+    char        **  key ;   /** List of string keys */
+    unsigned     *  hash ;  /** List of hash values for keys */
+} dictionary ;
+
+
+/*---------------------------------------------------------------------------
+                            Function prototypes
+ ---------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Compute the hash key for a string.
+  @param    key     Character string to use for key.
+  @return   1 unsigned int on at least 32 bits.
+
+  This hash function has been taken from an Article in Dr Dobbs Journal.
+  This is normally a collision-free function, distributing keys evenly.
+  The key is stored anyway in the struct so that collision can be avoided
+  by comparing the key itself in last resort.
+ */
+/*--------------------------------------------------------------------------*/
+unsigned dictionary_hash(const char * key);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Create a new dictionary object.
+  @param    size    Optional initial size of the dictionary.
+  @return   1 newly allocated dictionary object.
+
+  This function allocates a new dictionary object of given size and returns
+  it. If you do not know in advance (roughly) the number of entries in the
+  dictionary, give size=0.
+ */
+/*--------------------------------------------------------------------------*/
+dictionary * dictionary_new(size_t size);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Delete a dictionary object
+  @param    d   dictionary object to deallocate.
+  @return   void
+
+  Deallocate a dictionary object and all memory associated to it.
+ */
+/*--------------------------------------------------------------------------*/
+void dictionary_del(dictionary * vd);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get a value from a dictionary.
+  @param    d       dictionary object to search.
+  @param    key     Key to look for in the dictionary.
+  @param    def     Default value to return if key not found.
+  @return   1 pointer to internally allocated character string.
+
+  This function locates a key in a dictionary and returns a pointer to its
+  value, or the passed 'def' pointer if no such key can be found in
+  dictionary. The returned character pointer points to data internal to the
+  dictionary object, you should not try to free it or modify it.
+ */
+/*--------------------------------------------------------------------------*/
+const char * dictionary_get(const dictionary * d, const char * key, const char * def);
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Set a value in a dictionary.
+  @param    d       dictionary object to modify.
+  @param    key     Key to modify or add.
+  @param    val     Value to add.
+  @return   int     0 if Ok, anything else otherwise
+
+  If the given key is found in the dictionary, the associated value is
+  replaced by the provided one. If the key cannot be found in the
+  dictionary, it is added to it.
+
+  It is Ok to provide a NULL value for val, but NULL values for the dictionary
+  or the key are considered as errors: the function will return immediately
+  in such a case.
+
+  Notice that if you dictionary_set a variable to NULL, a call to
+  dictionary_get will return a NULL value: the variable will be found, and
+  its value (NULL) is returned. In other words, setting the variable
+  content to NULL is equivalent to deleting the variable from the
+  dictionary. It is not possible (in this implementation) to have a key in
+  the dictionary without value.
+
+  This function returns non-zero in case of failure.
+ */
+/*--------------------------------------------------------------------------*/
+int dictionary_set(dictionary * vd, const char * key, const char * val);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Delete a key in a dictionary
+  @param    d       dictionary object to modify.
+  @param    key     Key to remove.
+  @return   void
+
+  This function deletes a key in a dictionary. Nothing is done if the
+  key cannot be found.
+ */
+/*--------------------------------------------------------------------------*/
+void dictionary_unset(dictionary * d, const char * key);
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Dump a dictionary to an opened file pointer.
+  @param    d   Dictionary to dump
+  @param    f   Opened file pointer.
+  @return   void
+
+  Dumps a dictionary onto an opened file pointer. Key pairs are printed out
+  as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as
+  output file pointers.
+ */
+/*--------------------------------------------------------------------------*/
+void dictionary_dump(const dictionary * d, FILE * out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 949 - 0
pro/ini/iniparser.c

@@ -0,0 +1,949 @@
+
+/*-------------------------------------------------------------------------*/
+/**
+   @file    iniparser.c
+   @author  N. Devillard
+   @brief   Parser for ini files.
+*/
+/*--------------------------------------------------------------------------*/
+/*---------------------------- Includes ------------------------------------*/
+#include <ctype.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "iniparser.h"
+
+/*---------------------------- Defines -------------------------------------*/
+#define ASCIILINESZ         (1024)
+#define INI_INVALID_KEY     ((char*)-1)
+
+/*---------------------------------------------------------------------------
+                        Private to this module
+ ---------------------------------------------------------------------------*/
+/**
+ * This enum stores the status for each parsed line (internal use only).
+ */
+typedef enum _line_status_ {
+    LINE_UNPROCESSED,
+    LINE_ERROR,
+    LINE_EMPTY,
+    LINE_COMMENT,
+    LINE_SECTION,
+    LINE_VALUE
+} line_status ;
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Convert a string to lowercase.
+  @param    in   String to convert.
+  @param    out Output buffer.
+  @param    len Size of the out buffer.
+  @return   ptr to the out buffer or NULL if an error occured.
+
+  This function convert a string into lowercase.
+  At most len - 1 elements of the input string will be converted.
+ */
+/*--------------------------------------------------------------------------*/
+static const char * strlwc(const char * in, char *out, unsigned len)
+{
+    unsigned i ;
+
+    if (in==NULL || out == NULL || len==0) return NULL ;
+    i=0 ;
+    while (in[i] != '\0' && i < len-1) {
+        out[i] = (char)tolower((int)in[i]);
+        i++ ;
+    }
+    out[i] = '\0';
+    return out ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Duplicate a string
+  @param    s String to duplicate
+  @return   Pointer to a newly allocated string, to be freed with free()
+
+  This is a replacement for strdup(). This implementation is provided
+  for systems that do not have it.
+ */
+/*--------------------------------------------------------------------------*/
+static char * xstrdup(const char * s)
+{
+    char * t ;
+    size_t len ;
+    if (!s)
+        return NULL ;
+
+    len = strlen(s) + 1 ;
+    t = (char*) malloc(len) ;
+    if (t) {
+        memcpy(t, s, len) ;
+    }
+    return t ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Remove blanks at the beginning and the end of a string.
+  @param    str  String to parse and alter.
+  @return   unsigned New size of the string.
+ */
+/*--------------------------------------------------------------------------*/
+static unsigned strstrip(char * s)
+{
+    char *last = NULL ;
+    char *dest = s;
+
+    if (s==NULL) return 0;
+
+    last = s + strlen(s);
+    while (isspace((int)*s) && *s) s++;
+    while (last > s) {
+        if (!isspace((int)*(last-1)))
+            break ;
+        last -- ;
+    }
+    *last = (char)0;
+
+    memmove(dest,s,last - s + 1);
+    return last - s;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Default error callback for iniparser: wraps `fprintf(stderr, ...)`.
+ */
+/*--------------------------------------------------------------------------*/
+static int default_error_callback(const char *format, ...)
+{
+  int ret;
+  va_list argptr;
+  va_start(argptr, format);
+  ret = vfprintf(stderr, format, argptr);
+  va_end(argptr);
+  return ret;
+}
+
+static int (*iniparser_error_callback)(const char*, ...) = default_error_callback;
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Configure a function to receive the error messages.
+  @param    errback  Function to call.
+
+  By default, the error will be printed on stderr. If a null pointer is passed
+  as errback the error callback will be switched back to default.
+ */
+/*--------------------------------------------------------------------------*/
+void iniparser_set_error_callback(int (*errback)(const char *, ...))
+{
+  if (errback) {
+    iniparser_error_callback = errback;
+  } else {
+    iniparser_error_callback = default_error_callback;
+  }
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get number of sections in a dictionary
+  @param    d   Dictionary to examine
+  @return   int Number of sections found in dictionary
+
+  This function returns the number of sections found in a dictionary.
+  The test to recognize sections is done on the string stored in the
+  dictionary: a section name is given as "section" whereas a key is
+  stored as "section:key", thus the test looks for entries that do not
+  contain a colon.
+
+  This clearly fails in the case a section name contains a colon, but
+  this should simply be avoided.
+
+  This function returns -1 in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_getnsec(const dictionary * d)
+{
+    size_t i ;
+    int nsec ;
+
+    if (d==NULL) return -1 ;
+    nsec=0 ;
+    for (i=0 ; i<d->size ; i++) {
+        if (d->key[i]==NULL)
+            continue ;
+        if (strchr(d->key[i], ':')==NULL) {
+            nsec ++ ;
+        }
+    }
+    return nsec ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get name for section n in a dictionary.
+  @param    d   Dictionary to examine
+  @param    n   Section number (from 0 to nsec-1).
+  @return   Pointer to char string
+
+  This function locates the n-th section in a dictionary and returns
+  its name as a pointer to a string statically allocated inside the
+  dictionary. Do not free or modify the returned string!
+
+  This function returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+const char * iniparser_getsecname(const dictionary * d, int n)
+{
+    size_t i ;
+    int foundsec ;
+
+    if (d==NULL || n<0) return NULL ;
+    foundsec=0 ;
+    for (i=0 ; i<d->size ; i++) {
+        if (d->key[i]==NULL)
+            continue ;
+        if (strchr(d->key[i], ':')==NULL) {
+            foundsec++ ;
+            if (foundsec>n)
+                break ;
+        }
+    }
+    if (foundsec<=n) {
+        return NULL ;
+    }
+    return d->key[i] ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Dump a dictionary to an opened file pointer.
+  @param    d   Dictionary to dump.
+  @param    f   Opened file pointer to dump to.
+  @return   void
+
+  This function prints out the contents of a dictionary, one element by
+  line, onto the provided file pointer. It is OK to specify @c stderr
+  or @c stdout as output files. This function is meant for debugging
+  purposes mostly.
+ */
+/*--------------------------------------------------------------------------*/
+void iniparser_dump(const dictionary * d, FILE * f)
+{
+    size_t i ;
+
+    if (d==NULL || f==NULL) return ;
+    for (i=0 ; i<d->size ; i++) {
+        if (d->key[i]==NULL)
+            continue ;
+        if (d->val[i]!=NULL) {
+            fprintf(f, "[%s]=[%s]\n", d->key[i], d->val[i]);
+        } else {
+            fprintf(f, "[%s]=UNDEF\n", d->key[i]);
+        }
+    }
+    return ;
+}
+
+static void escape_value(char *escaped, char *value) {
+    char c;
+    int v = 0;
+    int e = 0;
+
+    if(!escaped || !value)
+        return;
+
+    while((c = value[v]) != '\0') {
+        if(c == '\\' || c == '"') {
+            escaped[e] = '\\';
+            e++;
+        }
+        escaped[e] = c;
+        v++;
+        e++;
+    }
+    escaped[e] = '\0';
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Save a dictionary to a loadable ini file
+  @param    d   Dictionary to dump
+  @param    f   Opened file pointer to dump to
+  @return   void
+
+  This function dumps a given dictionary into a loadable ini file.
+  It is Ok to specify @c stderr or @c stdout as output files.
+ */
+/*--------------------------------------------------------------------------*/
+void iniparser_dump_ini(const dictionary * d, FILE * f)
+{
+    size_t       i ;
+    size_t       nsec ;
+    const char * secname ;
+    char escaped[ASCIILINESZ+1] = "";
+
+    if (d==NULL || f==NULL) return ;
+
+    nsec = iniparser_getnsec(d);
+    if (nsec<1) {
+        /* No section in file: dump all keys as they are */
+        for (i=0 ; i<d->size ; i++) {
+            if (d->key[i]==NULL)
+                continue ;
+            escape_value(escaped, d->val[i]);
+            fprintf(f, "%s = \"%s\"\n", d->key[i], escaped);
+        }
+        return ;
+    }
+    for (i=0 ; i<nsec ; i++) {
+        secname = iniparser_getsecname(d, i) ;
+        iniparser_dumpsection_ini(d, secname, f);
+    }
+    fprintf(f, "\n");
+    return ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Save a dictionary section to a loadable ini file
+  @param    d   Dictionary to dump
+  @param    s   Section name of dictionary to dump
+  @param    f   Opened file pointer to dump to
+  @return   void
+
+  This function dumps a given section of a given dictionary into a loadable ini
+  file.  It is Ok to specify @c stderr or @c stdout as output files.
+ */
+/*--------------------------------------------------------------------------*/
+void iniparser_dumpsection_ini(const dictionary * d, const char * s, FILE * f)
+{
+    size_t  j ;
+    char    keym[ASCIILINESZ+1];
+    int     seclen ;
+    char escaped[ASCIILINESZ+1] = "";
+
+    if (d==NULL || f==NULL) return ;
+    if (! iniparser_find_entry(d, s)) return ;
+
+    seclen  = (int)strlen(s);
+    fprintf(f, "\n[%s]\n", s);
+    sprintf(keym, "%s:", s);
+    for (j=0 ; j<d->size ; j++) {
+        if (d->key[j]==NULL)
+            continue ;
+        if (!strncmp(d->key[j], keym, seclen+1)) {
+            escape_value(escaped, d->val[j]);
+            fprintf(f, "%-30s = \"%s\"\n", d->key[j]+seclen+1, escaped);
+        }
+    }
+    fprintf(f, "\n");
+    return ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the number of keys in a section of a dictionary.
+  @param    d   Dictionary to examine
+  @param    s   Section name of dictionary to examine
+  @return   Number of keys in section
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_getsecnkeys(const dictionary * d, const char * s)
+{
+    int     seclen, nkeys ;
+    char    keym[ASCIILINESZ+1];
+    size_t  j ;
+
+    nkeys = 0;
+
+    if (d==NULL) return nkeys;
+    if (! iniparser_find_entry(d, s)) return nkeys;
+
+    seclen  = (int)strlen(s);
+    strlwc(s, keym, sizeof(keym));
+    keym[seclen] = ':';
+
+    for (j=0 ; j<d->size ; j++) {
+        if (d->key[j]==NULL)
+            continue ;
+        if (!strncmp(d->key[j], keym, seclen+1))
+            nkeys++;
+    }
+
+    return nkeys;
+
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the number of keys in a section of a dictionary.
+  @param    d    Dictionary to examine
+  @param    s    Section name of dictionary to examine
+  @param    keys Already allocated array to store the keys in
+  @return   The pointer passed as `keys` argument or NULL in case of error
+
+  This function queries a dictionary and finds all keys in a given section.
+  The keys argument should be an array of pointers which size has been
+  determined by calling `iniparser_getsecnkeys` function prior to this one.
+
+  Each pointer in the returned char pointer-to-pointer is pointing to
+  a string allocated in the dictionary; do not free or modify them.
+ */
+/*--------------------------------------------------------------------------*/
+const char ** iniparser_getseckeys(const dictionary * d, const char * s, const char ** keys)
+{
+    size_t i, j, seclen ;
+    char keym[ASCIILINESZ+1];
+
+    if (d==NULL || keys==NULL) return NULL;
+    if (! iniparser_find_entry(d, s)) return NULL;
+
+    seclen  = strlen(s);
+    strlwc(s, keym, sizeof(keym));
+    keym[seclen] = ':';
+
+    i = 0;
+
+    for (j=0 ; j<d->size ; j++) {
+        if (d->key[j]==NULL)
+            continue ;
+        if (!strncmp(d->key[j], keym, seclen+1)) {
+            keys[i] = d->key[j];
+            i++;
+        }
+    }
+
+    return keys;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key
+  @param    d       Dictionary to search
+  @param    key     Key string to look for
+  @param    def     Default value to return if key not found.
+  @return   pointer to statically allocated character string
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the pointer passed as 'def' is returned.
+  The returned char pointer is pointing to a string allocated in
+  the dictionary, do not free or modify it.
+ */
+/*--------------------------------------------------------------------------*/
+const char * iniparser_getstring(const dictionary * d, const char * key, const char * def)
+{
+    const char * lc_key ;
+    const char * sval ;
+    char tmp_str[ASCIILINESZ+1];
+
+    if (d==NULL || key==NULL)
+        return def ;
+
+    lc_key = strlwc(key, tmp_str, sizeof(tmp_str));
+    sval = dictionary_get(d, lc_key, def);
+    return sval ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to an long int
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   long integer
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+
+  Supported values for integers include the usual C notation
+  so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
+  are supported. Examples:
+
+  "42"      ->  42
+  "042"     ->  34 (octal -> decimal)
+  "0x42"    ->  66 (hexa  -> decimal)
+
+  Warning: the conversion may overflow in various ways. Conversion is
+  totally outsourced to strtol(), see the associated man page for overflow
+  handling.
+
+  Credits: Thanks to A. Becker for suggesting strtol()
+ */
+/*--------------------------------------------------------------------------*/
+long int iniparser_getlongint(const dictionary * d, const char * key, long int notfound)
+{
+    const char * str ;
+
+    str = iniparser_getstring(d, key, INI_INVALID_KEY);
+    if (str==NULL || str==INI_INVALID_KEY) return notfound ;
+    return strtol(str, NULL, 0);
+}
+
+int64_t iniparser_getint64(const dictionary * d, const char * key, int64_t notfound)
+{
+    const char * str ;
+
+    str = iniparser_getstring(d, key, INI_INVALID_KEY);
+    if (str==NULL || str==INI_INVALID_KEY) return notfound ;
+    return strtoimax(str, NULL, 0);
+}
+
+uint64_t iniparser_getuint64(const dictionary * d, const char * key, uint64_t notfound)
+{
+    const char * str ;
+
+    str = iniparser_getstring(d, key, INI_INVALID_KEY);
+    if (str==NULL || str==INI_INVALID_KEY) return notfound ;
+    return strtoumax(str, NULL, 0);
+}
+
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to an int
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   integer
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+
+  Supported values for integers include the usual C notation
+  so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
+  are supported. Examples:
+
+  "42"      ->  42
+  "042"     ->  34 (octal -> decimal)
+  "0x42"    ->  66 (hexa  -> decimal)
+
+  Warning: the conversion may overflow in various ways. Conversion is
+  totally outsourced to strtol(), see the associated man page for overflow
+  handling.
+
+  Credits: Thanks to A. Becker for suggesting strtol()
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_getint(const dictionary * d, const char * key, int notfound)
+{
+    return (int)iniparser_getlongint(d, key, notfound);
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to a double
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   double
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+ */
+/*--------------------------------------------------------------------------*/
+double iniparser_getdouble(const dictionary * d, const char * key, double notfound)
+{
+    const char * str ;
+
+    str = iniparser_getstring(d, key, INI_INVALID_KEY);
+    if (str==NULL || str==INI_INVALID_KEY) return notfound ;
+    return atof(str);
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to a boolean
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   integer
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+
+  A true boolean is found if one of the following is matched:
+
+  - A string starting with 'y'
+  - A string starting with 'Y'
+  - A string starting with 't'
+  - A string starting with 'T'
+  - A string starting with '1'
+
+  A false boolean is found if one of the following is matched:
+
+  - A string starting with 'n'
+  - A string starting with 'N'
+  - A string starting with 'f'
+  - A string starting with 'F'
+  - A string starting with '0'
+
+  The notfound value returned if no boolean is identified, does not
+  necessarily have to be 0 or 1.
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_getboolean(const dictionary * d, const char * key, int notfound)
+{
+    int          ret ;
+    const char * c ;
+
+    c = iniparser_getstring(d, key, INI_INVALID_KEY);
+    if (c==NULL || c==INI_INVALID_KEY) return notfound ;
+    if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') {
+        ret = 1 ;
+    } else if (c[0]=='n' || c[0]=='N' || c[0]=='0' || c[0]=='f' || c[0]=='F') {
+        ret = 0 ;
+    } else {
+        ret = notfound ;
+    }
+    return ret;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Finds out if a given entry exists in a dictionary
+  @param    ini     Dictionary to search
+  @param    entry   Name of the entry to look for
+  @return   integer 1 if entry exists, 0 otherwise
+
+  Finds out if a given entry exists in the dictionary. Since sections
+  are stored as keys with NULL associated values, this is the only way
+  of querying for the presence of sections in a dictionary.
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_find_entry(const dictionary * ini, const char * entry)
+{
+    int found=0 ;
+    if (iniparser_getstring(ini, entry, INI_INVALID_KEY)!=INI_INVALID_KEY) {
+        found = 1 ;
+    }
+    return found ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Set an entry in a dictionary.
+  @param    ini     Dictionary to modify.
+  @param    entry   Entry to modify (entry name)
+  @param    val     New value to associate to the entry.
+  @return   int 0 if Ok, -1 otherwise.
+
+  If the given entry can be found in the dictionary, it is modified to
+  contain the provided value. If it cannot be found, the entry is created.
+  It is Ok to set val to NULL.
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_set(dictionary * ini, const char * entry, const char * val)
+{
+    char tmp_str[ASCIILINESZ+1];
+    return dictionary_set(ini, strlwc(entry, tmp_str, sizeof(tmp_str)), val) ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Delete an entry in a dictionary
+  @param    ini     Dictionary to modify
+  @param    entry   Entry to delete (entry name)
+  @return   void
+
+  If the given entry can be found, it is deleted from the dictionary.
+ */
+/*--------------------------------------------------------------------------*/
+void iniparser_unset(dictionary * ini, const char * entry)
+{
+    char tmp_str[ASCIILINESZ+1];
+    dictionary_unset(ini, strlwc(entry, tmp_str, sizeof(tmp_str)));
+}
+
+static void parse_quoted_value(char *value, char quote) {
+    char c;
+    char *quoted;
+    int q = 0, v = 0;
+    int esc = 0;
+
+    if(!value)
+        return;
+
+    quoted = xstrdup(value);
+
+    if(!quoted) {
+        iniparser_error_callback("iniparser: memory allocation failure\n");
+        goto end_of_value;
+    }
+
+    while((c = quoted[q]) != '\0') {
+        if(!esc) {
+            if(c == '\\') {
+                esc = 1;
+                q++;
+                continue;
+            }
+
+            if(c == quote) {
+                goto end_of_value;
+            }
+        }
+        esc = 0;
+        value[v] = c;
+        v++;
+        q++;
+    }
+end_of_value:
+    value[v] = '\0';
+    free(quoted);
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Load a single line from an INI file
+  @param    input_line  Input line, may be concatenated multi-line input
+  @param    section     Output space to store section
+  @param    key         Output space to store key
+  @param    value       Output space to store value
+  @return   line_status value
+ */
+/*--------------------------------------------------------------------------*/
+static line_status iniparser_line(
+    const char * input_line,
+    char * section,
+    char * key,
+    char * value)
+{
+    line_status sta ;
+    char * line = NULL;
+    size_t      len ;
+    int d_quote;
+
+    line = xstrdup(input_line);
+    len = strstrip(line);
+
+    sta = LINE_UNPROCESSED ;
+    if (len<1) {
+        /* Empty line */
+        sta = LINE_EMPTY ;
+    } else if (line[0]=='#' || line[0]==';') {
+        /* Comment line */
+        sta = LINE_COMMENT ;
+    } else if (line[0]=='[' && line[len-1]==']') {
+        /* Section name without opening square bracket */
+        sscanf(line, "[%[^\n]", section);
+        len = strlen(section);
+        /* Section name without closing square bracket */
+        if(section[len-1] == ']')
+        {
+            section[len-1] = '\0';
+        }
+        strstrip(section);
+        strlwc(section, section, len);
+        sta = LINE_SECTION ;
+    } else if ((d_quote = sscanf (line, "%[^=] = \"%[^\n]\"", key, value)) == 2
+               ||  sscanf (line, "%[^=] = '%[^\n]'",   key, value) == 2) {
+        /* Usual key=value with quotes, with or without comments */
+        strstrip(key);
+        strlwc(key, key, len);
+        if(d_quote == 2)
+            parse_quoted_value(value, '"');
+        else
+            parse_quoted_value(value, '\'');
+        /* Don't strip spaces from values surrounded with quotes */
+        sta = LINE_VALUE ;
+    } else if (sscanf (line, "%[^=] = %[^;#]", key, value) == 2) {
+        /* Usual key=value without quotes, with or without comments */
+        strstrip(key);
+        strlwc(key, key, len);
+        strstrip(value);
+        /*
+         * sscanf cannot handle '' or "" as empty values
+         * this is done here
+         */
+        if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) {
+            value[0]=0 ;
+        }
+        sta = LINE_VALUE ;
+    } else if (sscanf(line, "%[^=] = %[;#]", key, value)==2
+           ||  sscanf(line, "%[^=] %[=]", key, value) == 2) {
+        /*
+         * Special cases:
+         * key=
+         * key=;
+         * key=#
+         */
+        strstrip(key);
+        strlwc(key, key, len);
+        value[0]=0 ;
+        sta = LINE_VALUE ;
+    } else {
+        /* Generate syntax error */
+        sta = LINE_ERROR ;
+    }
+
+    free(line);
+    return sta ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Parse an ini file and return an allocated dictionary object
+  @param    in File to read.
+  @param    ininame Name of the ini file to read (only used for nicer error messages)
+  @return   Pointer to newly allocated dictionary
+
+  This is the parser for ini files. This function is called, providing
+  the file to be read. It returns a dictionary object that should not
+  be accessed directly, but through accessor functions instead.
+
+  The returned dictionary must be freed using iniparser_freedict().
+ */
+/*--------------------------------------------------------------------------*/
+dictionary * iniparser_load_file(FILE * in, const char * ininame)
+{
+    char line    [ASCIILINESZ+1] ;
+    char section [ASCIILINESZ+1] ;
+    char key     [ASCIILINESZ+1] ;
+    char tmp     [(ASCIILINESZ * 2) + 2] ;
+    char val     [ASCIILINESZ+1] ;
+
+    int  last=0 ;
+    int  len ;
+    int  lineno=0 ;
+    int  errs=0;
+    int  mem_err=0;
+
+    dictionary * dict ;
+
+    dict = dictionary_new(0) ;
+    if (!dict) {
+        return NULL ;
+    }
+
+    memset(line,    0, ASCIILINESZ);
+    memset(section, 0, ASCIILINESZ);
+    memset(key,     0, ASCIILINESZ);
+    memset(val,     0, ASCIILINESZ);
+    last=0 ;
+
+    while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) {
+        lineno++ ;
+        len = (int)strlen(line)-1;
+        if (len<=0)
+            continue;
+        /* Safety check against buffer overflows */
+        if (line[len]!='\n' && !feof(in)) {
+            iniparser_error_callback(
+              "iniparser: input line too long in %s (%d)\n",
+              ininame,
+              lineno);
+            dictionary_del(dict);
+            return NULL ;
+        }
+        /* Get rid of \n and spaces at end of line */
+        while ((len>=0) &&
+                ((line[len]=='\n') || (isspace(line[len])))) {
+            line[len]=0 ;
+            len-- ;
+        }
+        if (len < 0) { /* Line was entirely \n and/or spaces */
+            len = 0;
+        }
+        /* Detect multi-line */
+        if (line[len]=='\\') {
+            /* Multi-line value */
+            last=len ;
+            continue ;
+        } else {
+            last=0 ;
+        }
+        switch (iniparser_line(line, section, key, val)) {
+            case LINE_EMPTY:
+            case LINE_COMMENT:
+            break ;
+
+            case LINE_SECTION:
+            mem_err = dictionary_set(dict, section, NULL);
+            break ;
+
+            case LINE_VALUE:
+            sprintf(tmp, "%s:%s", section, key);
+            mem_err = dictionary_set(dict, tmp, val);
+            break ;
+
+            case LINE_ERROR:
+            iniparser_error_callback(
+              "iniparser: syntax error in %s (%d):\n-> %s\n",
+              ininame,
+              lineno,
+              line);
+            errs++ ;
+            break;
+
+            default:
+            break ;
+        }
+        memset(line, 0, ASCIILINESZ);
+        last=0;
+        if (mem_err<0) {
+            iniparser_error_callback("iniparser: memory allocation failure\n");
+            break ;
+        }
+    }
+    if (errs) {
+        dictionary_del(dict);
+        dict = NULL ;
+    }
+    return dict ;
+}
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Parse an ini file and return an allocated dictionary object
+  @param    ininame Name of the ini file to read.
+  @return   Pointer to newly allocated dictionary
+
+  This is the parser for ini files. This function is called, providing
+  the name of the file to be read. It returns a dictionary object that
+  should not be accessed directly, but through accessor functions
+  instead.
+
+  The returned dictionary must be freed using iniparser_freedict().
+ */
+/*--------------------------------------------------------------------------*/
+dictionary * iniparser_load(const char * ininame)
+{
+    FILE * in ;
+    dictionary * dict ;
+
+    if ((in=fopen(ininame, "r"))==NULL) {
+        iniparser_error_callback("iniparser: cannot open %s\n", ininame);
+        return NULL ;
+    }
+
+    dict = iniparser_load_file(in, ininame);
+    fclose(in);
+
+    return dict ;
+}
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Free all memory associated to an ini dictionary
+  @param    d Dictionary to free
+  @return   void
+
+  Free all memory associated to an ini dictionary.
+  It is mandatory to call this function before the dictionary object
+  gets out of the current context.
+ */
+/*--------------------------------------------------------------------------*/
+void iniparser_freedict(dictionary * d)
+{
+    dictionary_del(d);
+}

+ 446 - 0
pro/ini/iniparser.h

@@ -0,0 +1,446 @@
+
+/*-------------------------------------------------------------------------*/
+/**
+   @file    iniparser.h
+   @author  N. Devillard
+   @brief   Parser for ini files.
+*/
+/*--------------------------------------------------------------------------*/
+
+#ifndef _INIPARSER_H_
+#define _INIPARSER_H_
+
+/*---------------------------------------------------------------------------
+                                Includes
+ ---------------------------------------------------------------------------*/
+
+#include "dictionary.h"
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Configure a function to receive the error messages.
+  @param    errback  Function to call.
+
+  By default, the error will be printed on stderr. If a null pointer is passed
+  as errback the error callback will be switched back to default.
+ */
+/*--------------------------------------------------------------------------*/
+
+void iniparser_set_error_callback(int (*errback)(const char *, ...));
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get number of sections in a dictionary
+  @param    d   Dictionary to examine
+  @return   int Number of sections found in dictionary
+
+  This function returns the number of sections found in a dictionary.
+  The test to recognize sections is done on the string stored in the
+  dictionary: a section name is given as "section" whereas a key is
+  stored as "section:key", thus the test looks for entries that do not
+  contain a colon.
+
+  This clearly fails in the case a section name contains a colon, but
+  this should simply be avoided.
+
+  This function returns -1 in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+int iniparser_getnsec(const dictionary * d);
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get name for section n in a dictionary.
+  @param    d   Dictionary to examine
+  @param    n   Section number (from 0 to nsec-1).
+  @return   Pointer to char string
+
+  This function locates the n-th section in a dictionary and returns
+  its name as a pointer to a string statically allocated inside the
+  dictionary. Do not free or modify the returned string!
+
+  This function returns NULL in case of error.
+ */
+/*--------------------------------------------------------------------------*/
+
+const char * iniparser_getsecname(const dictionary * d, int n);
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Save a dictionary to a loadable ini file
+  @param    d   Dictionary to dump
+  @param    f   Opened file pointer to dump to
+
+  This function dumps a given dictionary into a loadable ini file.
+  It is Ok to specify @c stderr or @c stdout as output files.
+
+  All values are quoted, these charecters are escaped:
+
+  - ' : the quote character (e.g. "String with \"Quotes\"")
+  - \ : the backslash character (e.g. "C:\\tmp")
+
+ */
+/*--------------------------------------------------------------------------*/
+
+void iniparser_dump_ini(const dictionary * d, FILE * f);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Save a dictionary section to a loadable ini file
+  @param    d   Dictionary to dump
+  @param    s   Section name of dictionary to dump
+  @param    f   Opened file pointer to dump to
+
+  This function dumps a given section of a given dictionary into a loadable ini
+  file.  It is Ok to specify @c stderr or @c stdout as output files.
+ */
+/*--------------------------------------------------------------------------*/
+
+void iniparser_dumpsection_ini(const dictionary * d, const char * s, FILE * f);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Dump a dictionary to an opened file pointer.
+  @param    d   Dictionary to dump.
+  @param    f   Opened file pointer to dump to.
+
+  This function prints out the contents of a dictionary, one element by
+  line, onto the provided file pointer. It is OK to specify @c stderr
+  or @c stdout as output files. This function is meant for debugging
+  purposes mostly.
+ */
+/*--------------------------------------------------------------------------*/
+void iniparser_dump(const dictionary * d, FILE * f);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the number of keys in a section of a dictionary.
+  @param    d   Dictionary to examine
+  @param    s   Section name of dictionary to examine
+  @return   Number of keys in section
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_getsecnkeys(const dictionary * d, const char * s);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the number of keys in a section of a dictionary.
+  @param    d    Dictionary to examine
+  @param    s    Section name of dictionary to examine
+  @param    keys Already allocated array to store the keys in
+  @return   The pointer passed as `keys` argument or NULL in case of error
+
+  This function queries a dictionary and finds all keys in a given section.
+  The keys argument should be an array of pointers which size has been
+  determined by calling `iniparser_getsecnkeys` function prior to this one.
+
+  Each pointer in the returned char pointer-to-pointer is pointing to
+  a string allocated in the dictionary; do not free or modify them.
+ */
+/*--------------------------------------------------------------------------*/
+const char ** iniparser_getseckeys(const dictionary * d, const char * s, const char ** keys);
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key
+  @param    d       Dictionary to search
+  @param    key     Key string to look for
+  @param    def     Default value to return if key not found.
+  @return   pointer to statically allocated character string
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the pointer passed as 'def' is returned.
+  The returned char pointer is pointing to a string allocated in
+  the dictionary, do not free or modify it.
+ */
+/*--------------------------------------------------------------------------*/
+const char * iniparser_getstring(const dictionary * d, const char * key, const char * def);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to an int
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   integer
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+
+  Supported values for integers include the usual C notation
+  so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
+  are supported. Examples:
+
+  - "42"      ->  42
+  - "042"     ->  34 (octal -> decimal)
+  - "0x42"    ->  66 (hexa  -> decimal)
+
+  Warning: the conversion may overflow in various ways. Conversion is
+  totally outsourced to strtol(), see the associated man page for overflow
+  handling.
+
+  Credits: Thanks to A. Becker for suggesting strtol()
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_getint(const dictionary * d, const char * key, int notfound);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to an long int
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   integer
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+
+  Supported values for integers include the usual C notation
+  so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
+  are supported. Examples:
+
+  - "42"      ->  42
+  - "042"     ->  34 (octal -> decimal)
+  - "0x42"    ->  66 (hexa  -> decimal)
+
+  Warning: the conversion may overflow in various ways. Conversion is
+  totally outsourced to strtol(), see the associated man page for overflow
+  handling.
+ */
+/*--------------------------------------------------------------------------*/
+long int iniparser_getlongint(const dictionary * d, const char * key, long int notfound);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to an int64_t
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   integer
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+
+  Supported values for integers include the usual C notation
+  so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
+  are supported. Examples:
+
+  - "42"      ->  42
+  - "042"     ->  34 (octal -> decimal)
+  - "0x42"    ->  66 (hexa  -> decimal)
+
+  Warning: the conversion may overflow in various ways. Conversion is
+  totally outsourced to strtoimax(), see the associated man page for overflow
+  handling.
+
+  This function is usefull on 32bit architectures where `long int` is only
+  32bit.
+ */
+/*--------------------------------------------------------------------------*/
+int64_t iniparser_getint64(const dictionary * d, const char * key, int64_t notfound);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to an uint64_t
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   integer
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+
+  Supported values for integers include the usual C notation
+  so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
+  are supported. Examples:
+
+  - "42"      ->  42
+  - "042"     ->  34 (octal -> decimal)
+  - "0x42"    ->  66 (hexa  -> decimal)
+
+  Warning: the conversion may overflow in various ways. Conversion is
+  totally outsourced to strtoumax(), see the associated man page for overflow
+  handling.
+
+  This function is usefull on 32bit architectures where `long int` is only
+  32bit.
+ */
+/*--------------------------------------------------------------------------*/
+uint64_t iniparser_getuint64(const dictionary * d, const char * key, uint64_t notfound);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to a double
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   double
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+ */
+/*--------------------------------------------------------------------------*/
+double iniparser_getdouble(const dictionary * d, const char * key, double notfound);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Get the string associated to a key, convert to a boolean
+  @param    d Dictionary to search
+  @param    key Key string to look for
+  @param    notfound Value to return in case of error
+  @return   integer
+
+  This function queries a dictionary for a key. A key as read from an
+  ini file is given as "section:key". If the key cannot be found,
+  the notfound value is returned.
+
+  A true boolean is found if one of the following is matched:
+
+  - A string starting with 'y'
+  - A string starting with 'Y'
+  - A string starting with 't'
+  - A string starting with 'T'
+  - A string starting with '1'
+
+  A false boolean is found if one of the following is matched:
+
+  - A string starting with 'n'
+  - A string starting with 'N'
+  - A string starting with 'f'
+  - A string starting with 'F'
+  - A string starting with '0'
+
+  The notfound value returned if no boolean is identified, does not
+  necessarily have to be 0 or 1.
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_getboolean(const dictionary * d, const char * key, int notfound);
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Set an entry in a dictionary.
+  @param    ini     Dictionary to modify.
+  @param    entry   Entry to modify (entry name)
+  @param    val     New value to associate to the entry.
+  @return   int     0 if Ok, -1 otherwise.
+
+  If the given entry can be found in the dictionary, it is modified to
+  contain the provided value. If it cannot be found, the entry is created.
+  It is Ok to set val to NULL.
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_set(dictionary * ini, const char * entry, const char * val);
+
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Delete an entry in a dictionary
+  @param    ini     Dictionary to modify
+  @param    entry   Entry to delete (entry name)
+
+  If the given entry can be found, it is deleted from the dictionary.
+ */
+/*--------------------------------------------------------------------------*/
+void iniparser_unset(dictionary * ini, const char * entry);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Finds out if a given entry exists in a dictionary
+  @param    ini     Dictionary to search
+  @param    entry   Name of the entry to look for
+  @return   integer 1 if entry exists, 0 otherwise
+
+  Finds out if a given entry exists in the dictionary. Since sections
+  are stored as keys with NULL associated values, this is the only way
+  of querying for the presence of sections in a dictionary.
+ */
+/*--------------------------------------------------------------------------*/
+int iniparser_find_entry(const dictionary * ini, const char * entry) ;
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Parse an ini file and return an allocated dictionary object
+  @param    ininame Name of the ini file to read.
+  @return   Pointer to newly allocated dictionary
+
+  This is the parser for ini files. This function is called, providing
+  the name of the file to be read. It returns a dictionary object that
+  should not be accessed directly, but through accessor functions
+  instead.
+
+  Iff the value is a quoted string it supports some escape sequences:
+
+  - \" or ' : the quote character
+  (e.g. 'String with "Quotes"' or "String with 'Quotes'")
+  - \ : the backslash character (e.g. "C:\tmp")
+
+  Escape sequences always start with a backslash. Additional escape sequences
+  might be added in the future. Backslash characters must be escaped. Any other
+  sequence then those outlined above is invalid and may lead to unpredictable
+  results.
+
+  The returned dictionary must be freed using iniparser_freedict().
+ */
+/*--------------------------------------------------------------------------*/
+dictionary * iniparser_load(const char * ininame);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Parse an ini file and return an allocated dictionary object
+  @param    in File to read.
+  @param    ininame Name of the ini file to read (only used for nicer error messages)
+  @return   Pointer to newly allocated dictionary
+
+  This is the parser for ini files. This function is called, providing
+  the file to be read. It returns a dictionary object that should not
+  be accessed directly, but through accessor functions instead.
+
+  Iff the value is a quoted string it supports some escape sequences:
+
+  - \" or ' : the quote character
+  (e.g. 'String with "Quotes"' or "String with 'Quotes'")
+  - \ : the backslash character (e.g. "C:\tmp")
+
+  Escape sequences always start with a backslash. Additional escape sequences
+  might be added in the future. Backslash characters must be escaped. Any other
+  sequence then those outlined above is invalid and may lead to unpredictable
+  results.
+
+  The returned dictionary must be freed using iniparser_freedict().
+ */
+/*--------------------------------------------------------------------------*/
+dictionary * iniparser_load_file(FILE * in, const char * ininame);
+
+/*-------------------------------------------------------------------------*/
+/**
+  @brief    Free all memory associated to an ini dictionary
+  @param    d Dictionary to free
+
+  Free all memory associated to an ini dictionary.
+  It is mandatory to call this function before the dictionary object
+  gets out of the current context.
+ */
+/*--------------------------------------------------------------------------*/
+void iniparser_freedict(dictionary * d);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 79 - 86
pro/src/app.c

@@ -61,9 +61,9 @@ void* power_thread(void* arg)
     dev_search_last_Index(_globalDeviceManager->db, &nSaveTacIndex, strTacPower); // 查询日志最大点
     _globalDeviceManager->_global_alarmLanguage=create_hash_table(500);
     InitHashTable(_globalDeviceManager->_global_alarmLanguage);
-    unsigned int samp_time = _globalDeviceManager->_global_device_info->product_samp_time;
+    unsigned int samp_time = _globalDeviceManager->_globalDevInfo.product_samp_time;
     unsigned int usleepTime = samp_time*1000;
-    unsigned int sSaveTime = _globalDeviceManager->_global_device_info->product_save_time;
+    unsigned int sSaveTime = _globalDeviceManager->_globalDevInfo.product_save_time;
     log_d("samp_time:%dms save_time:%dms\n", samp_time,sSaveTime);
     int nMaxIndex=2000000000;
     int nDeleteNumber=1000/sSaveTime*3600*24*30*10;
@@ -155,7 +155,7 @@ void* power_thread(void* arg)
         //数据刷新
         pthread_mutex_lock(&__globalDeviceManage._power_update);
                 //清空三项总数据
-        if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+        if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
         {
             list_for_each_entry(pTreeAPowerInfo, &_globalDeviceManager->_globalPowerManger.list_Tree_AC, list_Tree_AC)
             {
@@ -184,8 +184,8 @@ void* power_thread(void* arg)
             memcpy(&_globalPowerInfo._power_info,
             &_globalDeviceManager->_all_ctrl_board[(int)_globalPowerMangerTemp->product_saddr]._PowerInfo[(int)_globalPowerMangerTemp->product_ch_addr-1],
             sizeof(PowerInfo));
-            if(_globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_AC ||
-                _globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_DC)
+            if(_globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_AC ||
+                _globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_DC)
             {
                 if (_chn<64)
                 {
@@ -210,7 +210,7 @@ void* power_thread(void* arg)
               case AC_SINGLE_B_TYPE:
                   {
                     //累加总电源信息
-                    _globalTotalPowerInfo.product_id = _globalDeviceManager->_global_device_info->product_id;
+                    _globalTotalPowerInfo.product_id = _globalDeviceManager->_globalDevInfo.product_id;
                     _globalTotalPowerInfo.product_ch_id = 0 ; //总电源通道信息为0
                     _globalTotalPowerInfo.product_status = 0 ;
                     _globalTotalPowerInfo._power_info.voltage =  _globalTotalPowerInfo._power_info.voltage > _globalPowerInfo._power_info.voltage ? _globalTotalPowerInfo._power_info.voltage : _globalPowerInfo._power_info.voltage;
@@ -221,7 +221,7 @@ void* power_thread(void* arg)
                     _globalTotalPowerInfo._power_info.factor = _globalTotalPowerInfo._power_info.factor > _globalPowerInfo._power_info.factor ? _globalTotalPowerInfo._power_info.factor : _globalPowerInfo._power_info.factor;
 
                     //补全信息
-                    _globalPowerInfo.product_id = _globalDeviceManager->_global_device_info->product_id;
+                    _globalPowerInfo.product_id = _globalDeviceManager->_globalDevInfo.product_id;
                     _globalPowerInfo.product_ch_id = _globalPowerMangerTemp->product_ch_id ;
                     _globalPowerInfo.product_status = _globalPowerInfo._power_info.status ;
 
@@ -284,7 +284,7 @@ void* power_thread(void* arg)
                         if(_globalPowerWarningInfo.w_consumption)dev_Alarm_send_message(_globalDeviceManager,_globalPowerMangerTemp,WARNING_P_UP);
                     }
                     //动作
-                    if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+                    if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
                     {
                         GlobalTreeACManager *_pTreeACPowerPhData = NULL;
                         memset(&_globalPowerInfo._power_info, 0, sizeof(_globalPowerInfo._power_info));
@@ -292,7 +292,7 @@ void* power_thread(void* arg)
                         list_for_each_entry(_pTreeACPowerMangerTemp, &_globalPowerMangerTemp->list_Tree_AC, list_Tree_AC)
                         {
                             //筛选控制中的数据
-                            if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B && _pTreeACPowerMangerTemp->product_ph_outputStatus == 2)
+                            if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B && _pTreeACPowerMangerTemp->product_ph_outputStatus == 2)
                             {
                                 continue;
                             }
@@ -428,11 +428,11 @@ void* power_thread(void* arg)
                     _globalPowerMangerTemp->product_ch_status = _globalPowerInfo._power_info.status ;
 
                     //累加总电源信息
-                    _globalTotalPowerInfo.product_id = _globalDeviceManager->_global_device_info->product_id;
+                    _globalTotalPowerInfo.product_id = _globalDeviceManager->_globalDevInfo.product_id;
                     _globalTotalPowerInfo.product_ch_id = 0 ; //总电源通道信息为0
                     _globalTotalPowerInfo.product_status = 0 ;
                     //补全信息
-                    _globalPowerInfo.product_id = _globalDeviceManager->_global_device_info->product_id;
+                    _globalPowerInfo.product_id = _globalDeviceManager->_globalDevInfo.product_id;
                     _globalPowerInfo.product_ch_id = _globalPowerMangerTemp->product_ch_id ;
 
                     gettimeofday(&tv, NULL);
@@ -525,7 +525,7 @@ void* power_thread(void* arg)
                     int k = 0;
                     list_for_each_entry(_pTreeACPowerMangerTemp, &_globalPowerMangerTemp->list_Tree_AC, list_Tree_AC)
                     {
-                        if (__globalDeviceManage._global_device_info->product_pwr_type==SmartPDU_Tree_AC_One&&_pTreeACPowerMangerTemp->product_ph_outputStatus==2)
+                        if (__globalDeviceManage._globalDevInfo.product_pwr_type==SmartPDU_Tree_AC_One&&_pTreeACPowerMangerTemp->product_ph_outputStatus==2)
                         {
                             continue;
                         }                        
@@ -640,11 +640,11 @@ void* power_thread(void* arg)
                     _globalDeviceManager->triphasic_mmap->close_delay[_chn] = _globalPowerMangerTemp->product_ch_stop_delay;
 
                     //累加总电源信息
-                    _globalTotalPowerInfo.product_id = _globalDeviceManager->_global_device_info->product_id;
+                    _globalTotalPowerInfo.product_id = _globalDeviceManager->_globalDevInfo.product_id;
                     _globalTotalPowerInfo.product_ch_id = 0 ; //总电源通道信息为0
                     _globalTotalPowerInfo.product_status = 0 ;
                     //补全信息
-                    _globalPowerInfo.product_id = _globalDeviceManager->_global_device_info->product_id;
+                    _globalPowerInfo.product_id = _globalDeviceManager->_globalDevInfo.product_id;
                     _globalPowerInfo.product_ch_id = _globalPowerMangerTemp->product_ch_id ;
 
                     gettimeofday(&tv, NULL);
@@ -772,18 +772,18 @@ void* power_thread(void* arg)
         }
 
         //all 
-        if(__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_AC
-         || __globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_DC)
+        if(__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_AC
+         || __globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_DC)
         {
             __globalDeviceManage.single_mmap->total_current = _globalTotalPowerInfo._power_info.current;
             __globalDeviceManage.single_mmap->total_power = _globalTotalPowerInfo._power_info.power;
             __globalDeviceManage.single_mmap->total_valtage = _globalTotalPowerInfo._power_info.voltage;
-            __globalDeviceManage.single_mmap->dev_chn = __globalDeviceManage._global_device_info->product_pwr_type << 8 | _chn;
+            __globalDeviceManage.single_mmap->dev_chn = __globalDeviceManage._globalDevInfo.product_pwr_type << 8 | _chn;
 
         }
         //输入数据再处理(三项)
         //memset(_pTreeACPowerMangerTemp,0,sizeof(GlobalTreeACManager));
-        if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_Tree || __globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One)
+        if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_Tree || __globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One)
         {
             _pTreeACPowerMangerTemp = NULL;
             list_for_each_entry(_pTreeACPowerMangerTemp, &_globalDeviceManager->_globalPowerManger.list_Tree_AC, list_Tree_AC)
@@ -840,9 +840,9 @@ void* power_thread(void* arg)
                     }
                 }
             }
-            __globalDeviceManage.triphasic_mmap->dev_chn = __globalDeviceManage._global_device_info->product_pwr_type << 8 | _chn;
+            __globalDeviceManage.triphasic_mmap->dev_chn = __globalDeviceManage._globalDevInfo.product_pwr_type << 8 | _chn;
         }
-        if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+        if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
         {
             _pTreeACPowerMangerTemp = NULL;
             list_for_each_entry(_pTreeACPowerMangerTemp, &_globalDeviceManager->_globalPowerManger.list_Tree_AC, list_Tree_AC)
@@ -883,7 +883,7 @@ void* power_thread(void* arg)
             }
             if (_globalDeviceManager->triphasic_mmap)
             {
-                __globalDeviceManage.triphasic_mmap->dev_chn = __globalDeviceManage._global_device_info->product_pwr_type << 8 | _chn;
+                __globalDeviceManage.triphasic_mmap->dev_chn = __globalDeviceManage._globalDevInfo.product_pwr_type << 8 | _chn;
             }
         }
 
@@ -1058,8 +1058,8 @@ void* breaker_thread(void *arg)
             // }
             if(temp->breaker_gather_addr)
             {
-                if(temp->breaker_gather_addr-BREADER_485_ADDR < BREAKER_BOARD_MAX && 
-                           (breaker_scann->breaker_flag[temp->breaker_gather_addr-BREADER_485_ADDR]) == 1)
+                if((temp->breaker_gather_addr-BREADER_485_ADDR < BREAKER_BOARD_MAX) && 
+                           ((breaker_scann->breaker_flag[temp->breaker_gather_addr-BREADER_485_ADDR]) == 1))
                 {
                     int chn = temp->breaker_chn;
                     temp->breaker_status = breaker_scann->board[temp->breaker_gather_addr-BREADER_485_ADDR].ch_status[chn-1];
@@ -1082,7 +1082,7 @@ void* sensor_thread(void* arg)
 {
 #if 1
    GlobalDeviceManager *_globalDeviceManager = (GlobalDeviceManager *)&__globalDeviceManage;
-    unsigned int samp_time = _globalDeviceManager->_global_device_info->product_samp_time;
+    unsigned int samp_time = _globalDeviceManager->_globalDevInfo.product_samp_time;
     GlobalSensorManger *_globalSensorMangerTemp;
     int ret = 0;
     GlobalSensorInfo _globalSensorInfo;
@@ -1159,12 +1159,12 @@ void* sensor_thread(void* arg)
                 t = localtime(&tv.tv_sec);
                 sprintf(_globalSensorInfo.samp_time, "%04d-%02d-%02d %02d:%02d:%02d.%03ld",
                         t->tm_year + 1900, t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000);
-                _globalSensorInfo.product_id = __globalDeviceManage._global_device_info->product_id;
+                _globalSensorInfo.product_id = __globalDeviceManage._globalDevInfo.product_id;
                 _globalSensorInfo.sensor_id = _globalSensorMangerTemp->sensor_id;
                 _globalSensorInfo.val1 = temperature;
                 _globalSensorInfo.val2 = humidity;
-                if(_globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_AC ||
-                _globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_DC)
+                if(_globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_AC ||
+                _globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_DC)
                 {
                     _globalDeviceManager->single_mmap->total_temp.temperature = _globalSensorInfo.val1 *100;
                     _globalDeviceManager->single_mmap->total_temp.humidity = _globalSensorInfo.val2 *100;
@@ -1435,18 +1435,13 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
     int io_thread_flag = 0 ;
     int sensor_thread_flag = 0 ;
     int nTac_chn=0;
+
+
+    //paras_load(&_globalDeviceManager->_globalDevInfo);
+
     //初始化用户登录列表
     INIT_LIST_HEAD(&_GlobalUserLoginInfo.list);
 
-    //设备管理内存分配
-    _globalDeviceManager->_global_device_info = (GlobalDeviceInfo*)malloc(sizeof(GlobalDeviceInfo));
-    if(_globalDeviceManager->_global_device_info==NULL)
-    {
-        log_e("_global_device_info malloc error.!");
-        //printf("_global_device_info malloc error.\n");
-        return -1 ;       
-    }
-    log_i("device memory init ok.\n");
     //使用的通道
     _globalDeviceManager->useSlaveCount = 0 ;
     
@@ -1462,7 +1457,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
     log_i("database %s open ok.\n", path);
     
     //查询设备总体参数
-    if(dev_get_device_info(_globalDeviceManager->db,_globalDeviceManager->_global_device_info)!=0)
+    if(dev_get_device_info(_globalDeviceManager->db,&_globalDeviceManager->_globalDevInfo)!=0)
     {
         log_e("get device info error.\n");
         return -1 ;
@@ -1470,14 +1465,13 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
     log_i("get device info ok.\n");
 
 
-    if(_globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_AC ||
-        _globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_DC)       // single AC
+    if(_globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_AC ||
+        _globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_DC)       // single AC
     {
         _globalDeviceManager->single_mmap =(cascade_single_mmap_t*)malloc(sizeof(cascade_single_mmap_t));
         if(_globalDeviceManager->single_mmap==NULL)
         {
-            log_e("_global_device_info malloc error.!");
-            //printf("_global_device_info malloc error.\n");
+            log_e("single_mmap malloc error.!");
             return -1 ;       
         }  
         memset(_globalDeviceManager->single_mmap, 0, sizeof(cascade_single_mmap_t));
@@ -1486,15 +1480,14 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
         _globalDeviceManager->triphasic_mmap =(cascade_triphasic_mmap_t*)malloc(sizeof(cascade_triphasic_mmap_t));
         if(_globalDeviceManager->triphasic_mmap== NULL)
         {
-            log_e("_global_device_info malloc error.!");
-            //printf("_global_device_info malloc error.\n");
+            log_e("triphasic_mmap malloc error.!");
             return -1 ;       
         }  
         memset(_globalDeviceManager->triphasic_mmap, 0, sizeof(cascade_triphasic_mmap_t));
     }
 
     //打印参数
-    //printf_global_device_info(_globalDeviceManager->_global_device_info);
+    //printf_global_device_info(&_globalDeviceManager->_globalDevInfo);
 
     //电源管理表初始化
     memset(&_globalDeviceManager->_globalPowerManger,0,sizeof(GlobalPowerManger));
@@ -1508,13 +1501,13 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
 
     //查询是否存在全部通道信息
     ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                    _globalDeviceManager->_global_device_info->product_id,0,
+                                    _globalDeviceManager->_globalDevInfo.product_id,0,
                                     0, //1*8+j
                                     &_globalDeviceManager->_globalPowerManger);
     //未查询到信息 则插入
     if(ret==-1)
     {
-        _globalDeviceManager->_globalPowerManger.product_id = _globalDeviceManager->_global_device_info->product_id;
+        _globalDeviceManager->_globalPowerManger.product_id = _globalDeviceManager->_globalDevInfo.product_id;
         _globalDeviceManager->_globalPowerManger.product_saddr = 0 ;
         _globalDeviceManager->_globalPowerManger.product_ch_id = 0;
         _globalDeviceManager->_globalPowerManger.product_ch_addr = 0;
@@ -1531,7 +1524,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
         _globalDeviceManager->_globalPowerManger.global_over_manager->product_vol_over_upper_threshold_ctrl = ALARM_CTRL_ALARM_ONLY;
 
         if(dev_insert_power_manage_info(_globalDeviceManager->db,
-                                    _globalDeviceManager->_global_device_info->product_id,
+                                    _globalDeviceManager->_globalDevInfo.product_id,
                                     0,
                                     &_globalDeviceManager->_globalPowerManger)!=0)
         {
@@ -1546,9 +1539,9 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
 
     INIT_LIST_HEAD(&_globalDeviceManager->_globalPowerManger.list_Tree_AC);
     
-    if (_globalDeviceManager->_global_device_info->product_pwr_type==SmartPDU_Tree_AC_Tree
-    ||_globalDeviceManager->_global_device_info->product_pwr_type==SmartPDU_Tree_AC_One
-    ||_globalDeviceManager->_global_device_info->product_pwr_type==SmartPDU_Tree_AC_One_B
+    if (_globalDeviceManager->_globalDevInfo.product_pwr_type==SmartPDU_Tree_AC_Tree
+    ||_globalDeviceManager->_globalDevInfo.product_pwr_type==SmartPDU_Tree_AC_One
+    ||_globalDeviceManager->_globalDevInfo.product_pwr_type==SmartPDU_Tree_AC_One_B
     )
     {
         __globalDeviceManage.nTreeACLshow=0;
@@ -1576,21 +1569,21 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
             }
             memset(_globalTACManager->global_over_manager, 0, sizeof(GlobalOverManager));
             ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                 _globalDeviceManager->_global_device_info->product_id, 0,TreeACindex + 1,
+                                                 _globalDeviceManager->_globalDevInfo.product_id, 0,TreeACindex + 1,
                                                  TreeACindex, // 1*8+j
                                                  _globalTACManager);
             _globalTACManager->product_ch_addr = TreeACindex + 1;
             // 未查询到信息 则插入
             if (ret == -1)
             {
-                _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                _globalTACManager->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                 _globalTACManager->product_saddr = 0;
                 _globalTACManager->product_ch_id = chn;
                 _globalTACManager->product_ch_addr = TreeACindex + 1;
                 _globalTACManager->product_ph_id = nTac_chn;
                 _globalTACManager->product_ph_type = (TreeACindex + 3) % 3;
                 if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                      _globalDeviceManager->_global_device_info->product_id,
+                                                      _globalDeviceManager->_globalDevInfo.product_id,
                                                       _globalTACManager->product_ch_id,
                                                       _globalTACManager) != 0)
                 {
@@ -1654,7 +1647,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                           i,
                           &type,
                           &nMaxChn,
-                          _globalDeviceManager->_global_device_info->product_pwr_type);
+                          _globalDeviceManager->_globalDevInfo.product_pwr_type);
         log_d("ret:%d saddr:%d type:%d ch_num:%d.\n",ret,i,type,nMaxChn);
         //int i =1 ;
         //type = AC_SINGLE_S_TYPE ;
@@ -1691,14 +1684,14 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                         memset(_globalPowerMangerTemp->global_over_manager,0,sizeof(GlobalOverManager));
                         //查询是否由通道信息
                         ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                        _globalDeviceManager->_global_device_info->product_id,
+                                                        _globalDeviceManager->_globalDevInfo.product_id,
                                                         i,
                                                         j+1, //1*8+j
                                                         _globalPowerMangerTemp);
                         //未查询到信息 则插入
                         if(ret==-1)
                         {
-                            _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                            _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                             _globalPowerMangerTemp->product_saddr = i ;
                             _globalPowerMangerTemp->product_ch_id = chn;
                             _globalPowerMangerTemp->product_ch_addr = j+1;
@@ -1717,7 +1710,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                             _globalPowerMangerTemp->global_over_manager->product_vol_over_upper_threshold_ctrl = ALARM_CTRL_ALARM_ONLY;
 
                             if(dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                        _globalDeviceManager->_global_device_info->product_id,
+                                                        _globalDeviceManager->_globalDevInfo.product_id,
                                                         _globalPowerMangerTemp->product_ch_id,
                                                         _globalPowerMangerTemp)!=0)
                             {
@@ -1731,7 +1724,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                             }
                             */
                         }
-                        if ( _globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+                        if ( _globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
                         {
                             // 初始化三相子通道
                             GlobalTreeACManager *_globalTACManager = NULL;
@@ -1753,7 +1746,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                     return -1;
                                 }
                                 ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                     _globalDeviceManager->_global_device_info->product_id, i,
+                                                                     _globalDeviceManager->_globalDevInfo.product_id, i,
                                                                      j + 1, // 1*8+j
                                                                      nTac_chn,
                                                                      _globalTACManager);
@@ -1761,7 +1754,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                 // 未查询到信息 则插入
                                 if (ret == -1)
                                 {
-                                    _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                    _globalTACManager->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                                     _globalTACManager->product_saddr = i;
                                     _globalTACManager->product_ch_id = _globalPowerMangerTemp->product_ch_id;
                                     _globalTACManager->product_ch_addr = j + 1;
@@ -1778,7 +1771,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                     }
 
                                     if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                          _globalDeviceManager->_global_device_info->product_id,
+                                                                          _globalDeviceManager->_globalDevInfo.product_id,
                                                                           _globalTACManager->product_ch_id,
                                                                           _globalTACManager) != 0)
                                     {
@@ -1839,13 +1832,13 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                         memset(_globalPowerMangerTemp->global_over_manager,0,sizeof(GlobalOverManager));
                         //查询是否由通道信息
                         ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                        _globalDeviceManager->_global_device_info->product_id,i,
+                                                        _globalDeviceManager->_globalDevInfo.product_id,i,
                                                         j+1, //1*8+j
                                                         _globalPowerMangerTemp);
                         //未查询到信息 则插入
                         if(ret==-1)
                         {
-                            _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                            _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                             _globalPowerMangerTemp->product_saddr = i ;
                             _globalPowerMangerTemp->product_ch_id = chn;
                             _globalPowerMangerTemp->product_ch_addr = j+1;
@@ -1863,7 +1856,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                             _globalPowerMangerTemp->global_over_manager->product_vol_over_upper_threshold_ctrl = ALARM_CTRL_ALARM_ONLY;
 
                             if(dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                        _globalDeviceManager->_global_device_info->product_id,
+                                                        _globalDeviceManager->_globalDevInfo.product_id,
                                                         _globalPowerMangerTemp->product_ch_id,
                                                         _globalPowerMangerTemp)!=0)
                             {
@@ -1910,14 +1903,14 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                         memset(_globalPowerMangerTemp->global_over_manager,0,sizeof(GlobalOverManager));
                         //查询是否由通道信息
                         ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                        _globalDeviceManager->_global_device_info->product_id,i,
+                                                        _globalDeviceManager->_globalDevInfo.product_id,i,
                                                         j+1, //1*8+j
                                                         _globalPowerMangerTemp);
                         _globalPowerMangerTemp->product_ch_addr = j+1;
                         //未查询到信息 则插入
                         if(ret==-1)
                         {
-                            _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                            _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                             _globalPowerMangerTemp->product_saddr = i ;
                             _globalPowerMangerTemp->product_ch_id = chn;
                             _globalPowerMangerTemp->product_ch_addr = j+1;
@@ -1936,7 +1929,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                             _globalPowerMangerTemp->global_over_manager->product_vol_over_upper_threshold_ctrl = ALARM_CTRL_ALARM_ONLY;
 
                             if(dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                        _globalDeviceManager->_global_device_info->product_id,
+                                                        _globalDeviceManager->_globalDevInfo.product_id,
                                                         _globalPowerMangerTemp->product_ch_id,
                                                         _globalPowerMangerTemp)!=0)
                             {
@@ -1952,7 +1945,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                         }
                         _globalPowerMangerTemp->product_saddr = i ;
                         _globalPowerMangerTemp->product_ch_type = type;
-                        if (dev_update_power_manage_genera_info(__globalDeviceManage.db,_globalDeviceManager->_global_device_info->product_id,chn,_globalPowerMangerTemp) != 0)
+                        if (dev_update_power_manage_genera_info(__globalDeviceManage.db,_globalDeviceManager->_globalDevInfo.product_id,chn,_globalPowerMangerTemp) != 0)
                         {
                             log_e("update pwr general data err.");
                         }
@@ -1968,7 +1961,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                     GlobalPowerManger *_globalPowerMangerTemp=NULL;                 
                     for (size_t j = 0; j < nMaxChn; j++)
                     {
-                        if (_globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One)
+                        if (_globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One)
                         {
                             log_i("TreeAC_TYPE_3-1!\n");
                             _globalPowerMangerTemp = (GlobalPowerManger *)malloc(sizeof(GlobalPowerManger));
@@ -1988,14 +1981,14 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                             memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
                             // 查询是否由通道信息
                             ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                            _globalDeviceManager->_global_device_info->product_id, i,
+                                                            _globalDeviceManager->_globalDevInfo.product_id, i,
                                                             j + 1, // 1*8+j
                                                             _globalPowerMangerTemp);
                             _globalPowerMangerTemp->product_ch_addr = j + 1;
                             // 未查询到信息 则插入
                             if (ret == -1)
                             {
-                                _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                                 _globalPowerMangerTemp->product_saddr = i;
                                 _globalPowerMangerTemp->product_ch_id = chn;
                                 _globalPowerMangerTemp->product_ch_addr = j + 1;
@@ -2014,7 +2007,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                 _globalPowerMangerTemp->global_over_manager->product_vol_over_upper_threshold_ctrl =ALARM_CTRL_ALARM_ONLY;
 
                                 if (dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                                 _globalDeviceManager->_global_device_info->product_id,
+                                                                 _globalDeviceManager->_globalDevInfo.product_id,
                                                                  _globalPowerMangerTemp->product_ch_id,
                                                                  _globalPowerMangerTemp) != 0)
                                 {
@@ -2024,7 +2017,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                             }
                             _globalPowerMangerTemp->product_saddr = i;
                             _globalPowerMangerTemp->product_ch_type = type;
-                            if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_global_device_info->product_id, chn, _globalPowerMangerTemp) != 0)
+                            if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_globalDevInfo.product_id, chn, _globalPowerMangerTemp) != 0)
                             {
                                 log_e("update pwr general data err.");
                             }
@@ -2050,7 +2043,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                     return -1;
                                 }
                                 ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                     _globalDeviceManager->_global_device_info->product_id, i,
+                                                                     _globalDeviceManager->_globalDevInfo.product_id, i,
                                                                      j + 1, // 1*8+j
                                                                      nTac_chn,
                                                                      _globalTACManager);
@@ -2058,7 +2051,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                 // 未查询到信息 则插入
                                 if (ret == -1)
                                 {
-                                    _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                    _globalTACManager->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                                     _globalTACManager->product_saddr = i;
                                     _globalTACManager->product_ch_id = _globalPowerMangerTemp->product_ch_id;
                                     _globalTACManager->product_ch_addr = j + 1;
@@ -2075,7 +2068,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                     }
 
                                     if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                          _globalDeviceManager->_global_device_info->product_id,
+                                                                          _globalDeviceManager->_globalDevInfo.product_id,
                                                                           _globalTACManager->product_ch_id,
                                                                           _globalTACManager) != 0)
                                     {
@@ -2115,14 +2108,14 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                 memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
                                 // 查询是否由通道信息
                                 ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                                _globalDeviceManager->_global_device_info->product_id, i,
+                                                                _globalDeviceManager->_globalDevInfo.product_id, i,
                                                                 j / 3 + 1, // 1*8+j
                                                                 _globalPowerMangerTemp);
                                 _globalPowerMangerTemp->product_ch_addr = j / 3 + 1;
                                 // 未查询到信息 则插入
                                 if (ret == -1)
                                 {
-                                    _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                    _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                                     _globalPowerMangerTemp->product_saddr = i;
                                     _globalPowerMangerTemp->product_ch_id = chn;
                                     _globalPowerMangerTemp->product_ch_addr = j / 3 + 1;
@@ -2141,7 +2134,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                     _globalPowerMangerTemp->global_over_manager->product_vol_over_upper_threshold_ctrl = ALARM_CTRL_ALARM_ONLY;
                                     
                                     if (dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                                     _globalDeviceManager->_global_device_info->product_id,
+                                                                     _globalDeviceManager->_globalDevInfo.product_id,
                                                                      _globalPowerMangerTemp->product_ch_id,
                                                                      _globalPowerMangerTemp) != 0)
                                     {
@@ -2151,7 +2144,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                 }
                                 _globalPowerMangerTemp->product_saddr = i;
                                 _globalPowerMangerTemp->product_ch_type = type;
-                                if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_global_device_info->product_id, chn, _globalPowerMangerTemp) != 0)
+                                if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_globalDevInfo.product_id, chn, _globalPowerMangerTemp) != 0)
                                 {
                                     log_e("update pwr general data err.");
                                 }
@@ -2176,7 +2169,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                 return -1;
                             }
                             ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                 _globalDeviceManager->_global_device_info->product_id, i,
+                                                                 _globalDeviceManager->_globalDevInfo.product_id, i,
                                                                  j + 1, // 1*8+j
                                                                  nTac_chn,
                                                                  _globalTACManager);
@@ -2184,7 +2177,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                             // 未查询到信息 则插入
                             if (ret == -1)
                             {
-                                _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                _globalTACManager->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                                 _globalTACManager->product_saddr = i;
                                 _globalTACManager->product_ch_id = _globalPowerMangerTemp->product_ch_id;
                                 _globalTACManager->product_ch_addr = j + 1;
@@ -2193,7 +2186,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
                                 _globalTACManager->product_ph_outputType = 1;   // 1三相2单相
                                 _globalTACManager->product_ph_outputStatus = 1; // 1输出
                                 if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                      _globalDeviceManager->_global_device_info->product_id,
+                                                                      _globalDeviceManager->_globalDevInfo.product_id,
                                                                       _globalTACManager->product_ch_id,
                                                                       _globalTACManager) != 0)
                                 {
@@ -2231,7 +2224,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
     /////////////////////////////////////////
     ///todo:此信息需要和数据库更新以后在关联
     ret = dev_get_sensor_manage_info(_globalDeviceManager->db,
-                                    _globalDeviceManager->_global_device_info->product_id,
+                                    _globalDeviceManager->_globalDevInfo.product_id,
                                     &_globalDeviceManager->_globalSensorManger);
     if(ret!=0)
     {
@@ -2241,7 +2234,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
         log_d("get sensor info ok.");
 
     dev_Alarm_Run_message(_globalDeviceManager,language_alarm_Init_Success[0],"sensor");
-    ret =dev_get_breaker_manage_info(_globalDeviceManager->db,_globalDeviceManager->_global_device_info->product_id,
+    ret =dev_get_breaker_manage_info(_globalDeviceManager->db,_globalDeviceManager->_globalDevInfo.product_id,
                 &_globalDeviceManager->g_new_global_breaker);
 
     if(ret!=0)
@@ -2279,7 +2272,7 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
         strcpy(_globalNTPManager.ntpaddress, "119.28.183.184");
         strcpy(_globalNTPManager.ntpName, "百度NTP");
         _globalNTPManager.port = 123;
-        _globalNTPManager.product_id = _globalDeviceManager->_global_device_info->product_id;
+        _globalNTPManager.product_id = _globalDeviceManager->_globalDevInfo.product_id;
         time_t t = time(NULL);
         struct tm* ptm = localtime(&t);
         sprintf(_globalNTPManager.time, "%04d-%02d-%02d %02d:%02d:%02d", ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);

+ 97 - 97
pro/src/appweb_handle.c

@@ -272,7 +272,7 @@ static void changeLanguages(void* conn)
     char* rx_body_buf=(char*)hm->body.buf;
 
     json_to_switch_language(rx_body_buf);
-    dev_update_device_genera_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info);
+    dev_update_device_genera_info(__globalDeviceManage.db,&__globalDeviceManage._globalDevInfo);
     ack_str = ctrl_sts_ack_to_json();
     http_reply(conn, 200, ack_str);
     cJSON_free((void*)ack_str);
@@ -483,13 +483,13 @@ static void overallStatusMonitoring(void* conn)
         else {
             GlobalPowerInfo __globalPowerInfo;
             memset(&__globalPowerInfo,0,sizeof(GlobalPowerInfo));
-            _over_all_pwr_back_info.product_name = __globalDeviceManage._global_device_info->product_name;
-            _over_all_pwr_back_info.product_id = __globalDeviceManage._global_device_info->product_id;
-            _over_all_pwr_back_info.product_number = __globalDeviceManage._global_device_info->product_number;
+            _over_all_pwr_back_info.product_name = __globalDeviceManage._globalDevInfo.product_name;
+            _over_all_pwr_back_info.product_id = __globalDeviceManage._globalDevInfo.product_id;
+            _over_all_pwr_back_info.product_number = __globalDeviceManage._globalDevInfo.product_number;
             //查询数据库总电源信息
-            if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_Tree 
-            ||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One
-            ||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B
+            if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_Tree 
+            ||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One
+            ||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B
             )
             {
                 if (strcmp(_over_all_sts_monitor.product_phOrder, "L1") == 0) // a相
@@ -512,7 +512,7 @@ static void overallStatusMonitoring(void* conn)
                 }
             }
             else {
-                if (dev_search_latest_power_info(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 0, &__globalPowerInfo) != 0)
+                if (dev_search_latest_power_info(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 0, &__globalPowerInfo) != 0)
                 {
                     log_e("serach total pwr err.");
                 }
@@ -612,7 +612,7 @@ static void overallStatusMonitoring(void* conn)
         
         INIT_LIST_HEAD(&_globalPowerInfo.list);
         ret = dev_search_power_info(__globalDeviceManage.db,
-                                __globalDeviceManage._global_device_info->product_id,
+                                __globalDeviceManage._globalDevInfo.product_id,
                                 0,
                                 _over_all_sts_monitor.start_time,
                                 _over_all_sts_monitor.end_time,
@@ -657,7 +657,7 @@ static void overallStatusMonitoring(void* conn)
         else
         {
         //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,0,TOTAL_VOLTAGE_TYPE,&__globalPowerInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
+        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,0,TOTAL_VOLTAGE_TYPE,&__globalPowerInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
         {
             log_e("serach total voltage err.");
         }
@@ -692,7 +692,7 @@ static void overallStatusMonitoring(void* conn)
         else
         {
         //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,0,TOTAL_CURRENT_TYPE,&__globalPowerInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
+        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,0,TOTAL_CURRENT_TYPE,&__globalPowerInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
         {
             log_e("serach total current err.");
         }
@@ -726,7 +726,7 @@ static void overallStatusMonitoring(void* conn)
         else
         {
         //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,0,TOTAL_POWER_TYPE,&__globalPowerInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
+        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,0,TOTAL_POWER_TYPE,&__globalPowerInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
         {
             log_e("serach total power err.");
         }
@@ -760,7 +760,7 @@ static void overallStatusMonitoring(void* conn)
         else
         {
         //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,0,TOTAL_POWER_CONS_TYPE,&__globalPowerInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
+        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,0,TOTAL_POWER_CONS_TYPE,&__globalPowerInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
         {
             log_e("serach total power consumption err.");
         }
@@ -799,7 +799,7 @@ static void overallStatusMonitoring(void* conn)
         //sprintf(stop_time, "%04d-%02d-%02d %02d:%02d:%02d", 1970, 1, 1, 23,59, 59);
         log_d(stop_time);
         //从数据库获取参数信息
-        if(dev_get_system_total_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,0,&__system_total_info,start_time,stop_time)!=0)
+        if(dev_get_system_total_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,0,&__system_total_info,start_time,stop_time)!=0)
         {
             log_e("serach total System total err.");
         }
@@ -835,7 +835,7 @@ static void overallStatusMonitoring(void* conn)
         memset(&__PowerTrendInfo,0,sizeof(GlobalPowerInfo));
         #if 1
         //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_power_trend_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,0,&__PowerTrendInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
+        if(dev_search_power_trend_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,0,&__PowerTrendInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
         {
             log_e("serach total power consumption err.");
         }
@@ -1056,16 +1056,16 @@ static void channelStatusMonitoring(void* conn)
                     log_e("_overChnPwrBackInfoTemp malloc err.");
                 }
                 //查询数据库总电源信息
-                if(dev_search_latest_power_info(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id,
+                if(dev_search_latest_power_info(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id,
                                                 product_chn_id, &_powerInfo)!=0)
                 {
                     log_e("serach total pwr err.");
                 }
                 {
                     //填数据
-                    _overChnPwrBackInfoTemp->product_name = __globalDeviceManage._global_device_info->product_name;
-                    _overChnPwrBackInfoTemp->product_number = __globalDeviceManage._global_device_info->product_number; 
-                    _overChnPwrBackInfoTemp->product_id = __globalDeviceManage._global_device_info->product_id;  
+                    _overChnPwrBackInfoTemp->product_name = __globalDeviceManage._globalDevInfo.product_name;
+                    _overChnPwrBackInfoTemp->product_number = __globalDeviceManage._globalDevInfo.product_number; 
+                    _overChnPwrBackInfoTemp->product_id = __globalDeviceManage._globalDevInfo.product_id;  
                     _overChnPwrBackInfoTemp->productChName = _globalPowerMangerTemp->product_ch_name;
                     _overChnPwrBackInfoTemp->productChId = _globalPowerMangerTemp->product_ch_id;
                     _overChnPwrBackInfoTemp->status = _powerInfo._power_info.status; 
@@ -1222,7 +1222,7 @@ static void channelStatusMonitoring(void* conn)
             if (strlen(_over_chn_pwr_request.productChName)<32)
             {
                 strcpy(_globalPowerMangerTemp->product_ch_name, _over_chn_pwr_request.productChName);
-                if (dev_update_power_manage_genera_info(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, _globalPowerMangerTemp->product_ch_id, _globalPowerMangerTemp) != 0)
+                if (dev_update_power_manage_genera_info(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, _globalPowerMangerTemp->product_ch_id, _globalPowerMangerTemp) != 0)
                 {
                     log_e("update pwr general data err.");
                 }
@@ -1248,7 +1248,7 @@ static void channelStatusMonitoring(void* conn)
         page_size = atoi(_over_chn_pwr_request.pageSize);
         //查询数据
         ret = dev_search_power_info(__globalDeviceManage.db,
-                                __globalDeviceManage._global_device_info->product_id,
+                                __globalDeviceManage._globalDevInfo.product_id,
                                 h_pwrchn,
                                 _over_chn_pwr_request.start_time,
                                 _over_chn_pwr_request.end_time,
@@ -1262,7 +1262,7 @@ static void channelStatusMonitoring(void* conn)
         }
         //应答
         ack_str = over_channel_power_history_to_json(&_globalPowerInfo,
-                                                    &__globalDeviceManage._global_device_info, 
+                                                    &__globalDeviceManage._globalDevInfo, 
                                                     _over_chn_pwr_request.productChName,
                                                     h_pwrchn);
 
@@ -1299,7 +1299,7 @@ static void channelStatusMonitoring(void* conn)
         //清0
         memset(&__globalPowerInfo,0,sizeof(GlobalPowerInfo));
         //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,product_chn_id,TOTAL_VOLTAGE_TYPE,&__globalPowerInfo,_over_chn_pwr_request.start_time,_over_chn_pwr_request.end_time)!=0)
+        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,product_chn_id,TOTAL_VOLTAGE_TYPE,&__globalPowerInfo,_over_chn_pwr_request.start_time,_over_chn_pwr_request.end_time)!=0)
         {
             log_e("serach total voltage err.");
         }
@@ -1330,7 +1330,7 @@ static void channelStatusMonitoring(void* conn)
         //清0
         memset(&__globalPowerInfo,0,sizeof(GlobalPowerInfo));
         //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,product_chn_id,TOTAL_CURRENT_TYPE,&__globalPowerInfo,_over_chn_pwr_request.start_time,_over_chn_pwr_request.end_time)!=0)
+        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,product_chn_id,TOTAL_CURRENT_TYPE,&__globalPowerInfo,_over_chn_pwr_request.start_time,_over_chn_pwr_request.end_time)!=0)
         {
             log_e("serach total current err.");
         }
@@ -1361,7 +1361,7 @@ static void channelStatusMonitoring(void* conn)
         //清0
         memset(&__globalPowerInfo,0,sizeof(GlobalPowerInfo));
         //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,product_chn_id,TOTAL_POWER_TYPE,&__globalPowerInfo,_over_chn_pwr_request.start_time,_over_chn_pwr_request.end_time)!=0)
+        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,product_chn_id,TOTAL_POWER_TYPE,&__globalPowerInfo,_over_chn_pwr_request.start_time,_over_chn_pwr_request.end_time)!=0)
         {
             log_e("serach total power err.");
         }
@@ -1392,7 +1392,7 @@ static void channelStatusMonitoring(void* conn)
         //清0
         memset(&__globalPowerInfo,0,sizeof(GlobalPowerInfo));
         //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,product_chn_id,TOTAL_POWER_CONS_TYPE,&__globalPowerInfo,_over_chn_pwr_request.start_time,_over_chn_pwr_request.end_time)!=0)
+        if(dev_search_time_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,product_chn_id,TOTAL_POWER_CONS_TYPE,&__globalPowerInfo,_over_chn_pwr_request.start_time,_over_chn_pwr_request.end_time)!=0)
         {
             log_e("serach total power consumption err.");
         }
@@ -1427,8 +1427,8 @@ static void channelStatusMonitoring(void* conn)
                 break;
             }
         }
-        if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One
-            ||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+        if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One
+            ||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
         {
             if (_over_chn_pwr_request.outputType == 1)
             {
@@ -1595,7 +1595,7 @@ static void sensorStatusMonitoring(void* conn)
         log_d("start delete handle.");
         int sensor_id_temp = _over_all_sensor_request.sensorId;
         
-        if(dev_delete_sensor_manage(__globalDeviceManage.db,  __globalDeviceManage._global_device_info->product_id,sensor_id_temp)!=0)
+        if(dev_delete_sensor_manage(__globalDeviceManage.db,  __globalDeviceManage._globalDevInfo.product_id,sensor_id_temp)!=0)
         {
             log_e("sensor delete failed.");
         }
@@ -1621,7 +1621,7 @@ static void sensorStatusMonitoring(void* conn)
         char temp[100];
         //sprintf(temp,"$删除$|$传感器$|%d",sensor_id_temp);
         sprintf(temp,"Delete sensor %d",sensor_id_temp);
-        dev_insert_alarm_ctrl(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
         ack_str = ctrl_sts_ack_to_json();
     }
@@ -1734,7 +1734,7 @@ static void sensorStatusMonitoring(void* conn)
 
             // 插入数据库
             if (dev_update_sensor_genera_manage(__globalDeviceManage.db,
-                                                __globalDeviceManage._global_device_info->product_id,
+                                                __globalDeviceManage._globalDevInfo.product_id,
                                                 _globalSensorMangerTemp->sensor_id,
                                                 _globalSensorMangerTemp) != 0)
             {
@@ -1746,7 +1746,7 @@ static void sensorStatusMonitoring(void* conn)
         char temp[100];
        // sprintf(temp,"$修改$|$传感器$|%d",sensor_id_temp);
         sprintf(temp,"Update sensor %d",sensor_id_temp);
-        dev_insert_alarm_ctrl(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
         ack_str = ctrl_sts_ack_to_json();
     }
@@ -1759,7 +1759,7 @@ static void sensorStatusMonitoring(void* conn)
         //清空数据
         memset(_globalSensorMangerTemp, 0, sizeof(GlobalSensorManger));
         //填充数据
-        _globalSensorMangerTemp->product_id = __globalDeviceManage._global_device_info->product_id ;
+        _globalSensorMangerTemp->product_id = __globalDeviceManage._globalDevInfo.product_id ;
         _globalSensorMangerTemp->sensor_id = _over_all_sensor_request.sensorId;
         strcpy( _globalSensorMangerTemp->sensor_name,_over_all_sensor_request.sensorName);
 
@@ -1859,7 +1859,7 @@ static void sensorStatusMonitoring(void* conn)
         char temp[100];
        // sprintf(temp,"$新增$|$传感器$|%d",_over_all_sensor_request.sensorId);
         sprintf(temp,"Add sensor %d",_over_all_sensor_request.sensorId);
-        dev_insert_alarm_ctrl(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
         ack_str = ctrl_sts_ack_to_json();
     }
@@ -1901,7 +1901,7 @@ static void sensorStatusMonitoring(void* conn)
         // log_d("page_size:%d",page_size);
         //查询数据
          ret = dev_search_sensor_info(__globalDeviceManage.db,
-                             __globalDeviceManage._global_device_info->product_id,
+                             __globalDeviceManage._globalDevInfo.product_id,
                              g_sensor_id,
                              _over_all_sensor_request.startTime,
                              _over_all_sensor_request.endTime,
@@ -2058,7 +2058,7 @@ static void alarmProtect(void *conn)
         INIT_LIST_HEAD(&_alarm_ack_info.list);
         //查询数据库,最近的10个报警信息
         ret = dev_serarch_all_alarm(__globalDeviceManage.db,
-            __globalDeviceManage._global_device_info->product_id,
+            __globalDeviceManage._globalDevInfo.product_id,
             0,1,10,
             &_alarm_ack_info,&nAlarmNumber);
         if(ret!=0)
@@ -2082,7 +2082,7 @@ static void alarmProtect(void *conn)
         INIT_LIST_HEAD(&_alarm_ack_info.list);
         //查询数据库
         ret = dev_serarch_all_alarm(__globalDeviceManage.db,
-            __globalDeviceManage._global_device_info->product_id,
+            __globalDeviceManage._globalDevInfo.product_id,
             0,_alarm_request_info.pagenum,_alarm_request_info.pagesize,
             &_alarm_ack_info,&nAlarmNumber);
         if(ret!=0)
@@ -2105,7 +2105,7 @@ static void alarmProtect(void *conn)
         INIT_LIST_HEAD(&_alarm_ack_info.list);
         //查询数据库
         ret = dev_serarch_all_alarm(__globalDeviceManage.db,
-            __globalDeviceManage._global_device_info->product_id,
+            __globalDeviceManage._globalDevInfo.product_id,
             1,_alarm_request_info.pagenum,_alarm_request_info.pagesize,
             &_alarm_ack_info,&nAlarmNumber);
         if(ret!=0)
@@ -2128,7 +2128,7 @@ static void alarmProtect(void *conn)
         INIT_LIST_HEAD(&_alarm_ack_info.list);
         //查询数据库
         ret = dev_serarch_all_alarm(__globalDeviceManage.db,
-            __globalDeviceManage._global_device_info->product_id,
+            __globalDeviceManage._globalDevInfo.product_id,
             2,_alarm_request_info.pagenum,_alarm_request_info.pagesize,
             &_alarm_ack_info,&nAlarmNumber);
         if(ret!=0)
@@ -2269,7 +2269,7 @@ static void alarmProtect(void *conn)
         
         //写入数据库
         ret = dev_update_power_manage_over_info(__globalDeviceManage.db,
-        __globalDeviceManage._global_device_info->product_id,
+        __globalDeviceManage._globalDevInfo.product_id,
         _globalPowerMangerSaveTemp->product_ch_id,
         _globalPowerMangerSaveTemp);
         if(ret!=0)
@@ -2299,7 +2299,7 @@ static void alarmProtect(void *conn)
         switch (_globalSensorMangerSaveTemp->sensor_type)
         {
         case SENSOR_TYPE_TEMPERATURE:
-            if (strcmp(_alarm_request_info._sensor_info.thresholdType, language_temperature[__globalDeviceManage._global_device_info->product_language]) == 0)
+            if (strcmp(_alarm_request_info._sensor_info.thresholdType, language_temperature[__globalDeviceManage._globalDevInfo.product_language]) == 0)
             {
                 _globalSensorMangerSaveTemp->over_manager->sensor_val1_upper_threshold = atof(_alarm_request_info._sensor_info.thresholdUpperValue);
                 _globalSensorMangerSaveTemp->over_manager->sensor_val1_lower_threshold = atof(_alarm_request_info._sensor_info.thresholdDownValue);
@@ -2321,7 +2321,7 @@ static void alarmProtect(void *conn)
                     _globalSensorMangerSaveTemp->over_manager->sensor_val1_lower_threshold_ctrl = ALARM_CTRL_ALARM_ONLY;
 
             }
-            else if (strcmp(_alarm_request_info._sensor_info.thresholdType, language_humidity[__globalDeviceManage._global_device_info->product_language]) == 0)
+            else if (strcmp(_alarm_request_info._sensor_info.thresholdType, language_humidity[__globalDeviceManage._globalDevInfo.product_language]) == 0)
             {
                 _globalSensorMangerSaveTemp->over_manager->sensor_val2_upper_threshold = atof(_alarm_request_info._sensor_info.thresholdUpperValue);
                 _globalSensorMangerSaveTemp->over_manager->sensor_val2_lower_threshold = atof(_alarm_request_info._sensor_info.thresholdDownValue);
@@ -2355,7 +2355,7 @@ static void alarmProtect(void *conn)
        
         //更新参数
         ret = dev_update_sensor_over_manage(__globalDeviceManage.db,
-                                    __globalDeviceManage._global_device_info->product_id,
+                                    __globalDeviceManage._globalDevInfo.product_id,
                                     g_sensor_id,
                                     _globalSensorMangerSaveTemp);
         if(ret!=0)
@@ -2416,7 +2416,7 @@ static void logInformation(void *conn)
             log_d(start_time);
             
             dev_search_alarm_info(__globalDeviceManage.db,
-                            __globalDeviceManage._global_device_info->product_id,
+                            __globalDeviceManage._globalDevInfo.product_id,
                             0,     //注意注意 此处需要查询的参数是0 1 2
                             start_time,//启动时间
                             stop_time,  //结束时间
@@ -2438,7 +2438,7 @@ static void logInformation(void *conn)
         else
         {
             dev_search_alarm_info(__globalDeviceManage.db,
-                            __globalDeviceManage._global_device_info->product_id,
+                            __globalDeviceManage._globalDevInfo.product_id,
                             0,     //注意注意 此处需要查询的参数是0 1 2
                             __logInformationRequestInfo.beginTime,//启动时间
                             __logInformationRequestInfo.endtime,  //结束时间
@@ -2486,7 +2486,7 @@ static void logInformation(void *conn)
             log_d(start_time);
 
             dev_search_alarm_info(__globalDeviceManage.db,
-                                  __globalDeviceManage._global_device_info->product_id,
+                                  __globalDeviceManage._globalDevInfo.product_id,
                                   3, // alarm_type,        操作日志
                                   start_time,
                                   stop_time,
@@ -2497,7 +2497,7 @@ static void logInformation(void *conn)
         else
         {
             dev_search_alarm_info(__globalDeviceManage.db,
-                                __globalDeviceManage._global_device_info->product_id,
+                                __globalDeviceManage._globalDevInfo.product_id,
                                 3,// alarm_type,        操作日志
                                 __logInformationRequestInfo.beginTime,
                                 __logInformationRequestInfo.endtime,
@@ -2539,7 +2539,7 @@ static void logInformation(void *conn)
         INIT_LIST_HEAD(&_alarm_ack_info.list);
 
         dev_search_alarm_info(__globalDeviceManage.db,
-                            __globalDeviceManage._global_device_info->product_id,
+                            __globalDeviceManage._globalDevInfo.product_id,
                             4,// alarm_type,        运行日志
                            start_time,
                            stop_time,
@@ -2578,7 +2578,7 @@ static void communicationManagement(void *conn)
     cJSON *cjson;
     _CommunicationManageRequestInfo _communicationManageRequestInfo;
 	_CommunicationManageRequestInfo reqInfo;
-    GlobalDeviceInfo *devInfo=__globalDeviceManage._global_device_info;
+    GlobalDeviceInfo *devInfo=&__globalDeviceManage._globalDevInfo;
     mg_stream_t *s=(mg_stream_t*)conn;
     struct mg_http_message *hm=s->ev_data;
     char *rx_body_buf=(char*)hm->body.buf;
@@ -2632,8 +2632,8 @@ static void communicationManagement(void *conn)
     else if(strcmp(reqInfo.type,"RsSave")==0)//淇濆瓨modbus鏁版嵁
     {
         ModbusInfo_t* info = &devInfo->_gmodbus_info;
-        bool isStrMaster=strcmp(reqInfo._rs_info.mode,language_alarm_RS485_master[__globalDeviceManage._global_device_info->product_language])==0;
-        bool isStrSlave=strcmp(reqInfo._rs_info.mode,language_alarm_RS485_slave[__globalDeviceManage._global_device_info->product_language])==0;
+        bool isStrMaster=strcmp(reqInfo._rs_info.mode,language_alarm_RS485_master[__globalDeviceManage._globalDevInfo.product_language])==0;
+        bool isStrSlave=strcmp(reqInfo._rs_info.mode,language_alarm_RS485_slave[__globalDeviceManage._globalDevInfo.product_language])==0;
         if (isStrMaster||isStrMaster)
         {
             if (isStrMaster)
@@ -2740,7 +2740,7 @@ static void serviceManagement(void *conn)
         _globalSNMPManager.public= malloc(32);
         strcpy(_globalSNMPManager.public, _serviceManageRequestInfo._snmp_info.public);
         _globalSNMPManager.trapmode = atoi(_serviceManageRequestInfo._snmp_info.trapmode);
-        _globalSNMPManager.product_id = __globalDeviceManage._global_device_info->product_id;
+        _globalSNMPManager.product_id = __globalDeviceManage._globalDevInfo.product_id;
         if (dev_update_snmp_info(__globalDeviceManage.db,_globalSNMPManager.product_id,&_globalSNMPManager) != 0)
         {
             log_e("update snmp info err.");
@@ -2773,7 +2773,7 @@ static void serviceManagement(void *conn)
         _globalNTPManager.ntpName= malloc(64);
         strcpy(_globalNTPManager.ntpName, _serviceManageRequestInfo._ntp_info.ntpName);
         _globalNTPManager.port = atoi(_serviceManageRequestInfo._ntp_info.port);
-        _globalNTPManager.product_id = __globalDeviceManage._global_device_info->product_id;
+        _globalNTPManager.product_id = __globalDeviceManage._globalDevInfo.product_id;
          _globalNTPManager.time= malloc(64);
         strcpy(_globalNTPManager.time, _serviceManageRequestInfo._ntp_info.time);
         const char* key = "GMT/UTC";
@@ -2893,7 +2893,7 @@ static void serviceManagement(void *conn)
            // sprintf(temp,"$设置$|$时间$|NTP %s",  _globalNTPManager.ntpaddress);
             sprintf(temp,"Set Date & Time sync from NTP %s", _globalNTPManager.ntpaddress);
         }
-        dev_insert_alarm_ctrl(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
 
         ack_str = ctrl_sts_ack_to_json();
@@ -2985,7 +2985,7 @@ static void serviceManagement(void *conn)
         char temp[100];
         //sprintf(temp, "$设置$|定时$");
         sprintf(temp, "Add scheduled tasks");
-        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
         ack_str = ctrl_sts_ack_to_json();
     }
@@ -3029,7 +3029,7 @@ static void serviceManagement(void *conn)
         char temp[100];
        // sprintf(temp, "$删除$|定时$");
         sprintf(temp, "Delete scheduled tasks");
-        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 3, temp);
         ack_str = ctrl_sts_ack_to_json();
     }
     // 时序设置
@@ -3136,7 +3136,7 @@ static void serviceManagement(void *conn)
                     pGroupNum++;
                 }
                 
-                dev_delete__group_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id);
+                dev_delete__group_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id);
                 for (size_t i = 0; i < pGroupNum; i++)
                 {
                     GroupInfo *new_group = (GroupInfo *)malloc(sizeof(GroupInfo));
@@ -3146,7 +3146,7 @@ static void serviceManagement(void *conn)
                     {
                         break;
                     }
-                    new_group->product_id = __globalDeviceManage._global_device_info->product_id;
+                    new_group->product_id = __globalDeviceManage._globalDevInfo.product_id;
                     new_group->GroupID = i + 1;
                     sprintf(new_group->GroupName, "Group%d", i + 1);
 
@@ -3178,7 +3178,7 @@ static void serviceManagement(void *conn)
 
             if (jgnum >= 0 && pGroupNum> 0 )
             {
-                dev_delete__group_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id);
+                dev_delete__group_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id);
                 for (size_t i = 0; i < pGroupNum; i++)
                 {
                     GroupInfo *new_group = (GroupInfo *)malloc(sizeof(GroupInfo));
@@ -3188,7 +3188,7 @@ static void serviceManagement(void *conn)
                     {
                         break;
                     }
-                    new_group->product_id = __globalDeviceManage._global_device_info->product_id;
+                    new_group->product_id = __globalDeviceManage._globalDevInfo.product_id;
                     new_group->GroupID = i + 1;
                     sprintf(new_group->GroupName, "Group%d", i + 1);
 
@@ -3240,7 +3240,7 @@ static void serviceManagement(void *conn)
                 if (_GroupInfoTemp->GroupID == ngroup)
                 {
 
-                    if (__globalDeviceManage._global_device_info->product_pwr_type == 1)
+                    if (__globalDeviceManage._globalDevInfo.product_pwr_type == 1)
                     { // 直流版本功能
                         char *pCHlist;
                         char *pCHListSave;
@@ -3321,7 +3321,7 @@ static void serviceManagement(void *conn)
         char temp[100];
         //sprintf(temp, "$打开$|$分组$|%d", ngroup);
         sprintf(temp, "Open group %d", ngroup);
-        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
         ack_str = ctrl_sts_ack_to_json();
     }
@@ -3342,7 +3342,7 @@ static void serviceManagement(void *conn)
                 {
                     /* code */
 
-                    if (__globalDeviceManage._global_device_info->product_pwr_type == 1)
+                    if (__globalDeviceManage._globalDevInfo.product_pwr_type == 1)
                     {
                         char *pCHlist;
                         char *pCHListSave;
@@ -3424,7 +3424,7 @@ static void serviceManagement(void *conn)
         char temp[100];
        // sprintf(temp, "$关闭$|$分组$|%d", ngroup);
         sprintf(temp, "Close group %d", ngroup);
-        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 3, temp);
         ack_str = ctrl_sts_ack_to_json();
     }
     
@@ -3511,7 +3511,7 @@ static void systemManagent(void *conn)
             char temp[100];
             //sprintf(temp, "$删除$|$用户$|%d", _UserRoleManageRequestInfo.userIds);
             sprintf(temp, "Delete user %d", _UserRoleManageRequestInfo.userIds);
-            dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 3, temp);
+            dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 3, temp);
     }   
     //添加用户
     else if(strcmp(_UserRoleManageRequestInfo.type,"addUser")==0)
@@ -3520,7 +3520,7 @@ static void systemManagent(void *conn)
         UserInfo *new_user = (UserInfo *)malloc(sizeof(UserInfo));
         memset(new_user,0,sizeof(UserInfo));
 
-        new_user->product_id =  __globalDeviceManage._global_device_info->product_id;
+        new_user->product_id =  __globalDeviceManage._globalDevInfo.product_id;
 
         int nMaxUserNum=1;
         UserInfo User_list;
@@ -3567,7 +3567,7 @@ static void systemManagent(void *conn)
         char temp[100];
         //sprintf(temp, "$添加$|$用户$|%s", _UserRoleManageRequestInfo.userName);
         sprintf(temp, "Add user %s", _UserRoleManageRequestInfo.userName);
-        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
         ack_str=ctrl_sts_ack_to_json();
     }   
@@ -3578,7 +3578,7 @@ static void systemManagent(void *conn)
         UserInfo *new_user = (UserInfo *)malloc(sizeof(UserInfo));
         memset(new_user,0,sizeof(UserInfo));
 
-        new_user->product_id =  __globalDeviceManage._global_device_info->product_id;
+        new_user->product_id =  __globalDeviceManage._globalDevInfo.product_id;
         new_user->userID = _UserRoleManageRequestInfo.userId;
         new_user->userName = malloc(256);
         strcpy(new_user->userName , _UserRoleManageRequestInfo.userName);
@@ -3595,7 +3595,7 @@ static void systemManagent(void *conn)
         char temp[100];
         //sprintf(temp, "$修改$|$用户$|%s", _UserRoleManageRequestInfo.userName);
          sprintf(temp, "Update user %s", _UserRoleManageRequestInfo.userName);
-        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
         ack_str=ctrl_sts_ack_to_json();
     }    
@@ -3630,22 +3630,22 @@ static void equipmentMintenance(void *conn)
     if(strcmp(_Over_equipment_mintenance.type,"listSbRestartQuery")==0 || strcmp(_Over_equipment_mintenance.type,"listSbWhQuery")==0)
     {
         // 查询设备总体参数
-       if (dev_get_device_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info) != 0)
+       if (dev_get_device_info(__globalDeviceManage.db,&__globalDeviceManage._globalDevInfo) != 0)
         {
             log_e("get device info error.\n");
             http_reply(conn, 400, NULL);
             return;
         }
 
-        _over_back_sts_info.product_name = __globalDeviceManage._global_device_info->product_name;
-        _over_back_sts_info.product_number = __globalDeviceManage._global_device_info->product_number;
-        _over_back_sts_info.product_id = __globalDeviceManage._global_device_info->product_id;
+        _over_back_sts_info.product_name = __globalDeviceManage._globalDevInfo.product_name;
+        _over_back_sts_info.product_number = __globalDeviceManage._globalDevInfo.product_number;
+        _over_back_sts_info.product_id = __globalDeviceManage._globalDevInfo.product_id;
         _over_back_sts_info.product_Code = malloc(8);
         strcpy(_over_back_sts_info.product_Code, "-");
        // _over_back_sts_info.product_type = malloc(32);
         //strcpy(_over_back_sts_info.product_type, "GC Series");
-        _over_back_sts_info.product_type=g_product_type_str[__globalDeviceManage._global_device_info->product_type];
-        _over_back_sts_info.productVersion = __globalDeviceManage._global_device_info->product_version;
+        _over_back_sts_info.product_type=g_product_type_str[__globalDeviceManage._globalDevInfo.product_type];
+        _over_back_sts_info.productVersion = __globalDeviceManage._globalDevInfo.product_version;
  
         _over_back_sts_info.product_sysTime = malloc(32);
         struct tm *t;
@@ -3667,13 +3667,13 @@ static void equipmentMintenance(void *conn)
 
         _over_back_sts_info.product_mac = get_mac_address("eth0");
 
-        _over_back_sts_info.product_RS485Addr = __globalDeviceManage._global_device_info->_gmodbus_info.product_modbus_addr;
+        _over_back_sts_info.product_RS485Addr = __globalDeviceManage._globalDevInfo._gmodbus_info.product_modbus_addr;
 
-        //_over_back_sts_info.product_status = __globalDeviceManage._global_device_info ->product_status;
+        //_over_back_sts_info.product_status = __globalDeviceManage._globalDevInfo.product_status;
         _over_back_sts_info.product_status = malloc(16);
         strcpy(_over_back_sts_info.product_status, "online");
 
-        _over_back_sts_info.product_type_id = __globalDeviceManage._global_device_info->product_pwr_type;
+        _over_back_sts_info.product_type_id = __globalDeviceManage._globalDevInfo.product_pwr_type;
 
         if (strcmp(_Over_equipment_mintenance.type, "listSbWhQuery") == 0)
         {
@@ -3684,7 +3684,7 @@ static void equipmentMintenance(void *conn)
     }
     else if(strcmp(_Over_equipment_mintenance.type,"listShfwQuery")==0)
     {
-        GlobalDeviceInfo *dev=__globalDeviceManage._global_device_info;
+        GlobalDeviceInfo *dev=&__globalDeviceManage._globalDevInfo;
         ack_str = vendor_info_to_json(dev);
     }
     else if(strcmp(_Over_equipment_mintenance.type,"sBRestart")==0) {  //restart
@@ -3692,23 +3692,23 @@ static void equipmentMintenance(void *conn)
         char temp[100];
         //sprintf(temp, "$系统$|$重启$");
         sprintf(temp, "System Reboot!");
-        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
         sys_reboot();
     }else if(strcmp(_Over_equipment_mintenance.type,"listKgSbQuery")==0)    // part of device infomation 
     {
         _OverBackBreakerInfo breaker_info;
-        if (dev_get_device_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info) != 0)
+        if (dev_get_device_info(__globalDeviceManage.db,&__globalDeviceManage._globalDevInfo) != 0)
         {
             log_e("get device info error.\n");
             http_reply(conn, 400, NULL);
             return;
         }
         printf("get listKgSbQuery infomation!!!\n");
-        breaker_info.product_id = __globalDeviceManage._global_device_info->product_id;
-        breaker_info.product_name = __globalDeviceManage._global_device_info->product_name;
-        breaker_info.product_number = __globalDeviceManage._global_device_info->product_number;
-        breaker_info.product_type = __globalDeviceManage._global_device_info->product_type;
+        breaker_info.product_id = __globalDeviceManage._globalDevInfo.product_id;
+        breaker_info.product_name = __globalDeviceManage._globalDevInfo.product_name;
+        breaker_info.product_number = __globalDeviceManage._globalDevInfo.product_number;
+        breaker_info.product_type = __globalDeviceManage._globalDevInfo.product_type;
         ack_str = over_breaker_product_list_info_to_json(&__globalDeviceManage,&breaker_info,false);
     }else if(strcmp(_Over_equipment_mintenance.type,"listKgTdQuery")==0)
     {
@@ -3728,9 +3728,9 @@ static void equipmentMintenance(void *conn)
             list_for_each_entry(_globalPowerTemp, &__globalDeviceManage._globalPowerManger.list, list)
             {
                 _OverBreakerChnInfo *temp = (_OverBreakerChnInfo *) malloc(sizeof(_OverBreakerChnInfo));
-                temp->product_id = __globalDeviceManage._global_device_info->product_id;
-                strcpy(temp->product_name,__globalDeviceManage._global_device_info->product_name);
-                strcpy(temp->product_number,__globalDeviceManage._global_device_info->product_number);
+                temp->product_id = __globalDeviceManage._globalDevInfo.product_id;
+                strcpy(temp->product_name,__globalDeviceManage._globalDevInfo.product_name);
+                strcpy(temp->product_number,__globalDeviceManage._globalDevInfo.product_number);
                 strcpy(temp->product_ch_name,_globalPowerTemp->product_ch_name);
                 temp->product_ch_id = _globalPowerTemp->product_ch_id;
                 printf("%s %s %s  %d\n",temp->product_name,temp->product_number,temp->product_ch_name,temp->product_ch_id);
@@ -3780,9 +3780,9 @@ static void equipmentMintenance(void *conn)
             //     info->product_id = temp->product_id;
             //     sprintf(buff,"Breaker %d",temp->breaker_id);
             //     strcpy(info->product_ch_name,buff);
-            //     sprintf(buff,"%s %d",__globalDeviceManage._global_device_info->product_name,temp->breaker_id);
+            //     sprintf(buff,"%s %d",__globalDeviceManage._globalDevInfo.product_name,temp->breaker_id);
             //     strcpy(info->productName,buff);
-            //     strcpy(info->product_number,__globalDeviceManage._global_device_info->product_number);
+            //     strcpy(info->product_number,__globalDeviceManage._globalDevInfo.product_number);
             //     strcpy(info->productChids,temp->breaker_chns_name);
             //     info->switch_id = temp->breaker_id;
             //     info->status = temp->breaker_status;
@@ -3825,8 +3825,8 @@ static void equipmentMintenance(void *conn)
                 info->product_id = temp->product_id;
                 sprintf(buff,"Breaker %d",temp->breaker_id);
                 strcpy(info->product_ch_name,buff);
-                strcpy(info->productName,__globalDeviceManage._global_device_info->product_name);
-                strcpy(info->product_number,__globalDeviceManage._global_device_info->product_number);
+                strcpy(info->productName,__globalDeviceManage._globalDevInfo.product_name);
+                strcpy(info->product_number,__globalDeviceManage._globalDevInfo.product_number);
                 strcpy(info->productChids,temp->breaker_chns_name);
                 info->switch_id = temp->breaker_id;
                 info->status = temp->breaker_status;
@@ -3894,7 +3894,7 @@ static void equipmentMintenance(void *conn)
             {
                 GlobalBreakerManager *breakerManager = (GlobalBreakerManager*) malloc(sizeof(GlobalBreakerManager));
                 memset(breakerManager,0,sizeof(GlobalBreakerManager));
-                breakerManager->product_id = __globalDeviceManage._global_device_info->product_id;
+                breakerManager->product_id = __globalDeviceManage._globalDevInfo.product_id;
                 breakerManager->breaker_gather_addr = atoi(_Over_equipment_mintenance.cjdz);
                 strcpy(breakerManager->breaker_com,_Over_equipment_mintenance.comkh);
                 strcpy(breakerManager->breaker_gather_type,_Over_equipment_mintenance.cjfs);
@@ -3977,7 +3977,7 @@ static void equipmentMintenance(void *conn)
                     strcpy(temp->breaker_switch_name,_Over_equipment_mintenance.switchName);
                     strcpy(temp->breaker_chns_name,_Over_equipment_mintenance.productChids);
                     dev_update_breaker_genera_manage(__globalDeviceManage.db,
-                    __globalDeviceManage._global_device_info->product_id,switch_id,temp);
+                    __globalDeviceManage._globalDevInfo.product_id,switch_id,temp);
                     break;
                 }
             }
@@ -4002,7 +4002,7 @@ static void equipmentMintenance(void *conn)
             {
                 if(node->breaker_id == _Over_equipment_mintenance.switchId)
                 {
-                    // dev_delete_breaker_manage(__globalDeviceManage2.db,__globalDeviceManage._global_device_info->product_id,
+                    // dev_delete_breaker_manage(__globalDeviceManage2.db,__globalDeviceManage._globalDevInfo.product_id,
                     //             _Over_equipment_mintenance.switchId);
                     list_del(&node->list);
                     free(node);
@@ -4023,7 +4023,7 @@ static void equipmentMintenance(void *conn)
             {
                 if(node->breaker_id == switch_id)
                 {
-                    dev_delete_breaker_manage(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,switch_id);
+                    dev_delete_breaker_manage(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,switch_id);
                     list_del(&node->list);
                     free(node);
                     node = NULL;
@@ -4040,7 +4040,7 @@ static void equipmentMintenance(void *conn)
         char temp[100];
         //sprintf(temp, "$系统$|$恢复出厂设置$");
         sprintf(temp, "System Reset!");
-        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, 3, temp);
+        dev_insert_alarm_ctrl(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 3, temp);
 
         sys_set_factory();
     }

+ 30 - 39
pro/src/cascade.c

@@ -79,7 +79,7 @@ static inline ModbusInfo_t *get_mb(void)
 
     return &mbinfo;
 #else
-    return &get_dm()->_global_device_info->_gmodbus_info;
+    return &get_dm()->_globalDevInfo._gmodbus_info;
 #endif
 }
 static int slave_init(cascade_handle_t *cas)
@@ -144,9 +144,9 @@ static int slave_get_info(cascade_handle_t *cas)
     slave_info_t *info=&cas->sInfo;
 
     info->cnt=0;
-    info->prod.product_type = dm->_global_device_info->product_type;
-    info->prod.product_pwr_type = dm->_global_device_info->product_pwr_type;
-    info->prod.product_id = dm->_global_device_info->product_id;
+    info->prod.product_type = dm->_globalDevInfo.product_type;
+    info->prod.product_pwr_type = dm->_globalDevInfo.product_pwr_type;
+    info->prod.product_id = dm->_globalDevInfo.product_id;
 
     if(!list_empty(&dm->_globalPowerManger.list_Tree_AC)) {
         cnt2 = 0;
@@ -182,7 +182,7 @@ static int slave_get_info(cascade_handle_t *cas)
             info->ch[cnt].stop_delay  = tmp->product_ch_stop_delay;
 
             info->ch[cnt].chinfo = tmp->_PowerInfo;
-            if (tmp->product_ch_type==TREE_AC_TYPE||dm->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B) {
+            if (tmp->product_ch_type==TREE_AC_TYPE||dm->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B) {
                 cnt2 = 0;
                 list_for_each_entry(tmp3, &tmp->list_Tree_AC, list_Tree_AC)
                 {
@@ -247,7 +247,7 @@ static int get_pwr_info(int chId, GlobalPowerManger *power)
     list_for_each_entry(tmp, &dm->_globalPowerManger.list, list)
     {
         if(tmp->product_ch_id==chId) {
-            power->product_id = dm->_global_device_info->product_id;
+            power->product_id = dm->_globalDevInfo.product_id;
             power->product_ch_id = tmp->product_ch_id;
             strcpy(power->product_ch_name, tmp->product_ch_name);
             power->product_ch_type = tmp->product_ch_type;
@@ -282,7 +282,7 @@ static int slave_breaker_update(cascade_breaker_update_t *data)
                     strcpy(temp->breaker_switch_name,data->switch_name);
                     strcpy(temp->breaker_chns_name,data->breaker_chns);
                     dev_update_breaker_genera_manage(dm->db,
-                    dm->_global_device_info->product_id,data->switch_id,temp);
+                    dm->_globalDevInfo.product_id,data->switch_id,temp);
                     ret = 0;
                     break;
                 }
@@ -315,7 +315,7 @@ static int slave_breaker_delete(cascade_braeker_delete_t *data)
                 }
                 if(temp->breaker_id == data->switch_id)
                 {
-                    dev_delete_breaker_manage(dm->db,dm->_global_device_info->product_id,data->switch_id);
+                    dev_delete_breaker_manage(dm->db,dm->_globalDevInfo.product_id,data->switch_id);
                     list_del(&temp->list);
                     free(temp);
                     if(!list_empty(&dm->g_new_global_breaker.list))
@@ -366,7 +366,7 @@ static int slave_breaker_add(cascade_breaker_add_t *data)
         }
         GlobalBreakerManager *breakerManager = (GlobalBreakerManager*) malloc(sizeof(GlobalBreakerManager));
         memset(breakerManager,0,sizeof(GlobalBreakerManager));
-        breakerManager->product_id = __globalDeviceManage._global_device_info->product_id;
+        breakerManager->product_id = __globalDeviceManage._globalDevInfo.product_id;
         breakerManager->breaker_gather_addr = data->cjdz;
         strcpy(breakerManager->breaker_com,data->com);
         strcpy(breakerManager->breaker_gather_type,data->cjfs);
@@ -441,7 +441,7 @@ static int slave_save(cascade_handle_t *cas)
         LOGE("____ get_pwr_info failed\n");
         return -1;
     }
-    r = dev_update_power_manage_genera_info(dm->db, dm->_global_device_info->product_id, cas->cmd.chId, &power);
+    r = dev_update_power_manage_genera_info(dm->db, dm->_globalDevInfo.product_id, cas->cmd.chId, &power);
 
     return r;
 }
@@ -893,17 +893,11 @@ static int power_init(cascade_handle_t *cas)
     GlobalDeviceManager *dm=get_dm();
     GlobalDeviceManager *dm2=get_dm2();
 
-    dm2->_global_device_info = (GlobalDeviceInfo*)malloc(sizeof(GlobalDeviceInfo));
-    if(dm2->_global_device_info==NULL) {
-        LOGE("____ power_init, malloc failed\n");
-        return -1;
-    }
-
-    dm2->_global_device_info->product_pwr_type = dm->_global_device_info->product_pwr_type;
-    dm2->_global_device_info->product_id = dm->_global_device_info->product_id;
-    strcpy(dm2->_global_device_info->product_name, dm->_global_device_info->product_name);
-    strcpy(dm2->_global_device_info->product_number, dm->_global_device_info->product_number);
-    strcpy(dm2->_global_device_info->product_status, dm->_global_device_info->product_status);
+    dm2->_globalDevInfo.product_pwr_type = dm->_globalDevInfo.product_pwr_type;
+    dm2->_globalDevInfo.product_id = dm->_globalDevInfo.product_id;
+    strcpy(dm2->_globalDevInfo.product_name, dm->_globalDevInfo.product_name);
+    strcpy(dm2->_globalDevInfo.product_number, dm->_globalDevInfo.product_number);
+    strcpy(dm2->_globalDevInfo.product_status, dm->_globalDevInfo.product_status);
     
     INIT_LIST_HEAD(&dm2->_globalPowerManger.list);
     INIT_LIST_HEAD(&dm2->_globalPowerManger.list_Tree_AC);
@@ -923,9 +917,6 @@ static int power_deinit(cascade_handle_t *cas)
     GlobalDeviceManager *dm2=get_dm2();
 
     power_clear(cas);
-    if(dm2->_global_device_info) {
-        free(dm2->_global_device_info);
-    }
 
     return 0;
 }
@@ -957,7 +948,7 @@ static int power_clear(cascade_handle_t *cas)
                 continue;
             }
 
-            if (tmp->product_ch_type==TREE_AC_TYPE||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B) {
+            if (tmp->product_ch_type==TREE_AC_TYPE||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B) {
                 if(list_empty(&tmp->list_Tree_AC)) {
                     continue;
                 }
@@ -1020,7 +1011,7 @@ static int power_add(cascade_handle_t *cas)
     cascade_lock();
     power_clear(cas);
 
-    dm2->_global_device_info->product_id = cur_dev_addr;
+    dm2->_globalDevInfo.product_id = cur_dev_addr;
     //插入总数据
     if(info->prod.product_pwr_type==SmartPDU_Tree_AC_Tree ||
        info->prod.product_pwr_type==SmartPDU_Tree_AC_One ||
@@ -1291,7 +1282,7 @@ static int master_cmd(cascade_handle_t *cas, cmd_data_t *cmd)
     GlobalPowerManger *tmp=NULL;
     GlobalDeviceManager *dm=get_dm();
     GlobalDeviceManager *dm2=get_dm2();
-    GlobalDeviceInfo    *dev=dm2->_global_device_info;
+    GlobalDeviceInfo    *dev=&dm2->_globalDevInfo;
     data_t rdata,wdata;
 
     if(cur_dev_addr==0) {
@@ -1379,7 +1370,7 @@ static int master_query(cascade_handle_t *cas)
     int i,r;
     GlobalPowerManger *tmp=NULL;
     GlobalDeviceManager *dm2=get_dm2();
-    GlobalDeviceInfo    *dev=dm2->_global_device_info;
+    GlobalDeviceInfo    *dev=&dm2->_globalDevInfo;
     cmd_data_t *cmd=&cas->cmd;
     data_t rdata,wdata;
 
@@ -1658,7 +1649,7 @@ static void* cmd_thread(void *arg)
     else {
         sprintf(temp,"$关闭$|$所有$|$通道$");
     }
-    dev_insert_alarm_ctrl(dm->db, dm->_global_device_info->product_id,3,temp);
+    dev_insert_alarm_ctrl(dm->db, dm->_globalDevInfo.product_id,3,temp);
     free(pcmd);
 
     pthread_exit(NULL);
@@ -1699,7 +1690,7 @@ static void* cmd_NF_thread(void *arg)
     else {
         sprintf(temp, "$关闭$|$通道$|%d Naught wire!", pcmd->chId);
     }
-    dev_insert_alarm_ctrl(dm->db, dm->_global_device_info->product_id,3,temp);
+    dev_insert_alarm_ctrl(dm->db, dm->_globalDevInfo.product_id,3,temp);
     free(pcmd);
 
     pthread_exit(NULL);
@@ -1881,10 +1872,10 @@ int cascade_get_ch(_OverChnPwrAckInfo *ch)
     GlobalDeviceManager* dm2=get_dm2();
     list_for_each_entry(tmp, &dm2->_globalPowerManger.list, list)
     {
-        if (tmp->product_ch_type==TREE_AC_TYPE||dm2->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B){
+        if (tmp->product_ch_type==TREE_AC_TYPE||dm2->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B){
             int nStatus=-1;//-1则状态不变,0、1则是子状态
             //判断是否三相单输出情况下
-            if(tmp->product_ch_type==TREE_AC_TYPE||dm2->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B) {
+            if(tmp->product_ch_type==TREE_AC_TYPE||dm2->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B) {
                 list_for_each_entry(tmp3, &tmp->list_Tree_AC, list_Tree_AC) {
                     if (2 == tmp3->product_ph_outputType &&1==tmp3->product_ph_outputStatus)
                     {//单项并且状态为输出
@@ -1900,9 +1891,9 @@ int cascade_get_ch(_OverChnPwrAckInfo *ch)
                     LOGE("pch malloc err.\n");
                     return -1;
                 }
-                pch->product_name = dm2->_global_device_info->product_name;
-                pch->product_number = dm2->_global_device_info->product_number;
-                pch->product_id = dm2->_global_device_info->product_id;
+                pch->product_name = dm2->_globalDevInfo.product_name;
+                pch->product_number = dm2->_globalDevInfo.product_number;
+                pch->product_id = dm2->_globalDevInfo.product_id;
                 pch->productChName = tmp->product_ch_name;
                 pch->productChId = tmp->product_ch_id;
                 pch->status = tmp->_PowerInfo.status;
@@ -1922,7 +1913,7 @@ int cascade_get_ch(_OverChnPwrAckInfo *ch)
                 pch->ph_consumption = tmp3->_PowerInfo.consumption;
                 pch->ph_outputType   = tmp3->product_ph_outputType;
                 pch->ph_outputStatus = tmp3->product_ph_outputStatus;
-                if ((dm2->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One||dm2->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B) && 
+                if ((dm2->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One||dm2->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B) && 
                     tmp3->product_ph_outputType == 2 && tmp3->product_ph_outputStatus == 2) // 如果是单项输出并且则非输出通道数据为0
                 { 
                     // 3-1模式 单项状态,不输出则数据为空
@@ -1949,9 +1940,9 @@ int cascade_get_ch(_OverChnPwrAckInfo *ch)
                 return -1;
             }
             // 填数据
-            pch->product_name = dm2->_global_device_info->product_name;
-            pch->product_number = dm2->_global_device_info->product_number;
-            pch->product_id = dm2->_global_device_info->product_id;
+            pch->product_name = dm2->_globalDevInfo.product_name;
+            pch->product_number = dm2->_globalDevInfo.product_number;
+            pch->product_id = dm2->_globalDevInfo.product_id;
             pch->productChName = tmp->product_ch_name;
             pch->productChId = tmp->product_ch_id;
             pch->status = tmp->_PowerInfo.status;

+ 18 - 18
pro/src/cascade_slave.c

@@ -134,8 +134,8 @@ int cascade_slave_init(void)
     slave_handle_t *sh=&slHandle;
     GlobalDeviceManager* mgr=get_dm();
 
-    if(mgr->_global_device_info->product_pwr_type == SmartPDU_AC ||
-        mgr->_global_device_info->product_pwr_type == SmartPDU_DC)       // single AC
+    if(mgr->_globalDevInfo.product_pwr_type == SmartPDU_AC ||
+        mgr->_globalDevInfo.product_pwr_type == SmartPDU_DC)       // single AC
     {
         if(sh->map)
         {
@@ -188,8 +188,8 @@ static void slave_read(slave_handle_t *sh, uint32_t addr,int num,uint32_t reg_ty
 {
     GlobalDeviceManager* mgr=get_dm();
 
-    if(mgr->_global_device_info->product_pwr_type == SmartPDU_AC || 
-            mgr->_global_device_info->product_pwr_type == SmartPDU_DC){    
+    if(mgr->_globalDevInfo.product_pwr_type == SmartPDU_AC || 
+            mgr->_globalDevInfo.product_pwr_type == SmartPDU_DC){    
         if(addr >= DEV_CHN_REG && addr <= ALL_SET_SWITCH_REG)
         {
             if(type == TYPE_U16)
@@ -326,8 +326,8 @@ void cascade_slave_write(uint32_t addr, uint16_t val)
     GlobalDeviceManager* mgr=get_dm();
     uint16_t buff[128] = {0};
 
-    if(mgr->_global_device_info->product_pwr_type == SmartPDU_AC 
-            || mgr->_global_device_info->product_pwr_type == SmartPDU_DC)   
+    if(mgr->_globalDevInfo.product_pwr_type == SmartPDU_AC 
+            || mgr->_globalDevInfo.product_pwr_type == SmartPDU_DC)   
     {
         switch(addr)
         {
@@ -341,7 +341,7 @@ void cascade_slave_write(uint32_t addr, uint16_t val)
                             break;
                         if((start_chn+1) == _globalPowerMangerTemp->product_ch_id)
                         {
-                            if(mgr->_global_device_info->product_pwr_type == SmartPDU_AC){
+                            if(mgr->_globalDevInfo.product_pwr_type == SmartPDU_AC){
                                 _globalPowerMangerTemp->product_ch_start_delay=val;
                                 g_switch_set_ac_single_s_start_time_delay(&__globalDeviceManage._globalRelaySampManger,_globalPowerMangerTemp->product_saddr,
                                                 _globalPowerMangerTemp->product_ch_addr,val);
@@ -372,7 +372,7 @@ void cascade_slave_write(uint32_t addr, uint16_t val)
                             break;
                         if((start_chn+1) == _globalPowerMangerTemp->product_ch_id)
                         {
-                            if(mgr->_global_device_info->product_pwr_type == SmartPDU_AC){
+                            if(mgr->_globalDevInfo.product_pwr_type == SmartPDU_AC){
                                   _globalPowerMangerTemp->product_ch_stop_delay=val;
                                 g_switch_set_ac_single_s_stop_time_delay(&__globalDeviceManage._globalRelaySampManger,_globalPowerMangerTemp->product_saddr,
                                                 _globalPowerMangerTemp->product_ch_addr,val);
@@ -453,9 +453,9 @@ void cascade_slave_write(uint32_t addr, uint16_t val)
                         int ret = 0;
 
                         _globalPowerMangerTemp->product_ch_start_delay = val;
-                        if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_Tree
-                        ||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One
-                        ||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B
+                        if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_Tree
+                        ||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One
+                        ||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B
                         )
                         {
                             printf("hwllo every one stop time !!!!\n");
@@ -493,9 +493,9 @@ void cascade_slave_write(uint32_t addr, uint16_t val)
                         int ret = 0;
 
                         _globalPowerMangerTemp->product_ch_stop_delay = val;
-                        if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_Tree
-                        ||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One
-                        ||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+                        if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_Tree
+                        ||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One
+                        ||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
                         {
                             ret = g_switch_set_t_ac_stop_time_delay(&__globalDeviceManage._globalRelaySampManger, 
                                                         _globalPowerMangerTemp->product_saddr, (_globalPowerMangerTemp->product_ch_addr - 1) * 3, val / 1000);
@@ -537,9 +537,9 @@ void cascade_slave_write(uint32_t addr, uint16_t val)
                         {
                             t_ac_CtrlType=_globalTACManager->product_ph_outputType;
                         }
-                        if (t_ac_CtrlType == 2&&(__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_Tree
-                        ||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One
-                        ||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B))
+                        if (t_ac_CtrlType == 2&&(__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_Tree
+                        ||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One
+                        ||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B))
                         {
                             if(_globalPowerMangerTemp->product_ch_type == AC_SINGLE_S_TYPE || _globalPowerMangerTemp->product_ch_type == AC_SINGLE_B_TYPE)
                             {
@@ -606,7 +606,7 @@ void cascade_slave_write(uint32_t addr, uint16_t val)
                                 sts |= ENABLE_TAC_STIME;
                                 sts |= ENABLE_TAC_ETIME;
                             }*/
-                            if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One)
+                            if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One)
                             {
                                 g_switch_set_t_ac_phchn_ctrl(&__globalDeviceManage._globalRelaySampManger,
                                                                 _globalPowerMangerTemp->product_saddr,

+ 1 - 1
pro/src/common.c

@@ -460,7 +460,7 @@ bool CheckLoginStatus(char* Token)
     }
 
     return true;
-    // return __globalDeviceManage._global_device_info->login_status;
+    // return __globalDeviceManage._globalDevInfo.login_status;
 }
 
 // 辅助函数:判断是否是闰年  

+ 5 - 4
pro/src/common.h

@@ -38,6 +38,7 @@
 #define DATABASE_NAME       "pdu_dat.db"
 #define DATABASE_BAK_NAME   "pdu_dat_bak.db"
 #define SNMP_MIB_NAME       "pduMIB"
+#define INI_FILE_NAME       "smartPDU.ini"
 
 //高配表头串口定义-----------------------------------------------
 //控制板通信串口
@@ -891,10 +892,10 @@ typedef struct
     pthread_t           io_thread;  //IO采集线程
     pthread_t           sensor_thread; //传感器采集现成
     bool                dev_samp_flag ; //电源采集线程标志
-    GlobalDeviceInfo*   _global_device_info;    //设备管理信息
-    GlobalPowerManger  _globalPowerManger;      //电源管理表
-    GlobalSensorManger _globalSensorManger;     //传感器管理表  
-    Modbus_Manger      sensor_modbus_manager;  //通信接口管理
+    GlobalDeviceInfo    _globalDevInfo;    //设备管理信息
+    GlobalPowerManger   _globalPowerManger;      //电源管理表
+    GlobalSensorManger  _globalSensorManger;     //传感器管理表  
+    Modbus_Manger       sensor_modbus_manager;  //通信接口管理
     unsigned int        useSlaveCount ;         //有效地址
     Modbus_Manger       _globalRelaySampManger; //内部继电器使用
     

+ 2 - 2
pro/src/dflt.c

@@ -13,12 +13,12 @@ GlobalDeviceInfo DFLT_PARAS={
         .product_pwr_type   = PROD_POWER_TYPE,
         .product_version    = VERSION,
         .product_language   = LANGUAGE,                  //多国语言
-        .product_count      = CASCADE_CNT,               //级联设备数
+        .product_count      = 0,                         //级联设备数
         .product_samp_time  = SMPLE_TIME,                //采集周期 单位ms
         .product_save_time  = SAVE_TIME,                 //保存周期 单位ms
         
         ._modbus_info = {                                //继电器控制端口
-            .product_modbus_type = 0,                    //modbus模式,0: master     1: slave
+            .product_modbus_type = 1,                    //modbus模式,0: master     1: slave
             .product_modbus_baud = 115200,
             .product_modbus_addr = 1,
             .product_relay_ctrl_port = "/dev/ttyAS2",    //继电器modbus控制端口路径

+ 90 - 90
pro/src/json_handle.c

@@ -221,7 +221,7 @@ char* user_info_to_json(void)
     cJSON_AddStringToObject(user_data_filed,"createTime","2024-01-23 22:15:10");
     cJSON_AddStringToObject(user_data_filed,"updateBy","");
     cJSON_AddStringToObject(user_data_filed,"updateTime","");    
-    cJSON_AddStringToObject(user_data_filed,"remark",language_root_name[__globalDeviceManage._global_device_info->product_language]);  
+    cJSON_AddStringToObject(user_data_filed,"remark",language_root_name[__globalDeviceManage._globalDevInfo.product_language]);  
     //添加参数信息
     cJSON* param_data_filed = cJSON_CreateObject();  
     cJSON_AddStringToObject(param_data_filed,"@type","java.util.HashMap");
@@ -252,7 +252,7 @@ char* user_info_to_json(void)
     cJSON_AddItemToObject(role_data_filed, "params", role_param_data_filed); 
     //添加信息
     cJSON_AddNumberToObject(role_data_filed,"roleId",_GlobalUserInfoNew.roleID);
-    cJSON_AddStringToObject(role_data_filed,"roleName",language_root_name[__globalDeviceManage._global_device_info->product_language]);
+    cJSON_AddStringToObject(role_data_filed,"roleName",language_root_name[__globalDeviceManage._globalDevInfo.product_language]);
     cJSON_AddStringToObject(role_data_filed,"roleKey","admin");   
     cJSON_AddNumberToObject(role_data_filed,"roleSort",1);
     cJSON_AddStringToObject(role_data_filed,"dataScope","1");   
@@ -306,7 +306,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(data1_filed,"alwaysShow",true);  
     //meta 
     cJSON* meta_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(meta_data1_filed,"title",language_power_monitor[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(meta_data1_filed,"title",language_power_monitor[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(meta_data1_filed,"icon","monitor");   
     cJSON_AddBoolToObject(meta_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(meta_data1_filed,"link","");     
@@ -319,7 +319,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children1_data1_filed,"hidden",false); 
     cJSON_AddStringToObject(children1_data1_filed,"component","power/monitorall/index");  
     cJSON* children1_meta1_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children1_meta1_data1_filed,"title",language_power_sts_monitor[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children1_meta1_data1_filed,"title",language_power_sts_monitor[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children1_meta1_data1_filed,"icon","monitor");   
     cJSON_AddBoolToObject(children1_meta1_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children1_meta1_data1_filed,"link","");    
@@ -331,7 +331,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children1_data2_filed,"hidden",false); 
     cJSON_AddStringToObject(children1_data2_filed,"component","power/channelstatus/index");  
     cJSON* children1_meta1_data2_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children1_meta1_data2_filed,"title",language_power_channel_sts_monitor[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children1_meta1_data2_filed,"title",language_power_channel_sts_monitor[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children1_meta1_data2_filed,"icon","server");   
     cJSON_AddBoolToObject(children1_meta1_data2_filed,"noCache",false); 
     cJSON_AddStringToObject(children1_meta1_data2_filed,"link","");    
@@ -344,7 +344,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children1_data2_1_filed,"hidden",false); 
     cJSON_AddStringToObject(children1_data2_1_filed,"component","power/switchtatus/index");  
     cJSON* children1_meta1_data2_1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children1_meta1_data2_1_filed,"title",language_power_switch_sts_monitor[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children1_meta1_data2_1_filed,"title",language_power_switch_sts_monitor[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children1_meta1_data2_1_filed,"icon","switch");   
     cJSON_AddBoolToObject(children1_meta1_data2_1_filed,"noCache",false); 
     cJSON_AddStringToObject(children1_meta1_data2_1_filed,"link","");    
@@ -357,7 +357,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children1_data3_filed,"hidden",false); 
     cJSON_AddStringToObject(children1_data3_filed,"component","power/monitorhistory/index");  
     cJSON* children1_meta1_data3_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children1_meta1_data3_filed,"title",language_power_history_search[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children1_meta1_data3_filed,"title",language_power_history_search[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children1_meta1_data3_filed,"icon","chart");   
     cJSON_AddBoolToObject(children1_meta1_data3_filed,"noCache",false); 
     cJSON_AddStringToObject(children1_meta1_data3_filed,"link","");    
@@ -375,7 +375,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddStringToObject(data2_filed,"component","Layout");
     cJSON_AddBoolToObject(data2_filed,"alwaysShow",true);  
     cJSON* meta_data2_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(meta_data2_filed,"title",language_sensor_monitoring[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(meta_data2_filed,"title",language_sensor_monitoring[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(meta_data2_filed,"icon","slider");   
     cJSON_AddBoolToObject(meta_data2_filed,"noCache",false); 
     cJSON_AddStringToObject(meta_data2_filed,"link","");     
@@ -388,7 +388,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children2_data1_filed,"hidden",false); 
     cJSON_AddStringToObject(children2_data1_filed,"component","sensor/sensorStatus/index");  
     cJSON* children2_meta1_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children2_meta1_data1_filed,"title",language_sensor_status_monitoring[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children2_meta1_data1_filed,"title",language_sensor_status_monitoring[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children2_meta1_data1_filed,"icon","monitor");   
     cJSON_AddBoolToObject(children2_meta1_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children2_meta1_data1_filed,"link","");    
@@ -400,7 +400,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children2_data2_filed,"hidden",false); 
     cJSON_AddStringToObject(children2_data2_filed,"component","sensor/sensorHistory/index");  
     cJSON* children2_meta2_data2_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children2_meta2_data2_filed,"title",language_sensor_history_search[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children2_meta2_data2_filed,"title",language_sensor_history_search[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children2_meta2_data2_filed,"icon","chart");   
     cJSON_AddBoolToObject(children2_meta2_data2_filed,"noCache",false); 
     cJSON_AddStringToObject(children2_meta2_data2_filed,"link","");    
@@ -418,7 +418,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddStringToObject(data3_filed,"component","Layout");
     cJSON_AddBoolToObject(data3_filed,"alwaysShow",true);  
     cJSON* meta_data3_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(meta_data3_filed,"title",language_Alarm_protection[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(meta_data3_filed,"title",language_Alarm_protection[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(meta_data3_filed,"icon","bug");   
     cJSON_AddBoolToObject(meta_data3_filed,"noCache",false); 
     cJSON_AddStringToObject(meta_data3_filed,"link","");     
@@ -431,7 +431,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children3_data1_filed,"hidden",false); 
     cJSON_AddStringToObject(children3_data1_filed,"component","jgbh/xtjg/index");  
     cJSON* children3_meta1_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children3_meta1_data1_filed,"title",language_Alarm_System[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children3_meta1_data1_filed,"title",language_Alarm_System[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children3_meta1_data1_filed,"icon","list");   
     cJSON_AddBoolToObject(children3_meta1_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children3_meta1_data1_filed,"link","");    
@@ -443,7 +443,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children3_data2_filed,"hidden",false); 
     cJSON_AddStringToObject(children3_data2_filed,"component","jgbh/fzsz/index");  
     cJSON* children3_meta2_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children3_meta2_data1_filed,"title",language_Alarm_Threshold_rule[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children3_meta2_data1_filed,"title",language_Alarm_Threshold_rule[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children3_meta2_data1_filed,"icon","build");   
     cJSON_AddBoolToObject(children3_meta2_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children3_meta2_data1_filed,"link","");    
@@ -462,7 +462,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddStringToObject(data4_filed,"component","Layout");
     cJSON_AddBoolToObject(data4_filed,"alwaysShow",true);  
     cJSON* meta_data4_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(meta_data4_filed,"title",language_log_information[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(meta_data4_filed,"title",language_log_information[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(meta_data4_filed,"icon","log");   
     cJSON_AddBoolToObject(meta_data4_filed,"noCache",false); 
     cJSON_AddStringToObject(meta_data4_filed,"link","");     
@@ -475,7 +475,7 @@ char* user_routers_info_to_json(void)
    // cJSON_AddBoolToObject(children4_data1_filed,"hidden",false); 
    // cJSON_AddStringToObject(children4_data1_filed,"component","rzxx/gjrz/index");  
    // cJSON* children4_meta1_data1_filed = cJSON_CreateObject(); 
-   // cJSON_AddStringToObject(children4_meta1_data1_filed,"title",language_log_Alarm[__globalDeviceManage._global_device_info->product_language]);   
+   // cJSON_AddStringToObject(children4_meta1_data1_filed,"title",language_log_Alarm[__globalDeviceManage._globalDevInfo.product_language]);   
    // cJSON_AddStringToObject(children4_meta1_data1_filed,"icon","#");   
    // cJSON_AddBoolToObject(children4_meta1_data1_filed,"noCache",false); 
    // cJSON_AddStringToObject(children4_meta1_data1_filed,"link","");    
@@ -487,7 +487,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children4_data2_filed,"hidden",false); 
     cJSON_AddStringToObject(children4_data2_filed,"component","rzxx/czrz/index");  
     cJSON* children4_meta2_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children4_meta2_data1_filed,"title",language_log_operation[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children4_meta2_data1_filed,"title",language_log_operation[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children4_meta2_data1_filed,"icon","chart");   
     cJSON_AddBoolToObject(children4_meta2_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children4_meta2_data1_filed,"link","");    
@@ -499,7 +499,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children4_data3_filed,"hidden",false); 
     cJSON_AddStringToObject(children4_data3_filed,"component","rzxx/yxrz/index");  
     cJSON* children4_meta3_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children4_meta3_data1_filed,"title",language_log_running[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children4_meta3_data1_filed,"title",language_log_running[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children4_meta3_data1_filed,"icon","documentation");   
     cJSON_AddBoolToObject(children4_meta3_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children4_meta3_data1_filed,"link","");    
@@ -518,7 +518,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(data_filed,"alwaysShow",true);    
     //meta
     cJSON* meta_data_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(meta_data_filed,"title",language_user_manage[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(meta_data_filed,"title",language_user_manage[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(meta_data_filed,"icon","system");   
     cJSON_AddBoolToObject(meta_data_filed,"noCache",false); 
     cJSON_AddStringToObject(meta_data_filed,"link","");     
@@ -531,7 +531,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children_data_filed,"hidden",false); 
     cJSON_AddStringToObject(children_data_filed,"component","system/user/index");  
     cJSON* children_meta_data_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children_meta_data_filed,"title",language_user_manage[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children_meta_data_filed,"title",language_user_manage[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children_meta_data_filed,"icon","user");   
     cJSON_AddBoolToObject(children_meta_data_filed,"noCache",false); 
     cJSON_AddStringToObject(children_meta_data_filed,"link","");    
@@ -543,7 +543,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children1_data_filed,"hidden",false); 
     cJSON_AddStringToObject(children1_data_filed,"component","system/role/index");  
     cJSON* children_meta1_data_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children_meta1_data_filed,"title",language_role_manage[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children_meta1_data_filed,"title",language_role_manage[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children_meta1_data_filed,"icon","peoples");   
     cJSON_AddBoolToObject(children_meta1_data_filed,"noCache",false); 
     cJSON_AddStringToObject(children_meta1_data_filed,"link","");    
@@ -555,7 +555,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children2_data_filed,"hidden",false); 
     cJSON_AddStringToObject(children2_data_filed,"component","system/menu/index");  
     cJSON* children_meta2_data_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children_meta2_data_filed,"title",language_menu_manage[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children_meta2_data_filed,"title",language_menu_manage[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children_meta2_data_filed,"icon","tree-table");   
     cJSON_AddBoolToObject(children_meta2_data_filed,"noCache",false); 
     cJSON_AddStringToObject(children_meta2_data_filed,"link","");    
@@ -573,7 +573,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddStringToObject(data5_filed,"component","Layout");
     cJSON_AddBoolToObject(data5_filed,"alwaysShow",true);  
     cJSON* meta_data5_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(meta_data5_filed,"title",language_communication_management[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(meta_data5_filed,"title",language_communication_management[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(meta_data5_filed,"icon","message");   
     cJSON_AddBoolToObject(meta_data5_filed,"noCache",false); 
     cJSON_AddStringToObject(meta_data5_filed,"link","");     
@@ -586,7 +586,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children5_data1_filed,"hidden",false); 
     cJSON_AddStringToObject(children5_data1_filed,"component","txgl/wksz/index");  
     cJSON* children5_meta1_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children5_meta1_data1_filed,"title",language_net_install[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children5_meta1_data1_filed,"title",language_net_install[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children5_meta1_data1_filed,"icon","input");   
     cJSON_AddBoolToObject(children5_meta1_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children5_meta1_data1_filed,"link","");    
@@ -598,7 +598,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children5_data2_filed,"hidden",false); 
     cJSON_AddStringToObject(children5_data2_filed,"component","txgl/rssz/index");  
     cJSON* children5_meta2_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children5_meta2_data1_filed,"title",language_RS485_install[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children5_meta2_data1_filed,"title",language_RS485_install[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children5_meta2_data1_filed,"icon","build");   
     cJSON_AddBoolToObject(children5_meta2_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children5_meta2_data1_filed,"link","");    
@@ -616,7 +616,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddStringToObject(data6_filed,"component","Layout");
     cJSON_AddBoolToObject(data6_filed,"alwaysShow",true);  
     cJSON* meta_data6_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(meta_data6_filed,"title",language_serve_manage[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(meta_data6_filed,"title",language_serve_manage[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(meta_data6_filed,"icon","server");   
     cJSON_AddBoolToObject(meta_data6_filed,"noCache",false); 
     cJSON_AddStringToObject(meta_data6_filed,"link","");     
@@ -629,7 +629,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children6_data1_filed,"hidden",false); 
     cJSON_AddStringToObject(children6_data1_filed,"component","fwgl/smtpsz/index");  
     cJSON* children6_meta1_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children6_meta1_data1_filed,"title",language_SMTP_install[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children6_meta1_data1_filed,"title",language_SMTP_install[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children6_meta1_data1_filed,"icon","edit");   
     cJSON_AddBoolToObject(children6_meta1_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children6_meta1_data1_filed,"link","");    
@@ -641,7 +641,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children6_data2_filed,"hidden",false); 
     cJSON_AddStringToObject(children6_data2_filed,"component","fwgl/snmpsz/index");  
     cJSON* children6_meta2_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children6_meta2_data1_filed,"title",language_SNMP_install[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children6_meta2_data1_filed,"title",language_SNMP_install[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children6_meta2_data1_filed,"icon","date-range");   
     cJSON_AddBoolToObject(children6_meta2_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children6_meta2_data1_filed,"link","");    
@@ -653,7 +653,7 @@ char* user_routers_info_to_json(void)
    // cJSON_AddBoolToObject(children6_data3_filed,"hidden",false); 
    // cJSON_AddStringToObject(children6_data3_filed,"component","fwgl/stsz/index");  
    // cJSON* children6_meta3_data1_filed = cJSON_CreateObject(); 
-   // cJSON_AddStringToObject(children6_meta3_data1_filed,"title",language_SNMP_TRAP_install[__globalDeviceManage._global_device_info->product_language]);   
+   // cJSON_AddStringToObject(children6_meta3_data1_filed,"title",language_SNMP_TRAP_install[__globalDeviceManage._globalDevInfo.product_language]);   
    // cJSON_AddStringToObject(children6_meta3_data1_filed,"icon","#");   
    // cJSON_AddBoolToObject(children6_meta3_data1_filed,"noCache",false); 
    // cJSON_AddStringToObject(children6_meta3_data1_filed,"link","");    
@@ -665,7 +665,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children6_data4_filed,"hidden",false); 
     cJSON_AddStringToObject(children6_data4_filed,"component","fwgl/mqsz/index");  
     cJSON* children6_meta4_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children6_meta4_data1_filed,"title",language_MQTT_iot_install[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children6_meta4_data1_filed,"title",language_MQTT_iot_install[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children6_meta4_data1_filed,"icon","dashboard");   
     cJSON_AddBoolToObject(children6_meta4_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children6_meta4_data1_filed,"link","");    
@@ -677,7 +677,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children6_data5_filed,"hidden",false); 
     cJSON_AddStringToObject(children6_data5_filed,"component","fwgl/ntpsz/index");  
     cJSON* children6_meta5_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children6_meta5_data1_filed,"title",language_NTP_install[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children6_meta5_data1_filed,"title",language_NTP_install[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children6_meta5_data1_filed,"icon","date-range");   
     cJSON_AddBoolToObject(children6_meta5_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children6_meta5_data1_filed,"link","");    
@@ -689,7 +689,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children6_data6_filed,"hidden",false); 
     cJSON_AddStringToObject(children6_data6_filed,"component","fwgl/dssz/index");  
     cJSON* children6_meta6_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children6_meta6_data1_filed,"title",language_Timing_install[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children6_meta6_data1_filed,"title",language_Timing_install[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children6_meta6_data1_filed,"icon","date");   
     cJSON_AddBoolToObject(children6_meta6_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children6_meta6_data1_filed,"link","");    
@@ -701,7 +701,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children6_data7_filed,"hidden",false); 
     cJSON_AddStringToObject(children6_data7_filed,"component","fwgl/sxsz/index");  
     cJSON* children6_meta7_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children6_meta7_data1_filed,"title",language_Sequential_setting[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children6_meta7_data1_filed,"title",language_Sequential_setting[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children6_meta7_data1_filed,"icon","drag");   
     cJSON_AddBoolToObject(children6_meta7_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children6_meta7_data1_filed,"link","");    
@@ -713,7 +713,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children6_data8_filed,"hidden",false); 
     cJSON_AddStringToObject(children6_data8_filed,"component","fwgl/fzsz/index");  
     cJSON* children6_meta8_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children6_meta8_data1_filed,"title",language_Group_setting[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children6_meta8_data1_filed,"title",language_Group_setting[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children6_meta8_data1_filed,"icon","education");   
     cJSON_AddBoolToObject(children6_meta8_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children6_meta8_data1_filed,"link","");    
@@ -734,7 +734,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddStringToObject(data7_filed,"component","Layout");
     cJSON_AddBoolToObject(data7_filed,"alwaysShow",true);  
     cJSON* meta_data7_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(meta_data7_filed,"title",language_maintenance_equipment[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(meta_data7_filed,"title",language_maintenance_equipment[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(meta_data7_filed,"icon","upload");   
     cJSON_AddBoolToObject(meta_data7_filed,"noCache",false); 
     cJSON_AddStringToObject(meta_data7_filed,"link","");     
@@ -747,7 +747,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children7_data1_filed,"hidden",false); 
     cJSON_AddStringToObject(children7_data1_filed,"component","sbwh/sbcq/index");  
     cJSON* children7_meta1_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children7_meta1_data1_filed,"title",language_Device_restart[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children7_meta1_data1_filed,"title",language_Device_restart[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children7_meta1_data1_filed,"icon","button");   
     cJSON_AddBoolToObject(children7_meta1_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children7_meta1_data1_filed,"link","");    
@@ -759,7 +759,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children7_data2_filed,"hidden",false); 
     cJSON_AddStringToObject(children7_data2_filed,"component","sbwh/gjsj/index");  
     cJSON* children7_meta2_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children7_meta2_data1_filed,"title",language_firmware_upgrade[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children7_meta2_data1_filed,"title",language_firmware_upgrade[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children7_meta2_data1_filed,"icon","redis-list");   
     cJSON_AddBoolToObject(children7_meta2_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children7_meta2_data1_filed,"link","");    
@@ -771,7 +771,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children7_data3_filed,"hidden",false); 
     cJSON_AddStringToObject(children7_data3_filed,"component","sbwh/hhccsz/index");  
     cJSON* children7_meta3_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children7_meta3_data1_filed,"title",language_back_factor_upgrade[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children7_meta3_data1_filed,"title",language_back_factor_upgrade[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children7_meta3_data1_filed,"icon","server");   
     cJSON_AddBoolToObject(children7_meta3_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children7_meta3_data1_filed,"link","");    
@@ -783,7 +783,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children7_data4_filed,"hidden",false); 
     cJSON_AddStringToObject(children7_data4_filed,"component","sbwh/pzdrdc/index");  
     cJSON* children7_meta4_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children7_meta4_data1_filed,"title",language_Configure_inport_export[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children7_meta4_data1_filed,"title",language_Configure_inport_export[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children7_meta4_data1_filed,"icon","upload");   
     cJSON_AddBoolToObject(children7_meta4_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children7_meta4_data1_filed,"link","");    
@@ -795,7 +795,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children7_data5_filed,"hidden",false); 
     cJSON_AddStringToObject(children7_data5_filed,"component","sbwh/shfw/index");  
     cJSON* children7_meta5_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children7_meta5_data1_filed,"title",language_after_sales_service[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children7_meta5_data1_filed,"title",language_after_sales_service[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children7_meta5_data1_filed,"icon","peoples");   
     cJSON_AddBoolToObject(children7_meta5_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children7_meta5_data1_filed,"link","");    
@@ -807,7 +807,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddBoolToObject(children7_data6_filed,"hidden",false); 
     cJSON_AddStringToObject(children7_data6_filed,"component","sbwh/gysb/index");  
     cJSON* children7_meta6_data1_filed = cJSON_CreateObject(); 
-    cJSON_AddStringToObject(children7_meta6_data1_filed,"title",language_about_Equipment[__globalDeviceManage._global_device_info->product_language]);   
+    cJSON_AddStringToObject(children7_meta6_data1_filed,"title",language_about_Equipment[__globalDeviceManage._globalDevInfo.product_language]);   
     cJSON_AddStringToObject(children7_meta6_data1_filed,"icon","table");   
     cJSON_AddBoolToObject(children7_meta6_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children7_meta6_data1_filed,"link","");    
@@ -1128,7 +1128,7 @@ char* json_to_system_config_info(void)
     cJSON* data_field = cJSON_CreateObject();   
 
     // 添加基本键值对
-    int nLanguageID=__globalDeviceManage._global_device_info->product_language+1;
+    int nLanguageID=__globalDeviceManage._globalDevInfo.product_language+1;
     cJSON_AddNumberToObject(data_field, "systemLanguage", nLanguageID);
     //返回websockt
     // cJSON_AddStringToObject(data_field,"webSocket","ws://192.168.2.132:6785/websocket/"); 
@@ -1167,18 +1167,18 @@ int json_to_switch_language(const char* str)
         log_d(cjson_language->valuestring);
         if(strcmp(cjson_language->valuestring,"zh-CN")==0)
         {
-            __globalDeviceManage._global_device_info->product_language = 0 ;
+            __globalDeviceManage._globalDevInfo.product_language = 0 ;
         }
        else  if(strcmp(cjson_language->valuestring,"en-US")==0)
         {
-            __globalDeviceManage._global_device_info->product_language = 1 ;
+            __globalDeviceManage._globalDevInfo.product_language = 1 ;
         }
         else  if(strcmp(cjson_language->valuestring,"ru-RU")==0)
         {
-            __globalDeviceManage._global_device_info->product_language = 2 ;
+            __globalDeviceManage._globalDevInfo.product_language = 2 ;
         }
         else
-            __globalDeviceManage._global_device_info->product_language = 0 ;
+            __globalDeviceManage._globalDevInfo.product_language = 0 ;
         
     }
     cJSON_Delete(cjson);
@@ -2158,7 +2158,7 @@ char *over_all_data_t_ac_to_json(_OverAllPwrAckInfo *_over_all_pwr_back_info,_Ov
     {
         date_Data_info[i] = cJSON_CreateObject();
         // 查询数据库总电源信息 传给所申请的参数结构体
-        if (dev_search_time_t_ac_power_info(__globalDeviceManage.db, __globalDeviceManage._global_device_info->product_id, i,total_type, &__globalPowerInfo,_over_all_sts_monitor->start_time,_over_all_sts_monitor->end_time) != 0)
+        if (dev_search_time_t_ac_power_info(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, i,total_type, &__globalPowerInfo,_over_all_sts_monitor->start_time,_over_all_sts_monitor->end_time) != 0)
         {
             log_e("serach total voltage err.");
         }
@@ -2363,7 +2363,7 @@ char* over_chn_pwr_monitor_to_json(_OverChnPwrAckInfo* _over_chn_pwr_back_info)
         cJSON_AddStringToObject(data_filed,"firingInterval",temp);
         sprintf(temp,"%d",_chnPwrTemp->product_ch_stop_delay/1000);     
         cJSON_AddStringToObject(data_filed,"closeInterval",temp);
-        if (_chnPwrTemp->product_type==TREE_AC_TYPE||__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+        if (_chnPwrTemp->product_type==TREE_AC_TYPE||__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
         {
             if (_chnPwrTemp->product_phType>=0&&_chnPwrTemp->product_phType<3)
             {
@@ -2671,8 +2671,8 @@ char* over_all_sensor_info_to_json(_OverSensorBackInfo* _over_all_sensor_back_in
         cJSON_AddNumberToObject(data_filed,"sensorAddr",_temp->sensorAddr);
         cJSON_AddStringToObject(data_filed,"cgqtd",_temp->sensorvaluech);
         cJSON_AddNumberToObject(data_filed,"airPressureValue",_temp->airPressureValue);
-        cJSON_AddStringToObject(data_filed,"productName",__globalDeviceManage._global_device_info->product_name);
-        cJSON_AddNumberToObject(data_filed,"productId",__globalDeviceManage._global_device_info->product_id);
+        cJSON_AddStringToObject(data_filed,"productName",__globalDeviceManage._globalDevInfo.product_name);
+        cJSON_AddNumberToObject(data_filed,"productId",__globalDeviceManage._globalDevInfo.product_id);
         sprintf(temp,"%0.2f",_temp->airflowValue);
         cJSON_AddStringToObject(data_filed,"airflowValue",temp);
 
@@ -2695,19 +2695,19 @@ char* over_all_sensor_info_to_json(_OverSensorBackInfo* _over_all_sensor_back_in
         //switch (_temp->sensorType)
         //{
         //case SENSOR_TYPE_TEMPERATURE:
-        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._global_device_info->product_language]);//_temp->sensorName);
+        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._globalDevInfo.product_language]);//_temp->sensorName);
         //    break;
         //case SENSOR_TYPE_SMOKE:
-        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._global_device_info->product_language]);
+        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._globalDevInfo.product_language]);
         //    break;
         //case SENSOR_TYPE_WATER:
-        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._global_device_info->product_language]);
+        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._globalDevInfo.product_language]);
         //    break;
         //case SENSOR_TYPE_GAS:
-        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._global_device_info->product_language]);
+        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._globalDevInfo.product_language]);
         //    break;
         //case SENSOR_TYPE_AIR_PRESS:
-        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._global_device_info->product_language]);
+        //    cJSON_AddStringToObject(data_filed,"sensorName",language_temperature[__globalDeviceManage._globalDevInfo.product_language]);
         //    break;
         //default:
         //    break;
@@ -2770,11 +2770,11 @@ char *breaker_status_ack_to_json(GlobalDeviceManager *gm,int slave)
                 strcpy(info->product_ch_name,buff);
                 if(slave)
                 {
-                    sprintf(buff,"%s %d",__globalDeviceManage._global_device_info->product_name, slave);
+                    sprintf(buff,"%s %d",__globalDeviceManage._globalDevInfo.product_name, slave);
                     strcpy(info->productName,buff);
                 }else
-                    strcpy(info->productName,__globalDeviceManage._global_device_info->product_name);
-                strcpy(info->product_number,__globalDeviceManage._global_device_info->product_number);
+                    strcpy(info->productName,__globalDeviceManage._globalDevInfo.product_name);
+                strcpy(info->product_number,__globalDeviceManage._globalDevInfo.product_number);
                 strcpy(info->productChids,temp->breaker_chns_name);
                 info->switch_id = temp->breaker_id;
                 info->status = temp->breaker_status;
@@ -2940,13 +2940,13 @@ char* over_sensor_history_info_to_json(_OverSensorBackInfo* _over_all_sensor_bac
                 cJSON_AddNumberToObject(data,"sensorType",_over_all_sensor_back_info->sensorType);
                 cJSON* type_data_array = cJSON_CreateArray();
                 cJSON* type_data_temp = cJSON_CreateObject();
-                cJSON_AddStringToObject(type_data_temp,"typeName",language_temperature[__globalDeviceManage._global_device_info->product_language]);
+                cJSON_AddStringToObject(type_data_temp,"typeName",language_temperature[__globalDeviceManage._globalDevInfo.product_language]);
                 cJSON* ydate_temp_array = cJSON_CreateFloatArray(_over_all_sensor_back_info->temp_humi_sensor.ydata[0],TOTAL_COUNT);
                 cJSON_AddItemToObject(type_data_temp,"ydata",ydate_temp_array);
                 cJSON_AddStringToObject(type_data_temp,"type","0");
                 cJSON_AddItemToArray(type_data_array,type_data_temp);
                 cJSON* type_data_humi = cJSON_CreateObject();
-                cJSON_AddStringToObject(type_data_humi,"typeName",language_humidity[__globalDeviceManage._global_device_info->product_language]);
+                cJSON_AddStringToObject(type_data_humi,"typeName",language_humidity[__globalDeviceManage._globalDevInfo.product_language]);
                 cJSON* ydate_humi_array = cJSON_CreateFloatArray(_over_all_sensor_back_info->temp_humi_sensor.ydata[1],TOTAL_COUNT);
                 cJSON_AddItemToObject(type_data_humi,"ydata",ydate_humi_array);
                 cJSON_AddStringToObject(type_data_humi,"type","1");
@@ -2965,7 +2965,7 @@ char* over_sensor_history_info_to_json(_OverSensorBackInfo* _over_all_sensor_bac
                 cJSON_AddNumberToObject(data,"sensorType",_over_all_sensor_back_info->sensorType);
                 cJSON* type_data_array = cJSON_CreateArray();
                 cJSON* type_data_gas = cJSON_CreateObject();
-                cJSON_AddStringToObject(type_data_gas,"typeName",language_atmosphere_gas[__globalDeviceManage._global_device_info->product_language]);
+                cJSON_AddStringToObject(type_data_gas,"typeName",language_atmosphere_gas[__globalDeviceManage._globalDevInfo.product_language]);
                 cJSON* ydate_gas_array = cJSON_CreateFloatArray(_over_all_sensor_back_info->gas_sensor.ydata,TOTAL_COUNT);
                 cJSON_AddItemToObject(type_data_gas,"ydata",ydate_gas_array);
                 cJSON_AddStringToObject(type_data_gas,"type","0");
@@ -2984,13 +2984,13 @@ char* over_sensor_history_info_to_json(_OverSensorBackInfo* _over_all_sensor_bac
                 cJSON_AddNumberToObject(data,"sensorType",_over_all_sensor_back_info->sensorType);
                 cJSON* type_data_array = cJSON_CreateArray();
                 cJSON* type_data_air = cJSON_CreateObject();
-                cJSON_AddStringToObject(type_data_air,"typeName",language_atmosphere_airflow[__globalDeviceManage._global_device_info->product_language]);
+                cJSON_AddStringToObject(type_data_air,"typeName",language_atmosphere_airflow[__globalDeviceManage._globalDevInfo.product_language]);
                 cJSON* ydate_air_array = cJSON_CreateFloatArray(_over_all_sensor_back_info->air_press_sensor.ydata[0],TOTAL_COUNT);
                 cJSON_AddItemToObject(type_data_air,"ydata",ydate_air_array);
                 cJSON_AddStringToObject(type_data_air,"type","0");
                 cJSON_AddItemToArray(type_data_array,type_data_air);
                 cJSON* type_data_press = cJSON_CreateObject();
-                cJSON_AddStringToObject(type_data_press,"typeName",language_atmosphere_pressure[__globalDeviceManage._global_device_info->product_language]);
+                cJSON_AddStringToObject(type_data_press,"typeName",language_atmosphere_pressure[__globalDeviceManage._globalDevInfo.product_language]);
                 cJSON* ydate_press_array = cJSON_CreateFloatArray(_over_all_sensor_back_info->air_press_sensor.ydata[1],TOTAL_COUNT);
                 cJSON_AddItemToObject(type_data_press,"ydata",ydate_press_array);
                 cJSON_AddStringToObject(type_data_press,"type","1");
@@ -3019,8 +3019,8 @@ char* over_sensor_history_info_to_json(_OverSensorBackInfo* _over_all_sensor_bac
         cJSON* data_filed = cJSON_CreateObject();
         cJSON_AddNumberToObject(data_filed, "accessControlStatus",_over_all_sensor_back_info->accessControlStatus);
         cJSON_AddNumberToObject(data_filed,"sensorAddr",_over_all_sensor_back_info->sensorAddr);
-            cJSON_AddStringToObject(data_filed,"productName",__globalDeviceManage._global_device_info->product_name);
-            cJSON_AddStringToObject(data_filed,"productNumber",__globalDeviceManage._global_device_info->product_number);
+            cJSON_AddStringToObject(data_filed,"productName",__globalDeviceManage._globalDevInfo.product_name);
+            cJSON_AddStringToObject(data_filed,"productNumber",__globalDeviceManage._globalDevInfo.product_number);
         cJSON_AddNumberToObject(data_filed, "alarmStatus",_over_all_sensor_back_info->alarmStatus);
         cJSON_AddNumberToObject(data_filed,"sensorBaud",_over_all_sensor_back_info->sensorBaud);
         cJSON_AddStringToObject(data_filed,"comSlogan",_over_all_sensor_back_info->comSlogan);
@@ -3068,15 +3068,15 @@ char* alarm_info_to_json(_AlarmAckInfo* _alarm_ack_info,int nAllNumber)
         cJSON_AddStringToObject(data_filed,"alarmDate",_temp->alarmDate);
         if (_temp->alarmType==0)
         {
-            cJSON_AddStringToObject(data_filed,"alarmType",language_alarm_Type_Power[__globalDeviceManage._global_device_info->product_language]);
+            cJSON_AddStringToObject(data_filed,"alarmType",language_alarm_Type_Power[__globalDeviceManage._globalDevInfo.product_language]);
         }
         else if (_temp->alarmType==1)
         {
-            cJSON_AddStringToObject(data_filed,"alarmType",language_alarm_Type_Sensor[__globalDeviceManage._global_device_info->product_language]);
+            cJSON_AddStringToObject(data_filed,"alarmType",language_alarm_Type_Sensor[__globalDeviceManage._globalDevInfo.product_language]);
         }
         else if (_temp->alarmType==2)
         {
-             cJSON_AddStringToObject(data_filed,"alarmType",language_alarm_Type_Network[__globalDeviceManage._global_device_info->product_language]);
+             cJSON_AddStringToObject(data_filed,"alarmType",language_alarm_Type_Network[__globalDeviceManage._globalDevInfo.product_language]);
         }
         else cJSON_AddStringToObject(data_filed,"alarmType","Unknown");
 
@@ -3125,9 +3125,9 @@ char* alarm_type_info_to_json(_AlarmAckInfo* _alarm_ack_info,int nAlarmNum)
         // cJSON_AddStringToObject(data_filed,"alarmType",temp);
         switch (_temp->alarmType)
         {
-            case 0:cJSON_AddStringToObject(data_filed,"alarmType",language_log_Power[__globalDeviceManage._global_device_info->product_language]);break;
-            case 3:cJSON_AddStringToObject(data_filed,"alarmType",language_opera_log_operation[__globalDeviceManage._global_device_info->product_language]);break;
-            case 4:cJSON_AddStringToObject(data_filed,"type",language_run_log_running[__globalDeviceManage._global_device_info->product_language]);break;
+            case 0:cJSON_AddStringToObject(data_filed,"alarmType",language_log_Power[__globalDeviceManage._globalDevInfo.product_language]);break;
+            case 3:cJSON_AddStringToObject(data_filed,"alarmType",language_opera_log_operation[__globalDeviceManage._globalDevInfo.product_language]);break;
+            case 4:cJSON_AddStringToObject(data_filed,"type",language_run_log_running[__globalDeviceManage._globalDevInfo.product_language]);break;
         }
         
         cJSON_AddStringToObject(data_filed,"deviceNumber",_temp->deviceNumber);
@@ -3184,9 +3184,9 @@ char* alarm_ctrl_type_info_to_json(_AlarmAckInfo* _alarm_ack_info,int nAlarmNum)
         // cJSON_AddStringToObject(data_filed,"alarmType",temp);
         //switch (_temp->alarmType)
         //{
-        //    case 0:cJSON_AddStringToObject(data_filed,"alarmType",language_log_Power[__globalDeviceManage._global_device_info->product_language]);break;
-        //    case 3:cJSON_AddStringToObject(data_filed,"alarmType",language_opera_log_operation[__globalDeviceManage._global_device_info->product_language]);break;
-        //    case 4:cJSON_AddStringToObject(data_filed,"alarmType",language_run_log_running[__globalDeviceManage._global_device_info->product_language]);break;
+        //    case 0:cJSON_AddStringToObject(data_filed,"alarmType",language_log_Power[__globalDeviceManage._globalDevInfo.product_language]);break;
+        //    case 3:cJSON_AddStringToObject(data_filed,"alarmType",language_opera_log_operation[__globalDeviceManage._globalDevInfo.product_language]);break;
+        //    case 4:cJSON_AddStringToObject(data_filed,"alarmType",language_run_log_running[__globalDeviceManage._globalDevInfo.product_language]);break;
         //}
         //cJSON_AddStringToObject(data_filed,"deviceNumber",_temp->deviceNumber);
         //cJSON_AddStringToObject(data_filed,"deviceName",_temp->deviceName);
@@ -3226,8 +3226,8 @@ char* alarm_power_threshold_to_json(GlobalPowerManger* _globalPowerManger)
     char Alarmtemp[32] = {0};
     sprintf(Closetemp, "%d", ALARM_CTRL_CLOSE_CH);
     sprintf(Alarmtemp, "%d", ALARM_CTRL_ALARM_ONLY);
-    // language_alarm_ctrl_Alarm[__globalDeviceManage._global_device_info->product_language]
-    // language_alarm_ctrl_CloseCH[__globalDeviceManage._global_device_info->product_language]
+    // language_alarm_ctrl_Alarm[__globalDeviceManage._globalDevInfo.product_language]
+    // language_alarm_ctrl_CloseCH[__globalDeviceManage._globalDevInfo.product_language]
 
     list_for_each_entry(_globalPowerMangerTemp, &_globalPowerManger->list, list)
     {
@@ -3373,8 +3373,8 @@ char* alarm_sensor_threshold_to_json(GlobalSensorManger* _globalSensorManger)
     char Alarmtemp[32] = {0};
     sprintf(Closetemp, "%d", ALARM_CTRL_CLOSE_CH);
     sprintf(Alarmtemp, "%d", ALARM_CTRL_ALARM_ONLY);
-    // language_alarm_ctrl_Alarm[__globalDeviceManage._global_device_info->product_language]
-    // language_alarm_ctrl_CloseCH[__globalDeviceManage._global_device_info->product_language]
+    // language_alarm_ctrl_Alarm[__globalDeviceManage._globalDevInfo.product_language]
+    // language_alarm_ctrl_CloseCH[__globalDeviceManage._globalDevInfo.product_language]
 
 
     //循环添加数据
@@ -3390,7 +3390,7 @@ char* alarm_sensor_threshold_to_json(GlobalSensorManger* _globalSensorManger)
             sprintf(temp, "%d", _globalSensorMangerTemp->sensor_id);
             cJSON_AddStringToObject(data_filed, "sensorId", temp);
             cJSON_AddNumberToObject(data_filed, "sensorType", _globalSensorMangerTemp->sensor_type);
-            cJSON_AddStringToObject(data_filed, "thresholdType",language_temperature[__globalDeviceManage._global_device_info->product_language]);
+            cJSON_AddStringToObject(data_filed, "thresholdType",language_temperature[__globalDeviceManage._globalDevInfo.product_language]);
             sprintf(temp, "%0.2f", _globalSensorMangerTemp->over_manager->sensor_val1_upper_threshold);
             cJSON_AddStringToObject(data_filed, "thresholdUpperValue", temp);
             sprintf(temp, "%0.2f", _globalSensorMangerTemp->over_manager->sensor_val1_lower_threshold);
@@ -3415,7 +3415,7 @@ char* alarm_sensor_threshold_to_json(GlobalSensorManger* _globalSensorManger)
             sprintf(temp, "%d", _globalSensorMangerTemp->sensor_id);
             cJSON_AddStringToObject(data_filed, "sensorId", temp);
             cJSON_AddNumberToObject(data_filed, "sensorType", _globalSensorMangerTemp->sensor_type);
-            cJSON_AddStringToObject(data_filed, "thresholdType", language_humidity[__globalDeviceManage._global_device_info->product_language]);
+            cJSON_AddStringToObject(data_filed, "thresholdType", language_humidity[__globalDeviceManage._globalDevInfo.product_language]);
             sprintf(temp, "%0.2f", _globalSensorMangerTemp->over_manager->sensor_val2_upper_threshold);
             cJSON_AddStringToObject(data_filed, "thresholdUpperValue", temp);
             sprintf(temp, "%0.2f", _globalSensorMangerTemp->over_manager->sensor_val2_lower_threshold);
@@ -3627,7 +3627,7 @@ char* ws_chn_status_ack_to_json(int type,_OverChnPwrAckInfo* _over_chn_pwr_back_
         cJSON_AddStringToObject(data_filed, "IPadress",_chnPwrTemp->ip_addr);
 #endif
         
-        if (_chnPwrTemp->product_type == TREE_AC_TYPE||gdm->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+        if (_chnPwrTemp->product_type == TREE_AC_TYPE||gdm->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
         {
             if (_chnPwrTemp->product_phType >= 0 && _chnPwrTemp->product_phType < 3)
             {
@@ -3723,11 +3723,11 @@ char* communication_rs_ack_to_json(ModbusInfo_t* _modbusInfo_t)
     cJSON* data_root_array = cJSON_CreateObject();  
     if ( !_modbusInfo_t->product_modbus_type)
     {
-        sprintf(temp,language_alarm_RS485_master[__globalDeviceManage._global_device_info->product_language]);
+        sprintf(temp,language_alarm_RS485_master[__globalDeviceManage._globalDevInfo.product_language]);
     }
     else
     {
-        sprintf(temp,language_alarm_RS485_slave[__globalDeviceManage._global_device_info->product_language]);
+        sprintf(temp,language_alarm_RS485_slave[__globalDeviceManage._globalDevInfo.product_language]);
     }
     cJSON_AddStringToObject(data_root_array, "mode", temp);  
 
@@ -4545,8 +4545,8 @@ char* service_sx_ack_to_json(int product_id, GlobalPowerManger * __PowerManage_t
         if (product_id == _powerSxManagerTemp->product_id && _powerSxManagerTemp->product_ch_id)
         {
             cJSON* data_filed = cJSON_CreateObject();   
-            cJSON_AddStringToObject(data_filed,"productName", __globalDeviceManage._global_device_info->product_name);
-            cJSON_AddNumberToObject(data_filed,"productId", __globalDeviceManage._global_device_info->product_id);
+            cJSON_AddStringToObject(data_filed,"productName", __globalDeviceManage._globalDevInfo.product_name);
+            cJSON_AddNumberToObject(data_filed,"productId", __globalDeviceManage._globalDevInfo.product_id);
             cJSON_AddStringToObject(data_filed,"productChName", _powerSxManagerTemp->product_ch_name);
             cJSON_AddNumberToObject(data_filed,"productChId",_powerSxManagerTemp->product_ch_id);
             if (_powerSxManagerTemp->_PowerSXManage)
@@ -4840,15 +4840,15 @@ char* GetRoleNameByID(int _RoleID,RoleInfo* __RoleInfo_t)
            {
                if (_RoleID == 1)
                {
-                   strcpy(nname, language_Role_Super_Admin[__globalDeviceManage._global_device_info->product_language]);
+                   strcpy(nname, language_Role_Super_Admin[__globalDeviceManage._globalDevInfo.product_language]);
                }
                else if (_RoleID == 2)
                {
-                   strcpy(nname, language_Role_Admin[__globalDeviceManage._global_device_info->product_language]);
+                   strcpy(nname, language_Role_Admin[__globalDeviceManage._globalDevInfo.product_language]);
                }
                else if (_RoleID == 3)
                {
-                   strcpy(nname, language_Role_User[__globalDeviceManage._global_device_info->product_language]);
+                   strcpy(nname, language_Role_User[__globalDeviceManage._globalDevInfo.product_language]);
                }
            }
             break;
@@ -5012,15 +5012,15 @@ char* service_userRole_ack_to_json(char* _userName,UserInfo* __UserInfo_t,RoleIn
         cJSON_AddStringToObject(data_filed, "roleId", buffer);
         if (_RoleInfoTemp1->roleID==1)
         {
-             cJSON_AddStringToObject(data_filed,"roleName",language_Role_Super_Admin[__globalDeviceManage._global_device_info->product_language]);
+             cJSON_AddStringToObject(data_filed,"roleName",language_Role_Super_Admin[__globalDeviceManage._globalDevInfo.product_language]);
         }
         else if (_RoleInfoTemp1->roleID==2)
         {
-             cJSON_AddStringToObject(data_filed,"roleName",language_Role_Admin[__globalDeviceManage._global_device_info->product_language]);
+             cJSON_AddStringToObject(data_filed,"roleName",language_Role_Admin[__globalDeviceManage._globalDevInfo.product_language]);
         }
         else
         {
-            cJSON_AddStringToObject(data_filed,"roleName",language_Role_User[__globalDeviceManage._global_device_info->product_language]);
+            cJSON_AddStringToObject(data_filed,"roleName",language_Role_User[__globalDeviceManage._globalDevInfo.product_language]);
         }
         //cJSON_AddStringToObject(data_filed,"roleName",_RoleInfoTemp1->roleName);
 

+ 1 - 1
pro/src/language_hashmap.c

@@ -84,7 +84,7 @@ void replace_sequences(char *str, HashTable *table) {
             HashEntry* pEnty= (HashEntry*)find_hash(table, key);
             if (pEnty)
             {
-               replacement=pEnty->value[__globalDeviceManage._global_device_info->product_language];  
+               replacement=pEnty->value[__globalDeviceManage._globalDevInfo.product_language];  
             }
             free(key); // 释放key占用的内存  
             if (replacement) {  

+ 1 - 1
pro/src/main.c

@@ -25,7 +25,7 @@ static void dev_ctrl_main(void* arg)
 
     //初始化modbus接口
     // g_modbus_init(&_globalDeviceManager->_globalRelaySampManger,
-    //             _globalDeviceManager->_global_device_info->product_relay_ctrl_port,
+    //             _globalDeviceManager->_globalDevInfo.product_relay_ctrl_port,
     //             0,//type
     //             1,//addr
     //             "RELAY");

+ 9 - 2
pro/src/netswitch.c

@@ -19,8 +19,11 @@
     #define LOGW            printf
 #endif
 
-#define SW_PORT_START       99329
 
+#define USE_STATIC_IP
+
+
+#define SW_PORT_START       99329
 #define NETSNMP_DS_APP_DONT_FIX_PDUS 0
 
 
@@ -466,6 +469,9 @@ static int sw_get(netswitch_info_t *sw)
     ns_handle_t *h=&nsHandle;
     
     if(h->ipflag==0) {
+#ifdef USE_STATIC_IP
+        strcpy(h->ipaddr, SW_HOST_IP);
+#else
         r = get_ipaddr(AF_INET, "eth0", h->ipaddr);
         if(r) {
             LOGE("____get ip4 failed\n");
@@ -476,6 +482,7 @@ static int sw_get(netswitch_info_t *sw)
                 return -1;
             }
         }
+#endif
         h->ipflag = 1;
     }
     //LOGD("___local ip: %s\n", h->ipaddr);
@@ -674,7 +681,7 @@ static sqlite3* get_db(void)
 }
 static int get_prod_id(void)
 {
-    return __globalDeviceManage._global_device_info->product_id;
+    return __globalDeviceManage._globalDevInfo.product_id;
 }
 static int sw_alarm(netswitch_evts_t *evts, netswitch_info_t *old, netswitch_info_t *new)
 {

+ 187 - 99
pro/src/paras.c

@@ -3,6 +3,7 @@
 #include "sys.h"
 #include "file.h"
 #include "paras.h"
+#include "cascade.h"
 
 
 #if 1
@@ -27,7 +28,7 @@ static int do_check(void *para)
 {
     return 0;
 }
-#if 0
+#if 1
 
 #include "dictionary.h"
 #include "iniparser.h"
@@ -46,24 +47,40 @@ typedef struct {
     unsigned short  product_save_time           ;//采集周期 单位ms
 }ProdInfo_t;
 
-static int ini_rw_prod(int rw, dictionary *dic, GlobalDeviceInfo *dev)
+static int ini_rw_prod(int rw, dictionary *dic, GlobalDeviceInfo *info)
 {
-    int r=-1;
+    int r=-1,ok=1;
     char *p=NULL;
     char temp[100];
     char *token=NULL;
 
-    token = "PRODUCT:ID";
+    if(info->product_language>=4) {
+        LOGE("___ product_language %d is wrong\n", info->product_language);
+        ok = 0;
+    }
+    if(info->product_type>=2) {
+        LOGE("___ product_type %d is wrong\n", info->product_type);
+        ok = 0;
+    }
+    if(info->product_pwr_type>=SmartPDU_Tree_AC_One_B) {
+        LOGE("___ product_pwr_type %d is wrong\n", info->product_pwr_type);
+        ok = 0;
+    }
+    if(!ok) {
+        return -1;
+    }
+
+    token = "product:id";
     if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
-        if(!p) {
+        r = iniparser_getint(dic, token, -1);
+        if(r==-1) {
             LOGE("___ iniparser_getstring %s failed\n", token);
             return -1; 
         }
-        dev->product_id = atoi(p);
+        info->product_id = r;
     }
     else {
-        sprintf(temp, "%d", dev->product_id);
+        sprintf(temp, "%d", info->product_id);
         r = iniparser_set(dic, token, temp);
         if(r) {
             LOGE("___ iniparser_set %s failed\n", token);
@@ -71,52 +88,51 @@ static int ini_rw_prod(int rw, dictionary *dic, GlobalDeviceInfo *dev)
         }
     }
 
-    token = "PRODUCT:NUMBER";
+    token = "product:number";
     if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
+        p = (char*)iniparser_getstring(dic, token, NULL);
         if(!p) {
             LOGE("___ iniparser_getstring %s failed\n", token);
             return -1; 
         }
-        dev->product_number = atoi(p);
+        strcpy(info->product_number, p);
     }
     else {
-        sprintf(temp, "%d", dev->product_number);
-        r = iniparser_set(dic, token, temp);
+        r = iniparser_set(dic, token, info->product_number);
         if(r) {
             LOGE("___ iniparser_set %s failed\n", token);
             return -1;
         }
     }
 
-    token = "PRODUCT:NAME";
+    token = "product:name";
     if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
+        p = (char*)iniparser_getstring(dic, token, NULL);
         if(!p) {
             LOGE("___ iniparser_getstring %s failed\n", token);
             return -1; 
         }
-        strcpy(dev->product_name, p);
+        strcpy(info->product_name, p);
     }
     else {
-        r = iniparser_set(dic, token, dev->product_name);
+        r = iniparser_set(dic, token, info->product_name);
         if(r) {
             LOGE("___ iniparser_set %s failed\n", token);
             return -1;
         }
     }
     
-    token = "PRODUCT:TYPE";
+    token = "product:type";
     if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
-        if(!p) {
-            LOGE("___ iniparser_getstring %s failed\n", token);
+        r = iniparser_getint(dic, token, -1);
+        if(r==-1) {
+            LOGE("___ iniparser_getint %s failed\n", token);
             return -1; 
         }
-        dev->product_type = atoi(p);
+        info->product_type = r;
     }
     else {
-        sprintf(temp, "%d", dev->product_type);
+        sprintf(temp, "%d", info->product_type);
         r = iniparser_set(dic, token, temp);
         if(r) {
             LOGE("___ iniparser_set %s failed\n", token);
@@ -124,17 +140,52 @@ static int ini_rw_prod(int rw, dictionary *dic, GlobalDeviceInfo *dev)
         }
     }
 
-    token = "PRODUCT:PWRTYPE";
+    token = "product:powertype";
     if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
+        r = iniparser_getint(dic, token, -1);
+        if(r==-1) {
+            LOGE("___ iniparser_getint %s failed\n", token);
+            return -1; 
+        }
+        info->product_pwr_type = r;
+    }
+    else {
+        sprintf(temp, "%d", info->product_pwr_type);
+        r = iniparser_set(dic, token, temp);
+        if(r) {
+            LOGE("___ iniparser_set %s failed\n", token);
+            return -1;
+        }
+    }
+
+    token = "product:version";
+    if(rw==INI_READ) {
+        p = (char*)iniparser_getstring(dic, token, NULL);
         if(!p) {
             LOGE("___ iniparser_getstring %s failed\n", token);
             return -1; 
         }
-        dev->product_pwr_type = atoi(p);
+        strcpy(info->product_version, p);
     }
     else {
-        sprintf(temp, "%d", dev->product_pwr_type);
+        r = iniparser_set(dic, token, info->product_version);
+        if(r) {
+            LOGE("___ iniparser_set %s failed\n", token);
+            return -1;
+        }
+    }
+
+    token = "product:language";
+    if(rw==INI_READ) {
+        r = iniparser_getint(dic, token, -1);
+        if(r==-1) {
+            LOGE("___ iniparser_getint %s failed\n", token);
+            return -1; 
+        }
+        info->product_language = r;
+    }
+    else {
+        sprintf(temp, "%d", info->product_language);
         r = iniparser_set(dic, token, temp);
         if(r) {
             LOGE("___ iniparser_set %s failed\n", token);
@@ -142,17 +193,17 @@ static int ini_rw_prod(int rw, dictionary *dic, GlobalDeviceInfo *dev)
         }
     }
 
-    token = "PRODUCT:SMPTIME";
+    token = "product:samptime";
     if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
+        p = (char*)iniparser_getstring(dic, token, NULL);
         if(!p) {
             LOGE("___ iniparser_getstring %s failed\n", token);
             return -1; 
         }
-        dev->product_samp_time = atoi(p);
+        info->product_samp_time = atoi(p);
     }
     else {
-        sprintf(temp, "%d", dev->product_samp_time);
+        sprintf(temp, "%d", info->product_samp_time);
         r = iniparser_set(dic, token, temp);
         if(r) {
             LOGE("___ iniparser_set %s failed\n", token);
@@ -160,56 +211,60 @@ static int ini_rw_prod(int rw, dictionary *dic, GlobalDeviceInfo *dev)
         }
     }
 
-    token = "PRODUCT:SAVTIME";
+    token = "product:savetime";
     if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
+        p = (char*)iniparser_getstring(dic, token, NULL);
         if(!p) {
             LOGE("___ iniparser_getstring %s failed\n", token);
             return -1; 
         }
-        dev->product_save_time = atoi(p);
+        info->product_save_time = atoi(p);
     }
     else {
-        sprintf(temp, "%d", dev->product_save_time);
+        sprintf(temp, "%d", info->product_save_time);
         r = iniparser_set(dic, token, temp);
         if(r) {
             LOGE("___ iniparser_set %s failed\n", token);
             return -1;
         }
     }
+
+    if(rw==INI_READ) {
+        info->product_count = 0;
+        info->product_status[0] = 0;
+    }
     
     return 0;
 }
-static int ini_rw_modbus(int rw, dictionary *dic, GlobalDeviceInfo *dev)
+static int ini_rw_modbus(int rw, dictionary *dic, GlobalDeviceInfo *info)
 {
     int r=-1;
-    char *p=NULL;
     char temp[100];
     char *token=NULL;
-    ModbusInfo_t *mb=&dev->_modbus_info;
-    ModbusInfo_t mbus=dev->_modbus_info;
+    ModbusInfo_t *mb=&info->_modbus_info;
 
-    token = "MODBUS:MODE";
-    if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
-        if(!p) {
-            LOGE("___ iniparser_getstring %s failed\n", token);
+    if(rw==INI_WRITE) {
+        if(mb->product_modbus_type!=0 || mb->product_modbus_type!=1) {
+            LOGE("___ set modbus, mode %d is invalid\n", mb->product_modbus_type);
             return -1; 
         }
-        int type = atoi(p);
-        if(type!=0 || type!=1) {
-            LOGE("___ read modbus, mode %d is invalid\n", type);
-            return -1; 
+
+        if(mb->product_modbus_type==1 && (mb->product_modbus_addr==0 || mb->product_modbus_addr>CASCADE_MAX)) {    //slave
+            LOGE("___ set modbus, slave addr %d is invalid\n", mb->product_modbus_addr);
         }
-        mbus.type = type;
     }
-    else {
-        if(mb->type!=0 || mb->type!=1) {
-            LOGE("___ set modbus, mode %d is invalid\n", mb->type);
+
+    token = "modbus:mode";
+    if(rw==INI_READ) {
+        r = iniparser_getint(dic, token, -1);
+        if(r==-1) {
+            LOGE("___ iniparser_getstring %s failed\n", token);
             return -1; 
         }
-
-        sprintf(temp, "%d", mb->type);
+        mb->product_modbus_type = r;
+    }
+    else {
+        sprintf(temp, "%d", mb->product_modbus_type);
         r = iniparser_set(dic, token, temp);
         if(r) {
             LOGE("___ iniparser_set %s failed\n", token);
@@ -217,14 +272,14 @@ static int ini_rw_modbus(int rw, dictionary *dic, GlobalDeviceInfo *dev)
         }
     }
 
-    token = "MODBUS:BAUDRATE";
+    token = "modbus:baudrate";
     if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
-        if(!p) {
+        r = iniparser_getint(dic, token, -1);
+        if(r==-1) {
             LOGE("___ iniparser_getstring %s failed\n", token);
             return -1; 
         }
-        mb->product_modbus_baud = atoi(p);
+        mb->product_modbus_baud = r;
     }
     else {
         sprintf(temp, "%d", mb->product_modbus_baud);
@@ -235,14 +290,14 @@ static int ini_rw_modbus(int rw, dictionary *dic, GlobalDeviceInfo *dev)
         }
     }
 
-    token = "MODBUS:ADDRESS";
+    token = "modbus:address";
     if(rw==INI_READ) {
-        p = iniparser_getstring(dic, token);
-        if(!p) {
+        r = iniparser_getint(dic, token, -1);
+        if(r==-1) {
             LOGE("___ iniparser_getstring %s failed\n", token);
             return -1; 
         }
-        mb->product_modbus_addr = atoi(p);
+        mb->product_modbus_addr = r;
     }
     else {
         sprintf(temp, "%d", mb->product_modbus_addr);
@@ -255,7 +310,7 @@ static int ini_rw_modbus(int rw, dictionary *dic, GlobalDeviceInfo *dev)
 
     return 0;
 }
-static int ini_rw_network(int rw, dictionary *dic, GlobalDeviceInfo *dev)
+static int ini_rw_network(int rw, dictionary *dic, GlobalDeviceInfo *info)
 {
     int r=-1;
     char *p=NULL;
@@ -264,58 +319,53 @@ static int ini_rw_network(int rw, dictionary *dic, GlobalDeviceInfo *dev)
 
     return 0;
 }
-
-#define INI_FILE            "smartPDU.ini"
-static int ini_make(void)
+static int ini_reset(void)
 {
     int r;
     dictionary *dic=NULL;
-    char *ininame=INI_FILE;
+    char *ininame=INI_FILE_NAME;
     char temp[200];
+    FILE *fp=NULL;
+    GlobalDeviceInfo *info=&DFLT_PARAS;
 
-    dic = dictionary_new(0);
-    if(!dic) {
-        LOGE("___dictionary_new failed\n");
+    sys_get_path(temp, ininame);
+    fp = fopen(temp, "w");
+    if (fp==NULL) {
+        LOGE("ini_reset, create %s failed\n", ininame);
         return -1;
     }
 
-    r = ini_rw_prod(INI_WRITE, dic, &DFLT_PARAS);
-    if(r) {
-        LOGE("___ini_w_prod failed\n");
-        goto quit;
-    }
-
-    sys_get_path(temp, ininame);
-    FILE *fp=fopen(temp, "w");
-    if(!fp) {
-        LOGE("___%s open failed\n", ininame);
-        goto quit;
-    }
-    r = iniparser_dump_ini(dic, fp);
+    fprintf(fp, "[product]\n");
+    fprintf(fp, "id        = %d\n", info->product_id);
+    fprintf(fp, "number    = %s\n", info->product_number);
+    fprintf(fp, "name      = %s\n", info->product_name);
+    fprintf(fp, "type      = %d\n", info->product_type);
+    fprintf(fp, "powertype = %d\n", info->product_pwr_type);
+    fprintf(fp, "version   = %s\n", info->product_version);
+    fprintf(fp, "language  = %d\n", info->product_language);
+    fprintf(fp, "samptime  = %d\n", info->product_samp_time);
+    fprintf(fp, "savetime  = %d\n", info->product_save_time);
     fclose(fp);
-    
-quit:
-    iniparser_freedict(dic);
-    return r;
+
+    return 0;
 }
-static int ini_load(GlobalDeviceInfo *dev)
+static int ini_load(GlobalDeviceInfo *info)
 {
     int r=-1;
     char *p=NULL;
-    char *ininame=INI_FILE;
-    ini_handle_t *h=&iniHandle;
+    char *ininame=INI_FILE_NAME;
     
     dictionary *dic=iniparser_load(ininame);
     if(dic == NULL){
-        ini_make();
+        ini_reset();
         dic = iniparser_load(ininame);
         if(dic == NULL) {
-            LOGE("___ %s create failed\n", ininame);
+            LOGE("___ iniparser_load failed\n");
             return -1;
         }
     }
     
-    r = ini_rw_prod(INI_READ, dic, dev);
+    r = ini_rw_prod(INI_READ, dic, info);
     if(r) {
         LOGE("___ini_r_prod failed\n");
     }
@@ -323,20 +373,58 @@ static int ini_load(GlobalDeviceInfo *dev)
 
     return r;
 }
+static int ini_save(GlobalDeviceInfo *info)
+{
+    int r=-1;
+    char *p=NULL;
+    char temp[200];
+    char *ininame=INI_FILE_NAME;
+    
+    dictionary *dic=iniparser_load(ininame);
+    if(dic == NULL){
+        LOGE("___ %s load failed\n", ininame);
+        return -1;
+    }
+    
+    r = ini_rw_prod(INI_WRITE, dic, info);
+    if(r) {
+        LOGE("___ini_r_prod failed\n");
+        goto quit;
+    }
+
+    sys_get_path(temp, ininame);
+    FILE *fp=fopen(temp, "w");
+    if(!fp) {
+        LOGE("___%s open failed\n", ininame);
+        goto quit;
+    }
+    iniparser_dump_ini(dic, fp);
+    fclose(fp);
+
+quit:
+    iniparser_freedict(dic);
+    return r;
+}
 #endif
 
 
 ////////////////////////////////////////////////////////////
-int paras_load(void)
+int paras_load(GlobalDeviceInfo *info)
 {
-    int i,r=-1;
-    
-    return r;
+    return ini_load(info);
 }
 
-int paras_reset(void)
+
+int paras_reset(GlobalDeviceInfo *info)
 {
-    return 0;
+    ini_reset();
+    return ini_load(info);
+}
+
+
+int paras_save(GlobalDeviceInfo *info)
+{
+    return ini_save(info);
 }
 
 

+ 3 - 3
pro/src/paras.h

@@ -12,9 +12,9 @@ typedef struct {
     char    version[32];
 }fw_info_t;
 
-int paras_load(void);
-int paras_save(void);
-int paras_reset(void);
+int paras_load(GlobalDeviceInfo *info);
+int paras_save(GlobalDeviceInfo *info);
+int paras_reset(GlobalDeviceInfo *info);
 
 #ifdef __cplusplus
 }

+ 2 - 2
pro/src/pduMIB_form.c

@@ -541,7 +541,7 @@ pduChannelTable_handler(
                      //       _over_all_pwr_back_info._Power_Trend_Info.ydata[POWER_REACTIVE_TYPE][i] = __PowerTrendInfo._power_trend_info.ydata[POWER_REACTIVE_TYPE][i];
                      //       _over_all_pwr_back_info._Power_Trend_Info.ydata[POWER_APPARENT_TYPE][i] = __PowerTrendInfo._power_trend_info.ydata[POWER_APPARENT_TYPE][i];
                      // }
-                     //if(dev_search_latest_power_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,iterator->product_ch_id,&powerInfo)!=0)
+                     //if(dev_search_latest_power_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,iterator->product_ch_id,&powerInfo)!=0)
                      //{
                      //   log_e("search total pwr err at pduChannelTable_handler from db.");
                      //}
@@ -876,7 +876,7 @@ pduGroupTable_handler(
                 char *pCHlist;
                 char *pCHListSave;
                 pCHlist = strtok_r(_GroupInfoTemp->GroupChList, ",", &pCHListSave);
-                if (__globalDeviceManage._global_device_info->product_pwr_type == 1)
+                if (__globalDeviceManage._globalDevInfo.product_pwr_type == 1)
                 {
                    unsigned short pAddrCtrl[50];
                    memset(pAddrCtrl, 0, sizeof(pAddrCtrl));

+ 8 - 8
pro/src/pduMIB_scalar.c

@@ -314,8 +314,8 @@ int handle_pduId(netsnmp_mib_handler *handler,
     {
 
     case MODE_GET:
-        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,&__globalDeviceManage._global_device_info->product_id,sizeof(ASN_INTEGER));
-        //                          /* XXX: a pointer to the scalar's data */&__globalDeviceManage._global_device_info->product_id,
+        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,&__globalDeviceManage._globalDevInfo.product_id,sizeof(ASN_INTEGER));
+        //                          /* XXX: a pointer to the scalar's data */&__globalDeviceManage._globalDevInfo.product_id,
         //                          /* XXX: the length of the data in bytes */sizeof(ASN_INTEGER));
         break;
 
@@ -344,12 +344,12 @@ int handle_pduName(netsnmp_mib_handler *handler,
     case MODE_GET:
 
         snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
-                                 __globalDeviceManage._global_device_info->product_name,                // 定义的变量名称buff
-                                 strlen(__globalDeviceManage._global_device_info->product_name) // buff的长度
+                                 __globalDeviceManage._globalDevInfo.product_name,                // 定义的变量名称buff
+                                 strlen(__globalDeviceManage._globalDevInfo.product_name) // buff的长度
         );
         // snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
-        //                          /* XXX: a pointer to the scalar's data */__globalDeviceManage._global_device_info->product_name,
-        //                          /* XXX: the length of the data in bytes */strlen(__globalDeviceManage._global_device_info->product_name));
+        //                          /* XXX: a pointer to the scalar's data */__globalDeviceManage._globalDevInfo.product_name,
+        //                          /* XXX: the length of the data in bytes */strlen(__globalDeviceManage._globalDevInfo.product_name));
         break;
 
     default:
@@ -376,7 +376,7 @@ int handle_pduType(netsnmp_mib_handler *handler,
 
     case MODE_GET:
         memset(buffer, 0, sizeof(buffer));
-        sprintf(buffer, "%d", __globalDeviceManage._global_device_info->product_pwr_type);
+        sprintf(buffer, "%d", __globalDeviceManage._globalDevInfo.product_pwr_type);
         snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
         break;
 
@@ -404,7 +404,7 @@ int handle_pduFirmware(netsnmp_mib_handler *handler,
 
     case MODE_GET:
         memset(buffer, 0, sizeof(buffer));
-        sprintf(buffer, "%s", __globalDeviceManage._global_device_info->product_version);
+        sprintf(buffer, "%s", __globalDeviceManage._globalDevInfo.product_version);
         snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, buffer, strlen(buffer));
         break;
 

+ 29 - 29
pro/src/sqlite_handle.c

@@ -417,12 +417,12 @@ int dev_search_latest_power_All_info(GlobalDeviceManager* globalDeviceManger,_Ov
         }
         
 
-        if (_globalPowerMangerTemp->product_ch_type==TREE_AC_TYPE||globalDeviceManger->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+        if (_globalPowerMangerTemp->product_ch_type==TREE_AC_TYPE||globalDeviceManger->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
         {
             GlobalTreeACManager* _TreeACTemp=NULL;
             int nStatus=-1;//-1则状态不变,0、1则是子状态
             //判断是否三相单输出情况下
-            if(_globalPowerMangerTemp->product_ch_type==TREE_AC_TYPE||globalDeviceManger->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+            if(_globalPowerMangerTemp->product_ch_type==TREE_AC_TYPE||globalDeviceManger->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
             {
                 list_for_each_entry(_TreeACTemp, &_globalPowerMangerTemp->list_Tree_AC, list_Tree_AC)
                 {
@@ -440,9 +440,9 @@ int dev_search_latest_power_All_info(GlobalDeviceManager* globalDeviceManger,_Ov
                     log_e("_overChnPwrBackInfoTemp malloc err.");
                     return -1;
                 }
-                _overChnPwrBackInfoTemp->product_name = globalDeviceManger->_global_device_info->product_name;
-                _overChnPwrBackInfoTemp->product_number = globalDeviceManger->_global_device_info->product_number;
-                _overChnPwrBackInfoTemp->product_id = globalDeviceManger->_global_device_info->product_id;
+                _overChnPwrBackInfoTemp->product_name = globalDeviceManger->_globalDevInfo.product_name;
+                _overChnPwrBackInfoTemp->product_number = globalDeviceManger->_globalDevInfo.product_number;
+                _overChnPwrBackInfoTemp->product_id = globalDeviceManger->_globalDevInfo.product_id;
                 _overChnPwrBackInfoTemp->productChName = _globalPowerMangerTemp->product_ch_name;
                 _overChnPwrBackInfoTemp->productChId = _globalPowerMangerTemp->product_ch_id;
                 _overChnPwrBackInfoTemp->status = _globalPowerMangerTemp->_PowerInfo.status;
@@ -463,7 +463,7 @@ int dev_search_latest_power_All_info(GlobalDeviceManager* globalDeviceManger,_Ov
                 _overChnPwrBackInfoTemp->ph_consumption = _TreeACTemp->_PowerInfo.consumption;
                 _overChnPwrBackInfoTemp->ph_outputType   = _TreeACTemp->product_ph_outputType;
                 _overChnPwrBackInfoTemp->ph_outputStatus = _TreeACTemp->product_ph_outputStatus;
-                if ((globalDeviceManger->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One ||globalDeviceManger->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B) && 
+                if ((globalDeviceManger->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One ||globalDeviceManger->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B) && 
                     _TreeACTemp->product_ph_outputType == 2 && _TreeACTemp->product_ph_outputStatus == 2) // 如果是单项输出并且则非输出通道数据为0
                 { 
                      // 3-1模式 单项状态,不输出则数据为空
@@ -505,9 +505,9 @@ int dev_search_latest_power_All_info(GlobalDeviceManager* globalDeviceManger,_Ov
                 return -1;
             }
             // 填数据
-            _overChnPwrBackInfoTemp->product_name = globalDeviceManger->_global_device_info->product_name;
-            _overChnPwrBackInfoTemp->product_number = globalDeviceManger->_global_device_info->product_number;
-            _overChnPwrBackInfoTemp->product_id = globalDeviceManger->_global_device_info->product_id;
+            _overChnPwrBackInfoTemp->product_name = globalDeviceManger->_globalDevInfo.product_name;
+            _overChnPwrBackInfoTemp->product_number = globalDeviceManger->_globalDevInfo.product_number;
+            _overChnPwrBackInfoTemp->product_id = globalDeviceManger->_globalDevInfo.product_id;
             _overChnPwrBackInfoTemp->productChName = _globalPowerMangerTemp->product_ch_name;
             _overChnPwrBackInfoTemp->productChId = _globalPowerMangerTemp->product_ch_id;
             _overChnPwrBackInfoTemp->status = _globalPowerMangerTemp->_PowerInfo.status;
@@ -546,9 +546,9 @@ int dev_search_latest_power_statistic_info(GlobalDeviceManager* globalDeviceMang
     float fNowVoltage =0.0f,fNowFreq =0.0f,fNowFactor =0.0f;
 
     memset(all,0,sizeof(_OverAllPwrAckInfo));
-    all->product_name = globalDeviceManger->_global_device_info->product_name;
-    all->product_id = globalDeviceManger->_global_device_info->product_id;
-    all->product_number = globalDeviceManger->_global_device_info->product_number;
+    all->product_name = globalDeviceManger->_globalDevInfo.product_name;
+    all->product_id = globalDeviceManger->_globalDevInfo.product_id;
+    all->product_number = globalDeviceManger->_globalDevInfo.product_number;
     int nTempSum=0;
 
     if(list_empty(&globalDeviceManger->_globalPowerManger.list)) {
@@ -863,9 +863,9 @@ int dev_search_latest_t_ac_power_statistic_info(int nCh, int nType, _OverAllPwrA
         __overChnPwrAckInfo->consumption = _pTreeACPowerMangerTemp->_PowerInfo.consumption;
         __overChnPwrAckInfo->factor = _pTreeACPowerMangerTemp->_PowerInfo.factor;
 
-       __overChnPwrAckInfo->product_name = globalDeviceManger->_global_device_info->product_name;
-        __overChnPwrAckInfo->product_number = globalDeviceManger->_global_device_info->product_number;
-        __overChnPwrAckInfo->product_id = globalDeviceManger->_global_device_info->product_id;
+       __overChnPwrAckInfo->product_name = globalDeviceManger->_globalDevInfo.product_name;
+        __overChnPwrAckInfo->product_number = globalDeviceManger->_globalDevInfo.product_number;
+        __overChnPwrAckInfo->product_id = globalDeviceManger->_globalDevInfo.product_id;
         return 0;
         break;
     }
@@ -2284,8 +2284,8 @@ int dev_serarch_all_alarm(sqlite3* db,
         strcpy(_alarmTemp->alarmNumber,pResult[i*ncolumn+0]);
         strcpy(_alarmTemp->alarmDate,pResult[i*ncolumn+1]);
         _alarmTemp->alarmType = atoi(pResult[i*ncolumn+2]);
-        strcpy(_alarmTemp->deviceNumber,__globalDeviceManage._global_device_info->product_number);
-        strcpy(_alarmTemp->deviceName,__globalDeviceManage._global_device_info->product_name);
+        strcpy(_alarmTemp->deviceNumber,__globalDeviceManage._globalDevInfo.product_number);
+        strcpy(_alarmTemp->deviceName,__globalDeviceManage._globalDevInfo.product_name);
         strcpy(_alarmTemp->alarmContent,pResult[i*ncolumn+4]);
         //尾部插入
         list_add_tail(&_alarmTemp->list, &_alarm_ack_info->list);
@@ -2384,8 +2384,8 @@ int dev_search_alarm_info(sqlite3* db,
         strcpy(_alarmTemp->alarmNumber,pResult[i*ncolumn+0]);
         strcpy(_alarmTemp->alarmDate,pResult[i*ncolumn+1]);
         _alarmTemp->alarmType = atoi(pResult[i*ncolumn+2]);
-        strcpy(_alarmTemp->deviceNumber,__globalDeviceManage._global_device_info->product_number);
-        strcpy(_alarmTemp->deviceName,__globalDeviceManage._global_device_info->product_name);
+        strcpy(_alarmTemp->deviceNumber,__globalDeviceManage._globalDevInfo.product_number);
+        strcpy(_alarmTemp->deviceName,__globalDeviceManage._globalDevInfo.product_name);
         strcpy(_alarmTemp->alarmContent,pResult[i*ncolumn+4]);
         //尾部插入
         list_add_tail(&_alarmTemp->list, &_alarm_ack_info->list);
@@ -2405,7 +2405,7 @@ int dev_get_ntp_info(sqlite3 *db,NTPManager* _globalNTPInfo)
     char* err_msg=NULL;
     char select_sql[1024] = {0};
 
-    sprintf(select_sql, "SELECT* from Table_NTPManage WHERE product_id = %d;", __globalDeviceManage._global_device_info->product_id);
+    sprintf(select_sql, "SELECT* from Table_NTPManage WHERE product_id = %d;", __globalDeviceManage._globalDevInfo.product_id);
     res = sqlite3_get_table(db, select_sql, &pResult, &nrow, &ncolumn, &err_msg);
     if(res != SQLITE_OK) {
         log_e("sqlite handle error: %s\n%s\n", err_msg,select_sql); sqlite3_free(err_msg);
@@ -2503,7 +2503,7 @@ int dev_get_snmp_info(sqlite3 *db, SNMPManager* _globalSNMPInfo)
     char* err_msg=NULL;
     char select_sql[1024] = {0};
 
-    sprintf(select_sql, "SELECT* from Table_SNMPManage WHERE product_id = %d;", __globalDeviceManage._global_device_info->product_id);
+    sprintf(select_sql, "SELECT* from Table_SNMPManage WHERE product_id = %d;", __globalDeviceManage._globalDevInfo.product_id);
     res = sqlite3_get_table(db, select_sql, &pResult, &nrow, &ncolumn, &err_msg);
     if(res != SQLITE_OK) {
         log_e("sqlite handle error: %s\n%s\n", err_msg,select_sql); sqlite3_free(err_msg);
@@ -2589,7 +2589,7 @@ int dev_get_smtp_info(sqlite3 *db, SMTPManager* _globalSMTPInfo)
     char* err_msg=NULL;
     char select_sql[1024] = {0};
 
-    sprintf(select_sql, "SELECT* from Table_SMTPManage WHERE product_id = %d;", __globalDeviceManage._global_device_info->product_id);
+    sprintf(select_sql, "SELECT* from Table_SMTPManage WHERE product_id = %d;", __globalDeviceManage._globalDevInfo.product_id);
     res = sqlite3_get_table(db, select_sql, &pResult, &nrow, &ncolumn, &err_msg);
     if(res != SQLITE_OK) {
         log_e("sqlite handle error: %s\n%s\n", err_msg,select_sql); sqlite3_free(err_msg);
@@ -2729,7 +2729,7 @@ int dev_get_group_info(sqlite3 *db, GroupInfo* _globalgroupInfo)
     char* err_msg=NULL;
     char select_sql[1024] = {0};
 
-    sprintf(select_sql, "SELECT* from Table_GroupManage WHERE product_id = %d;", __globalDeviceManage._global_device_info->product_id);
+    sprintf(select_sql, "SELECT* from Table_GroupManage WHERE product_id = %d;", __globalDeviceManage._globalDevInfo.product_id);
     res = sqlite3_get_table(db, select_sql, &pResult, &nrow, &ncolumn, &err_msg);
     if(res != SQLITE_OK) {
         log_e("sqlite handle error: %s\n%s\n", err_msg,select_sql); sqlite3_free(err_msg);
@@ -2752,7 +2752,7 @@ int dev_get_group_info(sqlite3 *db, GroupInfo* _globalgroupInfo)
         {
             break;
         }
-        new_group->product_id = __globalDeviceManage._global_device_info->product_id;
+        new_group->product_id = __globalDeviceManage._globalDevInfo.product_id;
         new_group->GroupID =  atoi(pResult[i*ncolumn+1]);
         strcpy(new_group->GroupName,pResult[i*ncolumn+2]);
         strcpy(new_group->GroupChList,pResult[i*ncolumn+3]);
@@ -2833,7 +2833,7 @@ int dev_get_user_info(sqlite3 *db, UserInfo* _globaluserInfo)
     char* err_msg=NULL;
     char select_sql[1024] = {0};
 
-    sprintf(select_sql, "SELECT* from Table_Userinfo WHERE product_id = %d;", __globalDeviceManage._global_device_info->product_id);
+    sprintf(select_sql, "SELECT* from Table_Userinfo WHERE product_id = %d;", __globalDeviceManage._globalDevInfo.product_id);
     res = sqlite3_get_table(db, select_sql, &pResult, &nrow, &ncolumn, &err_msg);
     if(res != SQLITE_OK) {
         log_e("sqlite handle error: %s\n%s\n", err_msg,select_sql); sqlite3_free(err_msg);
@@ -2856,7 +2856,7 @@ int dev_get_user_info(sqlite3 *db, UserInfo* _globaluserInfo)
         {
             break;
         }
-        new_user->product_id = __globalDeviceManage._global_device_info->product_id;
+        new_user->product_id = __globalDeviceManage._globalDevInfo.product_id;
         new_user->userID =  atoi(pResult[i*ncolumn+1]);
         new_user->userName = malloc(256);
         strcpy(new_user->userName,pResult[i*ncolumn+2]);
@@ -2968,7 +2968,7 @@ int dev_get_role_info(sqlite3 *db, RoleInfo* _globalRoleInfo)
     char* err_msg=NULL;
     char select_sql[1024] = {0};
 
-    sprintf(select_sql, "SELECT* from Table_RoleInfo WHERE product_id = %d;", __globalDeviceManage._global_device_info->product_id);
+    sprintf(select_sql, "SELECT* from Table_RoleInfo WHERE product_id = %d;", __globalDeviceManage._globalDevInfo.product_id);
     res = sqlite3_get_table(db, select_sql, &pResult, &nrow, &ncolumn, &err_msg);
     if(res != SQLITE_OK) {
         log_e("sqlite handle error: %s\n%s\n", err_msg,select_sql); sqlite3_free(err_msg);
@@ -2991,7 +2991,7 @@ int dev_get_role_info(sqlite3 *db, RoleInfo* _globalRoleInfo)
         {
             break;
         }
-        new_role->product_id = __globalDeviceManage._global_device_info->product_id;
+        new_role->product_id = __globalDeviceManage._globalDevInfo.product_id;
         new_role->roleID =  atoi(pResult[i*ncolumn+1]);
         new_role->roleName = malloc(256);
         strcpy(new_role->roleName,pResult[i*ncolumn+2]);
@@ -3027,7 +3027,7 @@ int dev_get_power_ds(sqlite3 *db,GlobalPowerManger* _powerAll,char* dateSelect)
 
     if (dateSelect)
     {
-        sprintf(select_sql, "SELECT* from Table_ChnTimerManage WHERE product_id = %d and date=date('%s');", __globalDeviceManage._global_device_info->product_id,dateSelect);
+        sprintf(select_sql, "SELECT* from Table_ChnTimerManage WHERE product_id = %d and date=date('%s');", __globalDeviceManage._globalDevInfo.product_id,dateSelect);
     }else{
         sprintf(select_sql, "SELECT* from Table_ChnTimerManage WHERE product_id = %d;", 1);
     }        

+ 35 - 35
pro/src/switch_ctrl.c

@@ -647,7 +647,7 @@ int g_switch_set_all_start_time_delay(void* manger,int ntype,int saddr,unsigned
     case TREE_AC_TYPE:
     {
         int ret = 0;
-        if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_Tree)
+        if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_Tree)
         {
             ret = g_switch_set_t_ac_start_time_delay(manger, saddr, (chn - 1) * 3, time / 1000);
             if (ret < 0)
@@ -725,7 +725,7 @@ int g_switch_set_all_stop_time_delay(void* manger,int ntype,int saddr,unsigned c
     case TREE_AC_TYPE:
     {
         int ret = 0;
-        if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_Tree)
+        if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_Tree)
         {
             ret = g_switch_set_t_ac_stop_time_delay(manger, saddr, (chn - 1) * 3, time / 1000);
             if (ret < 0)
@@ -834,7 +834,7 @@ int g_switch_set_all_chn_ctrl(void* manger,GlobalPowerManger* _globalPowerManger
         {
             t_ac_CtrlType=_globalTACManager->product_ph_outputType;
         }
-        if (t_ac_CtrlType == 2&&__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_Tree)
+        if (t_ac_CtrlType == 2&&__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_Tree)
         {
             unsigned short phsts=0;
             
@@ -891,7 +891,7 @@ int g_switch_set_all_chn_ctrl(void* manger,GlobalPowerManger* _globalPowerManger
                 sts |= ENABLE_TAC_STIME;
                 sts |= ENABLE_TAC_ETIME;
             }*/
-            if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One)
+            if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One)
             {
                 return g_switch_set_t_ac_phchn_ctrl(manger, saddr, (chn - 1), sts);
             }else{
@@ -1077,7 +1077,7 @@ int g_switch_set_all_single_threshold(void* manger,int ntype,int saddr,char chn,
                 if (_globalPowerMangerTemp->global_over_manager->product_pwrcon_upper_enable == 1)
                     sts |= ENABLE_TAC_P_UP;
             
-            if (__globalDeviceManage._global_device_info->product_pwr_type == SmartPDU_Tree_AC_One)
+            if (__globalDeviceManage._globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One)
             {
                 return g_switch_set_t_ac_phchn_ctrl(manger, saddr, (chn - 1), sts);
             }else{
@@ -2205,7 +2205,7 @@ int ResetChmData()
                                 i,
                                 &type,
                                 &nMaxChn,
-                                __globalDeviceManage._global_device_info->product_pwr_type);
+                                __globalDeviceManage._globalDevInfo.product_pwr_type);
         log_d("ret:%d saddr:%d type:%d ch_num:%d.\n", ret, i, type, nMaxChn);
         // 有效地址记录
 
@@ -2239,14 +2239,14 @@ int ResetChmData()
                     memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
                     // 查询是否由通道信息
                     ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                    _globalDeviceManager->_global_device_info->product_id,
+                                                    _globalDeviceManager->_globalDevInfo.product_id,
                                                     i,
                                                     j + 1, // 1*8+j
                                                     _globalPowerMangerTemp);
                     // 未查询到信息 则插入
                     if (ret == -1)
                     {
-                        _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                        _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                         _globalPowerMangerTemp->product_saddr = i;
                         _globalPowerMangerTemp->product_ch_id = chn;
                         _globalPowerMangerTemp->product_ch_addr = j + 1;
@@ -2259,7 +2259,7 @@ int ResetChmData()
                         _globalPowerMangerTemp->product_ch_stop_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
 
                         if (dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                         _globalDeviceManager->_global_device_info->product_id,
+                                                         _globalDeviceManager->_globalDevInfo.product_id,
                                                          _globalPowerMangerTemp->product_ch_id,
                                                          _globalPowerMangerTemp) != 0)
                         {
@@ -2273,7 +2273,7 @@ int ResetChmData()
                         }
                         */
                     }
-                        if ( _globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+                        if ( _globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One_B)
                     {
                         // 初始化三相子通道
                         GlobalTreeACManager *_globalTACManager = NULL;
@@ -2295,7 +2295,7 @@ int ResetChmData()
                                 return -1;
                             }
                             ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                 _globalDeviceManager->_global_device_info->product_id, i,
+                                                                 _globalDeviceManager->_globalDevInfo.product_id, i,
                                                                  j + 1, // 1*8+j
                                                                  nTac_chn,
                                                                  _globalTACManager);
@@ -2303,7 +2303,7 @@ int ResetChmData()
                             // 未查询到信息 则插入
                             if (ret == -1)
                             {
-                                _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                _globalTACManager->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                                 _globalTACManager->product_saddr = i;
                                 _globalTACManager->product_ch_id = _globalPowerMangerTemp->product_ch_id;
                                 _globalTACManager->product_ch_addr = j + 1;
@@ -2320,7 +2320,7 @@ int ResetChmData()
                                 }
 
                                 if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                      _globalDeviceManager->_global_device_info->product_id,
+                                                                      _globalDeviceManager->_globalDevInfo.product_id,
                                                                       _globalTACManager->product_ch_id,
                                                                       _globalTACManager) != 0)
                                 {
@@ -2372,13 +2372,13 @@ int ResetChmData()
                     memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
                     // 查询是否由通道信息
                     ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                    _globalDeviceManager->_global_device_info->product_id, i,
+                                                    _globalDeviceManager->_globalDevInfo.product_id, i,
                                                     j + 1, // 1*8+j
                                                     _globalPowerMangerTemp);
                     // 未查询到信息 则插入
                     if (ret == -1)
                     {
-                        _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                        _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                         _globalPowerMangerTemp->product_saddr = i;
                         _globalPowerMangerTemp->product_ch_id = chn;
                         _globalPowerMangerTemp->product_ch_addr = j + 1;
@@ -2389,7 +2389,7 @@ int ResetChmData()
                         _globalPowerMangerTemp->product_ch_start_delay = 1000;
                         _globalPowerMangerTemp->product_ch_stop_delay = 1000;
                         if (dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                         _globalDeviceManager->_global_device_info->product_id,
+                                                         _globalDeviceManager->_globalDevInfo.product_id,
                                                          _globalPowerMangerTemp->product_ch_id,
                                                          _globalPowerMangerTemp) != 0)
                         {
@@ -2432,14 +2432,14 @@ int ResetChmData()
                     memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
                     // 查询是否由通道信息
                     ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                    _globalDeviceManager->_global_device_info->product_id, i,
+                                                    _globalDeviceManager->_globalDevInfo.product_id, i,
                                                     j + 1, // 1*8+j
                                                     _globalPowerMangerTemp);
                     _globalPowerMangerTemp->product_ch_addr = j + 1;
                     // 未查询到信息 则插入
                     if (ret == -1)
                     {
-                        _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                        _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                         _globalPowerMangerTemp->product_saddr = i;
                         _globalPowerMangerTemp->product_ch_id = chn;
                         _globalPowerMangerTemp->product_ch_addr = j + 1;
@@ -2452,7 +2452,7 @@ int ResetChmData()
                         _globalPowerMangerTemp->product_ch_stop_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
 
                         if (dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                         _globalDeviceManager->_global_device_info->product_id,
+                                                         _globalDeviceManager->_globalDevInfo.product_id,
                                                          _globalPowerMangerTemp->product_ch_id,
                                                          _globalPowerMangerTemp) != 0)
                         {
@@ -2468,7 +2468,7 @@ int ResetChmData()
                     }
                     _globalPowerMangerTemp->product_saddr = i;
                     _globalPowerMangerTemp->product_ch_type = type;
-                    if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_global_device_info->product_id, chn, _globalPowerMangerTemp) != 0)
+                    if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_globalDevInfo.product_id, chn, _globalPowerMangerTemp) != 0)
                     {
                         log_e("update pwr general data err.");
                     }
@@ -2484,7 +2484,7 @@ int ResetChmData()
                 GlobalPowerManger *_globalPowerMangerTemp = NULL;
                 for (size_t j = 0; j < nMaxChn; j++)
                 {
-                    if (_globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One)
+                    if (_globalDeviceManager->_globalDevInfo.product_pwr_type == SmartPDU_Tree_AC_One)
                     {
                         log_i("TreeAC_TYPE_3-1!\n");
                         _globalPowerMangerTemp = (GlobalPowerManger *)malloc(sizeof(GlobalPowerManger));
@@ -2504,14 +2504,14 @@ int ResetChmData()
                         memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
                         // 查询是否由通道信息
                         ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                        _globalDeviceManager->_global_device_info->product_id, i,
+                                                        _globalDeviceManager->_globalDevInfo.product_id, i,
                                                         j + 1, // 1*8+j
                                                         _globalPowerMangerTemp);
                         _globalPowerMangerTemp->product_ch_addr = j + 1;
                         // 未查询到信息 则插入
                         if (ret == -1)
                         {
-                            _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                            _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                             _globalPowerMangerTemp->product_saddr = i;
                             _globalPowerMangerTemp->product_ch_id = chn;
                             _globalPowerMangerTemp->product_ch_addr = j + 1;
@@ -2524,7 +2524,7 @@ int ResetChmData()
                             _globalPowerMangerTemp->product_ch_stop_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
 
                             if (dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                             _globalDeviceManager->_global_device_info->product_id,
+                                                             _globalDeviceManager->_globalDevInfo.product_id,
                                                              _globalPowerMangerTemp->product_ch_id,
                                                              _globalPowerMangerTemp) != 0)
                             {
@@ -2534,7 +2534,7 @@ int ResetChmData()
                         }
                         _globalPowerMangerTemp->product_saddr = i;
                         _globalPowerMangerTemp->product_ch_type = type;
-                        if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_global_device_info->product_id, chn, _globalPowerMangerTemp) != 0)
+                        if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_globalDevInfo.product_id, chn, _globalPowerMangerTemp) != 0)
                         {
                             log_e("update pwr general data err.");
                         }
@@ -2560,7 +2560,7 @@ int ResetChmData()
                                 return -1;
                             }
                             ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                 _globalDeviceManager->_global_device_info->product_id, i,
+                                                                 _globalDeviceManager->_globalDevInfo.product_id, i,
                                                                  j + 1, // 1*8+j
                                                                  nTac_chn,
                                                                  _globalTACManager);
@@ -2568,7 +2568,7 @@ int ResetChmData()
                             // 未查询到信息 则插入
                             if (ret == -1)
                             {
-                                _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                _globalTACManager->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                                 _globalTACManager->product_saddr = i;
                                 _globalTACManager->product_ch_id = _globalPowerMangerTemp->product_ch_id;
                                 _globalTACManager->product_ch_addr = j + 1;
@@ -2585,7 +2585,7 @@ int ResetChmData()
                                 }
 
                                 if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                      _globalDeviceManager->_global_device_info->product_id,
+                                                                      _globalDeviceManager->_globalDevInfo.product_id,
                                                                       _globalTACManager->product_ch_id,
                                                                       _globalTACManager) != 0)
                                 {
@@ -2625,14 +2625,14 @@ int ResetChmData()
                             memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
                             // 查询是否由通道信息
                             ret = dev_get_power_manage_info(_globalDeviceManager->db,
-                                                            _globalDeviceManager->_global_device_info->product_id, i,
+                                                            _globalDeviceManager->_globalDevInfo.product_id, i,
                                                             j / 3 + 1, // 1*8+j
                                                             _globalPowerMangerTemp);
                             _globalPowerMangerTemp->product_ch_addr = j / 3 + 1;
                             // 未查询到信息 则插入
                             if (ret == -1)
                             {
-                                _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                _globalPowerMangerTemp->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                                 _globalPowerMangerTemp->product_saddr = i;
                                 _globalPowerMangerTemp->product_ch_id = chn;
                                 _globalPowerMangerTemp->product_ch_addr = j / 3 + 1;
@@ -2645,7 +2645,7 @@ int ResetChmData()
                                 _globalPowerMangerTemp->product_ch_stop_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
 
                                 if (dev_insert_power_manage_info(_globalDeviceManager->db,
-                                                                 _globalDeviceManager->_global_device_info->product_id,
+                                                                 _globalDeviceManager->_globalDevInfo.product_id,
                                                                  _globalPowerMangerTemp->product_ch_id,
                                                                  _globalPowerMangerTemp) != 0)
                                 {
@@ -2655,7 +2655,7 @@ int ResetChmData()
                             }
                             _globalPowerMangerTemp->product_saddr = i;
                             _globalPowerMangerTemp->product_ch_type = type;
-                            if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_global_device_info->product_id, chn, _globalPowerMangerTemp) != 0)
+                            if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_globalDevInfo.product_id, chn, _globalPowerMangerTemp) != 0)
                             {
                                 log_e("update pwr general data err.");
                             }
@@ -2680,7 +2680,7 @@ int ResetChmData()
                             return -1;
                         }
                         ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                             _globalDeviceManager->_global_device_info->product_id, i,
+                                                             _globalDeviceManager->_globalDevInfo.product_id, i,
                                                              j + 1, // 1*8+j
                                                              nTac_chn,
                                                              _globalTACManager);
@@ -2688,7 +2688,7 @@ int ResetChmData()
                         // 未查询到信息 则插入
                         if (ret == -1)
                         {
-                            _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                            _globalTACManager->product_id = _globalDeviceManager->_globalDevInfo.product_id;
                             _globalTACManager->product_saddr = i;
                             _globalTACManager->product_ch_id = _globalPowerMangerTemp->product_ch_id;
                             _globalTACManager->product_ch_addr = j + 1;
@@ -2697,7 +2697,7 @@ int ResetChmData()
                             _globalTACManager->product_ph_outputType = 1;   // 1三相2单相
                             _globalTACManager->product_ph_outputStatus = 1; // 1输出
                             if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
-                                                                  _globalDeviceManager->_global_device_info->product_id,
+                                                                  _globalDeviceManager->_globalDevInfo.product_id,
                                                                   _globalTACManager->product_ch_id,
                                                                   _globalTACManager) != 0)
                             {

+ 3 - 3
pro/src/websocket_handle.c

@@ -94,9 +94,9 @@ static void web_update(ws_handle_t *wh)
     if(ws_is_online(wh))
     {
         //overall info
-        if(gdm->_global_device_info->product_pwr_type==SmartPDU_Tree_AC_Tree ||
-            gdm->_global_device_info->product_pwr_type==SmartPDU_Tree_AC_One ||
-			gdm->_global_device_info->product_pwr_type==SmartPDU_Tree_AC_One_B)
+        if(gdm->_globalDevInfo.product_pwr_type==SmartPDU_Tree_AC_Tree ||
+            gdm->_globalDevInfo.product_pwr_type==SmartPDU_Tree_AC_One ||
+			gdm->_globalDevInfo.product_pwr_type==SmartPDU_Tree_AC_One_B)
 		{
             int nRet_L1 = -1;
             int nRet_L2 = -1;

+ 2 - 2
pub

@@ -8,7 +8,7 @@
 #  8:  ANDERSON_EN
 #  9:  USA_SL
 
-cust=9
+cust=8
 
 cmp_flag=1
 if [ $# -gt 0 ]; then
@@ -73,7 +73,7 @@ function do_copy()
         cp -f $custdir/logo/logo_neuter.png $curdir/output/t113i/root/run/app/image/logo.png
     elif [ $cust -eq 8 ]; then
         rm -rf  $curdir/output/t113i/root/run/web
-        cp -rf $custdir/web/Anderson/  $curdir/output/t113i/root/run/web
+        cp -rf $custdir/web/anderson  $curdir/output/t113i/root/run/web
         
         cp -f $custdir/db/ac_i3_o3_english.db $curdir/output/t113i/root/run/app/pdu_dat.db
         cp -f $custdir/logo/logo_neuter.png $curdir/output/t113i/root/run/app/image/logo.png