⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startup.c

📁 Open DMT Client C Source code
💻 C
📖 第 1 页 / 共 3 页
字号:
    } else    if (ndx > 15) {        return COMMAND_INDEX;    }        /* implement setting output state here */    // currently not supported    return COMMAND_FEATURE_NOT_SUPPORTED;}/* explicitly save properties [see PROP_CMD_SAVE_PROPS] */static CommandError_t _cmdSaveProperties(int protoNdx, Key_t key, const UInt8 *data, int dataLen){    // 'protoNdx' contains the handle to the protocol transport        // arguments are ignored    startupSaveProperties();    return COMMAND_OK;    }// ----------------------------------------------------------------------------/* initialize properties */void startupPropInitialize(utBool loadPropCache){    /* init properties */    propInitialize(utTrue);    /* firmware */    propInitFromString(PROP_STATE_FIRMWARE, DMTP_NAME_TYPE_VERSION);#if defined(TRANSPORT_MEDIA_SERIAL)    /* AccountID/DeviceID may be writable via BlueTooth transport (for OTA configuration) */    propSetReadOnly(PROP_STATE_ACCOUNT_ID, utFalse);    propSetReadOnly(PROP_STATE_DEVICE_ID , utFalse);#endif    /* property initialization */    propSetNotifyFtn(PROP_REFRESH_GET               , &_propertyPreGET);    propSetNotifyFtn(PROP_REFRESH_SET               , &_propertyPostSET);        /* set supporting commands */    propSetCommandFtn(PROP_CMD_SAVE_PROPS           , &_cmdSaveProperties);    propSetCommandFtn(PROP_CMD_STATUS_EVENT         , &_cmdSendStatus);    propSetCommandFtn(PROP_CMD_SET_OUTPUT           , &_cmdSetOutput);        /* copyright */    propSetString(PROP_STATE_COPYRIGHT              , COPYRIGHT);    /* connection properties */#if defined(TRANSPORT_MEDIA_FILE)    // disable Duplex connection (not wanted when just writing to a file)    propInitFromString(PROP_COMM_MAX_CONNECTIONS    , "1,0,0");     // no duplex connections, no quota    propInitFromString(PROP_COMM_MIN_XMIT_DELAY     , "0");    propInitFromString(PROP_COMM_MIN_XMIT_RATE      , "0");    propInitFromString(PROP_COMM_MAX_DUP_EVENTS     , "0");    propInitFromString(PROP_COMM_MAX_SIM_EVENTS     , "255");#elif defined(TRANSPORT_MEDIA_SERIAL) // comm config    // disable Simplex connection (not wanted when communicating over serial port)    propInitFromString(PROP_COMM_SPEAK_FIRST        , "0");    propInitFromString(PROP_COMM_FIRST_BRIEF        , "1");         // start with identification only    propInitFromString(PROP_COMM_MAX_CONNECTIONS    , "1,1,0");     // no simplex connections, no quota    propInitFromString(PROP_COMM_MIN_XMIT_DELAY     , "0");    propInitFromString(PROP_COMM_MIN_XMIT_RATE      , "0");    propInitFromString(PROP_COMM_MAX_XMIT_RATE      , "0");    propInitFromString(PROP_COMM_MAX_DUP_EVENTS     , "10");    propInitFromString(PROP_COMM_MAX_SIM_EVENTS     , "0");    //propInitFromString(PROP_COMM_ENCODINGS        , "0x6");       // HEX,Base64#elif defined(TRANSPORT_MEDIA_SOCKET) // comm config    propInitFromString(PROP_COMM_MAX_CONNECTIONS    , "20,10,30");    propInitFromString(PROP_COMM_MIN_XMIT_DELAY     , "60");        // seconds    propInitFromString(PROP_COMM_MIN_XMIT_RATE      , "60");        // seconds    propInitFromString(PROP_COMM_MAX_DUP_EVENTS     , "8");    propInitFromString(PROP_COMM_MAX_SIM_EVENTS     , "4");#elif defined(TRANSPORT_MEDIA_GPRS) // comm config    propInitFromString(PROP_COMM_MAX_CONNECTIONS    , "6,4,60");    propInitFromString(PROP_COMM_MIN_XMIT_DELAY     , "60");        // seconds    propInitFromString(PROP_COMM_MIN_XMIT_RATE      , "60");        // seconds    propInitFromString(PROP_COMM_MAX_DUP_EVENTS     , "8");    propInitFromString(PROP_COMM_MAX_SIM_EVENTS     , "4");#else // default values    propInitFromString(PROP_COMM_MAX_CONNECTIONS    , "4,2,120");    propInitFromString(PROP_COMM_MIN_XMIT_DELAY     , "90");        // seconds    propInitFromString(PROP_COMM_MIN_XMIT_RATE      , "600");       // seconds    propInitFromString(PROP_COMM_MAX_DUP_EVENTS     , "8");    propInitFromString(PROP_COMM_MAX_SIM_EVENTS     , "4");#endif    /* motion parameters */#if defined(TRANSPORT_MEDIA_FILE)    propInitFromString(PROP_MOTION_EXCESS_SPEED     , "0.0");       // kph    propInitFromString(PROP_MOTION_START            , "10.0");      // kph    propInitFromString(PROP_MOTION_IN_MOTION        , "60");        // seconds (1 minutes)    propInitFromString(PROP_MOTION_DORMANT_INTRVL   , "900");       // seconds (15 minutes)    propInitFromString(PROP_MOTION_DORMANT_COUNT    , "0");         // unlimited dormant messages#elif defined(TRANSPORT_MEDIA_SOCKET) // comm config    propInitFromString(PROP_MOTION_EXCESS_SPEED     , "0.0");       // kph    propInitFromString(PROP_MOTION_START            , "10.0");      // kph    propInitFromString(PROP_MOTION_IN_MOTION        , "900");       // seconds (15 minutes)    propInitFromString(PROP_MOTION_DORMANT_INTRVL   , "7200");      // seconds (2 hours)    propInitFromString(PROP_MOTION_DORMANT_COUNT    , "2");         // 2 dormant messages#else // default values    propInitFromString(PROP_MOTION_EXCESS_SPEED     , "0.0");       // kph    propInitFromString(PROP_MOTION_START            , "10.0");      // kph    propInitFromString(PROP_MOTION_IN_MOTION        , "600");       // seconds (10 minutes)    propInitFromString(PROP_MOTION_DORMANT_INTRVL   , "3600");      // seconds (1 hour)    propInitFromString(PROP_MOTION_DORMANT_COUNT    , "2");         // 2 dormant messages#endif    // "propLoadProperties(...)" may also be used to load properties from aux storage#if defined(PROPERTY_FILE)    if (*propertyFile) {        logDEBUG(LOGSRC,"Loading property config file: %s", propertyFile);        propLoadProperties(propertyFile, utTrue);    }    if (loadPropCache && *propertyCache) {        logDEBUG(LOGSRC,"Loading property cache file: %s", propertyCache);        propLoadProperties(propertyCache, utFalse);    } else {        // delete property cache file?        logDEBUG(LOGSRC,"Not loading property cache file");    }#endif    /* Serial # */    // If a default serial# has not already been set, get the actual device serial#    // (typically, a default serial number will not already be defined)    const char *serNum = propGetString(PROP_STATE_SERIAL, "");    if (!serNum || !*serNum) {        // Serial number not yet defined        propInitFromString(PROP_STATE_SERIAL, osGetSerialNumberID());        serNum = propGetString(PROP_STATE_SERIAL, "");    }    /* Unique ID */    UInt16 uniqLen = 0;    const UInt8 *uniqId = propGetBinary(PROP_STATE_UNIQUE_ID, (UInt8*)0, (UInt16*)0, &uniqLen);    if (!uniqId || (uniqLen < MIN_UNIQUE_SIZE)) {        // Unique ID not yet defined        UInt8 _uniqueID[] = UNIQUE_ID;        if (sizeof(_uniqueID) >= MIN_UNIQUE_SIZE) {            propSetBinary(PROP_STATE_UNIQUE_ID, _uniqueID, sizeof(_uniqueID)); // changed!            uniqId = propGetBinary(PROP_STATE_UNIQUE_ID, (UInt8*)0, (UInt16*)0, &uniqLen);        } else {            // leave unique-id undefined            //logDEBUG(LOGSRC,"Leaving Unique-ID undefined ...");        }    }    /* Account ID (primary) */    const char *acctId = propGetAccountID(); // propGetString(PROP_STATE_ACCOUNT_ID,"");    if (!acctId || !*acctId) {        // Account ID not yet defined        const char *_acctId = ACCOUNT_ID;        if (_acctId && *_acctId) {            // set default account id            propInitFromString(PROP_STATE_ACCOUNT_ID, _acctId);        } else {            // leave account-id undefined            // NOTE: Leaving the account ID undefined allows the server to utilize             // the Device-ID in a similar fashion as a Unique-ID for identifying            // a device record.        }        acctId = propGetAccountID();  // propGetString(PROP_STATE_ACCOUNT_ID,"");    }        /* Device ID (primary) */    const char *devId = propGetDeviceID(0); // propGetString(PROP_STATE_DEVICE_ID, "");    if (!devId || !*devId) {        // Device-ID not yet defined        const char *_devId = DEVICE_ID;        if (_devId && *_devId) {            // set default device id (if specified)            logDEBUG(LOGSRC,"Setting default Device: %s", DEVICE_ID);            propInitFromString(PROP_STATE_DEVICE_ID, _devId);        } else        if (serNum && *serNum) {            // set to serial number (if available)            logDEBUG(LOGSRC,"Setting Serial# Device: %s", serNum);            propInitFromString(PROP_STATE_DEVICE_ID, serNum);        } else {            // no default device id, and no serial#, make up a name            //propInitFromString(PROP_STATE_DEVICE_ID, "device");            // or leave undefined        }        devId = propGetDeviceID(0); // propGetString(PROP_STATE_DEVICE_ID,"");    }       /* Device ID (secondary) */#if defined(SECONDARY_SERIAL_TRANSPORT)    const char *devBt = propGetDeviceID(1); // propGetString(PROP_STATE_DEVICE_BT, "");    if (!devBt || !*devBt) {        devBt = devId;    } else {        devId = devBt;    }#endif    /* reset hostname to device id */    // This sets the bluetooth broadcast name on serial transport    osSetHostname(devId);    /* make sure all 'changed' flags are reset */    propClearChanged();    // Note that changing properties on the command line will set those properties to 'changed'.}/* save properties */utBool startupSaveProperties(){    if (*propertyCache) {        if (propHasChanged()) {            logINFO(LOGSRC,"Saving properties ...");            propSaveProperties(propertyCache, utFalse);            return utTrue;        } else {            return utFalse;        }    } else {        logDEBUG(LOGSRC,"No property cache! ...");        return utFalse;    }}/* save properties */utBool startupReboot(utBool reboot){        /* save state prior to reboot */    startupSaveProperties();    /* reboot */    // may not be supported on this platform    if (reboot) {        osReboot();        // should not return if reboot is supported    }        /* return reboot failed */    return utFalse;    }// ----------------------------------------------------------------------------/* main process loop callback */void startupMainLoopCallback(){    // This function gets called about once per second from the main processing loop.    // Other monitoring functions, etc. should go here.    /* periodic gps module call */    gpsModulePeriodic();    /* save changed properties */#if defined(PROPERTY_SAVE_INTERVAL) && defined(PROPERTY_FILE)    if (utcIsTimerExpired(lastSavePropertyTimer,lastSavePropertyInterval)) {        lastSavePropertyTimer = utcGetTimer(); // reset        lastSavePropertyInterval = PROPERTY_SAVE_INTERVAL;        startupSaveProperties();    }#endif    /* Expired upload */#if defined(ENBALE_UPLOAD)    if (uploadIsExpired()) {        // upload did not complete in allowed time        uploadCancel();    }#endif}// ----------------------------------------------------------------------------// ----------------------------------------------------------------------------// Main entry point#if defined(__DATE2__)#  define _DATETIME_    (__TIME__ " " __DATE2__ " PST")#else#  define _DATETIME_    (__TIME__ " " __DATE__ " PST")#endif/* print the application header banner */static void _printBanner(){    const char *header    = APPLICATION_DESCRIPTION;    const char *version   = propGetString(PROP_STATE_FIRMWARE,"");    const char *build     = _DATETIME_;    const char *features  = APPLICATION_FEATURES + 1;    const char *account   = propGetAccountID(); // propGetString(PROP_STATE_ACCOUNT_ID,"");    const char *device    = propGetDeviceID(0);  // propGetString(PROP_STATE_DEVICE_ID,"");    const char *serial    = propGetString(PROP_STATE_SERIAL,"");    char host[64] = { 0 };    osGetHostname(host, sizeof(host));    logPRINTF(LOGSRC,SYSLOG_INFO, "--------------------------------------------------------");    logPRINTF(LOGSRC,SYSLOG_INFO, "%s", header);    logPRINTF(LOGSRC,SYSLOG_INFO, "Ver: %s [%s]", version, build);    logPRINTF(LOGSRC,SYSLOG_INFO, "Att: %s", features);    logPRINTF(LOGSRC,SYSLOG_INFO, "Que: %lu max events [format $%04lX]", (UInt32)EVENT_QUEUE_SIZE, (UInt32)DEFAULT_EVENT_FORMAT);    logPRINTF(LOGSRC,SYSLOG_INFO, "Dev: %s/%s [%s:%s]", account, device, host, serial);    logPRINTF(LOGSRC,SYSLOG_INFO, "--------------------------------------------------------");}/* print usage information */static void _usage(const char *pgm){    FILE *out = stderr;    _printBanner();    fprintf(out, "Usage: \n");    fprintf(out, "  %s -h[elp]              - display this help and exit\n", pgm);    fprintf(out, "  %s -v[ersion]           - display version and exit\n", pgm);    fprintf(out, "  %s [options-1] [options-2]\n", pgm);    fprintf(out, "  Options-1:\n");    fprintf(out, "    [-deb[ug]]                 - Debug mode (ie. 'Debug' logging level)\n");    fprintf(out, "    [-log <level>]             - Set logging level (log to syslog)\n");    fprintf(out, "    [-pf[ile] <file> [save]]   - load properties from specified file\n");    fprintf(out, "  Options-2:\n");    fprintf(out, "    [-enc[oding] <enc>]        - Packet encoding\n");    fprintf(out, "    [-cksum]                   - Enable ASCII checksums\n");#if !defined(TRANSPORT_MEDIA_FILE) && !defined(TRANSPORT_MEDIA_SERIAL)    fprintf(out, "    [-dup[lex]]                - Force all packets to be sent via duplex\n");#endif#if !defined(TRANSPORT_MEDIA_SERIAL) && !defined(TRANSPORT_MEDIA_FILE)    fprintf(out, "    [-sim[plex]]               - Force all packets to be sent via simplex\n");#endif    fprintf(out, "    [-comlog]                  - Enable commPort data logging\n");    fprintf(out, "    [-gps <port> [<model>]]    - GPS serial port\n");#if defined(TRANSPORT_MEDIA_SOCKET) || defined(TRANSPORT_MEDIA_GPRS)    fprintf(out, "    [-server <host> [<port>]]  - Server protocol host and port\n");#endif#if defined(TRANSPORT_MEDIA_SERIAL) && !defined(TARGET_WINCE)    fprintf(out, "    [-serial <port> [<bps>]]   - Serial protocol comm port\n");#endif#if defined(TRANSPORT_MEDIA_GPRS) && !defined(TARGET_WINCE)    fprintf(out, "    [-gprs <port> [<bps>]]     - GPRS modem port\n");#endif#if defined(TRANSPORT_MEDIA_FILE)    fprintf(out, "    [-file <outfile>]          - Event data file\n");#endif    fprintf(out, "\n");}// main entry pointint startupDMTP(int argc, char *argv[], int runInThread){    PacketEncoding_t dftEncoding = DEFAULT_ENCODING;    utBool comLog = utFalse;    utBool loadPropCache = utTrue;    const char *portName = (char*)0;        /* init argument index */    if (!argv) { argc = 0; }    const char *pgmName = (argc > 0)? argv[0] : "?";    int argp = 1;    /* initialize file/stream i/o */    ioInitialize();         /* init syslog */    logInitialize(SYSLOG_NAME);        /* check for debug mode and logging */    // These are performed first to allow debug logging to occur _before_ properties    // are loaded and initialized.    for (; argp < argc; argp++) {        if (strEqualsIgnoreCase(argv[argp],"-debug") || strEqualsIgnoreCase(argv[argp],"-deb")) {            // -debug            setDebugMode(utTrue);            logDEBUG(LOGSRC,"Debug Mode ON ...\n");        } else        if (strEqualsIgnoreCase(argv[argp],"-log")) {            // -log <level>            argp++;            if ((argp < argc) && ((*argv[argp] != '-') || isdigit(*(argv[argp]+1)))) {                int level = logParseLevel(argv[argp]); // can be negative                logSetLevel(level);                logEnableSyslog((level >= 0)? utTrue : utFalse);            } else {                // log level is unchanged

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -