📄 systemmanager.c
字号:
/********************************************
* 系统变量初始化文件
* 主要初始化变量包括:
********************************************/
#include "typedef.h"
#include "global.h"
#include "systemmanager.h"
#include <string.h>
#include "menubuffer.h"
#include "nf_config.h"
#include "nvram.h"
#include "nf_file.h"
#include "position.h"
#include "msm9841.h"
#include "gps.h"
#include "playsound.h"
#include "common_function.h"
#include <stdio.h>
#include "16c554.h"
xdata SYSTEM_INFO systemInfo;
xdata DEVICEINFO deviceInfo;
xdata SIMCARD_INFO simInfo;
extern xdata BUS_INFO busInfo;//线路当前信息
bit e2changeFlag;
unsigned char savedataTimeout;
#define SAVEDATA_TIMEOUT 3
DEVICEINFO code romDeviceInfo = { 0x01, /*software version*/
0x10,
{0x11,0x22,0x33}, /*device ID*/
{0x08,0x05,0x09}, /*software date*/
{0x11,0x39,0x00}
};
unsigned long xdata resetFlag;
ALARM_ZONE gAlarmZone;
void init_systemmanager()
{
e2changeFlag = 0;
savedataTimeout = SAVEDATA_TIMEOUT;
memset((Byte*)&systemInfo, 0, sizeof(SYSTEM_INFO));
memset((Byte*)&simInfo, 0, sizeof(SIMCARD_INFO));
memset((Byte*)&systemInfo, 0, sizeof(SYSTEM_INFO));
memset((Byte*)&gAlarmZone, 0, sizeof(ALARM_ZONE));
simInfo.validFlag = TERM_PARA_INVALID;
memcpy((Byte*)&deviceInfo, (Byte*)&romDeviceInfo, sizeof(DEVICEINFO) );
init_nfconfigdata();
init_formatbuffer();
if( resetFlag == 0x12345678 )
{
systemInfo.bootStatus = 1;
systemInfo.hotCount ++;
}
else
{
resetFlag = 0x12345678;
systemInfo.bootStatus = 0;
systemInfo.hotCount = 0;
}
read_system_nvram();
init_filedata(busInfo.lineNum-1, busInfo.modeNum, busInfo.displayCurStation, busInfo.attrStation);
read_alllinename(busInfo.lineNum);
set_position_state(busInfo.direction, 0);
systemInfo.speedHold = 99;
systemInfo.curSpeed = 0;
gAlarmZone.num = 0;
systemInfo.runMode = RUN_NORMAL;
}
void read_system_nvram()
{
Byte tmpBuf[10];
nvram_read(NVRAM_AUTO_SEND, tmpBuf);
if ((tmpBuf[0] == 0x56) && (tmpBuf[1] == 0x78))
{
systemInfo.autoSendTime = tmpBuf[2]*256+tmpBuf[3];
systemInfo.onlineTime = tmpBuf[4];
systemInfo.arriveMeter = tmpBuf[5];
systemInfo.leftMeter = tmpBuf[6];
}
else
{
systemInfo.autoSendTime = 10;
systemInfo.onlineTime = 25;
systemInfo.arriveMeter = 90;
systemInfo.leftMeter = 30;
}
/* nvram_read(NVRAM_ONLINE, tmpBuf);
if ((tmpBuf[0] == 0x58) && (tmpBuf[1] == 0x76))
systemInfo.onlineTime = tmpBuf[2];
else
{
systemInfo.onlineTime = 25;
}
nvram_read(NVRAM_ARRIVE_METER, tmpBuf);
if ((tmpBuf[0] == 0x58) && (tmpBuf[1] == 0x76))
systemInfo.arriveMeter = tmpBuf[2];
else
{
systemInfo.arriveMeter = 90;
}
nvram_read(NVRAM_LEFT_METER, tmpBuf);
if ((tmpBuf[0] == 0x58) && (tmpBuf[1] == 0x76))
systemInfo.leftMeter = tmpBuf[2];
else
{
systemInfo.leftMeter = 30;
}*/
nvram_read(NVRAM_VOICE_VOLUME, tmpBuf);
if ((tmpBuf[0] >= 1) && (tmpBuf[0] <= 8))
systemInfo.volume = tmpBuf[0];
else
systemInfo.volume = 8;
msm_change_volume(8-systemInfo.volume);
nvram_read(NVRAM_BUS_LINEMODE, tmpBuf);
if ((tmpBuf[0] >= 1) && (tmpBuf[0] <= 6))
busInfo.modeNum = tmpBuf[0];
else
busInfo.modeNum = 1;
nvram_read(NVRAM_BUS_LINENUM, tmpBuf);
if ((tmpBuf[0] >= 1) && (tmpBuf[0] <= 6))
busInfo.lineNum = tmpBuf[0];
else
busInfo.lineNum = 1;
nvram_read(NVRAM_BUS_LINEDIRRECTION, tmpBuf);
if (tmpBuf[0] <= 1)
busInfo.direction = tmpBuf[0];
else
busInfo.direction = BUS_UPWARD;
nvram_read(NVRAM_STATION_NUM, tmpBuf);
if ((tmpBuf[0] >= 1) && (tmpBuf[0] < 128))
busInfo.displayCurStation = tmpBuf[0];
else
busInfo.displayCurStation = 1;
nvram_read(NVRAM_STATION_ATTR, tmpBuf);
if (tmpBuf[0] <= 2)
busInfo.attrStation = tmpBuf[0];
else
busInfo.attrStation = FIRST_STATION;
busInfo.lineAttr = NORMAL_LINE;
systemInfo.boardMode = MANUAL_BOARD;
systemInfo.runMode = RUN_NORMAL;
systemInfo.landFlag = 0;
systemInfo.year = 6;
systemInfo.mon = 6;
systemInfo.day = 9;
systemInfo.hour = 14;
systemInfo.min = 10;
systemInfo.sec = 0;
}
/********************************************
*每隔三秒保存:用来保存那些经常变化的内容,
*包括当前行车方向、当前站点序号以及当前站点属性。
*由主循环一秒钟调用一次
**********************************************/
void save_stationdata()
{
Byte tmpBuf[3];
if (0 == savedataTimeout)
{
if (1 == e2changeFlag)
{
e2changeFlag = 0;
tmpBuf[0] = busInfo.direction;
tmpBuf[1] = busInfo.displayCurStation;
tmpBuf[2] = busInfo.attrStation;
nvram_writestationData(tmpBuf);
}
savedataTimeout = SAVEDATA_TIMEOUT;
}
else
savedataTimeout--;
}
void set_stationdata_changed()
{
e2changeFlag = 1;
}
/***以下为电子围栏的处理函数*****/
//#define ALARMZONE_TIMEOUT 5
//#define ALARMZONE_SPEEDTIME 6//持续30s以上超时,将进行声音提示
//每5秒调用一次
/*x:经度;y:纬度*/
extern char debug_msg[1024];
void alarmzone_process()
{
/* GPS_DATA *gps_ptr;
Byte i;
long littlex, littley, largex, largey;
if (gAlarmZone.num > 0)
{
gAlarmZone.timeout++;
if (gAlarmZone.timeout >= ALARMZONE_TIMEOUT)
{
gAlarmZone.timeout = 0;
get_gps_data(&gps_ptr);
if (gps_ptr->valid != 0)
{
//对每个电子围栏进行检测
sprintf(debug_msg, "%02bd:VALID ", gps_ptr->valid);
siob_send(debug_msg, strlen(debug_msg));
for (i=0; i<gAlarmZone.num; i++)
{
if (gAlarmZone.zone[i].Point1X < gAlarmZone.zone[i].Point2X)
{
littlex = gAlarmZone.zone[i].Point1X;
largex = gAlarmZone.zone[i].Point2X;
}
else
{
littlex = gAlarmZone.zone[i].Point2X;
largex = gAlarmZone.zone[i].Point1X;
}
if (gAlarmZone.zone[i].Point1Y < gAlarmZone.zone[i].Point2Y)
{
littley = gAlarmZone.zone[i].Point1Y;
largey = gAlarmZone.zone[i].Point2Y;
}
else
{
littley = gAlarmZone.zone[i].Point2Y;
largey = gAlarmZone.zone[i].Point1Y;
}
if (1 == isInAlarmZone(gps_ptr->longitude, littlex, largex))
{
if (1 == isInAlarmZone(gps_ptr->latitude, littley, largey))
{
if (systemInfo.speedHold > gAlarmZone.zone[i].menuSpeed)
systemInfo.speedHold = gAlarmZone.zone[i].menuSpeed;
if (gps_ptr->speed > gAlarmZone.zone[i].speed)
break;
}
}
}
if ((i < gAlarmZone.num) && (gAlarmZone.speedouttime < ALARMZONE_SPEEDTIME))
gAlarmZone.speedouttime++;
else if ((i >= gAlarmZone.num) && (gAlarmZone.speedouttime > 0))
gAlarmZone.speedouttime--;
if (gAlarmZone.speedouttime >= ALARMZONE_SPEEDTIME)
{
gAlarmZone.speedouttime = ALARMZONE_SPEEDTIME;
//播放超速提示音
play_littlespeaker(LITTLESPEAKER_SPEEDALARM);
}
}
}
}*/
}
void add_alarmOneZone(Byte *pSrcBuf)
{
Byte tmpValue;
tmpValue = gAlarmZone.num;
memcpy((Byte*)&(gAlarmZone.zone[tmpValue].Point1X), pSrcBuf, 4);
memcpy((Byte*)&(gAlarmZone.zone[tmpValue].Point1Y), pSrcBuf+4, 4);
memcpy((Byte*)&(gAlarmZone.zone[tmpValue].Point2X), pSrcBuf+8, 4);
memcpy((Byte*)&(gAlarmZone.zone[tmpValue].Point2Y), pSrcBuf+12, 4);
gAlarmZone.zone[tmpValue].menuSpeed = pSrcBuf[16];
swap_ulong((Byte*)&(gAlarmZone.zone[tmpValue].Point1X));
swap_ulong((Byte*)&(gAlarmZone.zone[tmpValue].Point1Y));
swap_ulong((Byte*)&(gAlarmZone.zone[tmpValue].Point2X));
swap_ulong((Byte*)&(gAlarmZone.zone[tmpValue].Point2Y));
gAlarmZone.num++;
}
void set_systemlandflag()
{
systemInfo.landFlag = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -