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

📄 motion.c

📁 Open DMT Client C Source code
💻 C
📖 第 1 页 / 共 2 页
字号:
// ----------------------------------------------------------------------------// 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://  GPS fix checking for motion events.//  Examines changes in GPS fix data and generates motion events accordingly.// ---// Change History://  2006/01/04  Martin D. Flynn//     -Initial release//  2006/01/23  Martin D. Flynn//     -Init dormant timer at first non-motion GPS fix//  2006/02/13  Martin D. Flynn//     -Changed stop event checking to include an option to have the stop event//      time set to the time the vehicle actually stopped.  This also effects the//      behaviour of the in-motion message to sending in-motion events iff the //      vehicle is actually moving at the time the event is generated.  (See//      property PROP_MOTION_STOP_TYPE).//  2007/01/28  Martin D. Flynn//     -WindowsCE port//  2007/03/11  Martin D. Flynn//     -Modified 'stop' checking to allow for detection of other 'stop' indicators,//      such as an indication that the ignition has been turned off.//  2007/04/28  Martin D. Flynn//     -Added a 5kph setback to the excess-speed detection and event generation.//      Example: If a 100 kph excess speed is triggered, the vehicle must slow to//      below 95 kph to reset the excess speed indicator.// ----------------------------------------------------------------------------#include "stdafx.h" // TARGET_WINCE#include "custom/defaults.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include "custom/log.h"#include "custom/gps.h"#include "tools/stdtypes.h"#include "tools/gpstools.h"#include "tools/utctools.h"#include "base/propman.h"#include "base/statcode.h"#include "base/events.h"#include "modules/motion.h"// ----------------------------------------------------------------------------#define MOTION_START_PRIORITY       PRIORITY_NORMAL#define MOTION_STOP_PRIORITY        PRIORITY_NORMAL#define IN_MOTION_PRIORITY          PRIORITY_LOW#define DORMANT_PRIORITY            PRIORITY_LOW#define EXCESS_SPEED_PRIORITY       PRIORITY_NORMAL#define MOVING_PRIORITY             PRIORITY_NORMAL// ----------------------------------------------------------------------------#if defined(DEBUG_COMPILE)// no minimum when compiling for testing purposes#define MIN_IN_MOTION_INTERVAL      0L                  // seconds#define MIN_DORMANT_INTERVAL        0L                  // seconds#elif defined(TRANSPORT_MEDIA_NONE)// no minimum when sending to a file#define MIN_IN_MOTION_INTERVAL      0L                  // seconds#define MIN_DORMANT_INTERVAL        0L                  // seconds#elif defined(TRANSPORT_MEDIA_FILE)// no minimum when sending to a file#define MIN_IN_MOTION_INTERVAL      0L                  // seconds#define MIN_DORMANT_INTERVAL        0L                  // seconds#elif defined(TRANSPORT_MEDIA_SERIAL)// small minimum when sending to bluetooth#define MIN_IN_MOTION_INTERVAL      20L                 // seconds#define MIN_DORMANT_INTERVAL        20L                 // seconds#else// set default minimum when sending to server#define MIN_IN_MOTION_INTERVAL      60L                 // seconds#define MIN_DORMANT_INTERVAL        MINUTE_SECONDS(5)   // seconds#endif#define EXCESS_SPEED_SETBACK        5.0                 // kph// ----------------------------------------------------------------------------static utBool               motionInit  = utFalse;static GPS_t                lastMotionFix;              // needs to be initializedstatic GPS_t                lastStoppedFix;             // needs to be initializedstatic utBool               isInMotion                  = utFalse;static utBool               isExceedingSpeed            = utFalse;static TimerSec_t           lastStoppedTimer            = 0L;static TimerSec_t           lastInMotionMessageTimer    = 0L;static TimerSec_t           lastMovingMessageTimer      = 0L;static TimerSec_t           lastDormantMessageTimer     = 0L;static UInt32               dormantCount                = 0L;static eventAddFtn_t        ftnQueueEvent = 0;static threadMutex_t        motionMutex;#define MOTION_LOCK         MUTEX_LOCK(&motionMutex);#define MOTION_UNLOCK       MUTEX_UNLOCK(&motionMutex);// ----------------------------------------------------------------------------/* initialize motion module */void motionInitialize(eventAddFtn_t queueEvent){        /* init motion */    if (!motionInit) {        motionInit = utTrue;                /* event handler */        ftnQueueEvent = queueEvent;            /* clear GPS points */        gpsClear(&lastMotionFix);        gpsClear(&lastStoppedFix);            /* init motion mutex */        threadMutexInit(&motionMutex);            }}/* reset moving message timer */void motionResetMovingMessageTimer(){    MOTION_LOCK {        lastMovingMessageTimer = 0L;    } MOTION_UNLOCK}// ----------------------------------------------------------------------------/* add a motion event to the event queue */static void _queueMotionEvent(PacketPriority_t priority, StatusCode_t code, UInt32 timestamp, const GPS_t *gps){        /* make sure we have a GPS fix */    GPS_t gpsFix;    const GPS_t *gpsf = gps? gps : gpsGetLastGPS(&gpsFix, 0);        /* init event */    Event_t evRcd;    evSetEventDefaults(&evRcd, code, timestamp, gpsf);        /* queue event */    if (ftnQueueEvent) {        (*ftnQueueEvent)(priority, DEFAULT_EVENT_FORMAT, &evRcd);    }}// ----------------------------------------------------------------------------/* stop motion */static void _motionStop(UInt32 nowTime, const GPS_t *newFix){    // NOTE: 'isInMotion' is assumed to be true when this function is called!    // ('isInMotion' implies that we are tracking start/stop)    /* set to officially NOT moving */    isInMotion = utFalse;        /* send 'stop' event */    UInt16 defStopType = (UInt16)propGetUInt32(PROP_MOTION_STOP_TYPE, 0); // 0=after_delay, 1=when_stopped    UInt32 stoppedTime = nowTime;    const GPS_t *stoppedGPS = (GPS_t*)0;    if (defStopType == MOTION_STOP_AFTER_DELAY) {        // send 'stop' message with latest gps fix.        stoppedTime = nowTime;        stoppedGPS  = newFix;    } else    if (defStopType == MOTION_STOP_WHEN_STOPPED) {        // send 'stop' message with the last gps at the time we actually detected the stop.        stoppedTime = lastStoppedTimer? TIMER_TO_UTC(lastStoppedTimer) : nowTime;        stoppedGPS  = gpsIsValid(&lastStoppedFix)? &lastStoppedFix : newFix;    } else {        // default: send 'stop' message with latest gps fix.        stoppedTime = nowTime;        stoppedGPS  = newFix;    }    _queueMotionEvent(MOTION_STOP_PRIORITY, STATUS_MOTION_STOP, stoppedTime, stoppedGPS);    /* reset stopped fix */    gpsClear(&lastStoppedFix);    lastStoppedTimer = (TimerSec_t)0L;    }/* check new GPS fix for various motion events */static void _motionCheckGPS(const GPS_t *oldFix, const GPS_t *newFix){        /* 'start' definition */    // defStartType:

⌨️ 快捷键说明

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