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

📄 gps.c

📁 一个GPS解码程序
💻 C
📖 第 1 页 / 共 2 页
字号:
  if(dtmp<360)sgps->course=dtmp;else return false;
  ctmp=(*i++-0x30)*10+(*i++-0x30);
  if(ctmp<32)sgps->day=ctmp;else return false;
  ctmp=(*i++-0x30)*10+(*i++-0x30);
  if(ctmp<=12)sgps->month=ctmp;else return false;
  ctmp=(*i++-0x30)*10+(*i++-0x30);
  if(ctmp<100)sgps->year=ctmp;else return false;
  return true;
}


BOOL CalculateLen()reentrant  //the parameter point out length report or package report
{
  //080011,A,3953.3026,N,11619.9469,E,7.19,351.19,081102,0.0,W*61  
  if((mileter+daymileter-mileterLen)>TraLength)
  {
    mileterLen=mileter+daymileter;
    return true;
  }
  return false;
}


BOOL CalculatePLA()reentrant  //the parameter point out length report or package report
{
  //080011,A,3953.3026,N,11619.9469,E,7.19,351.19,081102,0.0,W*61  
  if((mileter+daymileter-mileterPLA)>200)
  {
    mileterPLA=mileter+daymileter;
    return true;
  }
  return false;
}

void CirCleClr()reentrant
{
  indin=indout;ifull=0;
  WriteEprom(EGPSBFIN,(uchar *)&indin,sizeof(indin));
  WriteEprom(EGPSBFOT,(uchar *)&indout,sizeof(indout));
  WriteEprom(EGPSFULL,(uchar *)&ifull,sizeof(ifull));  
}
INT16U CirCleSum()reentrant   //get the valible count of the sum
{
  if(indin==indout && ifull==1)return GPSMAX;   //最大
  if(indin>indout)return indin-indout;
  if(indin<indout)return GPSMAX-indout+indin;
  return 0;  //空
}

//you must first call the CirCleNum
//return:
INT16U CirCleIn(S_GPS *buff)reentrant       //FIFO in, 0:faild, one location data once
{
  INT16U ret;
  if(indin>=GPSMAX){indin=0;indout=0;ifull=0;}
  if(indin==indout && ifull==1)
  {
    if(indout<GPSMAX-1)indout++;else indout=0;
  }
  WriteEprom(((ulong)sizeof(S_GPS))*indin+EGPSBUFF,(uchar *)buff,sizeof(S_GPS));     //save one gps data 
  ret=indin;
  if(indin<GPSMAX-1)indin++;else indin=0;
  if(indin==indout)ifull=1;
  return ret;
}

//you must first call the CirCleSum
INT16U CirCleOut(S_GPS *buff)reentrant    //get the FIFO out pointer, its same to FIFOin
{
  INT16U ret;
  ReadEprom(((ulong)sizeof(S_GPS))*indout+EGPSBUFF,(uchar *)buff,sizeof(S_GPS));
  ret=indout;
  if(indout<GPSMAX-1)indout++;else indout=0;
  if(indout==indin)ifull=0;
  return ret;
}

void BuildMsgHead(uchar *msg,uchar ID,uchar CMD)reentrant
{
  int len;
  StrCpyN(msg,"##US",4);
  *(msg+4)=ID;
  ReadEprom(ESERIAL,msg+5,16);
  len=StrLen(msg+5);
  if(len<16)MyMemSet(msg+6+len,0,15-len);
  //StrCpyN(msg+5,SerialNum,15);
  *(msg+21)=CMD;
}
int BuildGpsMsg(uchar *msg)reentrant
{
  uchar i;
  INT16U count;
  S_MESSAGE *pmsg;
  pmsg=(S_MESSAGE *)msg; 
  count=CirCleSum();
  if(count==0)
  {
    Need_Work=false;
    return 0;
  }
  BuildMsgHead(pmsg->Head,CmdID++,0x83);
  if(count>12)count=12;
  if(GsmError)count=1;
  pmsg->PayloadLen=sizeof(S_GPS)*count;
  for(i=0;i<count;i++)CirCleOut((S_GPS *)(pmsg->Payload+sizeof(S_GPS)*i));
  StrCpyN(msg+24+sizeof(S_GPS)*count,"\r\n",2);
  return sizeof(S_GPS)*count+26;
}
int BuildGpsMsgEx(uchar *msg)reentrant  //imediately
{
  S_MESSAGE *pmsg;
  pmsg=(S_MESSAGE *)msg;
  BuildMsgHead(pmsg->Head,CmdID++,0x83); 
  pmsg->PayloadLen=sizeof(S_GPS);
  //CirCleOut((S_GPS *)pmsg->Payload);
  StrCpyN((char *)pmsg->Payload,(char *)&gps_Hold,sizeof(S_GPS));
  //if(((S_GPS *)(pmsg->Payload))->longitude>648000000)return 0;
  //if(((S_GPS *)(pmsg->Payload))->latitude>324000000)return 0;
  *(((char *)pmsg->Payload)+sizeof(S_GPS))=0;
  StrCpyN(msg+24+sizeof(S_GPS),"\r\n",2);
  return sizeof(S_GPS)+26;
}
int BuildHndMsg(uchar *msg)reentrant
{
  BuildMsgHead(msg,CmdID++,0x4D);
  SetIntToBuff(msg+22,0);
  StrCpyN(msg+24,"\r\n",2);
  return 26;
}

int BuildRplMsg(uchar *msg,uchar ID,uchar CMD,uchar ErrMsg)reentrant
{
  *(msg+24)=CMD;       //witch cmd I will replay
  BuildMsgHead(msg,ID,0x61);  
  SetIntToBuff(msg+22,2);
  *(msg+25)=ErrMsg;
  StrCpyN(msg+26,"\r\n",2);
  return 28;
}
int BuildProductMsg(uchar *msg,uchar ID)reentrant
{
  BuildMsgHead(msg,ID,0x64);
  SetIntToBuff(msg+22,16);
  ReadEprom(EPRODUCT,msg+24,16);
  StrCpyN(msg+24+16,"\r\n",2);
  return 42;
}
int BuildVoltMsg(uchar *msg,uchar ID)reentrant
{
  BuildMsgHead(msg,ID,0x62);
  SetIntToBuff(msg+22,4);
  *(unsigned long int *)(msg+24)= read_analog(MUX_POW_VOLTS)*10000;
  StrCpyN(msg+28,"\r\n",2);
  return 30;
}

int BuildChipTempretureMsg(uchar *msg,uchar ID)reentrant
{
  BuildMsgHead(msg,ID,0x65);
  SetIntToBuff(msg+22,4);
  *(unsigned long int *)(msg+24)=read_analog(MUX_CPU_TEMP)*1000;
  StrCpyN(msg+28,"\r\n",2);
  return 30;
}

int BuildHandMsg(uchar *msg,uchar msgindex)reentrant
{
  unsigned int lentmp;
  BuildMsgHead(msg,CmdID++,0x76);
  //SetIntToBuff(msg+22,1);
  *(msg+24)=msgindex;
  ReadEprom(EMESSAGE+(INT32U)50*(unsigned int)(msgindex-1)+1,msg+25,49);
  for(lentmp=0;lentmp<49;lentmp++)
  {
    if(msg[25+lentmp]==0x0D || msg[25+lentmp]==0x0A){msg[25+lentmp]=0;break;}
  }
  lentmp=StrLen(msg+25);
  SetIntToBuff(msg+22,lentmp+1);
  MyMemCpy(msg+25+lentmp,"\r\n",2);
  return 26+lentmp+1;
}
int BuildShortMsg(uchar *buff,uchar *msg,uint len)reentrant
{
  BuildMsgHead(buff,CmdID++,0x76);
  //SetIntToBuff(buff+22,1);
  *(buff+24)=31;
  MyMemCpy(buff+25,msg,len);
  SetIntToBuff(buff+22,len+1);
  MyMemCpy(buff+25+len,"\r\n",2);
  return 26+len+1;
}
/*
void FormatTime(uchar *mon,uchar *day,uchar *hour)reentrant
{
  *mon=gps_Hold.month;
  *day=gps_Hold.date;
  if(gps_Hold.hour<16)*hour=gps_Hold.hour+8;
  else
  {
    *hour=gps_Hold.hour-16;
	*day=gps_Hold.date+1;
    if(*day>Days[*mon])*day=1;
  }
}
*/
/*
int BuildVoiceAck(uchar *msg,uchar ID,uchar *src,uint len)reentrant//for 成都安彩语音
{
  unsigned int lentmp;
  uchar mon,day,hour;
  FormatTime(&mon,&day,&hour);
  BuildMsgHead(msg,ID,0x76);
  *(msg+24)=31;//voice ack
  OS_ENTER_CRITICAL();
  sprintf(msg+25,"%02u-%02u-%02u-%02u:%02u:%02u<",
          (uint)gps_Hold.year,(uint)mon,(uint)day,
		  (uint)hour,(uint)gps_Hold.min,(uint)gps_Hold.sec);  
  OS_EXIT_CRITICAL();
  lentmp=StrLen(msg+25);
  MyMemCpy(msg+25+lentmp,src,len);
  lentmp+=len;
  SetIntToBuff(msg+22,lentmp+1);
  MyMemCpy(msg+25+lentmp,"\r\n",2);
  return 26+lentmp+1;
}
*/
int BuildDDMsg(uchar *msg,uchar *src)reentrant
{
  BuildMsgHead(msg,CmdID++,0x2A);
  SetIntToBuff(msg+22,6);
  StrCpyN(msg+24,src,5);
  msg[24+5]=1;
  msg[24+6]=0x0D;msg[24+7]=0x0A;
  return 32;
}

int BuildParMsg(uchar *msg,uchar ID,uchar msgindex)reentrant
{
  BuildMsgHead(msg,ID,0x71);
  if(msgindex==1)
  {
    SetIntToBuff(msg+22,2);
    *(msg+24)=msgindex;
    *(msg+25)=CONFIG_BYTE;
    StrCpyN(msg+26,"\r\n",2);
  }
  return 28;
}
void SavePoint(uchar ByteEvent,uchar EventPam)reentrant
{
   gps_Hold.ByteState=ByteEvent;
   gps_Hold.ByteStatePam=EventPam;
   gps_Hold.BitState1=MobileEvent1;
   gps_Hold.BitState=MobileEvent;
   CirCleIn(&gps_Hold);//sALM=0;//save gps data and Clear Alarm
   Need_Work=1;
}
void RestoreP()reentrant
{
  ReadEprom(EGPSBFIN,(uchar *)&indin,2);
  ReadEprom(EGPSBFOT,(uchar *)&indout,2);
  ReadEprom(EGPSFULL,(uchar *)&ifull,1);
  if((indin>GPSMAX-1) || (indout>GPSMAX-1) || (ifull>1)){indin=0;indout=0;ifull=0;}
}

void BackupP()reentrant
{
  WriteEprom(EGPSBFIN,(uchar *)&indin,2);
  WriteEprom(EGPSBFOT,(uchar *)&indout,2);
  WriteEprom(EGPSFULL,(uchar *)&ifull,1);
}



void DirMsgToSer(uchar *buff,uint len)reentrant
{
  uchar sum;
  uint i;
  sum=0;
  for(i=0;i<len;i++)sum^=buff[i];
  StrCpy1(ShellBuff,"}}1");  
  SetIntToBuff(ShellBuff+3,len);
  MyMemCpy(ShellBuff+5,buff,len);
  ShellBuff[5+len]=sum;
  WriteCommBuf0(ShellBuff,len+6);
}
int DirMsgFromSer(uchar *buff,uchar *msg,uint len)reentrant
{
  BuildMsgHead(buff,CmdID++,0xA1);
  //SetIntToBuff(buff+22,1);
  MyMemCpy(buff+24,msg,len);
  SetIntToBuff(buff+22,len);
  MyMemCpy(buff+24+len,"\r\n",2);
  return 26+len;
}

⌨️ 快捷键说明

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