📄 motorola.h
字号:
void InicializaSerial(void);
void isr_UDRE_Serial(void);// trata transmiss鉶
void isr_UTX_Serial(void);
void isr_URX_Serial(void);// recebe dados da serial
int com_ace_ind = 0;
char com_ace[90];
char ultima_leitura[90];
//---------------------------------------------------------------------------
int le_moto(void);
char resp_sen[5];
char resp_prcvd[5];
char resp_open[3];
char ip_local[15];
char sinal_local[2];
char num_byte_rec[2]; //quantidade de bytes recebidos no modem
char msg_mot[256]; //para funcionar o display do .h
char pacote[100];
void InicializaSerial(void)
{
Display(msg_mot,sprintf(msg_mot,"%s"," "), 0, 0);
Display(msg_mot,sprintf(msg_mot,"%s"," "), 1, 0);
long int baud;
baud=57600L;
HAL_COMSetMode(COM3_SOCKET, COM_8BIT); // 8 bits de dados com uso de DMA
HAL_COMSetEvent(COM3_SOCKET, RX_READY); // deixa pronto para recep鏰o
HAL_COMSetBR(COM3_SOCKET, baud); // baudrate
HAL_COMTxEnable(COM3_SOCKET, 1);
HAL_COMRxEnable(COM3_SOCKET, 1);
HAL_COMSetRxRdyHandler(COM3_SOCKET, isr_URX_Serial); //trata a recepcao
HAL_COMSetTxEmptyHandler(COM3_SOCKET, isr_UTX_Serial);
HAL_COMSetTxRegEmptyHandler(COM3_SOCKET, isr_UDRE_Serial); // trata a transmissao.
HAL_COMEnable(COM3_SOCKET);
}
void isr_UDRE_Serial(void)
{
HAL_COMSetEvent(COM3_SOCKET, RX_READY|TX_COMPLETE);
}
void isr_UTX_Serial(void)
{
HAL_COMSetEvent(COM3_SOCKET, RX_READY);
}
void isr_URX_Serial(void)// recebe dados da serial
{
if (com_ace_ind < sizeof(com_ace)) {
com_ace[com_ace_ind] = HAL_COMRxByte(COM3_SOCKET); //recebe byte
if ((com_ace[com_ace_ind - 1] == 0x4F)&& (com_ace[com_ace_ind] == 0x4B)) {
for (int j = 0; j < sizeof(com_ace); j++) {
ultima_leitura[j]=com_ace[j];
}
}
else if ((com_ace[com_ace_ind - 3] == 0x45)&& (com_ace[com_ace_ind-2] == 0x52) &&
(com_ace[com_ace_ind - 1] == 0x52)&& (com_ace[com_ace_ind] == 0x4F)) {
for (int j = 0; j < sizeof(com_ace); j++) {
ultima_leitura[j]=com_ace[j];
}
}
}
else {
com_ace_ind = 0;
memset(com_ace, 0x00, sizeof(com_ace));
com_ace[com_ace_ind] = HAL_COMRxByte(COM3_SOCKET); //recebe byte
}
com_ace_ind++;
}
void at(void)
{//envia at
sprintf(pacote,"AT%c%c",0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int a = le_moto();
if(a==1) {
Display(msg_mot,sprintf(msg_mot,"%s","AT OK "), 1, 0);
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","AT ERRO!!! "), 1, 0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
void cpin(void)
{//envia cpin
sprintf(pacote,"AT+CPIN=\"1010\"%c%c",0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int a = le_moto();
if(a==1) {
Display(msg_mot,sprintf(msg_mot,"%s","CPIN OK "), 1, 0);
HAL_CPUWaitmS(10000);
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","CPIN ERRO!!! "), 1, 0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
void csq(void)
{//envia csq
sprintf(pacote,"AT+CSQ%c%c",0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int b=0;
int a = le_moto();
if(a==1) {
if((ultima_leitura[a] == 0x30) &&
((ultima_leitura[a+1]==0x30) || (ultima_leitura[a+1]==0x31))&&
(ultima_leitura[a+2]==0x2C)) {
Display(msg_mot,sprintf(msg_mot,"%s","SEM SINAL "), 1, 0);
break;
}
else {
for(int a=0; a<sizeof(ultima_leitura);a++) {
if(ultima_leitura[a]==0x3A) {
a+=3;
while(ultima_leitura[a]!=0x2C) {
sinal_local[b]=ultima_leitura[a++];
Display(msg_mot,sprintf(msg_mot,"%c",sinal_local[b]), 1, b);
b++;
}
HAL_CPUWaitmS(5000);
break;
}
}
}
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","CSQ ERRO!!! "), 1, 0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
void mipcall(void)
{//envia mipcall
sprintf(pacote,"AT+MIPCALL=1,\"tim.br\",\"tim\",\"tim\"%c%c",0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int b=0;
int a = le_moto();
if(a==1) {
for(int a=0; a<sizeof(ultima_leitura);a++) {
if(ultima_leitura[a]==0x3A) {
a++;
while(ultima_leitura[a]!=0x0D) {
ip_local[b]=ultima_leitura[a++];
Display(msg_mot,sprintf(msg_mot,"%c",ip_local[b]), 1, b);
b++;
}
HAL_CPUWaitmS(5000);
break;
}
}
Display(msg_mot,sprintf(msg_mot,"%s","Conectado "), 1, 0);
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","MIPCALL ERRO!!"),1,0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
void mipopen(void)
{//mipopen no servidor - abre socket
char *ip="200.230.208.16"; //servidor
char *porta="50080"; //porta do servidor
sprintf(pacote,"AT+MIPOPEN=1,1080,%s,%s,0%c%c",ip,porta,0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int b=0;
int a = le_moto();
if(a==1) {
for(int a=0; a<sizeof(ultima_leitura);a++) {
if(ultima_leitura[a]==0x3A) {
a++;
while(ultima_leitura[a]!=0x0D) {
resp_open[b]=ultima_leitura[a++];
Display(msg_mot,sprintf(msg_mot,"%c",resp_open[b]), 1, b);
b++;
}
HAL_CPUWaitmS(5000);
break;
}
}
Display(msg_mot,sprintf(msg_mot,"%s","Porta Aberta "), 1, 0);
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","MIPOPEN ERRO!!"),1,0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
void mipsend(void)
{//envia para o modem
char *dados="020000004154"; //dados a enviar
sprintf(pacote,"AT+MIPSEND=1,\"%s\"%c%c",dados,0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int b=0;
int a = le_moto();
if(a==1) {
for(int a=0; a<sizeof(ultima_leitura);a++) {
if((ultima_leitura[a]==0x3A) && (ultima_leitura[a-2]==0x4E)) {
a++;
while (ultima_leitura[a]!=0x0D) {
resp_sen[b]=ultima_leitura[a++];
Display(msg_mot,sprintf(msg_mot,"%c",resp_sen[b]), 1, b);
b++;
}
HAL_CPUWaitmS(5000);
break;
}
}
Display(msg_mot,sprintf(msg_mot,"%s","Enviado ao Modem"), 1, 0);
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","MIPSEND ERRO!!"),1,0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
void mippush(void)
{//envia ao servidor
sprintf(pacote,"AT+MIPPUSH=1%c%c",0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int b=0;
int a = le_moto();
if(a==1) {
for(int a=0; a<sizeof(ultima_leitura);a++) {
if((ultima_leitura[a]==0x3A) && (ultima_leitura[a-2]==0x56)) {
a++;
while(ultima_leitura[a]!=0x0D) {
resp_prcvd[b]=ultima_leitura[a++];
Display(msg_mot,sprintf(msg_mot,"%c",resp_prcvd[b]), 1, b);
b++;
}
HAL_CPUWaitmS(5000);
break;
}
}
Display(msg_mot,sprintf(msg_mot,"%s","MIPPUSH OK "), 1, 0);
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","MIPPUSH ERRO!!"),1,0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
void flush(void)
{
sprintf(pacote,"AT+MIPFLUSH=1%c%c",0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int a = le_moto();
if(a==1) {
Display(msg_mot,sprintf(msg_mot,"%s","MIPFLUSH OK "), 1, 0);
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","MIPFLUSH ERRO!!"),1,0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
void mipclose(void)
{
sprintf(pacote,"AT+MIPCLOSE=1%c%c",0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int a = le_moto();
if(a==1) {
Display(msg_mot,sprintf(msg_mot,"%s","MIPCLOSE OK "), 1, 0);
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","MIPCLOSE ERRO!!"),1,0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
void closemipcall(void)
{
sprintf(pacote,"AT+MIPCALL=0%c%c",0x0D,0x0A);
HAL_COMSetEvent(COM3_SOCKET, TX_READY);
for(int ind=0;pacote[ind]!=0x0A;ind++)
{
HAL_COMTxByte(COM3_SOCKET, pacote[ind]); // envia byte do pacote pela COM3_SOCKET
Display(msg_mot,sprintf(msg_mot,"%X",pacote[ind]), 0, 14);
HAL_CPUWaitmS(50);
}
memset(com_ace, 0x00, sizeof(com_ace));
memset(pacote, 0x00, sizeof(pacote));
com_ace_ind=0;
while(1) {
int a = le_moto();
if(a==1) {
Display(msg_mot,sprintf(msg_mot,"%s","CLOSE MIPCALL OK"), 1, 0);
break;
}
else if(a==2) {
Display(msg_mot,sprintf(msg_mot,"%s","C. MIPCALL ERRO!"),1,0);
break;
}
}
HAL_CPUWaitmS(500);
memset(ultima_leitura, 0x00, sizeof(ultima_leitura));
}
int le_moto(void)
{
int arg;
// while (1){
for(int a=0; a<sizeof(ultima_leitura); a++)
{
//procura OK
if((ultima_leitura[a]==0x4F) && (ultima_leitura[a+1]==0x4B)) {
arg=1;
break;
}
//procura "error"
else if((ultima_leitura[a]==0x45)&&(ultima_leitura[a+1]==0x52)&&(ultima_leitura[a+2]==0x52)) {
arg=2;
break;
}
else
arg=0;
}
HAL_CPUWaitmS(1000);
// if (ultima_leitura[a]!=0x00)
// break;
// }
return arg;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -