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

📄 trans_process.c

📁 通过车载终端采集GPS数据
💻 C
📖 第 1 页 / 共 3 页
字号:

#include "typedef.h"
#include "struct_def.h"
#include "common_function.h"
#include "gps.h"
#include "Trans_process.h"
#include "Rcv_process.h"
#include "gprs.h"
#include "string.h"
#include "stdio.h"
#include "global.h"
#include "position.h"
#include "24c512.h"
#include "nvram.h"
#include "updateprogram.h"
#include "centerinterface.h"
#include "commoninterface.h"
#include "nf_file.h"
#include "16c554.h"
#include "photo.h"

extern void get_gps_data(GPS_DATA **ptr);
extern IP_INFO_STRUCT ipInfo;
extern GPRS_INFO_STRUCT gprsInfo;
Int32 mess_num_runmode = 0;   /*行驶状态消息序号*/
Int16 gps_num = 0;            /*gps定位包计数器*/
Uchar trans_num = 0;          /*重发计次器*/
Int16 retry_num;              /*重发计数器*/
Int16 heart_num = 0;          /*心跳包计数*/
DWord serial_number = 0;      /*消息序号*/
extern DWord gphoto_msgnumber;
PROTOCOL_SEND_BUFFER sbuf;    /*消息缓存*/
PROTOCOL_PHOTO_BUFFER sbufPhoto;/*传送照片缓存*/

/*心跳包组包*/
void make_heartbeat_message(void)
{
    BUS_HEARTBEAT *gprs_info;
    serial_number++;
    gprs_info=(BUS_HEARTBEAT *) sbuf.buf[5];
    memcpy(gprs_info->mess_head.mess_sync,"NJPT",4);
    gprs_info->mess_head.mess_version = 2;
    gprs_info->mess_head.mess_reserve = 0;
    gprs_info->mess_head.mess_type = (Word)(HEART_BEAT);
    gprs_info->messageid = serial_number;
    get_device_id(gprs_info->terminal_id);
    get_bus_id(gprs_info->bus_id);
    gprs_info->mess_head.mess_length=14;		
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_type));
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_length));
}

/*定位信息组包*/
void make_gps_message(void)
{
    GPS_DATA gpsinfo;
    GPS_DATA *pgps;
    Uchar  cur_station;
    Uchar  station_unm;
    BUS_POSITION *gprs_info;
    pgps = &gpsinfo;
    gprs_info = (BUS_POSITION *) sbuf.buf[4];  
    memcpy(gprs_info->mess_head.mess_sync,"NJPT",4);
    gprs_info->mess_head.mess_version = 2;
    gprs_info->mess_head.mess_reserve = 0;
    gprs_info->mess_head.mess_type = (Word)(GPSINFO);
    get_line_id(gprs_info->line_id);
    get_bus_id(gprs_info->bus_id);
    get_cur_tranStation(&cur_station);
    station_unm = cur_station;
    get_station_id(station_unm,gprs_info->station_id);
    gprs_info->tag = 0x10;
    get_device_id(gprs_info->terminalid);
    
    gprs_info->renew = 0xff; 
    get_gps_data(&pgps);
 //   siob_send(gprs_info->terminalid, 10);//for debug
    if (pgps->valid == 0)
    {
        pgps->valid = 'V';
    }
    else
    {
        pgps->valid = 'A';
    }
    gprs_info->gps_flag = pgps->valid;
    memcpy(&(gprs_info->longitude), &(pgps->longitude),4);
    memcpy(&(gprs_info->latitude), &(pgps->latitude),4);
    get_term_data(gprs_info->date);
    get_term_time(gprs_info->time);
    gprs_info->speed = pgps->speed;
    gprs_info->direction = (Int32)((pgps->direction) * 10);
    gprs_info->mess_head.mess_length = 41;
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_type));
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_length));
    swap_ulong((Uchar *)(&gprs_info->longitude));
    swap_ulong((Uchar *)(&gprs_info->latitude));
    swap_uint((Uchar *)(&gprs_info->speed));
    swap_ulong((Uchar *)(&gprs_info->direction));		
}

/*行驶状态(到/出站)消息组包*/
void make_runmode_message(Uchar action, Uchar p_value)
{
    Uchar  sta_type;
    Uchar  station_unm;
    BUS_RUNMODE *gprs_info;
    gprs_info = (BUS_RUNMODE *) sbuf.buf[2];
    serial_number++;
    memcpy(gprs_info->mess_head.mess_sync, "NJPT", 4);
    gprs_info->mess_head.mess_version = 2;
    gprs_info->mess_head.mess_reserve = 0;
    gprs_info->mess_head.mess_type = (Word)(RUNMODE);
    gprs_info->messageid = serial_number;
    get_line_id(gprs_info->line_id);
    get_bus_id(gprs_info->bus_id);
    station_unm = p_value & 0x3F;
    gprs_info->station_num = station_unm;
    get_station_id(p_value,gprs_info->station_id);
    get_cur_direction(&(gprs_info->rundir));
    if(gprs_info->rundir == 0)
    {
        gprs_info->rundir = 0x01;
    }
    else
    {
        gprs_info->rundir = 0x02;
    }
    sta_type = first_last_station(station_unm);
    if(sta_type == 0)
    {
        gprs_info->messmode = 201;
    }
    else if(sta_type == 1)
    {
        gprs_info->messmode = 101;
    }
    else if( action == 0 ) /*0:进站,1:出站,3溜站*/
    {
        gprs_info->messmode = 102;
    }
    else if( action == 1 )
    {
        gprs_info->messmode = 202;
    }
    else if( action == 3)
    {
        gprs_info->messmode = 240;
    }
    gprs_info->mess_head.mess_length = 22;
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_type));
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_length));
    sbuf.valid[2]=1;   
}

/*按键消息组包*/
void make_press_message(Uchar press)
{
    Uchar  station_unm;
    BUS_RUNMODE *gprs_info;
    gprs_info = (BUS_RUNMODE *) sbuf.buf[2];
    serial_number++;
    memcpy(gprs_info->mess_head.mess_sync, "NJPT", 4);
    gprs_info->mess_head.mess_version = 2;
    gprs_info->mess_head.mess_reserve = 0;
    gprs_info->mess_head.mess_type = (Word)(RUNMODE);
    gprs_info->messageid = serial_number;
    get_line_id(&(gprs_info->line_id));
    get_bus_id(&(gprs_info->bus_id));
    get_cur_tranStation(&station_unm);
    gprs_info->station_num = station_unm;
    get_station_id(station_unm,gprs_info->station_id);
    get_cur_direction(&(gprs_info->rundir));
    gprs_info->messmode = press;
    if(gprs_info->rundir == 0)
    {
        gprs_info->rundir = 0x01;
    }
    else
    {
        gprs_info->rundir = 0x02;
    }
    gprs_info->mess_head.mess_length = 22;
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_type));
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_length));
    sbuf.valid[2] = 1;
}

/*确认消息组包*/
void make_ack_message(char idPtr[4])
{
    ACK_MESSAGE_FRAME *gprs_info;
    
    gprs_info = (ACK_MESSAGE_FRAME *) sbuf.buf[2];
    serial_number++;
    memcpy(gprs_info->mess_head.mess_sync, "NJPT", 4);
    gprs_info->mess_head.mess_version = 2;
    gprs_info->mess_head.mess_reserve = 0;
    gprs_info->mess_head.mess_type = (Word)(ACK_MESSAGE);
    
    gprs_info->messageid = serial_number;
    get_line_id(&(gprs_info->line_id));
    get_bus_id(&(gprs_info->bus_id));

    get_term_data(gprs_info->date);
    get_term_time(gprs_info->time);

    memcpy(gprs_info->message_id, idPtr, 4);

    gprs_info->mess_head.mess_length = 25;
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_type));
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_length));
    sbuf.valid[2] = 1;
}


/*客流采集消息组包*/
void make_passenger_message(Uchar up_num, Uchar down_num, Int16 on_num)
{
    Uchar  station_unm;
    BUS_PASSENGER *gprs_info;
    gprs_info = (BUS_PASSENGER *) sbuf.buf[2];
    serial_number++;
    memcpy(gprs_info->mess_head.mess_sync, "NJPT", 4);
    gprs_info->mess_head.mess_version = 4;
    gprs_info->mess_head.mess_reserve = 0;
    gprs_info->mess_head.mess_type = (Word)(PASSENGER);
    gprs_info->messageid=serial_number;
    get_line_id(gprs_info->line_id);
    get_bus_id(gprs_info->bus_id);
    get_cur_tranStation(&station_unm);
    gprs_info->station_num = station_unm;
    get_station_id(gprs_info->station_num,gprs_info->station_id);  
    get_cur_direction(&(gprs_info->rundir));
    if(gprs_info->rundir == 0)
    {
        gprs_info->rundir = 0x01;
    }
    else
    {
        gprs_info->rundir = 0x02;
    }
    gprs_info->messmode = 0x77;
    
    gprs_info->upnumber = up_num;
    gprs_info->downnumber = down_num;
    gprs_info->number = on_num;
    get_term_data(gprs_info->gpsTime);
    get_term_time(gprs_info->gpsTime+3);
    gprs_info->mess_head.mess_length = 35;
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_type));
    swap_uint((Uchar *)(&gprs_info->mess_head.mess_length));
    swap_uint((Uchar *)(&gprs_info->number));	
    sbuf.valid[2] = 1;     
}


/*上下班考核消息打包*/
/*xhb  hl  1:上班    2下班  3请求营运   4退出营运    5请求营运计划  6请求状态
   ptr为驾驶员工号长度4字节*/
void make_assess_message(Uchar hl)
{
    Uchar  station_unm;    
    
    if (6 == hl)
    {
        //new version (version 4)需要变成发送注册消息
        BUS_ASSESS_NEW* gprs_info;
        SIMCARD_INFO* pSimcard;
        pSimcard = get_simcard();
        gprs_info = (BUS_ASSESS_NEW *) sbuf.buf[2];
        serial_number++;
        memcpy(gprs_info->mess_head.mess_sync, "NJPT", 4);
        gprs_info->mess_head.mess_version = 4;//2;
        gprs_info->mess_head.mess_reserve = 0;
        gprs_info->mess_head.mess_type = (Word)(ASSESS);
        gprs_info->messageid = serial_number;
        get_line_id(gprs_info->line_id);
        get_bus_id(gprs_info->bus_id);
        get_cur_tranStation( &station_unm);
        gprs_info->sta_num = station_unm;
        get_station_id(gprs_info->sta_num,&(gprs_info->station_id));
        get_cur_direction(&(gprs_info->rundir));
        gprs_info->messagetype = 0xDD;

        get_driver_id(gprs_info->driverid);
        get_term_data(gprs_info->time);
        get_term_time(gprs_info->time+3);
        get_device_id(gprs_info->hostId);
        
        //在一体式中,将终端ID设置为全"0xff"
        memset(gprs_info->termId, 0xff, 3);
 //       siob_send(gprs_info->hostId, 10);// for debug
        get_device_info(gprs_info->hostSoft);
        //在一体式中,将终端版本号设置为全"0xff"
        memset(gprs_info->termSoft, 0xff, 4);
        memcpy(gprs_info->simcard, pSimcard->card, 20);
        get_lineIDloaded(gprs_info->line);
       // memcpy(gprs_info->line, pTerm->lineID, 24);
        gprs_info->mess_head.mess_length = 0x5b;//debug;//sizeof(BUS_ASSESS_NEW)-sizeof(struct _mess_head_info);	
        swap_uint((Uchar *)(&gprs_info->mess_head.mess_type));
        swap_uint((Uchar *)(&gprs_info->mess_head.mess_length));	
        sbuf.valid[2] = 1;    
    }
    else
    {
        //old version (version 2)
        BUS_ASSESS *gprs_info;
        gprs_info = (BUS_ASSESS *) sbuf.buf[2];
        serial_number++;
        memcpy(gprs_info->mess_head.mess_sync, "NJPT", 4);
        gprs_info->mess_head.mess_version = 2;
        gprs_info->mess_head.mess_reserve = 0;
        gprs_info->mess_head.mess_type = (Word)(ASSESS);
        gprs_info->messageid = serial_number;
        get_line_id(gprs_info->line_id);
        get_bus_id(gprs_info->bus_id);
        get_cur_tranStation( &station_unm);
        gprs_info->sta_num = station_unm;
        get_station_id(gprs_info->sta_num,&(gprs_info->station_id));
        get_cur_direction(&(gprs_info->rundir));
    
        switch(hl)
        {
            case 1:
                gprs_info->messagetype = 0xAA;
                break;
                
            case 2:
                gprs_info->messagetype = 0x55;
                break;
                
            case 3:
                gprs_info->messagetype = 0xBB;
                break;
                
            case 4:
                gprs_info->messagetype = 0x66;
                break;
                
            case 5:
                gprs_info->messagetype = 0xCC;
                break;
                

⌨️ 快捷键说明

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