📄 propman.c
字号:
// ----------------------------------------------------------------------------// Copyright 2006-2007, Martin D. Flynn// All rights reserved// ----------------------------------------------------------------------------//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// // http://www.apache.org/licenses/LICENSE-2.0// // Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.//// ----------------------------------------------------------------------------// Description:// Property manager// Handles typed properties needed by the protocol.// Note: this module has not yet been made thread-safe.// ---// Change History:// 2006/01/04 Martin D. Flynn// -Initial release// 2006/01/17 Martin D. Flynn// -Changed property keyname strings// -Added PROP_GEOF_ARRIVE_DELAY/PROP_GEOF_DEPART_DELAY properties// 2006/01/29 Martin D. Flynn// -Force KVA_NONDEFAULT attributes on properties loaded from a file// -Changed property save to default saving with key-name (rather than key-id)// -Added "propClearChanged()" function for clearing property 'changed' state.// 2006/02/16 Martin D. Flynn// -Removed 'SAVE' attribute from config properties that should remain static.// 2006/04/06 Martin D. Flynn// -Changed communication property defaults// 2006/05/07 Martin D. Flynn// -Added PROP_CMD_GEOF_ADMIN property.// -Added PROP_GEOF_COUNT property.// -Added PROP_GEOF_VERSION property.// 2006/07/13 Martin D. Flynn// -Updated DFT_PROTOCOL_VERSION to reflect protocol document version change.// 2007/01/28 Martin D. Flynn// -WindowsCE port// -Added several new properties (see 'props.h')// -Added 'propSetSave' function to override property 'save' attribute// -Replaced DFT_PROTOCOL_VERSION with PROTOCOL_VERSION (set in 'defaults.h')// -Changed the following properties to store odometer values in 1 meter units:// PROP_GPS_ACCURACY, PROP_GPS_DISTANCE_DELTA, // PROP_ODOMETER_#_VALUE, PROP_ODOMETER_#_LIMIT// -Changed the following properties to store elapsed time values in seconds:// PROP_ELAPSED_#_VALUE, PROP_ELAPSED_#_LIMIT// -Property key lookups now use a binary search.// 2007/04/28 Martin D. Flynn// -Change default PROP_COMM_HOST to an empty string (""). While using "localhost"// as the default for debugging purposes, it doesn't make sense in an embedded// client. This value should be explicitly defined/set in the 'props.conf' file.// ----------------------------------------------------------------------------#include "stdafx.h" // TARGET_WINCE#include "custom/defaults.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include <ctype.h>#include <math.h>#include "custom/log.h"#include "tools/strtools.h"#include "tools/gpstools.h"#include "tools/utctools.h"#include "tools/bintools.h"#include "tools/io.h"#include "base/propman.h"#include "base/packet.h"// ----------------------------------------------------------------------------#if defined(TARGET_WINCE)// poor-mans 'rint' (WinCE doesn't seem to have it's own 'rint' function)#define RINT(X) (UInt32)((X) + 0.5)#else#define RINT(X) rint(X)#endif// ----------------------------------------------------------------------------#define PROP_LOCK // implement property manager locking#define PROP_UNLOCK // implement property manager unlocking// ----------------------------------------------------------------------------// These are the default settings for specific property values that may need// to be customized for a particular client application. During client app// initialization the appropriate calls to the following function should be made.// "propInitFromString(<PopKey>, <StringValue>);"// should be called.//#define DFT_FIRMWARE_VERSION "DMTP_C_" RELEASE_VERSION // default firmware version#define DFT_FIRMWARE_VERSION APPLICATION_NAME "_C." RELEASE_VERSION#define DFT_COMM_HOST "" // (was "localhost")#define DFT_COMM_PORT "31000" // this default may change at any time#define DFT_ACCESS_PIN "0x3132333435363738" // "12345678"// 'true' to save with key name, 'false' to save with key code#define PROP_SAVE_KEY_NAME utTrue// ----------------------------------------------------------------------------#define WO (KVA_HIDDEN | KVA_WRITEONLY)#define RO (KVA_READONLY)#define SAVE (KVA_SAVE)#define UInt32_to_Double(U,T) ((double)(U) / pow(10.0,(double)KVT_DEC(T)))#define Double_to_UInt32(D,T) ((UInt32)RINT((D) * pow(10.0,(double)KVT_DEC(T))))// ----------------------------------------------------------------------------// Property definition table// Notes:// - The values in the 'name' column are arbitrary, and are just suggestions in the// OpenDMTP protocol. As such, they may change at any time without notice. If you// rely on the specified property 'name' in your property files, make sure you double // check your property files against the names specified here at the time you plan to // upgrade your code to the newest version.static utBool binarySearchOK = utFalse; // false, until verifiedstatic KeyValue_t properties[] = {#ifdef CUSTOM_PROPERTIES#include "custom/custprop.inc"#endif //KeyCode Name Type Attr Ndx Init // --- local serial port configuration { PROP_CFG_XPORT_PORT , "cfg.xpo.port" , KVT_STRING , RO , 1, "" }, { PROP_CFG_XPORT_BPS , "cfg.xpo.bps" , KVT_UINT32 , RO , 1, "" }, { PROP_CFG_XPORT_DEBUG , "cfg.xpo.debug" , KVT_BOOLEAN , RO , 1, "0" }, { PROP_CFG_GPS_PORT , "cfg.gps.port" , KVT_STRING , RO , 1, "" }, { PROP_CFG_GPS_BPS , "cfg.gps.bps" , KVT_UINT32 , RO , 1, "4800" }, { PROP_CFG_GPS_MODEL , "cfg.gps.model" , KVT_STRING , RO , 1, "" }, { PROP_CFG_GPS_DEBUG , "cfg.gps.debug" , KVT_BOOLEAN , RO , 1, "0" }, { PROP_CFG_SERIAL0_PORT , "cfg.sp0.port" , KVT_STRING , RO , 1, "" }, { PROP_CFG_SERIAL0_BPS , "cfg.sp0.bps" , KVT_UINT32 , RO , 1, "" }, { PROP_CFG_SERIAL0_DEBUG , "cfg.sp0.debug" , KVT_BOOLEAN , RO , 1, "0" }, { PROP_CFG_SERIAL1_PORT , "cfg.sp1.port" , KVT_STRING , RO , 1, "" }, { PROP_CFG_SERIAL1_BPS , "cfg.sp1.bps" , KVT_UINT32 , RO , 1, "" }, { PROP_CFG_SERIAL1_DEBUG , "cfg.sp1.debug" , KVT_BOOLEAN , RO , 1, "0" }, { PROP_CFG_SERIAL2_PORT , "cfg.sp2.port" , KVT_STRING , RO , 1, "" }, { PROP_CFG_SERIAL2_BPS , "cfg.sp2.bps" , KVT_UINT32 , RO , 1, "" }, { PROP_CFG_SERIAL2_DEBUG , "cfg.sp2.debug" , KVT_BOOLEAN , RO , 1, "0" }, { PROP_CFG_SERIAL3_PORT , "cfg.sp3.port" , KVT_STRING , RO , 1, "" }, { PROP_CFG_SERIAL3_BPS , "cfg.sp3.bps" , KVT_UINT32 , RO , 1, "" }, { PROP_CFG_SERIAL3_DEBUG , "cfg.sp3.debug" , KVT_BOOLEAN , RO , 1, "0" }, // --- miscellaneous commands { PROP_CMD_SAVE_PROPS , "cmd.saveprops" , KVT_COMMAND , WO , 1, 0 }, { PROP_CMD_AUTHORIZE , "cmd.auth" , KVT_COMMAND , WO , 1, 0 }, { PROP_CMD_STATUS_EVENT , "cmd.status" , KVT_COMMAND , WO , 1, 0 }, { PROP_CMD_SET_OUTPUT , "cmd.output" , KVT_COMMAND , WO , 1, 0 }, { PROP_CMD_RESET , "cmd.reset" , KVT_COMMAND , WO , 1, 0 }, // --- retained state properties { PROP_STATE_PROTOCOL , "sta.proto" , KVT_UINT8 , RO , 3, PROTOCOL_VERSION }, { PROP_STATE_FIRMWARE , "sta.firm" , KVT_STRING , RO , 1, DFT_FIRMWARE_VERSION }, { PROP_STATE_COPYRIGHT , "sta.copyright" , KVT_STRING , RO , 1, "" }, { PROP_STATE_SERIAL , "sta.serial" , KVT_STRING , RO , 1, "" }, { PROP_STATE_UNIQUE_ID , "sta.uniq" , KVT_BINARY , RO , 30, "" }, { PROP_STATE_ACCOUNT_ID , "sta.account" , KVT_STRING , RO , 1, "" }, { PROP_STATE_DEVICE_ID , "sta.device" , KVT_STRING , RO , 1, "" },#if defined(SECONDARY_SERIAL_TRANSPORT) { PROP_STATE_DEVICE_BT , "sta.device.bt" , KVT_STRING , SAVE , 1, "" },#endif { PROP_STATE_USER_ID , "sta.user" , KVT_STRING , SAVE , 1, "" }, { PROP_STATE_USER_TIME , "sta.user.time" , KVT_UINT32 , RO|SAVE , 1, "0" }, { PROP_STATE_TIME , "sta.time" , KVT_UINT32 , RO , 1, "0" }, { PROP_STATE_GPS , "sta.gpsloc" , KVT_GPS , RO|SAVE , 1, "" }, { PROP_STATE_GPS_DIAGNOSTIC , "sta.gpsdiag" , KVT_UINT32 , RO , 5, "0,0,0,0,0" }, { PROP_STATE_QUEUED_EVENTS , "sta.evtqueue" , KVT_UINT32 , RO , 2, "0,0" }, { PROP_STATE_DEV_DIAGNOSTIC , "sta.devdiag" , KVT_UINT32 , RO|SAVE , 5, "0,0,0,0,0" }, // --- Communication protocol properties { PROP_COMM_SPEAK_FIRST , "com.first" , KVT_BOOLEAN , SAVE , 1, "1" }, { PROP_COMM_FIRST_BRIEF , "com.brief" , KVT_BOOLEAN , SAVE , 1, "0" }, { PROP_COMM_MAX_CONNECTIONS , "com.maxconn" , KVT_UINT8 , SAVE , 3, "8,4,60" }, // total/duplex/minutes { PROP_COMM_MIN_XMIT_DELAY , "com.mindelay" , KVT_UINT16 , SAVE , 1, "180" }, { PROP_COMM_MIN_XMIT_RATE , "com.minrate" , KVT_UINT32 , SAVE , 1, "180" }, { PROP_COMM_MAX_XMIT_RATE , "com.maxrate" , KVT_UINT32 , SAVE , 1, "3600" }, { PROP_COMM_MAX_DUP_EVENTS , "com.maxduplex" , KVT_UINT8 , SAVE , 1, "10" }, { PROP_COMM_MAX_SIM_EVENTS , "com.maxsimplex" , KVT_UINT8 , SAVE , 1, "2" }, // --- Communication connection properties { PROP_COMM_SETTINGS , "com.settings" , KVT_STRING , SAVE , 1, "" }, { PROP_COMM_HOST , "com.host" , KVT_STRING , SAVE , 1, DFT_COMM_HOST }, { PROP_COMM_PORT , "com.port" , KVT_UINT16 , SAVE , 1, DFT_COMM_PORT }, { PROP_COMM_DNS_1 , "com.dns1" , KVT_STRING , SAVE , 1, "" }, { PROP_COMM_DNS_2 , "com.dns2" , KVT_STRING , SAVE , 1, "" }, { PROP_COMM_CONNECTION , "com.connection" , KVT_STRING , SAVE , 1, "" }, { PROP_COMM_APN_NAME , "com.apnname" , KVT_STRING , SAVE , 1, "" }, { PROP_COMM_APN_SERVER , "com.apnserv" , KVT_STRING , SAVE , 1, "" }, { PROP_COMM_APN_USER , "com.apnuser" , KVT_STRING , SAVE , 1, "" }, { PROP_COMM_APN_PASSWORD , "com.apnpass" , KVT_STRING , SAVE , 1, "" }, { PROP_COMM_APN_PHONE , "com.apnphone" , KVT_STRING , SAVE , 1, "" }, // "*99***1#" { PROP_COMM_APN_SETTINGS , "com.apnsett" , KVT_STRING , SAVE , 1, "" }, { PROP_COMM_MIN_SIGNAL , "com.minsignal" , KVT_INT16 , SAVE , 1, "7" }, { PROP_COMM_ACCESS_PIN , "com.pin" , KVT_BINARY , SAVE , 8, DFT_ACCESS_PIN }, // --- Packet/Data format properties { PROP_COMM_CUSTOM_FORMATS , "com.custfmt" , KVT_UINT8 , SAVE , 1, "0" }, { PROP_COMM_ENCODINGS , "com.encodng" , KVT_UINT8 , SAVE , 1, "0x7" }, { PROP_COMM_BYTES_READ , "com.rdcnt" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_COMM_BYTES_WRITTEN , "com.wrcnt" , KVT_UINT32 , SAVE , 1, "0" }, // --- GPS properties { PROP_GPS_SAMPLE_RATE , "gps.smprate" , KVT_UINT16 , SAVE , 1, "7" }, { PROP_GPS_AQUIRE_WAIT , "gps.aquwait" , KVT_UINT16 , SAVE , 1, "0" }, { PROP_GPS_EXPIRATION , "gps.expire" , KVT_UINT16 , SAVE , 1, "300" }, { PROP_GPS_CLOCK_DELTA , "gps.updclock" , KVT_BOOLEAN , SAVE , 1, "15" }, { PROP_GPS_ACCURACY , "gps.accuracy" , KVT_UINT16 , SAVE , 1, "0" }, { PROP_GPS_MIN_SPEED , "gps.minspd" , KVT_UINT16|KVT_DEC(1) , SAVE , 1, "8.0" }, { PROP_GPS_DISTANCE_DELTA , "gps.dstdelt" , KVT_UINT32 , SAVE , 1, "500" }, // --- GeoZone properties { PROP_CMD_GEOF_ADMIN , "gf.admin" , KVT_COMMAND , WO , 1, 0 }, { PROP_GEOF_COUNT , "gf.count" , KVT_UINT16 , RO , 1, "0" }, { PROP_GEOF_VERSION , "gf.version" , KVT_STRING , SAVE , 1, "" }, { PROP_GEOF_ARRIVE_DELAY , "gf.arr.delay" , KVT_UINT32 , SAVE , 1, "30" }, { PROP_GEOF_DEPART_DELAY , "gf.dep.delay" , KVT_UINT32 , SAVE , 1, "10" }, { PROP_GEOF_CURRENT , "gf.current" , KVT_UINT32 , SAVE , 1, "0" }, // --- GeoCorr properties { PROP_CMD_GEOC_ADMIN , "gc.admin" , KVT_COMMAND , WO , 1, 0 }, { PROP_GEOC_ACTIVE_ID , "gc.active" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_GEOC_VIOLATION_INTRVL , "gc.vio.rate" , KVT_UINT16 , SAVE , 1, "300" }, { PROP_GEOC_VIOLATION_COUNT , "gc.vio.cnt" , KVT_UINT16 , SAVE , 1, "0" }, // --- Motion properties { PROP_MOTION_START_TYPE , "mot.start.type" , KVT_UINT8 , SAVE , 1, "0" }, { PROP_MOTION_START , "mot.start" , KVT_UINT16|KVT_DEC(1) , SAVE , 1, "0.0" }, { PROP_MOTION_IN_MOTION , "mot.inmotion" , KVT_UINT16 , SAVE , 1, "0" }, { PROP_MOTION_STOP , "mot.stop" , KVT_UINT16 , SAVE , 1, "600" }, { PROP_MOTION_STOP_TYPE , "mot.stop.type" , KVT_UINT8 , SAVE , 1, "0" }, { PROP_MOTION_DORMANT_INTRVL , "mot.dorm.rate" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_MOTION_DORMANT_COUNT , "mot.dorm.cnt" , KVT_UINT16 , SAVE , 1, "1" }, { PROP_MOTION_EXCESS_SPEED , "mot.exspeed" , KVT_UINT16|KVT_DEC(1) , SAVE , 1, "0.0" }, { PROP_MOTION_MOVING_INTRVL , "mot.moving" , KVT_UINT16 , SAVE , 1, "0" }, // --- Odometer properties { PROP_ODOMETER_0_VALUE , "odo.0.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_1_VALUE , "odo.1.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_2_VALUE , "odo.2.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_3_VALUE , "odo.3.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_4_VALUE , "odo.4.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_5_VALUE , "odo.5.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_6_VALUE , "odo.6.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_7_VALUE , "odo.7.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_0_LIMIT , "odo.0.limit" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_1_LIMIT , "odo.1.limit" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_2_LIMIT , "odo.2.limit" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_3_LIMIT , "odo.3.limit" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_4_LIMIT , "odo.4.limit" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_5_LIMIT , "odo.5.limit" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_6_LIMIT , "odo.6.limit" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_7_LIMIT , "odo.7.limit" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ODOMETER_0_GPS , "odo.0.gps" , KVT_GPS , RO|SAVE , 1, "0" }, { PROP_ODOMETER_1_GPS , "odo.1.gps" , KVT_GPS , RO|SAVE , 1, "0" }, { PROP_ODOMETER_2_GPS , "odo.2.gps" , KVT_GPS , RO|SAVE , 1, "0" }, { PROP_ODOMETER_3_GPS , "odo.3.gps" , KVT_GPS , RO|SAVE , 1, "0" }, { PROP_ODOMETER_4_GPS , "odo.4.gps" , KVT_GPS , RO|SAVE , 1, "0" }, { PROP_ODOMETER_5_GPS , "odo.5.gps" , KVT_GPS , RO|SAVE , 1, "0" }, { PROP_ODOMETER_6_GPS , "odo.6.gps" , KVT_GPS , RO|SAVE , 1, "0" }, { PROP_ODOMETER_7_GPS , "odo.7.gps" , KVT_GPS , RO|SAVE , 1, "0" }, // --- Digital input properties { PROP_INPUT_STATE , "inp.state" , KVT_UINT32 , RO , 1, "0" }, // DON"T SAVE { PROP_INPUT_CONFIG_0 , "inp.0.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_INPUT_CONFIG_1 , "inp.1.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_INPUT_CONFIG_2 , "inp.2.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_INPUT_CONFIG_3 , "inp.3.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_INPUT_CONFIG_4 , "inp.4.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_INPUT_CONFIG_5 , "inp.5.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_INPUT_CONFIG_6 , "inp.6.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_INPUT_CONFIG_7 , "inp.7.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, //{ PROP_INPUT_CONFIG_8 , "inp.8.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, //{ PROP_INPUT_CONFIG_9 , "inp.9.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, //{ PROP_INPUT_CONFIG_A , "inp.A.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, //{ PROP_INPUT_CONFIG_B , "inp.B.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, //{ PROP_INPUT_CONFIG_C , "inp.C.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, //{ PROP_INPUT_CONFIG_D , "inp.D.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, //{ PROP_INPUT_CONFIG_E , "inp.E.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, //{ PROP_INPUT_CONFIG_F , "inp.F.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, // --- Digitaloutput properties { PROP_OUTPUT_CONFIG_0 , "out.0.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_OUTPUT_CONFIG_1 , "out.1.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_OUTPUT_CONFIG_2 , "out.2.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_OUTPUT_CONFIG_3 , "out.3.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_OUTPUT_CONFIG_4 , "out.4.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_OUTPUT_CONFIG_5 , "out.5.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_OUTPUT_CONFIG_6 , "out.6.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, { PROP_OUTPUT_CONFIG_7 , "out.7.conf" , KVT_UINT32 , SAVE , 2, "0,0" }, // --- Elapsed time properties { PROP_ELAPSED_0_VALUE , "ela.0.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ELAPSED_1_VALUE , "ela.1.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ELAPSED_2_VALUE , "ela.2.value" , KVT_UINT32 , SAVE , 1, "0" }, { PROP_ELAPSED_3_VALUE , "ela.3.value" , KVT_UINT32 , SAVE , 1, "0" },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -