📄 hanset.c
字号:
#define HANDSET_GLOBAL 1
#include "includes.h"
#pragma ROM HANDTASKPROC[]
const ENTRY_PROC far HANDTASKPROC[] ={
{HANDUARTRECV,Deal_Handrecv},
//{HANDUARTSEND,Deal_Handsend},
};
#pragma ROM HANDMSGENTRYPROC[]
const ENTRY_PROC far HANDMSGENTRYPROC[] ={
{0x01,Handle_01Msg},
{0x02,Handle_02Msg},
{0x03,Handle_03Msg},
{0x04,Handle_04Msg},
{0x05,Handle_05Msg},
{0x06,Handle_06Msg},
{0x07,Handle_07Msg},
{0x08,Handle_08Msg},
{0x4f,Handle_4Fmsg},
};
#pragma ROM tabhex[]
const char far tabhex[]="0123456789ABCDEF";
typedef struct
{
uchar flag[2];
uint len;
uchar msgtype;
uchar userdata[200];
uint handlen;
}HANDMSG;
HANDMSG handmsg;
typedef struct
{
DATE date;
TIME time;
}_DATE_TIME_STRUCT;
//HANDMSG handsendmsg;
TIMER *Handtime_Timer;
TIMER *Handsleep_Timer;
TIMER *Send_Sms_Timer;
uchar need_send_sms_again; //added by leon
uchar need_handle_dialing; //added by leon
//---------------------------------------------
void Power_Off_Proc(void)
{
Hand_Power = _HAND_OFF;
LCDPOWER_CON = VOL_LOW;
}
void Init_Handset(void)
{
LCDPOWER_CON = VOL_HIGH;
handuart.sendtail = 0;
handuart.sendhead = 0;
handuart.sendstatus = _IDLE;
Handtime_Timer = Create_Timer(Send_H04Msg);
Handsleep_Timer = Create_Timer(Power_Off_Proc);
Send_Sms_Timer = Create_Timer(Send_Sms_Proc); //added by leon
Hand_Power = _HAND_ON;
hand_Sleep_Status = _HAND_WAKE;
//#ifndef DEBUG_AT
Start_Timer(Handtime_Timer,10,SECOND);
//#endif
}
void Wake_Handset(void)
{
Stop_Timer(Handsleep_Timer);
hand_Sleep_Status = _HAND_WAKE;
#ifdef DEBUG_SLEEP
Uart1Send(" WAKE HANDSET");
#endif
if(Hand_Power!=_HAND_ON)
{
Stop_Timer(Handsleep_Timer);
Hand_Power = _HAND_ON;
LCDPOWER_CON = VOL_HIGH;
}
}
void Sleep_Handset(void)
{
if(hand_Sleep_Status == _HAND_WAKE)
{
#ifdef DEBUG_SLEEP
Uart1Send(" NEED SLEEP HANDSET");
#endif
hand_Sleep_Status = _HAND_SLEEP;
Start_Timer(Handsleep_Timer,20, MINUTE);
}
}
void Wake_Once_Handset(void)
{
if(hand_Sleep_Status == _HAND_WAKE) return;
Wake_Handset();
Sleep_Handset();
}
void hand_send(uchar far *ptr,uint len)
{
uchar i;
uchar j;
uchar xlen;
if(len==0) return;
// clr_watchdog();
while(len!=0)
{
// clr_watchdog();
if(len>100)xlen = 100;else xlen = (uchar)len;
i = (handuart.sendtail+MAXHANDSENDBUFFER-handuart.sendhead)%MAXHANDSENDBUFFER;
while((MAXHANDSENDBUFFER-1-i)<xlen)
{
i = (handuart.sendtail+MAXHANDSENDBUFFER-handuart.sendhead)%MAXHANDSENDBUFFER;
// clr_watchdog();
}
j = handuart.sendtail;
for(i=0; i<xlen; i++)
{
handuart.sendbuf[j++] = ptr[i];
if(j>=MAXHANDSENDBUFFER) j = 0;
}
handuart.sendtail = j;
if(handuart.sendstatus ==_IDLE)
{
handuart.sendstatus = _BUSY;
asm (" INT #19");
}
ptr += xlen;
len -= xlen;
}
}
#ifdef DEBUG_ALL
void Uart1Send(uchar far *p)
{
uchar buf[2];
uint len;
buf[0] = 0x0d;
buf[1] = 0x0a;
len = _stringlen(p);
hand_send(p,len);
hand_send(buf,2);
}
void Uart1hex(uchar ch)
{
uchar buf[2];
buf[0] = tabhex[ch>>4];
buf[1] = tabhex[ch&0x0f];
hand_send(buf,2);
}
void Uart1SendHex(uchar far *p,uint len)
{
uint i;
for(i=0; i<len; i++)
{
Uart1hex(p[i]);
}
}
void Uart1Word(DWORD ch)
{
uchar buf[20];
uchar i;
uchar j;
uchar temp;
i=0;
if(ch==0)
{
buf[0] = '0';
buf[1] = 0x0d;
buf[2] = 0x0a;
hand_send(buf,3);
return;
}
while(ch!=0)
{
buf[i++] = ch%10+'0';
ch /= 10;
}
for(j=0; j<i/2; j++)
{
temp = buf[j];
buf[j] = buf[i-1-j];
buf[i-1-j] = temp;
}
hand_send(buf,i);
buf[0] = 0x0d;
buf[1] = 0x0a;
hand_send(buf,2);
}
#endif
void Assemble_HandCom(uchar msgtype)
{
Init_Stream();
Write_Byte_Stream('@');
Write_Byte_Stream('@');
Write_Byte_Stream('@');
Write_Byte_Stream('@');
Write_Byte_Stream(msgtype);
}
void Assemble_Hand_tail(void)
{
Write_Absword_Stream(2,Get_Stream_Len()+4);
write_crc_stream();
Write_Byte_Stream(0x0d);
Write_Byte_Stream(0x0a);
hand_send(Get_Stream_Headptr(),Get_Stream_Len()); // 发送
}
void Send_H01Msg(void)
{
Assemble_HandCom(0x01);
Write_Byte_Stream(0x44);
Assemble_Hand_tail();
}
void Send_H02Msg(uchar ack,uchar key)
{
Assemble_HandCom(0x02);
Write_Byte_Stream(ack);
if(key!=0xff)
{
Write_Byte_Stream(key);
}
Assemble_Hand_tail();
}
void Send_H03Msg(uchar *ptr,uint len) //文字
{
Assemble_HandCom(0x03);
Write_Ptr_Stream(ptr,len);
Assemble_Hand_tail();
}
void Send_H04Msg(void) //发送时间ok//
{
_DATE_TIME_STRUCT datetime;
uchar *ptr;
uchar *bakptr;
uchar i;
ptr = (uchar *)(&datetime.date.day);
bakptr = (uchar *)(&handset_datetime.date.day);
for(i=0; i<5; i++)
{
ptr[i] = bakptr[i];
}
AddHour(ptr,8);
Assemble_HandCom(0x04);
Write_Ptr_Stream(ptr,5);
Assemble_Hand_tail();
Start_Timer(Handtime_Timer,10,SECOND);
}
void Send_H05Msg(uint status) //状态信息//
{
Assemble_HandCom(0x05);
Write_Word_Stream(status);
Assemble_Hand_tail();
}
void Send_H06Msg(uchar attrib) //约定文字显示//
{
Assemble_HandCom(0x06);
Write_Byte_Stream(attrib);
Assemble_Hand_tail();
}
void Send_H07Msg(uchar *telptr,uchar tellen) //有来电及号码显示//
{
Assemble_HandCom(0x07);
Write_Ptr_Stream(telptr,tellen);
Assemble_Hand_tail();
}
void Send_H08Msg(uchar *smsptr,uchar smslen,uchar *tel,uchar tellen)//短信//
{
Assemble_HandCom(0x08);
Write_Code_Stream(tel,'F',tellen,14);
Write_Ptr_Stream(smsptr,smslen);
Assemble_Hand_tail();
}
void Send_H09Msg(uchar attrib) //电话状态//
{
Assemble_HandCom(0x09);
Write_Byte_Stream(attrib);
Assemble_Hand_tail();
}
void Send_H0BMsg(uchar msgtype,uchar simid,uchar index) //ok
{
uchar *ptr;
uchar temp;
Assemble_HandCom(0x0B);
Write_Byte_Stream(msgtype);
switch(msgtype)
{
case 1:
Write_Byte_Stream(0x30+simid);
Write_Ptr_Stream(save.simcard[simid].MyNumb,_Strlen(save.simcard[simid].MyNumb,15));
break;
case 2: //pwd
Write_Ptr_Stream(save.psw.handpsw,8);
break;
case 3:
Write_Byte_Stream(0x30+simid);
Write_Code_Stream(save.simcard[simid].IpAddr,'F',_Strlen(save.simcard[simid].IpAddr,15),15);
Write_Code_Stream(save.simcard[simid].SocketPort,'F',_Strlen(save.simcard[simid].SocketPort,5),5);
Write_Code_Stream(save.simcard[simid].User,'F',_Strlen(save.simcard[simid].User,20),20);
Write_Code_Stream(save.simcard[simid].Password,'F',_Strlen(save.simcard[simid].Password,20),20);
break;
case 4:
Write_Byte_Stream(0x30+simid);
Write_Code_Stream(save.simcard[simid].Apn,'F',_Strlen(save.simcard[simid].Apn,20),20);
break;
case 5:
Write_Byte_Stream(save.basevalue.gprs_mode*5);
break;
case 6: //modified by leon 050923
Write_Ptr_Stream(save.phonenumber.ManageCentreNumb[0],_Strlen(save.phonenumber.ManageCentreNumb[0],15));
break;
case 7: //modified by leon 050923
#ifdef DEBUG_HANDSET
hand_send(save.phonenumber.MessageServiceNumb[0],15);
#endif
Write_Ptr_Stream(save.phonenumber.MessageServiceNumb[0],_Strlen(save.phonenumber.MessageServiceNumb[0],15));
break; //modified by leon 050923
case 8:
Write_Ptr_Stream(save.phonenumber.ListenNumb[0],_Strlen(save.phonenumber.ListenNumb[0],15));
break;
case 0x16: //added by leon 050923
Write_Ptr_Stream(save.phonenumber.ManageCentreNumb[1],_Strlen(save.phonenumber.ManageCentreNumb[1],15));
break;
case 0x17: //added by leon 050923
Write_Ptr_Stream(save.phonenumber.MessageServiceNumb[1],_Strlen(save.phonenumber.MessageServiceNumb[1],15));
break;
case 0x18: //added by leon 050923
Write_Ptr_Stream(save.phonenumber.ListenNumb[1],_Strlen(save.phonenumber.ListenNumb[1],15));
break;
case 9:
Write_Byte_Stream(0x30+simid);
Write_Byte_Stream(index);
if(simid==0)
{
Write_Ptr_Stream(save.phonenumber.User0Limit[index],_Strlen(save.phonenumber.User0Limit[index],15));
}
else
{
Write_Ptr_Stream(save.phonenumber.User1Limit[index],_Strlen(save.phonenumber.User1Limit[index],15));
}
break;
case 0x0a:
Write_Word_Stream(save.basevalue.max_speed);
break;
case 0x0b:
Write_Word_Stream(save.basevalue.low_voltage);
break;
case 0x0c:
Write_Byte_Stream(index);
ptr = &save.alarmtime.voltage;
Write_Byte_Stream(ptr[index-1]);
break;
case 0x0d:
Write_Byte_Stream(save.basevalue.gprs_time/1000);
break;
case 0x0e: //modified by leon 051013
Write_Byte_Stream(index);
ptr = (uchar *)&save.simsel.judge_port[index].mainland_port.top_left.lati;
Write_Ptr_Stream(ptr,48);
break;
case 0x0f:
Write_Byte_Stream(save.basevalue.io.ch);
break;
case 0x10:
temp = save.basevalue.mode.bit.voice*2+save.basevalue.mode.bit.dial;
temp |= 0x08;
Write_Byte_Stream(temp);
break;
case 0x11:
temp = save.basevalue.mode.bit.consume;
Write_Byte_Stream(temp);
break;
}
Assemble_Hand_tail();
}
void Send_H0CMsg(uchar ack)
{
Assemble_HandCom(0x0c);
Write_Byte_Stream(ack);
Assemble_Hand_tail();
}
void Send_H5FMsg(uchar msgtype,uchar cmd1,uchar cmd2)
{
Assemble_HandCom(0x5F);
Write_Byte_Stream(msgtype);
switch(msgtype)
{
case 0x04:
break;
case 0x05:
break;
case 0x06:
break;
case 0x07:
if(cmd1!=0xff)
Write_Byte_Stream(cmd1);
if(cmd2!=0xff)
Write_Byte_Stream(cmd2);
break;
}
Assemble_Hand_tail();
}
void Handle_01Msg(void)
{
if(handmsg.userdata[0]==0xaa)
{
Send_H01Msg();
}
}
void Handle_02Msg(void)
{
}
void Handle_03Msg(void) //less sos help//
{
uchar simid; //added by leon 050915
Send_H02Msg(0x01,handmsg.userdata[0]);
switch(handmsg.userdata[0])
{
case 0x04:
Send_H09Msg(2);
Pickup();
break;
case 0x05:
if(AutoDial.attrib==1&&Is_Autodail())
{
Stop_Autodial();
}
Hangup();
break;
case 0x06: //SOS HELP//
Send_Sos_Help();
simid = save.basevalue.mode.bit.simid; //added by leon 050915
Auto_Dial(save.phonenumber.ListenNumb[simid],_Strlen(save.phonenumber.ListenNumb[simid],15),1,4);
break;
case 0x07:
if(gsmstatus.talkmode!= _TALK_ON)break;
if(gsmstatus.tel!=_TEL_IDLE)
{
if(gsmstatus.talk==_HAND_TALK)
{
ToneSetting(save.basevalue.volume);
Voice_Sel(_VOICE_TALK);
}else if(gsmstatus.talk==_VOICE_TALK)
{
ToneSetting(save.basevalue.handvolume);
Voice_Sel(_HAND_TALK);
}
}
break;
case 0x08:
if(gsmstatus.talkmode!= _TALK_ON)break;
if(gsmstatus.tel==_TEL_IDLE)break;
if(gsmstatus.talk==_VOICE_TALK)
{
if(save.basevalue.volume>=20)
{
save.basevalue.volume-=5;
}
else
{
save.basevalue.volume=25;
}
ToneSetting(save.basevalue.volume);
}
else if(gsmstatus.talk==_HAND_TALK)
{
if(save.basevalue.handvolume>=20)
{
save.basevalue.handvolume-=5;
}
else
{
save.basevalue.handvolume=15;
}
ToneSetting(save.basevalue.handvolume);
}
Para_Crc(PARA_BASE_VALUE);
Store_Paras();
break;
case 0x09:
if(gsmstatus.talkmode!= _TALK_ON)break;
if(gsmstatus.tel==_TEL_IDLE)break;
if(gsmstatus.talk==_VOICE_TALK)
{
if(save.basevalue.volume<250)
{
save.basevalue.volume+=5;
}
else
{
save.basevalue.volume=255;
}
ToneSetting(save.basevalue.volume);
}
else if(gsmstatus.talk==_HAND_TALK)
{
if(save.basevalue.handvolume<250)
{
save.basevalue.handvolume+=5;
}
else
{
save.basevalue.handvolume=255;
}
ToneSetting(save.basevalue.handvolume);
}
Para_Crc(PARA_BASE_VALUE);
Store_Paras();
break;
case 0x10:
case 0x11:
case 0x12:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -