📄 nettask.c
字号:
/**********************************************************************
chengjy@felab, copyright 2002-2004
netTask.c
总的任务解析。
所有函数格式统一 :
char t0xXXXX(char *pBuff)
所有函数都被调用:
void netCMDExplain();
所有的函数的返回值都为char 型,分为STATUS_NORMAL(成功)和失败
(STATUS_ERROR等)。具体任务内容参见通讯协议。本文件仅仅给出
软件框架,用户可以根据自己的通讯协议添加或者删除函数,
并修改具体的内容。
调用:
netSvr.c
char netCMDAdd(unsigned char *pBuff, int buffLen, int cmdNum, unsigned char priority);
被调用:
netSvr.c
void netCMDExplain();
**********************************************************************/
#include "vxWorks.h"
#include "logLib.h"
#include "taskLib.h"
#include "stdio.h"
#include "memLib.h"
#include "stdLib.h"
#include "sysLib.h"
#include "bootLib.h"
#include "board.h"
#include "netVariFunc.h"
#include "usrLib.h"
int testInt32;
short testShort16;
char testChar8;
/*全局变量相关信息*/
struct TaskVariInfo variInfo[] =
{
{0x0000,((UINT)&semFlash), sizeof(SEM_ID), "SEM_ID semFlash"},
{0x0100,((UINT)&(boardWorkEnv.boardInit)), sizeof(int), "boardWorkEnv.(int)boardInit"},
{0x0101,((UINT)&(boardWorkEnv.autoBootFlag)), sizeof(char), "boardWorkEnv.(char)autoBootFlag"},
{0x0102,((UINT)&(boardWorkEnv.dmaAutoFlag)), sizeof(char), "boardWorkEnv.(char)dmaAutoFlag"},
{0x0200,((UINT)&(boardIndex.swVersion)), sizeof(char), "boardIndex.(char)swVersion"},
{0x0201,((UINT)&(boardIndex.swDiscri)), sizeof(char), "boardIndex.(char)swDiscr[100]"},
{0x0202,((UINT)&(boardIndex.localIP[0])), sizeof(char), "boardIndex.(char)localIP[16]"},
{0x0203,((UINT)&(boardIndex.remoteIP[0])), sizeof(char), "boardIndex.(char)remoteIP[16]"},
{0x0204,((UINT)&(boardIndex.localPort)), sizeof(int), "boardIndex.(int)localPort"},
{0x0300,((UINT)&(queueHead[0])),sizeof(struct cmdSingle *), "struct cmdSingle *queueHead[QUEUE_NUM]"},
{0x0301,((UINT)&(queueRear[0])),sizeof(struct cmdSingle *), "struct cmdSingle *queueRear[QUEUE_NUM]"},
{0x0302,((UINT)&(queueLen[0])), sizeof(int), "int queueLen[QUEUE_NUM]"},
{0x0400,((UINT)&testInt32), sizeof(int), "int testInt32"},
{0x0401,((UINT)&testShort16), sizeof(short), "short testShort16"},
{0x0402,((UINT)&testChar8), sizeof(char), "char testChar8"},
/*此处还可以继续填加其它全局变量参数*/
{VARI_END_NUM,0,0,"0"}
};
/*函数接口相关信息*/
struct TaskFuncInfo funcInfo[]=
{
/*用户函数*/
{0x0000,(FUNCPTR)flashInit, 0, "void flashInit()"},
{0x0001,(FUNCPTR)flashIDCheck, sizeof(char), "char flashIDCheck()"},
{0x0002,(FUNCPTR)flashDataSet, sizeof(char), "char flashDataSet(int dataNum,char *pBuff,int buffLen)"},
{0x0003,(FUNCPTR)flashDataGet, sizeof(char), "char flashDataGet(int dataNum,char *pBuff,int buffLen)"},
{0x0004,(FUNCPTR)flashDataErase, sizeof(char), "char flashDataErase(int dataNum, int eraseLen)"},
{0x0005,(FUNCPTR)flashUnLock, sizeof(char), "char flashUnLock(int dataNum, int unLockLen)"},
{0x0006,(FUNCPTR)flashShutDown, 0, "void flashShutDown()"},
{0x0100,(FUNCPTR)queueInit, 0, "void queueInit()"},
{0x0101,(FUNCPTR)queueAdd, sizeof(char), "char queueAdd(int index, unsigned char* pBuff, int pri)"},
{0x0102,(FUNCPTR)queueDelHead, sizeof(char), "char queueDelHead(int index)"},
{0x0103,(FUNCPTR)queueDelAll, sizeof(char), "char queueDelAll()"},
{0x0200,(FUNCPTR)memMod, 0, "void memMod(UINT pMem, char memSize, UINT value)"},
{0x0300,(FUNCPTR)usrDefaultParamLoad,0, "void usrDefaultParamLoad()"},
{0x0301,(FUNCPTR)usrParamShow, 0, "void usrParamShow()"},
/*库函数*/
{0xF000,(FUNCPTR)semCCreate, sizeof(SEM_ID),"SEM_ID semCCreate(int options, SEM_B_STATE initialState)"},
{0xF001,(FUNCPTR)semBCreate, sizeof(SEM_ID),"SEM_ID semBCreate(int options, SEM_B_STATE initialState)"},
{0xF002,(FUNCPTR)semMCreate, sizeof(SEM_ID),"SEM_ID semMCreate(int options, SEM_B_STATE initialState)"},
{0xF003,(FUNCPTR)semDelete, sizeof(STATUS),"STATUS semDelete(SEM_ID semId)"},
{0xF004,(FUNCPTR)semGive, sizeof(STATUS),"STATUS semGive(SEM_ID semId"},
{0xF005,(FUNCPTR)semTake, sizeof(STATUS),"STATUS semTake(SEM_ID semId, int timeout)"},
{0xF100,(FUNCPTR)d, 0, "void d(void*adrs, int nuints, int width)"},
{0xF101,(FUNCPTR)help, 0, "void help()"},
{0xF102,(FUNCPTR)i, 0, "void i(int taskNameOrId)"},
{0xF200,(FUNCPTR)taskDelete, sizeof(STATUS),"STATUS taskDelete(int tid)"},
/*此处还可以添加其它函数的接口信息*/
{FUNC_END_NUM,NULL, 0, "NULL"}
};
/*netSvr.c*/
extern char netCMDAdd(unsigned char *pBuff, int buffLen, int cmdNum, unsigned char priority);
/*flash.c*/
extern void flashInit();
extern char flashDataSet(int dataNum,char *pBuff,int buffLen);
extern char flashDataErase(int dataNum, int eraseLen);
extern void flashShutDown();
extern struct BoardWorkEnv boardWorkEnv;
/*可接受的命令号*/
char t0x0200(unsigned char *pBuff); /*参数配置*/
char t0x0400(unsigned char *pBuff); /*reset*/
char t0x1600(unsigned char *pBuff); /*flash程序下载*/
char t0xFF00(unsigned char *pBuff); /*全局变量调试通道*/
char t0xFF01(unsigned char *pBuff); /*函数调试通道*/
/**********************************************************************
char t0x0200(unsigned char *pBuff)
函数描述: 获得控制界面发来的配置信息,配置全局变量
网络返回: 执行结束后发送9byte帧
调用:
netTask.c:
char netCMDAdd(unsigned char *pBuff, int buffLen, int cmdNum, unsigned char priority)
**********************************************************************/
char t0x0200(unsigned char *pBuff)
{
char state = STATUS_NORMAL;
unsigned char *pSendBuff;
int i, len;
logMsg("t0x0200: beging...\n",0,0,0,0,0,0);
/*解析参数并配置参数,根据情况设定state参数*/
/*测试用代码,打印0x0200的所有参数*/
len = pBuff[2]*0x01000000+pBuff[3]*0x00010000+pBuff[4]*0x00000100+pBuff[5]-8;
if(len!=0)
{
logMsg("t0x0200: print out %d params for 0x0200\n",len,0,0,0,0,0);
for(i=0;i<len;i++)
{
printf("%c",pBuff[i+8]);
if(i%60==59)
printf("\n");
}
printf("\n");
}
else
{
logMsg("t0x0200: 0x0200 has no params\n",0,0,0,0,0,0);
}
/*网络返回*/
pSendBuff = malloc(9*sizeof(char));
if(pSendBuff!=NULL)
{
pSendBuff[8] = state;
netCMDAdd(pSendBuff,9,0x0200,QUEUE_PRI_LOW);
}
else
{
logMsg("t0x0200: unable to malloc net return buff\n",0,0,0,0,0,0);
state = STATUS_ERROR;
}
logMsg("t0x0200: ended\n",0,0,0,0,0,0);
return(state);
}
/**********************************************************************
char t0x0400(unsigned char *pBuff)
函数描述: 单板重启动
网络返回: 无
调用: 无
**********************************************************************/
char t0x0400(unsigned char *pBuff)
{
logMsg("t0x0400: beging...\n",0,0,0,0,0,0);
reboot(BOOT_NORMAL); /*之后的语句不会被执行*/
logMsg("t0x0400: ended\n",0,0,0,0,0,0);
return(STATUS_NORMAL);
}
/**********************************************************************
char t0x1600(unsigned char*pBuff)
函数描述: 将vxWorks文件(对于单板来说就时vxWorks.bin)
下载到FLASH,准备下次启动时使用。
网络返回: 配置后发送发送9byte帧
调用:
flash.c
void flashInit();
char flashDataSet(int dataNum,char *pBuff,int buffLen);
char flashDataErase(int dataNum, int eraseLen);
void flashShutDown();
**********************************************************************/
char t0x1600(unsigned char*pBuff)
{
char state;
unsigned char *pSendBuff;
int len;
int i;
logMsg("t0x1600: begin...\n",0,0,0,0,0,0);
/*len表示vxWorks.bin的总长度*/
len = pBuff[2]*0x01000000+pBuff[3]*0x00010000+pBuff[4]*0x00000100+pBuff[5]-8;
/*在vxWorks.bin前添加4byte表示总长度信息,一起写入flash*/
pBuff[4]=(unsigned char)((len>>24)&0xFF);
pBuff[5]=(unsigned char)((len>>16)&0xFF);
pBuff[6]=(unsigned char)((len>>8)&0xFF);
pBuff[7]=(unsigned char)(len&0xFF);
logMsg("t0x1600: write vxWorks.bin for %d bytes to flash\n",len,0,0,0,0,0);
flashInit();
if(!(boardWorkEnv.boardInit&BOARD_FLASH_INITED))
{
state = STATUS_ERROR;
}
else
{
state = flashDataErase(FLASH_DATA_CPU,len+4);
if(state==STATUS_NORMAL)
state = flashDataSet(FLASH_DATA_CPU,pBuff+4,len+4);
}
flashShutDown();
/*网络返回*/
pSendBuff = malloc(9*sizeof(char));
if(pSendBuff!=NULL)
{
pSendBuff[8] = state;
netCMDAdd(pSendBuff,9,0x1600,QUEUE_PRI_LOW);
}
else
{
logMsg("t0x1600: unable to malloc net return buff\n",0,0,0,0,0,0);
state = STATUS_ERROR;
}
logMsg("t0x1600: ended\n",0,0,0,0,0,0);
return(state);
}
/**********************************************************************
char t0xFF00(unsigned char*pBuff)
函数描述: 对VxWorks下的全局变量进行读写操作,具体格式
参见通讯协议
网络返回: 无
调用: 无
**********************************************************************/
char t0xFF00(unsigned char *pBuff)
{
int i;
unsigned short variNum;
unsigned char *pVari;
if(pBuff[8]==CMD_VARI_HELP) /*帮助信息*/
{
/*打印关于全局变量的帮助信息*/
logMsg("t0xFF00: print out help on variables:\n",0,0,0,0,0,0);
printf("num pointer size information\n");
i=0;
while(variInfo[i].variNum!= VARI_END_NUM)
{
printf("0x%04x 0x%08x %2d %s\n",
variInfo[i].variNum,variInfo[i].variPointer,variInfo[i].variLen,variInfo[i].variName);
i++;
}
}
else if(pBuff[8] == CMD_VARI_READ) /*读取变量*/
{
/*查找全局变量值*/
i=0;
variNum = pBuff[9]*0x100+pBuff[10];
while(variInfo[i].variNum!=VARI_END_NUM)
{
if(variInfo[i].variNum==variNum)
break;
else
i++;
}
if(variInfo[i].variNum!=VARI_END_NUM)
{
/*存在此序号对应的全局变量,根据长度打印内容*/
logMsg("t0xFF00: read value of -- \n",0,0,0,0,0,0);
logMsg("%s\n",(int)(variInfo[i].variName),0,0,0,0,0);
if(variInfo[i].variLen==1)
{
logMsg("t0xFF00: *(unsigned char*)0x%08x = 0x%02x\n",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -