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

📄 sm_list.c

📁 在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LEA_4S的驱动,位置速寻算法,语音芯片ISD4004的录放音驱动,LED页面管理等等.从启动代码到操作系统的移植以及到业
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************
**                                                              *
**  FILE         :  SM_List.C                                   *
**  COPYRIGHT    :  (c) 2001 .Xiamen Yaxon NetWork CO.LTD       *
**                                                              *
**                                                              *
**  By : CCH 2002.1.15                                          *
****************************************************************/
#include "includes.h"
#include "bsp.h"
#include "tools.h"
#include "message.h"
#include "errtask.h"
#include "timetask.h"
#include "gsmtask.h"
#include "list.h"
#include "at_sm.h"
#include "pdumode.h"
#include "sm_list.h"
#include "gprsdrv.h"
#include "zprint.h"
#include "printer.h"
/*
********************************************************************************
*                  DEFINE CONFIG PARAMETERS
********************************************************************************
*/
#define SML_SIZE_DATA               160
#define BIG_SIZE_DATA               1024
#define SML_NUM_MEM                 5
#define BIG_NUM_MEM                 2
#define MAX_GPSCELL                 1
#define MAX_IVUDPCELL               2

#define MAX_TEST                    3                   /* UNIT: SECOND */
#define MAX_RESEND                  3                   /* UNIT: SECOND */
#define MAX_FLOWTIME                120                 /* UNIT: SECOND */
#define MAX_WAITTIME                60                  /* UNIT: SECOND */

#define PERIOD_RESEND               SECOND, 1


/*
********************************************************************************
*                  DEFINE CELL STRUCTURE
********************************************************************************
*/
#define CELL_COMMON                     INT16U      attrib; \
                                        BOOLEAN     isbig; \
                                        INT8U       resend; \
                                        INT8U       flowtime; \
                                        INT8U       tellen; \
                                        INT8U       tel[SYS_TELLEN]; \
                                        void        (*fp)(INT8U result); \
                                        INT16U      datalen
                                       
typedef struct {
    CELL_COMMON;
    INT8U   data[1];
} CELL_STRUCT;

typedef struct {
    CELL_COMMON;
    INT8U   data[SML_SIZE_DATA];
} SML_CELL_STRUCT;

typedef struct {
    CELL_COMMON;
    INT8U   data[BIG_SIZE_DATA];
} BIG_CELL_STRUCT;


/*
********************************************************************************
*                  DEFINE MODULE VARIANT
********************************************************************************
*/
static struct {
    NODE            reserve;
    SML_CELL_STRUCT cell;
} smlmemory[SML_NUM_MEM];

static struct {
    NODE            reserve;
    BIG_CELL_STRUCT cell;
} bigmemory[BIG_NUM_MEM];

static INT8U numtest;
static LIST  smlist, tcplist, udplist, ivudplist, gpslist, waitlist, smlfreelist, bigfreelist;
static LIST *listcollect[] = {&smlist, &tcplist, &udplist, &ivudplist, &gpslist, &waitlist, &smlfreelist, &bigfreelist};
static TMR_TSK *resendtmr;

static INT8U tempbuf[160];




static void PrintSM(INT16U attrib, CELL_STRUCT *pcell)
{
    #if DEBUG_UARTNo_GSMSTATUS <= 3
    PrintFromUART(DEBUG_UARTNo_GSMSTATUS, "<send short message>\n");

    PrintFromUART(DEBUG_UARTNo_GSMSTATUS, "tel  is: ");
    if (attrib & SM_ATTR_GPRS_CODEMASK) {
        if ((attrib & SM_ATTR_GPRS_CODEMASK) == SM_ATTR_TCP)
            PrintFromUART(DEBUG_UARTNo_GSMSTATUS, "TCP");
        else if ((attrib & SM_ATTR_GPRS_CODEMASK) == SM_ATTR_UDP)
            PrintFromUART(DEBUG_UARTNo_GSMSTATUS, "UDP");
        else if ((attrib & SM_ATTR_GPRS_CODEMASK) == SM_ATTR_IVUDP)
            PrintFromUART(DEBUG_UARTNo_GSMSTATUS, "IV UDP");
    } else {
        SendFromUART_MEM(DEBUG_UARTNo_GSMSTATUS, pcell->tel, pcell->tellen);
    }
    PrintFromUART(DEBUG_UARTNo_GSMSTATUS, "\n");
    PrintFromUART(DEBUG_UARTNo_GSMSTATUS, "data is:\n");
    
    if (pcell->datalen > 160)
    	FormatPrintDataBlock(FORMAT_HEX, DEBUG_UARTNo_GSMSTATUS, pcell->data, 160);
       //PrintString('x',  pcell->data, 160);
    else
        FormatPrintDataBlock(FORMAT_HEX, DEBUG_UARTNo_GSMSTATUS, pcell->data, pcell->datalen);
       //PrintString('x',  pcell->data, pcell->datalen);
    #else
    attrib = attrib;
    pcell  = pcell;
    #endif
}


