40 changed files with 954 additions and 685 deletions
@ -0,0 +1,11 @@ |
|||
{ |
|||
"files.associations": { |
|||
"UART0.C": "cpp", |
|||
"msp_uart0.C": "cpp", |
|||
"msp_uart2.C": "cpp", |
|||
"asp_oid.h": "c", |
|||
"msp_uart2.h": "c", |
|||
"task_w600.h": "c", |
|||
"UART2.C": "cpp" |
|||
} |
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,55 +1,130 @@ |
|||
#include "app_task_speech.h" |
|||
#include "app_task_tcp.h" |
|||
#include "../msp/msp_uart3.h" |
|||
#include "../msp/msp_uart0.h" |
|||
|
|||
|
|||
|
|||
#define START_CODE 0x7E |
|||
#define END_CODE 0xEF |
|||
|
|||
|
|||
TS_TASK_SPEECH ts_speech; |
|||
|
|||
|
|||
void L3_task_speech_init(void) |
|||
{ |
|||
U8 i; |
|||
//U8 music[6] = {0x7E,0x04,0xAE,0x1E,0x30,0xEF};
|
|||
//L0_uart0_sendArray((U8 *)&open,9);
|
|||
//U8 code open[9] = {0x7E,0x07,0xA3,0x43,0x30,0x30,0x39,0x86,0xEF};
|
|||
//L0_uart3_sendArray((U8 *)&open , 9);
|
|||
L1_task_init(&ts_speech.task); |
|||
L3_task_s_go(ts_speech,D_task_init); |
|||
for(i=0;i<CC_SPEECH_INFO;i++) |
|||
{ |
|||
ts_speech.cc_speech_info[i].mask = 0; |
|||
} |
|||
ts_speech.cc_speech_info[0].oper = SPEECH_NAME_PLAY; |
|||
ts_speech.cc_speech_info[0].mask = 0; |
|||
} |
|||
void L3_task_speech_handle(TS_tcp *s) |
|||
|
|||
#define D_task_wait_tcp_order 0x61 |
|||
#define D_task_speech_send 0x62 |
|||
|
|||
void L3_task_speech_handle(TS_TASK_SPEECH *s) |
|||
{ |
|||
TTSS_Task_init() |
|||
L2_task_go(D_task_wait_tcp_order); |
|||
TTSS_Task_step(D_task_wait_tcp_order) |
|||
if(s_uart2_tcp_rec.ok && (ts_tcp.slaverIndex != 0)) |
|||
//if(s_uart2_tcp_rec.ok)
|
|||
{ |
|||
s_uart2_tcp_rec.ok = 0; |
|||
s->pkg = (TS_PH3_ccmodbus*)(s_uart2_tcp_rec.sp); |
|||
if(s->pkg->slaver == SERVER_ID) |
|||
{ |
|||
L3_ccmodbus_slaver_ack(s->pkg,s->ack); |
|||
s->ccmd_speech_info[0].start = START_CODE; |
|||
s->ccmd_speech_info[0].num = 0x07; |
|||
s->ccmd_speech_info[0].oper = SPEECH_NAME_PLAY; |
|||
s->ccmd_speech_info[0].title = 0x43; |
|||
//ts_speech.ccmd_speech_info[0].buf = (U8*)&R.spee_order;
|
|||
s->ccmd_speech_info[0].end = END_CODE; |
|||
//Lc_buf_copy_uc((U8 *)&s->ccmd_speech_info[0].buf,(U8 *)&R.spee_order,(U16)2);
|
|||
//L0_uart0_sendArray((U8 *)&R.spee_order,2); //00 04
|
|||
s->slaverIndex = 0; |
|||
s->pkglen = L3_pack_speech(&s->speech_pkg , &s->ccmd_speech_info + s->slaverIndex); |
|||
L2_task_go(D_task_speech_send); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
L2_task_go(D_task_wait_tcp_order); |
|||
} |
|||
TTSS_Task_step(D_task_speech_send) |
|||
{ |
|||
L0_uart3_sendArray((U8 *)&s->speech_pkg, s->pkglen); |
|||
//L0_uart0_sendArray((U8*)&s->speech_pkg,s->pkglen);
|
|||
} |
|||
L2_task_go(D_task_wait_tcp_order); |
|||
TTSS_Task_end(); |
|||
} |
|||
|
|||
U8 ascTable[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; |
|||
|
|||
U8 *hexBytes2AsciiBytes(U8 asciiBytes[],U8 hexBytes[],U8 hexBytesLen) |
|||
{ |
|||
U8 i = 0; |
|||
for(i=0;i<hexBytesLen;i++) |
|||
{ |
|||
asciiBytes[i*2] = ascTable[hexBytes[i] >> 4 & 0x0F]; |
|||
asciiBytes[i*2 + 1] = ascTable[hexBytes[i] >> 0 & 0x0F]; |
|||
|
|||
} |
|||
return asciiBytes; |
|||
} |
|||
|
|||
U8 L3_pack_speech_A3(TS_SPEECH *pspeech , U8 *tcp_buf ,U8 *buf)//tcp传来的buf
|
|||
U8 Fun_SC_Check(U8 *p1, unsigned short int len) |
|||
{ |
|||
long name; |
|||
U8 sum = 0; |
|||
for(;len > 0; len--) |
|||
{ |
|||
sum += *p1++; |
|||
} |
|||
|
|||
return sum; |
|||
} |
|||
|
|||
|
|||
|
|||
U8 L3_pack_speech_A3(TS_SPEECH *pspeech , U8 start ,U8 num ,U8 title ,U8 end)//tcp传来的buf
|
|||
{ |
|||
int name; |
|||
U8 tcp_buf[6]; |
|||
U8 str_buf[6]; |
|||
U8 bufsize = 9; |
|||
pspeech->start = START_CODE; |
|||
pspeech->num = 0x07; |
|||
pspeech->start = start; |
|||
pspeech->num = num; |
|||
pspeech->oper = SPEECH_NAME_PLAY; |
|||
pspeech->title = 0x43; |
|||
name = hexToDec(&tcp_buf); |
|||
tcp_buf[0] = (int)(name/100); |
|||
tcp_buf[1] = (int)((name%100)/10); |
|||
tcp_buf[2] = (int)(name%10); |
|||
Lc_hex2ascii(&tcp_buf,&pspeech->buf,3); |
|||
pspeech->crc = (pspeech->num + pspeech->oper + pspeech->buf[0] + pspeech->buf[1] + pspeech->buf[2] + pspeech->buf[3])>> 0 & 0xFF//累加和校验
|
|||
pspeech->end = END_CODE; |
|||
|
|||
pspeech->title = title; |
|||
Lc_buf_copy_uc((U8 *)&tcp_buf,(U8 *)&R.spee_order,(U16)2); |
|||
hexBytes2AsciiBytes(str_buf,tcp_buf,2); |
|||
name = getIndexOfSigns(str_buf[2])*16+getIndexOfSigns(str_buf[3])*1; |
|||
pspeech->buf[0] = (U8)(name/100) ; |
|||
pspeech->buf[1] = (U8)((name%100)/10); |
|||
pspeech->buf[2] = (U8)(name%10); |
|||
//L0_uart0_sendArray((U8*)&tcp_buf,3);
|
|||
Lc_hex2ascii((U8 *)&pspeech->buf,(U8 *)&pspeech->buf,3); |
|||
pspeech->crc = Fun_SC_Check(&pspeech->num,6); //累加和校验
|
|||
pspeech->end = end; |
|||
return bufsize; |
|||
} |
|||
U8 L3_pack_ccmodbus(TS_SPEECH *pspeech , CC_SPEECH_INFO *speech_info) |
|||
|
|||
U8 L3_pack_speech(TS_SPEECH *pspeech, CCMD_SPEECH_INFO
*speech_info) |
|||
{ |
|||
U16 pkglen = 0; |
|||
switch(speech_info->oper) |
|||
{ |
|||
case SPEECH_NAME_PLAY: |
|||
pkglen = L3_pack_ccmodbus_03(pspeech,tcp_buf,speech_info->buf); |
|||
break; |
|||
default: |
|||
break; |
|||
case SPEECH_NAME_PLAY: |
|||
pkglen = L3_pack_speech_A3(pspeech,speech_info->start,speech_info->num,speech_info->title,speech_info->end); |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
pccmodbus->num = pkglen; |
|||
return pkglen + 3; |
|||
return pkglen; |
|||
} |
|||
|
|||
|
@ -1,184 +0,0 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// 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:
|
|||
// 20160413 CC-ACC-VH02
|
|||
// 连接至 J22 RXD0 TXD0
|
|||
//P5_DIR &= ~BITN1; //p5.1输出TXD
|
|||
//P5_DIR |= BITN0; //p5.0输入RXD
|
|||
//P5_SEL0 &= ~(BITN0 +BITN1); //设置P5.0 P5.1为UART0 RXD TXD
|
|||
//P5_SEL1 |= BITN0 +BITN1;
|
|||
|
|||
/*****************************************************************************
|
|||
update by cc @201700110 |
|||
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 |
|||
个需要平衡的事情. |
|||
|
|||
clib/clib.c: |
|||
公用的函数 和硬件无关 |
|||
放置串行模式(串口等其他通讯总线类的输出)输出的函数, |
|||
一些覆盖模式输出的(lcd等固屏输出的)的也可使用 |
|||
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/Uprotocol2app |
|||
协议到应用 |
|||
为了适应不同的通讯协议需要不同的uart口来对应 和应用相关 |
|||
|
|||
typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------ |
|||
L3_UARTcom0_exp_protocol 解析应用协议 |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/urec2protocol: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 标头式或者标尾式 |
|||
公用的串口通讯定义 |
|||
struct _s_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_ |
|||
void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中 |
|||
-------------------------------------------------------------------------------------------- |
|||
msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 |
|||
L0_UART0_Init |
|||
UART0_IRQHandler |
|||
L0_Usend_uc------UserDef |
|||
----------------------------------------------------------------------------------------- |
|||
********************************************************************************/ |
|||
#include "../msp/msp_uart3.h" |
|||
#include "../msp/time.h" |
|||
#include <stdio.h> |
|||
|
|||
static volatile Ts_uart_send_buf idata ts_uart3_send_shop; |
|||
struct _tp_handler_x s_uart3_rec; |
|||
TS_PH4_modbus s_uart3_ack; |
|||
|
|||
void L0_uart3_init(void) |
|||
{ |
|||
//#if(MainFre_11M == D_sys_MainFre) //115200bps@11.0592MHz
|
|||
// S3CON = 0x10; //8位数据,可变波特率
|
|||
// S3CON |= 0x40; //串口3选择定时器3为波特率发生器
|
|||
// T4T3M |= 0x02; //定时器3时钟为Fosc,即1T
|
|||
// T3L = 0xE8; //设定定时初值
|
|||
// T3H = 0xFF; //设定定时初值
|
|||
// T4T3M |= 0x08; //启动定时器3
|
|||
|
|||
//#elif (MainFre_22M == D_sys_MainFre) //115200bps@22.1184MHz
|
|||
// S3CON = 0x10; //8位数据,可变波特率
|
|||
// S3CON |= 0x40; //串口3选择定时器3为波特率发生器
|
|||
// T4T3M |= 0x02; //定时器3时钟为Fosc,即1T
|
|||
// T3L = 0xD0; //设定定时初值
|
|||
// T3H = 0xFF; //设定定时初值
|
|||
// T4T3M |= 0x08; //启动定时器3
|
|||
//#endif
|
|||
#if 0
|
|||
S3CON = 0x10; //8位数据,可变波特率
|
|||
S3CON &= 0xBF; //串口3选择定时器2为波特率发生器
|
|||
AUXR |= 0x04; //定时器时钟1T模式
|
|||
T2L = 0xD0; //设置定时初始值
|
|||
T2H = 0xFF; //设置定时初始值
|
|||
AUXR |= 0x10; //定时器2开始计时
|
|||
#endif |
|||
//512000
|
|||
S3CON = 0x10; //8位数据,可变波特率
|
|||
S3CON |= 0x40; //串口3选择定时器3为波特率发生器
|
|||
T4T3M &= 0xFD; //定时器时钟12T模式
|
|||
T3L = 0xFF; //设置定时初始值
|
|||
T3H = 0xFF; //设置定时初始值
|
|||
T4T3M |= 0x08; //定时器3开始计时
|
|||
} |
|||
|
|||
void L0_uart3_buf_init(void) |
|||
{ |
|||
ts_uart[uNum3].p = &ts_uart3_send_shop; |
|||
ts_uart[uNum3].p->now = 0; |
|||
ts_uart[uNum3].p->ok = D_ready; |
|||
ts_uart[uNum3].t = &s_uart3_rec; |
|||
ts_uart[uNum3].t->head = 0; |
|||
ts_uart[uNum3].t->ok = 0; |
|||
ts_uart[uNum3].tp_handler = L1_s2b_PH4; |
|||
ts_uart[uNum3].ack = (U8*)&s_uart3_ack; |
|||
L0_uart3_init(); |
|||
//D_uart3_ES_INT_OPEN(); //打开串口中断
|
|||
D_uart3_ES_INT(1); //打开串口中断
|
|||
|
|||
#if (D_UART3_485_TYPE != TYPE_485_NONE) |
|||
D_UART3_485_RX() //默认处于接收状态
|
|||
#endif |
|||
} |
|||
|
|||
void L0_uart3_sendArray(U8 * buf, U16 len) |
|||
{ |
|||
//#if (D_UART3_485_TYPE != TYPE_485_NONE)
|
|||
// D_UART3_485_TX() //切换到输出状态
|
|||
//#endif
|
|||
L0_uartN_sendArray(uNum3,buf,len); |
|||
} |
|||
|
|||
/*************************************************
|
|||
UART 中断 |
|||
*************************************************/ |
|||
#define D_SERVE_UART3 interrupt 17 |
|||
void INTERRUPT_UART3(void) D_SERVE_UART3// using 3
|
|||
{ |
|||
NOP(); NOP(); NOP(); |
|||
if(L0_uart3_IntRI()) //如果是U0接收中断
|
|||
{ |
|||
L0_uart3_IntRIClear(); //清除接收中断标志
|
|||
ts_uart[uNum3].t->reg = L0_uartN_get(uNum3); |
|||
ts_uart[uNum3].tp_handler(ts_uart[uNum3].t); |
|||
//L0_timer4_start();
|
|||
} |
|||
if(L0_uart3_IntTI()) |
|||
{ |
|||
if(L0_uart3_IntTI()) //如果是U0发送中断
|
|||
{ |
|||
L0_uart3_IntTIClear(); //清除发送中断标志
|
|||
if(ts_uart[uNum3].p->max != ts_uart[uNum3].p->now) |
|||
{ |
|||
L0_uartN_set(uNum3,ts_uart[uNum3].p->p[ts_uart[uNum3].p->now]); |
|||
ts_uart[uNum3].p->now ++; |
|||
} |
|||
else |
|||
{ |
|||
ts_uart[uNum3].p->ok = D_ready; |
|||
ts_uart[uNum3].p->max = 0; |
|||
ts_uart[uNum3].p->now = 0;//可以发送下一个数据
|
|||
#if (D_UART3_485_TYPE != TYPE_485_NONE) |
|||
D_UART3_485_RX() //切换到接收状态
|
|||
#endif |
|||
} |
|||
} |
|||
} |
|||
NOP(); NOP(); NOP(); |
|||
} |
|||
|
|||
void timer4_isrHanddle(void) D_SERVE_TIMER4 |
|||
{ |
|||
struct _tp_handler_x *p = &s_uart3_rec; |
|||
if((p->head == 1) && (p->num >= D_s_modbus_min)) |
|||
{ |
|||
p->head = 0; |
|||
crc16(p->crc,p->buf,p->num - 2); //校验CRC
|
|||
if(p->crc[0] == p->buf[p->num-2] && p->crc[1] == p->buf[p->num-1]) |
|||
{ |
|||
if(p->ok == 0) |
|||
{ |
|||
p->ok = 1; |
|||
} |
|||
} |
|||
//LED0 ^= 1;
|
|||
} |
|||
L0_timer4_stop(); |
|||
} |
|||
|
|||
|
@ -1,93 +0,0 @@ |
|||
//////////////////////////////////////////////////////////////////////////
|
|||
/// 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 @201700110 |
|||
针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 |
|||
个需要平衡的事情. |
|||
|
|||
clib/clib.c: |
|||
公用的函数 和硬件无关 |
|||
放置串行模式(串口等其他通讯总线类的输出)输出的函数, |
|||
一些覆盖模式输出的(lcd等固屏输出的)的也可使用 |
|||
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/Uprotocol2app |
|||
协议到应用 |
|||
为了适应不同的通讯协议需要不同的uart口来对应 和应用相关 |
|||
|
|||
typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------ |
|||
L3_UARTcom0_exp_protocol 解析应用协议 |
|||
----------------------------------------------------------------------------------------- |
|||
uartcom/urec2protocol: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 标头式或者标尾式 |
|||
公用的串口通讯定义 |
|||
struct _s_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_ |
|||
void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中 |
|||
-------------------------------------------------------------------------------------------- |
|||
msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 |
|||
L0_uart3_Init |
|||
uart3_IRQHandler |
|||
L0_Usend_uc------UserDef |
|||
----------------------------------------------------------------------------------------- |
|||
********************************************************************************/ |
|||
|
|||
|
|||
#ifndef _uart3_H |
|||
#define _uart3_H |
|||
|
|||
#include "../bsp/bsp_config.h" |
|||
#include "../tpc/modbus.h" |
|||
#include "msp_uart_x.h" |
|||
|
|||
#define uNum3 2 |
|||
|
|||
//#define S4SM0 BITN7
|
|||
#define D_uart3_ES_INT(x) (x) ? (BITN_1(IE2,ES3)) : (BITN_0(IE2,ES3)) |
|||
//#define D_uart3_ES_INT_CLOSE() BITN_0(IE2,ES3)
|
|||
//#define D_uart3_ES_INT_OPEN() BITN_1(IE2,ES3)
|
|||
#define L0_uart3_IntRI() (S3CON & S3RI)//BITN_G(SCON,U0RI)
|
|||
#define L0_uart3_IntTI() (S3CON & S3TI)//BITN_G(SCON,U0TI)
|
|||
#define L0_uart3_IntRIClear(); BITN_0(S3CON,S3RI) |
|||
#define L0_uart3_IntTIClear(); BITN_0(S3CON,S3TI) |
|||
#define L0_uart3_set(x) S3BUF = (x); |
|||
#define L0_uart3_get() (S3BUF) |
|||
|
|||
|
|||
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|||
|
|||
extern void L0_uart3_buf_init(void); |
|||
extern void L0_uart3_sendArray(U8 * buf, U16 len); |
|||
|
|||
#define L0_uart3_uc(X) L0_uartN_uc(uNum3,X) |
|||
#define L0_uart3_us(X) L0_uartN_us(uNum3,X) |
|||
#define L0_uart3_ul(X) L0_uartN_ul(uNum3,X) |
|||
#define L0_uart3_0d0a() L0_uartN_0d0a(uNum3) |
|||
#define L0_uart3_uchex(X) L0_uartN_uchex(uNum3,X) |
|||
#define L0_uart3_ushex(X) L0_uartN_ushex(uNum3,X) |
|||
#define L0_uart3_ulhex(X) L0_uartN_ulhex(uNum3,X) |
|||
#define L0_uart3_sendstr(buf) L0_uartN_sendstr(uNum3,buf) |
|||
#define L1_uart3_uchexArray(buf) L1_uartN_uchexArray(uNum3,buf) |
|||
|
|||
extern TP_Handler_X s_uart3_rec; |
|||
extern TS_PH4_modbus s_uart3_ack; |
|||
|
|||
#endif //#ifndef _uart3_H
|
|||
|
Loading…
Reference in new issue