平车主控板(运维板)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
6.0 KiB

//////////////////////////////////////////////////////////////////////////
/// COPYRIGHT NOTICE
/// Copyright (c) 2015, 传控科技
/// All rights reserved.
///
/// @file main.c
/// @brief main app
///
///(本文件实现的功能的详述)
///
/// @version 1.1 CCsens technology
/// @author CC
/// @date 20150102
///
///
/// 修订说明:最初版本
/// Modified by:
/// Modified date:
/// Version:
/// Descriptions:
/*****************************************************************************
update by cc @201501101001
.
uartcom/uartlib.c:
(线),
(lcd等固屏输出的)使
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...)
-----------------------------------------------------------------------------------------
uartcom/uartcom0
uart相关的通讯协议 com + n
uart口来对应
typedef struct _ts_lcm_pro_; ? LCM的协议------------
L3_UARTcom0_exp_protocol
-----------------------------------------------------------------------------------------
uartcom/uprotocol: uartcom + n服务的
struct _s_protocol_ ()------struct _s_protocol_
void L1_uart_2buf(struct _s_protocol_ *p)
--------------------------------------------------------------------------------------------
msp/uartx.c cpu相关
L0_UART0_Init
UART0_IRQHandler
L0_Usend_uc----------s_at0
-----------------------------------------------------------------------------------------
********************************************************************************/
#include "uartlib.h"
void (*L0pf_send_uc)(U8 ww);
/********************************************************************
*
* : L0_Usend_uc_hex
* : :L0_Usend_uc_hex(0x0c); output " 0c "
* :
* : SendHUcLc_HexToChar
* :
* :
***********************************************************************/
void Lcp_uc_hex(void (*L0pf_send_uc)(char ww),char ww)
{
L0pf_send_uc(Lc_Hex2Char((ww>>4)&0x0f));
L0pf_send_uc(Lc_Hex2Char(ww&0x0f));
}
void Lcp_us_hex(void (*L0pf_send_uc)(char ww),U16 ww)
{//
U8 t;
t = (U8)(((ww >> 8)&0x00ff));
Lcp_uc_hex(L0pf_send_uc,t);
t = (U8)(((ww )&0x00ff));
Lcp_uc_hex(L0pf_send_uc,t);
}
void Lc_print(char *dat,...)
{
const char *s;
vS32 d;
char buf[16];
va_list ap;//va_list 是一个字符指针,可以理解为指向当前参数的一个指针,
//取参必须通过这个指针进行。
//<Step 1> 在调用参数表之前,定义一个 va_list 类型的变量,
//(假设va_list 类型变量被定义为ap);
va_start(ap, dat);
// 然后应该对ap 进行初始化,让它指向可变参数表里面的第一个参数,
//这是通过 va_start 来实现的,第一个参数是 ap 本身,第二个参数是在
//变参表前面紧挨着的一个变量,即“...”之前的那个参数;
// <Step 3> 然后是获取参数,调用va_arg,它的第一个参数是ap,
//第二个参数是要获取的参数的指定类型,然后返回这个指定类型的值,
//并且把 ap 的位置指向变参表的下一个变量位置;
//"e645654675y73\0"
while ( *dat != 0) // 判断是否到达字符串结束符
{
if ( *dat == 0x5c ) //'\'
{
switch ( *++dat )
{
case 'r': //回车符
L0pf_send_uc(0x0d);
dat ++;
break;
case 'n': //换行符
L0pf_send_uc(0x0a);
dat ++;
break;
case 't': //
L0pf_send_uc(0x09);
dat ++;
break;
default:
dat ++;
break;
}
}
else if ( *dat == '%')
{ //
switch ( *++dat )
{
case 'C':
case 'c': //字符
//va_arg()里的任务就是根据指定的参数类型
//取得本参数的值,并且把指针调到下一
//个参数的起始地址
//#define va_arg(ap,t)
//( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
//char *ap; %c " , 0x30,
s = va_arg(ap, const char *); // 0x30
L0pf_send_uc((char)s); // '0'
dat++;
break;
case 'd': //十进制
//" %d",0x30,
//" %d",48,
// int i = 48;
//" %d",i,
d = va_arg(ap, int); // 0x30 =48d
Lc_int2a(d, buf, 10); //"buf="48" buf[0]='4' buf[1]='8'
for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s
{ //\0
L0pf_send_uc(*s);
//printf("%c",*s);
}
dat++;
break;
case 'X':
case 'x': //字符串
d = va_arg(ap, int); // 0x30 =48d
dat++;//%X2 %X4 %X8
Lc_int2a(d, buf, *dat); //"buf="48" buf[0]='4' buf[1]='8'
for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s
{ //\0
L0pf_send_uc(*s);
}
dat++;
break;
case 'S':
case 's': //字符串
s = va_arg(ap, const char *);
for ( ; *s; s++)
{
L0pf_send_uc(*s);
}
dat++;
break;
case 'f': //十进制
d = va_arg(ap, int);
Lc_int2a(d, buf, 10);
for (s = buf; *s; s++)
{
L0pf_send_uc(*s);
}
dat++;
break;
default:
dat++;
break;
}
} /* end of else if */
else
{
L0pf_send_uc( *dat++);
}
}//end while....
}//