static void DelCell(CELL_STRUCT *cell, INT8U result)
{
    void (*fp)(INT8U result);
    
    if (cell != 0) {
        OSQPost(GsmTaskMsgQue, MSG_SMLIST_FREE, 0, 0);
        fp = cell->fp;
        if (cell->isbig)
            AppendListEle(&bigfreelist, (LISTMEM *)cell);
        else
            AppendListEle(&smlfreelist, (LISTMEM *)cell);
        if (fp != 0) fp(result);
    }
}

static void Informer(INT8U result, void *pdata)
{
    CELL_STRUCT *cell;
    LIST *curlist;
    
    curlist = (LIST*)pdata;
    if ((cell = (CELL_STRUCT *)GetListHead(curlist)) != 0) {
        switch (cell->attrib & SM_ATTR_SENDMASK)
        {
            case SM_ATTR_COMMON:
                numtest = 0;
                DelCell((CELL_STRUCT *)DelListHead(curlist), result);
                break;
            case SM_ATTR_SUCCESS:
                if (result == _SUCCESS || numtest > MAX_TEST) {
                    numtest = 0;
                    DelCell((CELL_STRUCT *)DelListHead(curlist), result);
                } else {
                    numtest++;
                }
                break;
            case SM_ATTR_ACK:
                if (result == _SUCCESS || numtest > MAX_TEST) {
                    numtest = 0;
                    cell->flowtime = 0;
                    AppendListEle(&waitlist, DelListHead(curlist));
                } else {
                    numtest++;
                }
                break;
            default:
                numtest = 0;
                DelCell((CELL_STRUCT *)DelListHead(curlist), result);
        }
        OSQPost(GsmTaskMsgQue, MSG_SMLIST_TSK, 0, 0);
    }
}

static void ResendTmrProc(void)
{
    INT8U i;
    CELL_STRUCT *cell, *nextcell;
    
    StartTmr(resendtmr, PERIOD_RESEND);
    cell = (CELL_STRUCT *)GetListHead(&waitlist);
    while (cell != 0) {
        cell->flowtime++;
        if (cell->flowtime > MAX_FLOWTIME) {
            cell->flowtime = 0;
            cell->resend++;
            nextcell = (CELL_STRUCT *)DelListEle(&waitlist, (LISTMEM *)cell);
            if (cell->resend > MAX_RESEND) {
                DelCell(cell, _OVERTIME);
            } else {
                if (cell->attrib & SM_ATTR_GPS) 
                    AppendListEle(&gpslist, (LISTMEM *)cell);
                else if (cell->attrib & SM_ATTR_TCP)
                    AppendListEle(&tcplist, (LISTMEM *)cell);
                else if (cell->attrib & SM_ATTR_UDP)
                    AppendListEle(&udplist, (LISTMEM *)cell);
                else if (cell->attrib & SM_ATTR_IVUDP)
                    AppendListEle(&ivudplist, (LISTMEM *)cell);
                else
                    AppendListEle(&smlist, (LISTMEM *)cell);
                OSQPost(GsmTaskMsgQue, MSG_SMLIST_TSK, 0, 0);
            }
            cell = nextcell;
        } else {
            cell = (CELL_STRUCT *)ListNextEle((LISTMEM *)cell);
        }
    }
        
    for (i = 0; i < 5; i++) {
        cell = (CELL_STRUCT *)GetListHead(listcollect[i]);
        if (cell != 0) {
            cell->flowtime++;
            if (cell->flowtime > MAX_WAITTIME) {
                Informer(_OVERTIME, listcollect[i]);
            }
        }
    }
}

static void DiagnoseProc(void)
{
    INT8U i, count;
    
    if (GetTmrSwitch(resendtmr) != ON) ErrExit(ERR_SMLIST_TMR);
    
    count = 0;
    for (i = 0; i < sizeof(listcollect) / sizeof(listcollect[0]); i++) {

⌨️ 快捷键说明

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