gsm模块的代码问题
有人编写了下面的代码是关于gsm接口的模块,要我在里面编写sms发送,接受,初始化。。。。。的代码(此人暂时联系不上),可是我现在不知道怎么读下面的代码,不知道它们的意思是什么,比如说 这个宏定义 #define GSM_INTERFACE_MSGQ_MSG_CNT 20 ,#define GSM_INTERFACE_TIMER_STEP 500 要说明什么问题是什么意思,什么是多线程,什么是定时器。。。。。???是个初学的大家不要见笑,我只是实话实话,想读懂代码然后在编写代码。因为没什么开发的经验所以想问问大家如何快的入门真正的开发。先谢谢大家了*******************************************************************************/
#include "fsu.h"
#include "osvl.h"
#define GSM_INTERFACE_MSGQ_MSG_CNT 20
#define GSM_INTERFACE_MSGQ_MSG_MAX_LEN 40
#define GSM_INTERFACE_THREAD_PRIORITY OSVL_THREAD_PRIORITY_BELOW_NORMAL
#define GSM_INTERFACE_THREAD_STACK_SIZE 8096
#define GSM_INTERFACE_TIMER_STEP 500
#define GSM_INTERFACE_TIMER_OPTION OSVL_TIMER_FOREVER
OSVL_HANDLE g_hGSM_interfaceMsgQ = OSVL_NULL;
OSVL_HANDLE g_hGSM_interfaceThread = OSVL_NULL;
OSVL_INT g_hGSM_interfaceTimer;
OSVL_DWORD fsu_GSM_interface_Thread(OSVL_DWORD dwParam)
{
int bSuc = 0;
char buf[200];
int len;
osvl_DateTime DateTime;
while(1)
{
len = osvl_msg_Read(g_hGSM_interfaceMsgQ, (OSVL_CHAR *)buf, sizeof(buf), OSVL_INFINITE);
if((len)&&(buf[0] == 'S'))
{
osvl_rtc_GetCurDateTime(&DateTime);
osvl_trace("fsu_GSM_interface_Thread Rece At %04d-%02d-%02d %02d:%02d:%02d\r\n",
DateTime.year,
DateTime.month,
DateTime.day,
DateTime.hour,
DateTime.min,
DateTime.sec
);
}
}
return bSuc;
}
OSVL_VOID fsu_GSM_interface_Timer(OSVL_INT nTimerID, OSVL_DWORD dwParam, OSVL_DWORD dwOption)
{
char buf[]="S";
// osvl_msg_Write(g_hGSM_interfaceMsgQ, (OSVL_CHAR *)buf, sizeof(buf), 0, OSVL_MSG_NORMAL);
}
/*******************************************************************************
* GSM接口初始化
******************************************************************************/
int GSM_interface_Init(void)
{
// GSM_interface_config *pGSM_interface_Conf;
int bSuc = 1;
g_hGSM_interfaceMsgQ = osvl_msg_Create(GSM_INTERFACE_MSGQ_MSG_CNT, GSM_INTERFACE_MSGQ_MSG_MAX_LEN, 0);
osvl_assert(g_hGSM_interfaceMsgQ);
if (!g_hGSM_interfaceMsgQ)
{
osvl_set_errno(FSU_ER_GSM_INTERFACE_INIT_MSGQ);
return 0;
}
g_hGSM_interfaceThread = osvl_thread_CreateThread(GSM_INTERFACE_THREAD_PRIORITY,
fsu_GSM_interface_Thread, (OSVL_DWORD)g_hGSM_interfaceMsgQ, GSM_INTERFACE_THREAD_STACK_SIZE);
osvl_assert(g_hGSM_interfaceThread);
if (!g_hGSM_interfaceThread)
{
osvl_set_errno(FSU_ER_GSM_INTERFACE_INIT_THREAD);
return bSuc;
}
g_hGSM_interfaceTimer = osvl_timer_CreateTimer(fsu_GSM_interface_Timer, 0);
osvl_assert(g_hGSM_interfaceTimer);
if (!g_hGSM_interfaceTimer)
{
osvl_set_errno(FSU_ER_GSM_INTERFACE_INIT_CREATE_TIMER);
return 0;
}
bSuc = osvl_timer_SetTimer(g_hGSM_interfaceTimer, GSM_INTERFACE_TIMER_STEP, GSM_INTERFACE_TIMER_OPTION);
osvl_assert(bSuc);
if (!bSuc)
{
osvl_set_errno(FSU_ER_GSM_INTERFACE_INIT_SET_TIMER);
return bSuc;
}
return bSuc;
}
/*******************************************************************************
* GSM接口关闭
******************************************************************************/
int GSM_interface_DeInit(void)
{
int bSuc = 1;
bSuc = osvl_timer_DeleteTimer(g_hGSM_interfaceTimer);
osvl_assert(bSuc);
if (!bSuc)
{
osvl_set_errno(FSU_ER_GSM_INTERFACE_DEINIT_TIMER);
return bSuc;
}
bSuc = osvl_thread_KillThread(g_hGSM_interfaceThread);
osvl_assert(bSuc);
if (!bSuc)
{
osvl_set_errno(FSU_ER_GSM_INTERFACE_DEINIT_THREAD);
return bSuc;
}
bSuc = osvl_msg_Close(g_hGSM_interfaceMsgQ);
osvl_assert(bSuc);
if (!bSuc)
{
osvl_set_errno(FSU_ER_GSM_INTERFACE_DEINIT_THREAD);
return bSuc;
}
return bSuc;
}
/*******************************************************************************
* 读GSM接口数据
******************************************************************************/
unsigned int GSM_interface_GPRS_ReadNChars(int nChannel,
unsigned char *buffer,
unsigned int chars_to_read)
{
unsigned int nNum = 0;
return nNum;
}
/*******************************************************************************
* 往GSM接口写数据
******************************************************************************/
unsigned int GSM_interface_GPRS_WriteNChars(int nChannel,
unsigned char *buffer,
unsigned int chars_to_write)
{
unsigned int i;
unsigned int nNum = chars_to_write;
osvl_trace("GSM_interface_GPRS_WriteNChars Len=%d --", chars_to_write);
for(i=0; i<chars_to_write; i++)
{
osvl_trace("-%02X", buffer[i]);
}
osvl_trace("\r\n");
return nNum;
}
/*******************************************************************************
* 读GSM接口数据
******************************************************************************/
unsigned int GSM_interface_SMS_ReadNChars(int nChannel,
unsigned char *buffer,
unsigned int chars_to_read)
{
unsigned int nNum = 0;
return nNum;
}
/*******************************************************************************
* 往GSM接口写数据
******************************************************************************/
unsigned int GSM_interface_SMS_WriteNChars(int nChannel,
unsigned char *buffer,
unsigned int chars_to_write)
{
unsigned int i;
unsigned int nNum = chars_to_write;
osvl_trace("GSM_interface_SMS_WriteNChars Len=%d --", chars_to_write);
for(i=0; i<chars_to_write; i++)
{
osvl_trace("-%02X", buffer[i]);
}
osvl_trace("\r\n");
return nNum;
}