packet.c

来自「嵌入式系统基础课件」· C语言 代码 · 共 54 行

C
54
字号
#include "libepc.h"
#include "os_cpu.h"
#include "os_cfg.h"
#include "ucos_ii.h"
#include "serial.h"
#include "inbound.h"
#include "elapsed.h"

void ReceivePackets(void)
	{
	SerialInit() ;
	for (;;)
		{
		int type, byte, bytes ;
		BYTE8 *bfr ;

		if (SerialGet() != 0xFF) continue ;
		switch (type = SerialGet())
			{
			default:
				continue ;
			case 1:
			case 2:
				break ;
			}

		bytes = SerialGet();
		bfr = (BYTE8 *) malloc(bytes) ;
		if (!bfr) for (;;) ;

		for (byte = 0; byte < bytes; byte++)
			{
			bfr[byte] = SerialGet() ;
			}
		switch (type)
			{
			case 1:
				PostText(bfr) ;
				break ;
			case 2:
				PostTime(bfr) ;
				break ;
			}
		}
	}

void SendPacket(int type, BYTE8 *bfr, int bytes)
	{
	SerialInit() ;
	...
	You fill in the rest!
	...
	}

⌨️ 快捷键说明

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