📄 mc35.c
字号:
DESCRIPTION: Sends a character to the MC35
PARAMETER1: A character to be sent to the MC35
END DESCRIPTION **********************************************************/
nodebug void MC35_Putc(char put_char)
{
serCputc(put_char);
}
/* --------------------------------------------------------------------- */
/*** BeginHeader CofMC35_Putc */
scofunc void CofMC35_Putc(char put_char);
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
CofMC35_Putc <MC35.LIB>
SYNTAX: void CofMC35_Putc(char put_char);
DESCRIPTION: Sends a character to the MC35. Yields to other tasks while
sending.
PARAMETER1: A character to be sent to the MC35
END DESCRIPTION **********************************************************/
nodebug scofunc void CofMC35_Putc(char put_char)
{
wfd {cof_serCputc(put_char); }
}
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Send */
void MC35_Send(char *send_string);
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
MC35_Send <MC35.LIB>
SYNTAX: void MC35_Send(char *send_string);
DESCRIPTION: Sends a string to the MC35
PARAMETER1: A null terminated string to be sent to the MC35
END DESCRIPTION **********************************************************/
nodebug void MC35_Send(char *send_string)
{
serCputs(send_string);
}
/* --------------------------------------------------------------------- */
/*** BeginHeader CofMC35_Send */
scofunc void CofMC35_Send(char *send_string);
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
CofMC35_Send <MC35.LIB>
SYNTAX: void CofMC35_Send(char *send_string);
DESCRIPTION: Sends a string to the MC35. Yields to other tasks while
sending.
PARAMETER1: A null terminated string to be sent to the MC35
END DESCRIPTION **********************************************************/
nodebug scofunc void CofMC35_Send(char *send_string)
{
wfd {cof_serCputs(send_string); }
}
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Expect */
int MC35_Expect(char *expect_string, unsigned long timeout);
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
MC35_Expect <MC35.LIB>
SYNTAX: int MC35_Expect(char *send_string, unsigned long timeout);
DESCRIPTION: Listens for a specific string to be sent by the MC35.
PARAMETER1: A null-terminated string to listen for.
PARAMETER2: The maximum wait in milliseconds for a character
RETURN VALUE: 1 if the expected string was received
0 if a timeout occured before receiving the string
END DESCRIPTION **********************************************************/
int MC35_Expect(char *expect_string, unsigned long timeout)
{
auto int expect_length, match_position;
auto unsigned long t;
auto int received;
expect_length = strlen(expect_string);
match_position = 0;
while(match_position < expect_length)
{
t = MS_TIMER;
while((received = serCgetc()) < 0)
{
VdHitWd(wd); // 复位内部看门狗
WDI_Rst(); // 复位外部看门狗
if(MS_TIMER - t > timeout) return 0; //timed out
}
if(MC35_DEBUG)
{
putchar(received);
}
if(received == expect_string[match_position])
{
match_position++;
}
else
{
match_position = 0; //no match, start over
if(received == expect_string[match_position]) match_position++;
}
}
return 1;
}
/* --------------------------------------------------------------------- */
/*** BeginHeader CofMC35_Expect */
scofunc int CofMC35_Expect(char *expect_string, unsigned long timeout);
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
CofMC35_Expect <MC35.LIB>
SYNTAX: int CofMC35_Expect(char *send_string, unsigned long timeout);
DESCRIPTION: Listens for a specific string to be sent by the MC35. Yields
to other tasks while waiting for input.
PARAMETER1: A null-terminated string to listen for.
PARAMETER2: The maximum wait in milliseconds for a character
RETURN VALUE: 1 if the expected string was received
0 if a timeout occured before receiving the string
END DESCRIPTION **********************************************************/
nodebug scofunc int CofMC35_Expect(char *expect_string, unsigned long timeout)
{
auto int expect_length, match_position;
auto unsigned long t;
auto int received;
expect_length = strlen(expect_string);
match_position = 0;
while(match_position < expect_length)
{
t = MS_TIMER;
while((received = serCgetc()) < 0)
{
if(MS_TIMER - t > timeout) return 0; //timed out
yield;
}
if(MC35_DEBUG)
{
putchar(received); //DEBUG
}
if(received == expect_string[match_position])
{
match_position++;
}
else
{
match_position = 0; //no match, start over
if(received == expect_string[match_position]) match_position++;
}
}
return 1;
}
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Hangup */
int MC35_Hangup();
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
MC35_Hangup <MC35.LIB>
SYNTAX: int MC35_Hangup();
DESCRIPTION: Sends "+++" and "ATH" commands
RETURN VALUE: 1 - success 0 - MC35 not responding
END DESCRIPTION **********************************************************/
nodebug int MC35_Hangup()
{
auto unsigned long t;
if(MC35_Connected())
{
//force command mode
DelayMs(1000);
VdHitWd(wd); // 复位内部看门狗
WDI_Rst(); // 复位外部看门狗
DelayMs(1000);
VdHitWd(wd); // 复位内部看门狗
WDI_Rst(); // 复位外部看门狗
DelayMs(1000);
VdHitWd(wd); // 复位内部看门狗
WDI_Rst(); // 复位外部看门狗
MC35_Send("+++");
DelayMs(1000);
VdHitWd(wd); // 复位内部看门狗
WDI_Rst(); // 复位外部看门狗
serCrdFlush();
MC35_Send(MC35_Hangup_Command);
MC35_Expect(MC35_OK_String, 1000)
}
serCrdFlush(); // Flush MC35 receive buffer
serCwrFlush(); // Flush MC35 send buffer
if(MC35_Connected()) return 0; // DCD is active
return 1;
}
/* --------------------------------------------------------------------- */
/*** BeginHeader CofMC35_Hangup */
scofunc int CofMC35_Hangup();
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
CofMC35_Hangup <MC35.LIB>
SYNTAX: int CofMC35_Hangup();
DESCRIPTION: Sends "+++" and "ATH" commands. Yields to other tasks
while waiting for responses.
RETURN VALUE: 1 - success 0 - MC35 not responding
END DESCRIPTION **********************************************************/
nodebug scofunc int CofMC35_Hangup()
{
auto int status;
if(MC35_Connected())
{
//force command mode
waitfor(DelayMs(1000)); //leading guard time
waitfor(DelayMs(1000));
waitfor(DelayMs(1000));
wfd { CofMC35_Send("+++"); }
waitfor(DelayMs(1000));
serCrdFlush();
wfd { CofMC35_Send(MC35_Hangup_Command); }
wfd { CofMC35_Expect(MC35_OK_String, 1000); }
}
serCrdFlush(); // Flush MC35 receive buffer
serCwrFlush(); // Flush MC35 send buffer
if(MC35_Connected()) return 0; // DCD is active
return 1;
}
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Close */
void MC35_Close();
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
MC35_Close <MC35.LIB>
SYNTAX: void MC35_Close();
DESCRIPTION: Closes the serial driver down
END DESCRIPTION **********************************************************/
nodebug void MC35_Close()
{
MC35_SetDTR(0); // DTR inactive
if(MC35_Connected()) MC35_Hangup();
serCclose();
}
/* --------------------------------------------------------------------- */
/*** BeginHeader cofMC35_Close */
scofunc void cofMC35_Close();
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
cofMC35_Close <MC35.LIB>
SYNTAX: void cofMC35_Close();
DESCRIPTION: Closes the serial driver down
END DESCRIPTION **********************************************************/
nodebug scofunc void cofMC35_Close()
{
MC35_SetDTR(0); // DTR inactive
if(MC35_Connected())
{
wfd { CofMC35_Hangup(); }
}
serCclose();
}
/* --------------------------------------------------------------------- */
/*** BeginHeader */
#endif
/*** EndHeader */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -