📄 monitor.c
字号:
}
return TRUE;
}
static BOOLEAN CheckEntry_EXTRA(MONITORENTRY_STRUCT *entry)
{
INT8U updatemode;
HWORD_UNION temp;
if ((entry->servicetype & 0x07) > _DIFGPS) return FALSE;
updatemode = entry->servicetype & 0x18;
if (updatemode > _TIMING_OR_FIXEDSPACE) return FALSE;
if (updatemode == _TIMING || updatemode == _TIMING_OR_FIXEDSPACE) {
temp.hword = entry->periodtime;
temp.bytes.low &= 0x3f;
if (temp.hword == 0) return FALSE;
}
if (updatemode == _FIXEDSPACE || updatemode == _TIMING_OR_FIXEDSPACE) {
temp.hword = entry->fixedspace;
temp.bytes.high &= 0x7f;
if (temp.hword == 0) return FALSE;
entry->servicetype = (entry->servicetype & 0xf8) | _STDGPS;
}
return TRUE;
}
static void SetMonitorPara(INT8U id, MONITORENTRY_STRUCT *entry)
{
HWORD_UNION temp;
if (monitor[id].channeltype == MT_EMPTY) {
monitor[id].meterid = InstallMeter(MeterProc, id);
monitor[id].periodtmr = CreateTimer(PeriodTmrProc, id);
monitor[id].monitortmr = CreateTimer(MonitorTmrProc, id);
monitor[id].querytime = PERIOD_DEFQUERY;
}
monitor[id].channeltype = entry->channeltype;
monitor[id].gpscansleep = entry->gpscansleep;
monitor[id].egcode = entry->egcode;
monitor[id].servicetype = entry->servicetype;
monitor[id].monitortime = entry->monitortime;
monitor[id].periodtime = entry->periodtime;
monitor[id].fixedspace = entry->fixedspace;
monitor[id].mttellen = entry->mttellen;
memcpy(monitor[id].mttel, entry->mttel, sizeof(monitor[id].mttel));
gpsbuf[id].numgps = 0;
temp.hword = monitor[id].monitortime;
if (monitor[id].channeltype & MT_ALARM)
StartTmr(monitor[id].periodtmr, PERIOD_STARTDELAY1);
else
StartTmr(monitor[id].periodtmr, PERIOD_STARTDELAY2);
StartTmr(monitor[id].monitortmr, MINUTE, temp.bytes.high * 60 + temp.bytes.low);
}
static INT8U FindMonitor(INT8U masktype, MONITORENTRY_STRUCT *entry)
{
INT8U i;
for (i = 0; i < MAX_MONITOR; i++) {
if (monitor[i].channeltype & masktype) {
if (entry == 0) {
return i;
} else if (monitor[i].channeltype != MT_EMPTY) {
if (monitor[i].egcode != entry->egcode) continue;
if (CmpString_Byte(entry->oldtel, entry->oldtellen, '0') || entry->oldtellen == 0)
return i;
if (ACmpString(CASESENSITIVE, entry->oldtel, monitor[i].mttel, entry->oldtellen, monitor[i].mttellen) == STR_EQUAL)
return i;
if (CmpString_Byte(monitor[i].mttel, monitor[i].mttellen, '0'))
return i;
}
}
}
return 0xff;
}
__inline INT8U FindBlankMonitor(void)
{
return FindMonitor(MT_EMPTY, 0);
}
static INT8U FindEntryMonitor(INT8U channeltype, MONITORENTRY_STRUCT *entry)
{
if (channeltype == MT_POSITION || channeltype == MT_ALARM || channeltype == MT_AUTOMONITOR)
return FindMonitor(channeltype, 0);
else
return FindMonitor(channeltype, entry);
}
static void DelAllMonitor(void)
{
INT8U i, channeltype;
for (i = 0; i < MAX_MONITOR; i++) {
channeltype = monitor[i].channeltype;
if (channeltype != MT_EMPTY && (channeltype & MT_ALARM) == 0) Cancel(i, _DEL_USER);
}
}
static void DiagnoseProc(void)
{
INT8U i, ct;
ct = 0;
for (i = 0; i < MAX_MONITOR; i++) {
if (monitor[i].channeltype != MT_EMPTY) ct++;
}
if (ct != nummonitor) ErrExit(ERR_MONITOR_MEM);
if (GetTmrSwitch(querytmr) != ON) ErrExit(ERR_MONITOR_TMR);
if (!PubParaValid(MONITORSTATUS_)) ErrExit(ERR_MONITOR_STATUS);
}
void AddAutoMonitor(void)
{
INT8U tag;
tempmonitor.egcode = EgCode.egcode;
tempmonitor.channeltype = MT_AUTOMONITOR;
tempmonitor.oldtel = 0;
tempmonitor.oldtellen = 0;
if (PubParaValid(ALARMTEL_)) {
tempmonitor.mttellen = AlarmTel.len;
tempmonitor.mttel = AlarmTel.tel;
} else {
tempmonitor.mttellen = 0;
tempmonitor.mttel = 0;
}
if (FindEntryMonitor(MT_MONITOR, &tempmonitor) != 0xFF) return;
//change by qzc
if ((AutoMonitorPara.ctlflag & 0x01) == 0x01) {
if((AutoMonitorPara.ctlflag & 0x80)==0x80) //空重车组
{
tag=2;
}
else
{
if (SensorValid_FILTER(_ACC)) tag=0;
else tag = 1;
}
tempmonitor.gpscansleep = TRUE;
tempmonitor.servicetype = AutoMonitorPara.para[tag].servicetype;
tempmonitor.monitortime = AutoMonitorPara.para[tag].monitortime;
tempmonitor.periodtime = AutoMonitorPara.para[tag].monitorperiod;
tempmonitor.fixedspace = AutoMonitorPara.para[tag].fixedspace;
if (tempmonitor.periodtime == 0x0000 && tempmonitor.fixedspace == 0x00000) {
tempmonitor.delreason = _DEL_USER;
DelMonitor(&tempmonitor);
} else {
AddMonitor(&tempmonitor);
}
} else {
tempmonitor.delreason = _DEL_USER;
DelMonitor(&tempmonitor);
}
}
void InitMonitor(void)
{
INT8U i;
sendchn = 0;
nummonitor = 0;
for (i = 0; i < MAX_MONITOR; i++) {
monitor[i].channeltype = MT_EMPTY;
sendbuf[i].isempty = TRUE;
}
querytmr = CreateTimer(QueryTmrProc, 0);
StartTmr(querytmr, PERIOD_QUERY);
if (!PubParaValid(MONITORSTATUS_)) {
MonitorStatus.status = _ALLOW;
StorePubPara(MONITORSTATUS_);
}
AddAutoMonitor();
InstallDiagProc(DiagnoseProc);
#if EN_NOSIGNALRESEND > 0
InitBlindAreaResend();
#endif
InstallDiagProc(DiagnoseProc);
}
BOOLEAN QueryMonitor(MONITORENTRY_STRUCT *entry, INT16U querytime)
{
INT8U curid, channeltype;
HWORD_UNION temp;
entry->oldtel = entry->mttel;
entry->oldtellen = entry->mttellen;
channeltype = entry->channeltype;
if (channeltype & MT_MONITOR) {
channeltype |= MT_ALARM;
}
if ((curid = FindEntryMonitor(channeltype, entry)) == 0xFF) {
return FALSE;
} else {
temp.hword = querytime;
monitor[curid].querytime = temp.bytes.high * 60 + temp.bytes.low;
return TRUE;
}
}
BOOLEAN DelMonitor(MONITORENTRY_STRUCT *entry)
{
INT8U curid, channeltype;
if (!CheckEntry_BASE(entry)) return FALSE;
entry->oldtel = entry->mttel;
entry->oldtellen = entry->mttellen;
channeltype = entry->channeltype;
if (channeltype & MT_MONITOR) {
channeltype |= MT_ALARM;
}
if ((curid = FindEntryMonitor(channeltype, entry)) != 0xFF) {
Cancel(curid, entry->delreason);
return TRUE;
} else {
return FALSE;
}
}
BOOLEAN ModifyMonitor(MONITORENTRY_STRUCT *entry)
{
INT8U curid, channeltype;
if (!CheckEntry_BASE(entry) || !CheckEntry_EXTRA(entry)) return FALSE;
channeltype = entry->channeltype;
if (channeltype & MT_MONITOR) {
channeltype |= (MT_ALARM | MT_AUTOMONITOR);
}
if ((curid = FindEntryMonitor(channeltype, entry)) == 0xFF) {
return FALSE;
} else {
if (monitor[curid].channeltype & MT_ALARM) {
entry->channeltype |= MT_ALARM;
if (!monitor[curid].gpscansleep) entry->gpscansleep = FALSE;
}
if (monitor[curid].channeltype & MT_AUTOMONITOR) {
entry->channeltype |= MT_AUTOMONITOR;
}
if (monitor[curid].gpscansleep != entry->gpscansleep) {
if (entry->gpscansleep) ReleaseGps();
else ApplyGps();
}
SetMonitorPara(curid, entry);
return TRUE;
}
}
INT8U AddMonitor(MONITORENTRY_STRUCT *entry)
{
INT8U curid;
if (!CheckEntry_BASE(entry) || !CheckEntry_EXTRA(entry)) return _ADD_FAILURE;
entry->oldtel = entry->mttel;
entry->oldtellen = entry->mttellen;
if (ModifyMonitor(entry)) return _ADD_SUCCESS;
if (!CanMonitor() && (entry->channeltype & MT_ALARM) == 0) return _ADD_REJECT;
if ((curid = FindBlankMonitor()) == 0xFF) {
return _ADD_FAILURE;
} else {
nummonitor++;
if (!entry->gpscansleep) ApplyGps();
SetMonitorPara(curid, entry);
return _ADD_SUCCESS;
}
}
void ChangeMonitorEgcode(void)
{
INT8U i;
for (i = 0; i < MAX_MONITOR; i++) {
if (monitor[i].channeltype & MT_EMPTY) continue;
if (monitor[i].channeltype & (MT_POSITION | MT_ALARM | MT_AUTOMONITOR))
monitor[i].egcode = EgCode.egcode;
else
Cancel(i, _DEL_CHANGEEGCODE);
}
}
void MonitorTskEntry(void)
{
INT8U i;
INT16U channeltype;
#if EN_NOSIGNALRESEND > 0
SYSFRAME_UP_STRUCT *tempframe;
#endif
for (i = 0; i < MAX_MONITOR; i++) {
if (sendchn >= MAX_MONITOR) sendchn = 0;
if (!sendbuf[sendchn].isempty) {
channeltype = GetServiceAttrib(SER_MONITOR);
if (monitor[sendchn].channeltype & MT_ALARM) {
channeltype = GetServiceAttrib(SER_ALARM);
}
if (monitor[sendchn].channeltype & MT_POSITION) {
channeltype = GetServiceAttrib(SER_POSITION);
}
if (monitor[sendchn].mttellen == 0 ||
CmpString_Byte(monitor[sendchn].mttel, monitor[sendchn].mttellen, '0'))
channeltype &= ~SM_ATTR_SM_CODEMASK;
channeltype |= SM_ATTR_GPS;
#if EN_NOSIGNALRESEND > 0
tempframe = (SYSFRAME_UP_STRUCT *)sendbuf[sendchn].buffer;
if(tempframe->type[0]==0x01 && tempframe->type[1]!=0x44) {
if(!NetworkRegisted()) {
PrepareStoreDate(channeltype, monitor[sendchn].mttel, monitor[sendchn].mttellen, sendbuf[sendchn].buffer);//直接把数据写入扇区
}
}
#endif
if (SendSM(channeltype, monitor[sendchn].mttel,
monitor[sendchn].mttellen, sendbuf[sendchn].buffer, sendbuf[sendchn].len, (void (*)(INT8U)) 0)) {
sendbuf[sendchn++].isempty = TRUE;
}
break;
} else {
sendchn++;
}
}
}
void AllowMonitor(void)
{
if (MonitorStatus.status != _ALLOW) {
MonitorStatus.status = _ALLOW;
StorePubPara(MONITORSTATUS_);
OSQPost(GsmTaskMsgQue, MSG_MONITOR_ALLOW, 0, 0);
}
}
void RejectMonitor(void)
{
if (MonitorStatus.status != (INT8U)(~_ALLOW)) {
MonitorStatus.status = (INT8U)~_ALLOW;
StorePubPara(MONITORSTATUS_);
DelAllMonitor();
}
}
BOOLEAN CanMonitor(void)
{
if (MonitorStatus.status == _ALLOW) return TRUE;
else return FALSE;
}
INT8U QueryPosition(INT8U *ptr)
{
HWORD_UNION temp;
InitStrm(&wstrm, ptr, 1024);
WriteBYTE_Strm(&wstrm, _STDGPS | 0x40);
MovStrmPtr(&wstrm, GetSysTime_Date((DATE_STRUCT *)GetStrmPtr(&wstrm)));
/* if (GpsDataValid()) {*/
/* MovStrmPtr(&wstrm, GetGpsTime((TIME_STRUCT *)GetStrmPtr(&wstrm)));*/
/* } else {*/
MovStrmPtr(&wstrm, SysTimeToGpsTime((TIME_STRUCT *)GetStrmPtr(&wstrm)));
/* }*/
temp = GetDatumData((DATUM_STRUCT *)GetStrmPtr(&wstrm));
ConvertDatumData((DATUM_STRUCT *)GetStrmPtr(&wstrm));
MovStrmPtr(&wstrm, temp.bytes.low);
WriteBYTE_Strm(&wstrm, temp.bytes.high & 0x7f);
return GetStrmLen(&wstrm);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -