📄 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"
/*netSvr.c*/
extern char netCMDAdd(unsigned char *pBuff, int buffLen, int cmdNum, unsigned char priority);
/*可接受的命令号*/
char t0x0200(unsigned char *pBuff); /*参数配置*/
char t0x0400(unsigned char *pBuff); /*reset*/
char t0x1600(unsigned char*pBuff); /*flash程序下载*/
/**********************************************************************
char t0x0200(unsigned char *pBuff)
函数描述: 获得控制界面发来的配置信息,配置全局变量
网络返回: 执行结束后发送9byte帧
调用:
netSvr.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操作函数
**********************************************************************/
char t0x1600(unsigned char*pBuff)
{
char state;
unsigned char *pSendBuff;
int len;
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);
/*网络返回*/
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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -