3090 lines
91 KiB
C
3090 lines
91 KiB
C
/********************************************************************************
|
||
|
||
**** Copyright (C), 2017, xx xx xx xx info&tech Co., Ltd. ****
|
||
|
||
********************************************************************************
|
||
* File Name : uart.c
|
||
* Author : barry
|
||
* Date : 2017-03-01
|
||
* Description : .C file function description
|
||
* Version : 1.0
|
||
* Function List :
|
||
*
|
||
* Record :
|
||
* 1.Date : 2017-03-01
|
||
* Author : barry
|
||
* Modification: Created file
|
||
|
||
*************************************************************************************************************/
|
||
|
||
#include "uart.h"
|
||
#include "addr.h"
|
||
#include "debug_printf.h"
|
||
#include "bl24c512.h"
|
||
#include "WaterMetermanager.h"
|
||
#include "Led.h"
|
||
#include "keywd.h"
|
||
#include "update.h"
|
||
#include "Flash.h"
|
||
#include "PHY.h"
|
||
#include "rtc_ext.h"
|
||
|
||
#define HW_OLD_VER 0
|
||
|
||
|
||
extern void concent_gateopen();
|
||
extern void concent_gateclose();
|
||
|
||
void uart_dma_tx_callback(struct st_uart_port* uartPort);
|
||
void MBUS_slave_process_task(void *ptr);
|
||
void MBUS_slave_detected_task(void *ptr);
|
||
void Read_DataSave_TimeProcess(u8* time);;
|
||
u8* GetCurrentTime( void );
|
||
/* RTOS variable */
|
||
QueueSetHandle_t mPortsQueueSet;
|
||
SemaphoreHandle_t uart_sync_Semaphore;
|
||
SemaphoreHandle_t mbus_port_Mutex;
|
||
SemaphoreHandle_t port_radio_Semaphore;
|
||
|
||
|
||
TaskHandle_t up_send_led_handle;
|
||
TaskHandle_t up_receive_led_handle;
|
||
TaskHandle_t down_send_led_handle;
|
||
TaskHandle_t down_receive_led_handle;
|
||
TaskHandle_t temp_saved_handle;
|
||
QueueHandle_t WATERMETER485_Task;
|
||
QueueHandle_t RFPORT_Task;
|
||
TaskHandle_t operation_led_handle;
|
||
|
||
static u32 PortInvalidCounter = 0x00; //
|
||
static u32 Port485InvalidCounter = 0x00; //重新规划,当前参数表示下行抄表通讯端口计数
|
||
|
||
|
||
|
||
static TimerHandle_t mbus_switch_handle;
|
||
|
||
/* define port */
|
||
u8 plc_rxbuf[COM_PLC_RX_BUFFER_SIZE];
|
||
u8 plc_txbuf[COM_PLC_TX_BUFFER_SIZE];
|
||
create_uart_port(COM_PLC, plc_rxbuf, plc_txbuf)
|
||
|
||
u8 master_rxbuf[COM_MBUS_MASTER_RX_BUFFER_SIZE];
|
||
u8 master_txbuf[COM_MBUS_MASTER_TX_BUFFER_SIZE];
|
||
create_uart_port(COM_MBUS_MASTER, master_rxbuf, master_txbuf)
|
||
|
||
u8 RS485_rxBuf[COM_485_RX_BUFFER_SIZE];
|
||
u8 RS485_tx_buf[COM_485_RX_BUFFER_SIZE];
|
||
create_uart_port(COM_485, RS485_rxBuf, RS485_tx_buf)
|
||
|
||
|
||
|
||
u8 radio_rxbuf[COM_RADIO_RX_BUFFER_SIZE];
|
||
u8 radio_txbuf[COM_RADIO_TX_BUFFER_SIZE];
|
||
create_uart_port(COM_RADIO, radio_rxbuf, radio_txbuf)
|
||
|
||
|
||
void mbus_master_tx_begin();
|
||
void send_to_mbus(void *ptr);
|
||
|
||
|
||
//定义模拟串口属性
|
||
void RS4852_process_task(void *ptr);
|
||
u8 RS4852_rxbuf[COM_4852_RX_BUFFER_SIZE];
|
||
u8 RS4852_txbuf[COM_4852_TX_BUFFER_SIZE];
|
||
struct st_uart_port RS4852_port = USART_PORT_PARAMS(COM_4852, RS4852_rxbuf, RS4852_txbuf);
|
||
|
||
enum
|
||
{
|
||
RS4852_STATUS_NONE,
|
||
RS4852_STATUS_TXING,
|
||
RS4852_STATUS_RXING,
|
||
RS4852_STATUS_RX_READY,
|
||
RS4852_STATUS_RX_END,
|
||
};
|
||
|
||
struct RS4852
|
||
{
|
||
u8 Status;
|
||
u8 Step;
|
||
u8 TXBit;
|
||
u8 TXByte;
|
||
u8 RXBit;
|
||
u8 RXByte;
|
||
}RS4852_UNIT = {00};
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//通配符表地址
|
||
u8 ApplMeterCommonID[6] = {0xBB,0xBB,0xBB,0xBB,0xBB,0xBB,};
|
||
|
||
u8 MbusChargeTime; //MBUS抄表前充电时间
|
||
|
||
|
||
/* extern variable */
|
||
extern u8 DI901F[2];
|
||
extern u8 DI1F90[2];
|
||
extern u8 DIA017[2];
|
||
extern u8 cmd_read_woterMter[4];
|
||
extern u8 cmd_read_frozen[4];
|
||
extern u8 cmd_E5E50000[4];
|
||
extern u8 cmd_E5E50001[4];
|
||
extern u8 cmd_FJWGData[4];
|
||
extern u8 cmd_OnOff_Key[4];
|
||
extern struct st_meter_temp_value * meter_list;
|
||
extern void sj_data_ack(u8 * meter,u8 * data);
|
||
extern bool get_dl_task_state();
|
||
extern void sj_data_ack(u8 * meter,u8 * data);
|
||
extern void plc_buff_sem_give();
|
||
extern void plc_uart_buff_set(u8 * buff,u16 len);
|
||
extern void control_key_ack(u8 key);
|
||
extern bool get_isupdatestate();
|
||
static bool is_overload_flag = false;
|
||
extern void smt_set_value(u8 * val,u8 len);
|
||
extern void XYDX485Data_process_task(void *ptr);
|
||
|
||
void send_to_mbus_set(u8 * buf,u16 len);
|
||
|
||
|
||
SemaphoreHandle_t send_to_semaphore;
|
||
|
||
|
||
|
||
u8 mbus_mode = MBUS_MODE_MASTER;
|
||
|
||
|
||
void Clear485PortINValidCount( void )
|
||
{
|
||
Port485InvalidCounter = 0x00;
|
||
}
|
||
|
||
|
||
|
||
void ClearPortINValidCount( void )
|
||
{
|
||
PortInvalidCounter = 0x00;
|
||
}
|
||
|
||
void PortINValidCountProcess( u32 time )
|
||
{
|
||
PortInvalidCounter += time;
|
||
Port485InvalidCounter += time;
|
||
}
|
||
|
||
u32 GetPortINValidCount( void )
|
||
{
|
||
return Port485InvalidCounter > PortInvalidCounter ?Port485InvalidCounter:PortInvalidCounter;
|
||
}
|
||
|
||
|
||
u32 Get485PortIIdleCount( void )
|
||
{
|
||
return Port485InvalidCounter;
|
||
}
|
||
|
||
|
||
void close_mbus_switch()
|
||
{
|
||
GPIO_SetBits(MBUS_POWER_CTRL_PIN_PORT, MBUS_POWER_CTRL_PIN);
|
||
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
GPIO_InitStructure.GPIO_Pin = MBUS_POWER_CTRL_PIN;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(MBUS_POWER_CTRL_PIN_PORT, &GPIO_InitStructure);
|
||
|
||
vTaskDelay( (50 /portTICK_RATE_MS) );
|
||
|
||
GPIO_InitStructure.GPIO_Pin = MBUS_POWER_CTRL_PIN;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(MBUS_POWER_CTRL_PIN_PORT, &GPIO_InitStructure);
|
||
|
||
GPIO_SetBits(MBUS_POWER_CTRL_PIN_PORT, MBUS_POWER_CTRL_PIN);
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : mbus_switch_timeOut_callback_function
|
||
* Description : nnone
|
||
* Input : TimerHandle_t xTimer
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void mbus_switch_timeOut_callback_function(TimerHandle_t xTimer)
|
||
{
|
||
// GPIO_InitTypeDef GPIO_InitStructure;
|
||
//
|
||
// GPIO_InitStructure.GPIO_Pin = MBUS_EXTIN_PIN; //检测高电压
|
||
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
// GPIO_Init(MBUS_EXTIN_PORT, &GPIO_InitStructure);
|
||
//
|
||
// vTaskDelay( 100/portTICK_RATE_MS );
|
||
// close_mbus_switch();
|
||
//
|
||
// GPIO_InitStructure.GPIO_Pin = MBUS_EXTIN_PIN; //检测高电压
|
||
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
// GPIO_Init(MBUS_EXTIN_PORT, &GPIO_InitStructure);
|
||
//
|
||
|
||
|
||
close_mbus_switch();
|
||
st_rtc_ext * time = (st_rtc_ext *)GetCurrentTime();
|
||
printf("\r\n%02x-%02x-%02x %02x:%02x:%02x \r\n", time->year,time->month,time->day,time->hour,time->min,time->sec);
|
||
|
||
printf("\r\n\r\n 关闭切换close switch\r\n\r\n");
|
||
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : set_curent_protocl
|
||
* Description : none
|
||
* Input : u8 config
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170426
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
|
||
/*****************************************************************************
|
||
* Function : read_power_level
|
||
* Description : none
|
||
* Input : void
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170412
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
bool read_power_level(void)
|
||
{
|
||
return (bool)power_level_state();
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : set_mbus_master_params
|
||
* Description : none
|
||
* Input : u32 baud
|
||
u16 check
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170413
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void set_mbus_master_params(u32 baud, u16 check)
|
||
{
|
||
COM_MBUS_MASTER_port.init.uart_param.USART_BaudRate = baud;
|
||
COM_MBUS_MASTER_port.init.uart_param.USART_Parity = check;
|
||
hal_InitCOM(&COM_MBUS_MASTER_port);
|
||
}
|
||
/*****************************************************************************
|
||
* Function : set_PLC_UART_baud
|
||
* Description : none
|
||
* Input : u32 baud
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170314
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void set_PLC_UART_baud(u32 baud)
|
||
{
|
||
COM_PLC_port.init.uart_param.USART_BaudRate = baud;
|
||
COM_PLC_port.init.uart_param.USART_Parity = USART_Parity_Even;
|
||
hal_InitCOM(&COM_PLC_port);
|
||
}
|
||
|
||
void set_PLC_UART_gprs()
|
||
{
|
||
COM_PLC_port.init.uart_param.USART_BaudRate = COM_PLC_BAUD;
|
||
COM_PLC_port.init.uart_param.USART_Parity = COM_PLC_CHECK;
|
||
hal_InitCOM(&COM_PLC_port);
|
||
}
|
||
|
||
|
||
void set_PLC_UART_update()
|
||
{
|
||
COM_PLC_port.init.uart_param.USART_BaudRate = 2400;
|
||
COM_PLC_port.init.uart_param.USART_Parity = USART_Parity_Even;
|
||
hal_InitCOM(&COM_PLC_port);
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : create_queue_send_packet
|
||
* Description : none
|
||
* Input : u8 * buf
|
||
u16 length
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
u16 create_queue_send_packet(u8 * buf, u16 length)
|
||
{
|
||
for (u16 i = 0 ; i < length; i++)
|
||
{
|
||
buf[(length -1) + 4 - i ] = buf[length - i - 1];
|
||
}
|
||
buf[0] = 0xFE;
|
||
buf[1] = 0xFE;
|
||
buf[2] = 0xFE;
|
||
buf[3] = 0xFE;
|
||
|
||
return length + 4;
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : uplink_ack_send
|
||
* Description : none
|
||
* Input : u8 uplink
|
||
u8 *buf
|
||
u16 length
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170315
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void uplink_ack_send(u8 uplink, u8 *buf, u16 length)
|
||
{
|
||
if (uplink == UP_PORT_PLC)
|
||
{
|
||
port_send(&COM_PLC_port, buf, length);
|
||
}
|
||
else
|
||
{
|
||
up_485_Tx(buf, length);
|
||
}
|
||
|
||
//xTaskNotifyGive(up_send_led_handle);
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : simulate_mbus_plc_rx
|
||
* Description : none
|
||
* Input : u8 *buf
|
||
u8 len
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void simulate_mbus_plc_rx(u8 *buf, u16 len)
|
||
{
|
||
//MemCpy(COM_PLC_port.data.rxBuf, buf, len);
|
||
//COM_PLC_port.data.rx_len = len;
|
||
//printf("PLC SIMUL RX:");
|
||
//printf_buf(COM_PLC_port.data.rxBuf, len);
|
||
// xSemaphoreGive(COM_PLC_port.xSemaphore);
|
||
|
||
send_to_mbus_set(buf,len);
|
||
xSemaphoreGive(send_to_semaphore);
|
||
}
|
||
|
||
/*****************************************************************************
|
||
Prototype : hal_sRF_ITConfig
|
||
Description : none
|
||
Input : en_GDOx_IrqLine irqLine
|
||
FunctionalState NewState
|
||
Output : None
|
||
Return Value :
|
||
Date : 2014/3/15
|
||
Author : Barry
|
||
*****************************************************************************/
|
||
void mbus_gpio_init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
//EXTI_InitTypeDef EXTI_InitStructure;
|
||
//NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
st_gpio_config PLC_RESET_cfg = PLC_RESET_CFG;
|
||
|
||
/*
|
||
st_gpio_config IRDATX_cfg = IRDA_TPIN_CFG;
|
||
st_gpio_config IRDARX_cfg = IRDA_RPIN_CFG;
|
||
st_gpio_config RFTX_cfg = RF_DOWN_TPIN_CFG;
|
||
st_gpio_config RFRX_cfg = RF_DOWN_RPIN_CFG;
|
||
|
||
st_gpio_config RS485TX_cfg = RS485_UP_TPIN_CFG;
|
||
st_gpio_config RS485RX_cfg = RS485_UP_RPIN_CFG;
|
||
st_gpio_config mbus_switch =MBUS_SWITCH_CFG;
|
||
st_gpio_config mbus_ext = MBUS_EXT_CFG;
|
||
st_gpio_config mbus_overload = MBUS_OVERLOAD_CFG;
|
||
st_gpio_config RS485_overload = RS485_OVERLOAD_CFG;
|
||
st_gpio_config RS485_ext = RS485_EXT_CFG;
|
||
st_gpio_config pow_level = MBUS_POW_LEVEL_CFG;
|
||
st_gpio_config RS485_pow_ctrl = RS485_CTRL_CFG;
|
||
*/
|
||
|
||
|
||
RCC_APB2PeriphClockCmd( MBUS_POWER_CTRL_PORT_CLK |PLC_RESET_PIN_CLK |MBUS_OVERLOAD_CLK, ENABLE);
|
||
|
||
close_mbus_switch();
|
||
|
||
|
||
GPIO_InitStructure.GPIO_Pin = MBUS_EXTIN_PIN; //检测高电压
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(MBUS_EXTIN_PORT, &GPIO_InitStructure);
|
||
|
||
GPIO_InitStructure.GPIO_Pin = MBUS_OVERLOAD_PIN; //检测低电压
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(MBUS_OVERLOAD_PORT, &GPIO_InitStructure);
|
||
|
||
gpio_init(PLC_RESET_cfg);
|
||
|
||
PLC_RESET_LOW();
|
||
|
||
/*
|
||
GPIO_EXTILineConfig(MBUS_EXT_FLAG_PORT_SOURCE, MBUS_EXT_FLAG_PIN_SOURCE);
|
||
|
||
EXTI_InitStructure.EXTI_Line = MBUS_EXT_FLAG_LINE;
|
||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
|
||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||
EXTI_Init(&EXTI_InitStructure);
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
*/
|
||
|
||
/*
|
||
gpio_init(IRDATX_cfg);
|
||
gpio_init(IRDARX_cfg);
|
||
gpio_init(RFTX_cfg);
|
||
gpio_init(RFRX_cfg);
|
||
gpio_init(PLC_RESET_cfg);
|
||
|
||
gpio_init(mbus_switch);
|
||
gpio_init(mbus_ext);
|
||
gpio_init(mbus_overload);
|
||
|
||
gpio_init(RS485_overload);
|
||
gpio_init(RS485_ext);
|
||
gpio_init(RS485_pow_ctrl);
|
||
|
||
gpio_init(pow_level);
|
||
*/
|
||
|
||
|
||
/*
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
EXTI_InitTypeDef EXTI_InitStructure;
|
||
|
||
GPIO_EXTILineConfig(MBUS_OVERLOAD_FLAG_PORT_SOURCE, MBUS_OVERLOAD_FLAG_PIN_SOURCE);
|
||
GPIO_InitStructure.GPIO_Pin = MBUS_OVERLOAD_FLAG_PIN;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(MBUS_OVERLOAD_FLAG_PIN_PORT, &GPIO_InitStructure);
|
||
|
||
EXTI_InitStructure.EXTI_Line = MBUS_OVERLOAD_FLAG_LINE;
|
||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||
EXTI_Init(&EXTI_InitStructure);
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
*/
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : power_level_set
|
||
* Description : none
|
||
* Input : bool high
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170412
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void set_power_level(bool high)
|
||
{
|
||
RCC_APB2PeriphClockCmd( POWER_LEVEL_PORT_CLK, ENABLE);
|
||
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
GPIO_InitStructure.GPIO_Pin = POWER_LEVEL_PIN;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; //有上拉电阻
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||
GPIO_Init(POWER_LEVEL_PORT, &GPIO_InitStructure);
|
||
|
||
if (high)
|
||
{
|
||
SET_POWER_LEVEL_LOW();
|
||
}
|
||
else
|
||
{
|
||
SET_POWER_LEVEL_HIGH();
|
||
}
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : uart_int_rx_frame
|
||
* Description : none
|
||
* Input : struct st_uart_port* uartPort
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void uart_int_rx_frame(struct st_uart_port* uartPort)
|
||
{
|
||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||
|
||
if (uartPort->data.rx_index >= COM_MBUS_MASTER_RX_BUFFER_SIZE)
|
||
{
|
||
uartPort->data.rx_index = 0;
|
||
}
|
||
|
||
uartPort->data.rxBuf[uartPort->data.rx_index++] = USART_ReceiveData(uartPort->init.com);
|
||
uartPort->data.rx_timeout = xTaskGetTickCount() + PORT_RX_TIMEOUT;
|
||
|
||
|
||
if(uartPort->port_No == 2 )
|
||
{
|
||
if ( uartPort->data.rx_index == 1 )
|
||
{
|
||
if ((uartPort->data.rxBuf[0] == 0x68) || (uartPort->data.rxBuf[0] == 0xEB) || ((uartPort->data.rxBuf[0] == 0xAA)))
|
||
{
|
||
xSemaphoreGiveFromISR( uart_sync_Semaphore, &xHigherPriorityTaskWoken );
|
||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
||
}
|
||
else if(uartPort->data.rxBuf[0] == 0x53)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
uartPort->data.rx_index = 0;
|
||
uartPort->data.rx_timeout = 0;
|
||
}
|
||
}
|
||
else if( (uartPort->data.rx_index >= 0x08) && (uartPort->data.rxBuf[uartPort->data.rx_index - 1] == 0x45) )
|
||
{
|
||
xSemaphoreGiveFromISR( uart_sync_Semaphore, &xHigherPriorityTaskWoken );
|
||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
||
}
|
||
}
|
||
else
|
||
{
|
||
xSemaphoreGiveFromISR( uart_sync_Semaphore, &xHigherPriorityTaskWoken );
|
||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
||
}
|
||
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : uart_dma_tx_callback
|
||
* Description : none
|
||
* Input : struct st_uart_port* uartPort
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void uart_dma_tx_callback(struct st_uart_port* uartPort)
|
||
{
|
||
uartPort->data.tx_timeout = 0;
|
||
if ((uartPort->init.com == COM_MBUS_MASTER_NO) || (uartPort->init.com == COM_485_NO))
|
||
{
|
||
uartPort->init.com ->CR1 |= (0x04);
|
||
USART_ITConfig( uartPort->init.com , USART_IT_RXNE, ENABLE);
|
||
}
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : set_port_prams
|
||
* Description : none
|
||
* Input : u16 meter_protcl
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void set_port_prams(u16 meter_protcl)
|
||
{
|
||
switch (meter_protcl)
|
||
{
|
||
case MBUS_901F_2400_E:
|
||
case MBUS_1F90_2400_E:
|
||
COM_MBUS_MASTER_port.init.uart_param.USART_BaudRate = 2400;
|
||
COM_MBUS_MASTER_port.init.uart_param.USART_Parity = USART_Parity_Even;
|
||
//COM_MBUS_SLAVE_port.init.uart_param.USART_BaudRate = 2400;
|
||
//COM_MBUS_SLAVE_port.init.uart_param.USART_Parity = USART_Parity_Even;
|
||
|
||
//hal_InitCOM(&COM_MBUS_SLAVE_port);
|
||
hal_InitCOM(&COM_MBUS_MASTER_port);
|
||
|
||
break;
|
||
|
||
case MBUS_HHCQ_2400_N:
|
||
COM_MBUS_MASTER_port.init.uart_param.USART_BaudRate = 2400;
|
||
COM_MBUS_MASTER_port.init.uart_param.USART_Parity = USART_Parity_No;
|
||
//COM_MBUS_SLAVE_port.init.uart_param.USART_BaudRate = 2400;
|
||
//COM_MBUS_SLAVE_port.init.uart_param.USART_Parity = USART_Parity_No;
|
||
|
||
// hal_InitCOM(&COM_MBUS_SLAVE_port);
|
||
hal_InitCOM(&COM_MBUS_MASTER_port);
|
||
|
||
break;
|
||
|
||
case MBUS_YZSJ_1200_E:
|
||
case MBUS_HZJD_1200_E:
|
||
COM_MBUS_MASTER_port.init.uart_param.USART_BaudRate = 1200;
|
||
COM_MBUS_MASTER_port.init.uart_param.USART_Parity = USART_Parity_Even;
|
||
//COM_MBUS_SLAVE_port.init.uart_param.USART_BaudRate = 1200;
|
||
//COM_MBUS_SLAVE_port.init.uart_param.USART_Parity = USART_Parity_Even;
|
||
|
||
//hal_InitCOM(&COM_MBUS_SLAVE_port);
|
||
hal_InitCOM(&COM_MBUS_MASTER_port);
|
||
|
||
break;
|
||
|
||
case RS485_NJSM_1200_N:
|
||
COM_485_port.init.uart_param.USART_BaudRate = 1200;
|
||
COM_485_port.init.uart_param.USART_Parity = USART_Parity_No;
|
||
hal_InitCOM(&COM_485_port);
|
||
break;
|
||
|
||
case RS485_CS485_2400_E:
|
||
COM_485_port.init.uart_param.USART_BaudRate = 2400;
|
||
COM_485_port.init.uart_param.USART_Parity = USART_Parity_Even;
|
||
hal_InitCOM(&COM_485_port);
|
||
break;
|
||
case RS485_XYDX_2400_8N2:
|
||
COM_485_port.init.uart_param.USART_BaudRate = 2400;
|
||
COM_485_port.init.uart_param.USART_Parity = USART_Parity_No;
|
||
COM_485_port.init.uart_param.USART_StopBits = USART_StopBits_2;
|
||
hal_InitCOM(&COM_485_port);
|
||
break;
|
||
case MUT_RS232_CD_115200_N:
|
||
COM_RADIO_port.init.uart_param.USART_BaudRate = 115200;
|
||
COM_RADIO_port.init.uart_param.USART_Parity = USART_Parity_No;
|
||
COM_RADIO_port.init.uart_param.USART_StopBits = USART_StopBits_1;
|
||
hal_InitCOM(&COM_RADIO_port);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : uplinkPacket_create
|
||
* Description : none
|
||
* Input : st_params * ptr
|
||
u8* outBuf
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170413
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void uplinkPacket_create(st_params * ptr, u8* outBuf)
|
||
{
|
||
switch (ptr->up_protol)
|
||
{
|
||
case UP_VER_OF_COMMON:
|
||
if (cmp_datas(ptr->plc_DI, cmd_read_woterMter, 4))
|
||
{
|
||
COM_uplinkPacket_create(ptr, outBuf);
|
||
}
|
||
else
|
||
{
|
||
COM_frozen_uplinkPacket_create(ptr, outBuf);
|
||
}
|
||
break;
|
||
|
||
case UP_VER_OF_WHSF:
|
||
WHSF_uplinkPacket_create(ptr, outBuf);
|
||
break;
|
||
|
||
case UP_VER_OF_E5E50001:
|
||
E5E50001_uplinkPacket_create(ptr, outBuf);
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : get_readMeter_params
|
||
* Description : none
|
||
* Input : u8 *buf
|
||
st_params * ptr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
bool get_readMeter_params(u8 *buf, st_params * ptr)
|
||
{
|
||
ST_645_head * head_645_ptr = (ST_645_head*)buf;
|
||
|
||
u8 cmp_addr_rusult = cmp_addr(head_645_ptr->addr);
|
||
|
||
un_upPaket upPacket_ptr = { .com_upPacket_ptr = (ST_645_read_meter *)buf,
|
||
.whsf_upPacket_ptr = (ST_645_SFDX_read_meter *)buf,
|
||
.e5e50000_upPacket_ptr = (ST_E5E50000_packet *)buf,
|
||
.e5e50001_upPacket_ptr = (ST_E5E50001_packet *)buf,
|
||
};
|
||
|
||
MemCpy(ptr->plc_DI, head_645_ptr->DI, 4);
|
||
|
||
for (u16 i = 0; i < 4; i++)
|
||
{
|
||
*(ptr->plc_DI + i) -= 0x33;
|
||
}
|
||
|
||
|
||
if (cmp_datas(ptr->plc_DI, cmd_read_woterMter, 4) || cmp_datas(ptr->plc_DI, cmd_read_frozen, 4))
|
||
{
|
||
if (head_645_ptr->len == 0x0c)
|
||
{
|
||
for (u16 i = 0; i <head_645_ptr->len; i++)
|
||
{
|
||
*(head_645_ptr->DI + i) -= 0x33;
|
||
}
|
||
|
||
if (cmp_addr_rusult != ADDR_NEQ)
|
||
{
|
||
ptr->up_protol = UP_VER_OF_COMMON;
|
||
ptr->meter_type = upPacket_ptr.com_upPacket_ptr->type;
|
||
MemCpy(ptr->meter_addr, upPacket_ptr.com_upPacket_ptr->meter_id, 7);
|
||
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
}
|
||
else if(cmp_datas(ptr->plc_DI, cmd_OnOff_Key, 4))
|
||
{
|
||
if (head_645_ptr->len == 0x0E)
|
||
{
|
||
u8* Pstr = head_645_ptr->DI;
|
||
|
||
for (u16 i = 0; i <head_645_ptr->len; i++)
|
||
{
|
||
*(head_645_ptr->DI + i) -= 0x33;
|
||
}
|
||
|
||
|
||
if (cmp_addr_rusult != ADDR_NEQ)
|
||
{
|
||
if( (Pstr[4] == 0xFF) && (Pstr[5] == 0xFF) )
|
||
{
|
||
ptr->meter_type = Pstr[6];
|
||
MemCpy(ptr->meter_addr, &Pstr[7], 7);
|
||
ptr->up_protol = UP_VER_OF_ON_KEY;
|
||
return true;
|
||
}
|
||
else if( (Pstr[4] == 0x00) && (Pstr[5] == 0x00) )
|
||
{
|
||
ptr->meter_type = Pstr[6];
|
||
MemCpy(ptr->meter_addr, &Pstr[7], 7);
|
||
ptr->up_protol = UP_VER_OF_OFF_KEY;
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
}
|
||
else if (cmp_datas(ptr->plc_DI, DI901F, 2) || cmp_datas(ptr->plc_DI, DI901F, 2))
|
||
{
|
||
if (head_645_ptr->len == 0x06)
|
||
{
|
||
for (u16 i = 0; i <head_645_ptr->len; i++)
|
||
{
|
||
*(head_645_ptr->DI + i) -= 0x33;
|
||
}
|
||
ptr->up_protol = UP_VER_OF_WHSF;
|
||
ptr->meter_type = 0x10;
|
||
MemCpy(ptr->meter_addr, upPacket_ptr.whsf_upPacket_ptr->addr, 6);
|
||
ptr->meter_addr[6] = upPacket_ptr.whsf_upPacket_ptr->MSB;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
else if (cmp_datas(ptr->plc_DI, cmd_E5E50000, 4))
|
||
{
|
||
//需要获得参数: 表计地址,表计端口,表计参数,表计抄表帧,抄表帧长度
|
||
ptr->up_protol = UP_VER_OF_E5E50000;
|
||
ptr->meter_port = upPacket_ptr.e5e50000_upPacket_ptr->port;
|
||
ptr->meter_config = upPacket_ptr.e5e50000_upPacket_ptr->meter_config;
|
||
ptr->meter_type = upPacket_ptr.e5e50000_upPacket_ptr->meter_type;
|
||
ptr->e5e5datLen = head_645_ptr->len - 14;
|
||
MemCpy(ptr->meter_addr, upPacket_ptr.e5e50000_upPacket_ptr->meter_id, 7);
|
||
MemCpy(ptr->e5e5dat, upPacket_ptr.e5e50000_upPacket_ptr->meter_id + 7, ptr->e5e5datLen);
|
||
|
||
return false;
|
||
}
|
||
else //stand 645
|
||
{
|
||
ptr->up_protol = UP_VER_OF_standard;
|
||
return false;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : get_read_meter_packet
|
||
* Description : none
|
||
* Input : u16 meter_protcl
|
||
u8 *meter_id
|
||
u8 *outBuf
|
||
u16 *outLen
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
bool get_read_meter_packet(u16 meter_protcl, u8 type, u8 *meter_id, u8 *outBuf, u16 *outLen)
|
||
{
|
||
static u16 last_protcl = PORT_NONE;
|
||
|
||
if (last_protcl != meter_protcl)
|
||
{
|
||
set_port_prams(meter_protcl);
|
||
}
|
||
|
||
switch (meter_protcl)
|
||
{
|
||
case MBUS_901F_2400_E:
|
||
create_read_J188_Meter(type, meter_id, TRUE, outBuf, outLen);
|
||
break;
|
||
case MBUS_1F90_2400_E:
|
||
case MUT_SPI_LORA:
|
||
create_read_J188_Meter(type, meter_id, FALSE, outBuf, outLen);
|
||
break;
|
||
case MBUS_HHCQ_2400_N:
|
||
create_read_HHCQ_Meter(meter_id, outBuf, outLen);
|
||
break;
|
||
case MBUS_YZSJ_1200_E:
|
||
create_read_YZSJ_Meter(meter_id,outBuf, outLen);
|
||
break;
|
||
case MBUS_HZJD_1200_E:
|
||
create_read_HZJD_Meter(meter_id,outBuf, outLen);
|
||
break;
|
||
case RS485_NJSM_1200_N:
|
||
create_read_NJSM485_Meter(meter_id,outBuf, outLen);
|
||
break;
|
||
case RS485_CS485_2400_E:
|
||
create_read_CS485_Meter(meter_id,outBuf, outLen);
|
||
break;
|
||
case RS485_XYDX_2400_8N2:
|
||
CreatHubei_Protocol_ReadXYWaterMeterDataFrame(outBuf,outLen,meter_id);
|
||
break;
|
||
case MUT_RS232_CD_115200_N:
|
||
CreatReadChangDeConcentratorData(meter_id,outBuf, outLen);
|
||
break;
|
||
/*
|
||
case MUT_CQXM_LORA:
|
||
create_read_HYgas_Meter(meter_id,outBuf, outLen);
|
||
break;
|
||
*/
|
||
default:
|
||
last_protcl = meter_protcl;
|
||
* outLen = 0;
|
||
return FALSE;
|
||
break;
|
||
}
|
||
|
||
last_protcl = meter_protcl;
|
||
return TRUE;
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : meter_ack_packet_process
|
||
* Description : none
|
||
* Input : u16 meter_protl
|
||
u8 *inbuf
|
||
u8 inLen
|
||
st_params * ptr
|
||
u8* outBuf
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170224
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
bool meter_ack_packet_process(u16 meter_protl, u8 *inbuf, u16 inLen, st_params * ptr, u8* outBuf)
|
||
{
|
||
bool ack_status = false;
|
||
u8* pData = NULL;
|
||
switch (meter_protl)
|
||
{
|
||
case MBUS_901F_2400_E:
|
||
case MBUS_1F90_2400_E:
|
||
case MUT_SPI_LORA:
|
||
ack_status = J188_ackPacket_analyse(inbuf, inLen, ptr->meter_addr, ptr->data, ptr->status);
|
||
break;
|
||
|
||
case MBUS_HHCQ_2400_N:
|
||
ack_status = HHCQ_ackPacket_analyse(inbuf, inLen, ptr->meter_addr, ptr->data, ptr->status);
|
||
break;
|
||
|
||
case MBUS_YZSJ_1200_E:
|
||
ack_status = YZSJ_ackPacket_analyse(inbuf, inLen, ptr->meter_addr, ptr->data, ptr->status);
|
||
break;
|
||
|
||
case MBUS_HZJD_1200_E:
|
||
ack_status = HZJD_ackPacket_analyse(inbuf, inLen, ptr->meter_addr, ptr->data, ptr->status);
|
||
break;
|
||
|
||
case RS485_NJSM_1200_N:
|
||
ack_status = NJSM485_ackPacket_analyse(inbuf, inLen, ptr->meter_addr, ptr->data, ptr->status);
|
||
break;
|
||
|
||
case RS485_CS485_2400_E:
|
||
ack_status = CS485_ackPacket_analyse(inbuf, inLen, ptr->meter_addr, ptr->data, ptr->status);
|
||
break;
|
||
|
||
case RS485_XYDX_2400_8N2:
|
||
pData = CheckHubei_Protocol_ReadXYWaterMeterAckDataFrame( inbuf, inLen,ptr->meter_addr,NULL);
|
||
if(pData != NULL)
|
||
{
|
||
ack_status = true;
|
||
AnalyzeXYDXAckDataFrameProcess(pData,ptr);
|
||
}
|
||
break;
|
||
|
||
case MUT_RS232_CD_115200_N:
|
||
ack_status = FALSE;
|
||
//ack_status = CDRS232_ackPacket_analyse(inbuf, inLen, ptr->meter_addr, ptr->data, ptr->status);
|
||
break;
|
||
default:
|
||
ack_status = FALSE;
|
||
break;
|
||
}
|
||
|
||
if (ack_status && outBuf)
|
||
{
|
||
uplinkPacket_create(ptr, outBuf);
|
||
}
|
||
|
||
return ack_status;
|
||
}
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : read_meter_process
|
||
* Description : none
|
||
* Input : u16 meter_protcl
|
||
st_params *read_params
|
||
u8 *outbuf
|
||
u16 *length
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : read_standard_elcMeter
|
||
* Description : none
|
||
* Input : u8 *buf
|
||
u8 length
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170417
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
//void read_standard_elcMeter(u8 *buf, u8 length)
|
||
//{
|
||
// QueueSetMemberHandle_t rxPortMember;
|
||
// RS4852_SendDataPacket(buf, length);
|
||
// u8 * Ptr645 = NULL;
|
||
//
|
||
// //xTaskNotifyGive(down_send_led_handle);
|
||
// rxPortMember = xQueueSelectFromSet( mPortsQueueSet, pdMS_TO_TICKS(2000));
|
||
//
|
||
// if (rxPortMember != NULL)
|
||
// {
|
||
// //xTaskNotifyGive(down_receive_led_handle);
|
||
// }
|
||
//
|
||
// if (rxPortMember == COM_485_port.xSemaphore)
|
||
// {
|
||
// xSemaphoreTake(COM_485_port.xSemaphore, 0);
|
||
// Ptr645 = search_645_packet(COM_485_port.data.rxBuf, COM_485_port.data.rx_len);
|
||
// port_send(&COM_PLC_port, Ptr645, get_645_packet_length(Ptr645));
|
||
// }
|
||
//}
|
||
|
||
|
||
|
||
void SendOperationUartLedCmd( EN_LED_TYPE led)
|
||
{
|
||
CurrentOperationLED = &led_list[led];
|
||
// xTaskNotifyGive(operation_led_handle);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
void RS485DataRequenstReady( void )
|
||
{
|
||
if(RS485_in_state() == 0x00)
|
||
{
|
||
return ;
|
||
}
|
||
printf("[485] 12 V Open!\r\n");
|
||
open_RS485_switch();
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : read_SaiDa_WaterMeter
|
||
* Description : none
|
||
* Input : u8 *addr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record :根据PLC接收到的645帧里的水表地址创建读取水表集中器该地址的
|
||
水表数据,并根据该地址检查水表帧,同时根据该地址返回电表集中器
|
||
水表数据
|
||
|
||
*****************************************************************************/
|
||
//void read_SaiDa_WaterMeter(u8 *addr)
|
||
//{
|
||
// u8 TempBuff[50] = {0x00};
|
||
// u8 Length = 0x00;
|
||
// u8 * pData = NULL;
|
||
// QueueSetMemberHandle_t rxPortMember;
|
||
//
|
||
//
|
||
// CreatFuJian_Protocol_ReadWaterGasMeterDataBlockFrame(TempBuff,&Length,addr);
|
||
//
|
||
// RS4852_SendDataPacket(TempBuff, Length);
|
||
//
|
||
//
|
||
// SendOperationUartLedCmd( RS4852_TX_LED );
|
||
// //xTaskNotifyGive(operation_led_handle);
|
||
// rxPortMember = xQueueSelectFromSet( mPortsQueueSet, pdMS_TO_TICKS(2000));
|
||
//
|
||
// if (rxPortMember != NULL)
|
||
// {
|
||
// //xTaskNotifyGive(operation_led_handle);
|
||
// SendOperationUartLedCmd( RS4852_RX_LED );
|
||
// }
|
||
//
|
||
// if (rxPortMember == COM_485_port.xSemaphore)
|
||
// {
|
||
// xSemaphoreTake(COM_485_port.xSemaphore, 0);
|
||
// //Ptr645 = search_645_packet(COM_485_port.data.rxBuf, COM_485_port.data.rx_len);
|
||
// pData = CheckFuJian_Protocol_ReadWaterGasMeterDataBlockAckFrame( COM_485_port.data.rxBuf, COM_485_port.data.rx_len,addr);
|
||
// if(pData == NULL)
|
||
// {//数据错误
|
||
//
|
||
//
|
||
// CreatFuJian_Protocol_WaterGasMeter645DataERRORACKFrame( TempBuff,&Length,addr );
|
||
// port_send(&COM_PLC_port, TempBuff, Length);
|
||
// printf_buf(TempBuff, Length);
|
||
// printf(" concentrator Ack Frame Chack ERROR\r\n");
|
||
//
|
||
//
|
||
// }
|
||
// else
|
||
// {
|
||
//
|
||
// CreatFuJian_Protocol_WaterGasMeter645DataACKFrame( TempBuff,&Length,addr,pData,GetCurrentTime());
|
||
// port_send(&COM_PLC_port, TempBuff, Length);
|
||
//
|
||
// printf("plc ack to station:");
|
||
// printf_buf(TempBuff, Length);
|
||
//
|
||
//
|
||
// }
|
||
//
|
||
// MemSet(COM_485_port.data.rxBuf, 0x00, COM_485_port.data.rx_len);
|
||
// return ;
|
||
// }
|
||
//
|
||
// printf(" OutTime OR Not 485 Data\r\n");
|
||
//}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//COM_RADIO_port.xSemaphore
|
||
/*****************************************************************************
|
||
* Function : XYDX485Data_process_task
|
||
* Description : none
|
||
* Input : void * ptr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170704
|
||
* Author : Thomas
|
||
* Modification: Created function
|
||
*****************************************************************************/
|
||
void RadioPortData_process_task(void *ptr)
|
||
{
|
||
// u8* pData = NULL;
|
||
RFPORT_Task = xQueueCreate( 1, sizeof( void* ) );
|
||
u32 RFPortData = (u32)&COM_RADIO_port.data.rxBuf[0];
|
||
PLST_RADIO_MONITOR_DATA_TYPE head_645_ptr = NULL;
|
||
st_params TempM = {0x00};
|
||
st_params * pstr = &TempM;
|
||
|
||
for (;;)
|
||
{
|
||
//此处可改为等待PLC与485两种信号,对信号做同样处理,但是对于485做上行,需要统一下行接口在哪里
|
||
xSemaphoreTake(COM_RADIO_port.xSemaphore, portMAX_DELAY);
|
||
|
||
xQueueSendToBack( RFPORT_Task, &RFPortData, 10);
|
||
|
||
head_645_ptr = (PLST_RADIO_MONITOR_DATA_TYPE )search_645_packet(COM_RADIO_port.data.rxBuf, COM_RADIO_port.data.rx_len);
|
||
|
||
if(head_645_ptr == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
if( (MemCmp(head_645_ptr->CAddr,ApplMeterCommonID,0x06) == 0x00) && (head_645_ptr->ControlWord == 0x79) && (head_645_ptr->DataLength == 0x0D) )
|
||
{
|
||
MemCpy(pstr->meter_addr,head_645_ptr->MAddr,0x07);
|
||
pstr->data[0] = 0x2C;
|
||
MemCpy(&pstr->data[1],head_645_ptr->Data,0x04);
|
||
MemCpy(pstr->status,head_645_ptr->Status,0x02);
|
||
UpdateRFReceiveData(pstr->meter_addr,&pstr->data[1],pstr->status);
|
||
}
|
||
else if( ( MemCmp(head_645_ptr->CAddr,ApplMeterCommonID,0x06) == 0x00 ) && ( head_645_ptr->DataLength == 0x00 ) && (head_645_ptr->ControlWord == 0x71) )
|
||
{
|
||
DLT645_07_watermetertype_ack(COM_RADIO_port.data.txBuf);
|
||
port_send(&COM_RADIO_port, COM_RADIO_port.data.txBuf, get_645_packet_length(COM_RADIO_port.data.txBuf));
|
||
printf("ack to water meter type:");
|
||
printf_buf(COM_RADIO_port.data.txBuf, get_645_packet_length(COM_RADIO_port.data.txBuf));
|
||
}
|
||
if(( MemCmp(head_645_ptr->CAddr,ApplMeterCommonID,0x06) == 0x00 ) && ( head_645_ptr->DataLength == 0x02 ) && (head_645_ptr->ControlWord == 0x72) )
|
||
{
|
||
}
|
||
xQueueReset((QueueHandle_t)COM_RADIO_port.xSemaphore);
|
||
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : read_SaiDa_WaterMeter
|
||
* Description : none
|
||
* Input : u8 *addr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record :根据PLC接收到的645帧里的水表地址创建读取水表集中器该地址的
|
||
水表数据,并根据该地址检查水表帧,同时根据该地址返回电表集中器
|
||
水表数据
|
||
|
||
*****************************************************************************/
|
||
//void read_XinYuan_WaterMeter(st_params * pstr)
|
||
//{
|
||
// u8 TempBuff[50] = {0x00};
|
||
// u8 Length = 0x00;
|
||
// u8 * pData = NULL;
|
||
// //QueueSetMemberHandle_t rxPortMember;
|
||
// u8* WaterMeter485Data = NULL;
|
||
// //struct st_meter_temp_value * list_ptr = NULL;
|
||
//
|
||
//
|
||
// RS485DataRequenstReady();
|
||
// vTaskDelay(500/portTICK_RATE_MS);
|
||
// //此版本为福建连江提供的兴源鼎新水表J188协议
|
||
// //CreatFuJian_Protocol_ReadXYWaterMeterDataBlockFrame(TempBuff,&Length,addr);
|
||
//
|
||
// //此版本为湖北提供的兴源鼎新水表总线协议
|
||
// CreatHubei_Protocol_ReadXYWaterMeterDataFrame(TempBuff,&Length,pstr->meter_addr);
|
||
//
|
||
// RS4852_SendDataPacket(TempBuff, Length);
|
||
// printf("RS485 Read XinYuan Meter:");
|
||
// printf_buf(TempBuff, Length);
|
||
// SendOperationUartLedCmd( RS4852_TX_LED );
|
||
// //xTaskNotifyGive(operation_led_handle);
|
||
// {
|
||
// //if (rxPortMember == COM_485_port.xSemaphore)
|
||
// {
|
||
// //xSemaphoreTake(COM_485_port.xSemaphore, 0);
|
||
// //Ptr645 = search_645_packet(COM_485_port.data.rxBuf, COM_485_port.data.rx_len);
|
||
// pData = CheckHubei_Protocol_ReadXYWaterMeterAckDataFrame( COM_485_port.data.rxBuf, COM_485_port.data.rx_len,pstr->meter_addr,NULL);
|
||
//
|
||
// if(pData == NULL)
|
||
// {//数据错误
|
||
//
|
||
// close_RS485_switch();
|
||
// CreatFuJian_Protocol_WaterGasMeter645DataERRORACKFrame( TempBuff,&Length,pstr->meter_addr );
|
||
// port_send(&COM_PLC_port, TempBuff, Length);
|
||
// printf_buf(TempBuff, Length);
|
||
//
|
||
// return ;
|
||
// //printf(" concentrator Ack Frame Check ERROR\r\n");
|
||
//
|
||
//
|
||
// }
|
||
// else
|
||
// {
|
||
// close_RS485_switch();
|
||
//
|
||
// AnalyzeXYDXAckDataFrameProcess(pData,pstr);
|
||
// pstr->data[0] = 0x2C;
|
||
//
|
||
//
|
||
// uplinkPacket_create(pstr, COM_PLC_port.data.txBuf);
|
||
// port_send(&COM_PLC_port, COM_PLC_port.data.txBuf, get_645_packet_length(COM_PLC_port.data.txBuf));
|
||
// printf("repeat ack to station:");
|
||
// printf_buf(COM_PLC_port.data.txBuf, get_645_packet_length(COM_PLC_port.data.txBuf));
|
||
//
|
||
//// list_ptr = process_recevied_id(pstr->meter_addr);
|
||
//// if (list_ptr)
|
||
//// {
|
||
//// MemCpy(list_ptr->data,pstr->data , 5);
|
||
//// MemCpy(list_ptr->ST,pstr->status,0x02);
|
||
////
|
||
//// //list_ptr->startPoint = xTaskGetTickCount();
|
||
//// list_ptr->status = READ_METER_OK;
|
||
//// printf("update id:");
|
||
//// printf_buf(pstr->meter_addr, 7);
|
||
//// }
|
||
// }
|
||
//
|
||
// MemSet(COM_485_port.data.rxBuf, 0x00, COM_485_port.data.rx_len);
|
||
// return ;
|
||
// }
|
||
// }
|
||
// printf("12 V Close!\r\n");
|
||
// close_RS485_switch();
|
||
// printf(" OutTime OR Not 485 Data\r\n");
|
||
//}
|
||
|
||
/*****************************************************************************
|
||
* Function : hal_InitCOM
|
||
* Description : none
|
||
* Input : struct st_uart_port * port
|
||
* Output : None
|
||
* Return : void
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170228
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void hal_InitCOM(struct st_uart_port * port)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
USART_InitTypeDef USART_InitStructure;
|
||
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
RCC_APB2PeriphClockCmd( port->init.com_tx_port_clk| port->init.xom_rx_port_clk | RCC_APB2Periph_AFIO, ENABLE);
|
||
|
||
if (port->init.com == USART1)
|
||
{
|
||
RCC_APB2PeriphClockCmd(port->init.com_clk, ENABLE);
|
||
}
|
||
else
|
||
{
|
||
RCC_APB1PeriphClockCmd(port->init.com_clk, ENABLE);
|
||
}
|
||
|
||
/* Configure USART Tx as alternate function push-pull */
|
||
GPIO_InitStructure.GPIO_Pin = port->init.com_tx_pin;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(port->init.com_tx_port, &GPIO_InitStructure);
|
||
|
||
/* Configure USART Rx as input pull-up */
|
||
GPIO_InitStructure.GPIO_Pin = port->init.com_rx_pin;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||
GPIO_Init(port->init.com_rx_port, &GPIO_InitStructure);
|
||
|
||
|
||
USART_InitStructure.USART_BaudRate = port->init.uart_param.USART_BaudRate;
|
||
USART_InitStructure.USART_WordLength = (port->init.uart_param.USART_Parity == USART_Parity_No)? USART_WordLength_8b: port->init.uart_param.USART_WordLength;
|
||
|
||
|
||
|
||
USART_InitStructure.USART_StopBits = port->init.uart_param.USART_StopBits;
|
||
USART_InitStructure.USART_Parity = port->init.uart_param.USART_Parity;
|
||
USART_InitStructure.USART_HardwareFlowControl = port->init.uart_param.USART_HardwareFlowControl;
|
||
USART_InitStructure.USART_Mode = port->init.uart_param.USART_Mode;
|
||
USART_Init(port->init.com, &USART_InitStructure);
|
||
|
||
USART_Cmd(port->init.com, ENABLE);
|
||
|
||
if (port->init.com_IRQn)
|
||
{
|
||
NVIC_InitStructure.NVIC_IRQChannel = port->init.com_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
}
|
||
|
||
if (port->init.com_DMA_CLK != 0)
|
||
{
|
||
NVIC_InitStructure.NVIC_IRQChannel = port->init.com_DMA_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
|
||
/* Enable DMA Clock */
|
||
RCC_AHBPeriphClockCmd(port->init.com_DMA_CLK, ENABLE);
|
||
|
||
/* Enable USART DMA TX request */
|
||
USART_DMACmd(port->init.com, USART_DMAReq_Tx, ENABLE);
|
||
}
|
||
|
||
USART_ClearFlag(port->init.com, USART_FLAG_RXNE);
|
||
|
||
/* Enable the USART RXNE Interrupt */
|
||
USART_ITConfig(port->init.com, USART_IT_RXNE, ENABLE);
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : init_uart_port
|
||
* Description : none
|
||
* Input : struct st_uart_port * port
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170314
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void init_uart_port(struct st_uart_port * port)
|
||
{
|
||
hal_InitCOM(port);
|
||
vSemaphoreCreateBinary(port->xSemaphore);
|
||
|
||
if (port->xSemaphore)
|
||
{
|
||
xSemaphoreTake(port->xSemaphore, 0);
|
||
}
|
||
else
|
||
{
|
||
printf("create port xSemaphore failed\r\n");
|
||
}
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : hal_UartDMATx
|
||
* Description : none
|
||
* Input : struct st_uart_port* uart_port
|
||
u8 *pBuf
|
||
u16 length
|
||
* Output : None
|
||
* Return : void
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170426
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void hal_UartDMATx(struct st_uart_port* uart_port, u8 *pBuf, u16 length)
|
||
{
|
||
DMA_InitTypeDef DMA_InitStructure;
|
||
|
||
if (length > 0)
|
||
{
|
||
|
||
if(length > uart_port->chl.txbufLength)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (uart_port->init.com == COM_PLC_NO)
|
||
{
|
||
DMA_InitStructure.DMA_BufferSize = length;
|
||
}
|
||
|
||
/* USART_Tx_DMA_Channel (triggered by USART Tx event) Config */
|
||
DMA_DeInit(uart_port->chl.com_TX_DMA_CHANNEL);
|
||
DMA_InitStructure.DMA_PeripheralBaseAddr = uart_port->chl.com_DR_BASE;
|
||
DMA_InitStructure.DMA_MemoryBaseAddr = (u32) pBuf;
|
||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
|
||
DMA_InitStructure.DMA_BufferSize = length;
|
||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
|
||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||
DMA_Init(uart_port->chl.com_TX_DMA_CHANNEL, &DMA_InitStructure);
|
||
|
||
/* Enable DMA Channel Transfer Complete interrupt interrupt */
|
||
DMA_ITConfig(uart_port->chl.com_TX_DMA_CHANNEL, DMA_IT_TC | DMA_IT_TE, ENABLE);
|
||
|
||
/* Enable USART DMA TX Channel */
|
||
DMA_Cmd(uart_port->chl.com_TX_DMA_CHANNEL, ENABLE);
|
||
}
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : add_list_node
|
||
* Description : none
|
||
* Input : st_params* params
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170418
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : auto_sync_list_meters
|
||
* Description : none
|
||
* Input : void
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170517
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void auto_sync_list_meters(void)
|
||
{
|
||
//xTaskNotifyGive(temp_saved_handle);
|
||
}
|
||
/*****************************************************************************
|
||
* Function : refresh_node_from_list
|
||
* Description : none
|
||
* Input : void
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170517
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
/*****************************************************************************
|
||
* Function : led_process_task
|
||
* Description : none
|
||
* Input : void * ptr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170313
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void led_process_task(void * ptr)
|
||
{
|
||
#define LED_LIGHTING_TIME 300 / portTICK_RATE_MS
|
||
|
||
off_all_led();
|
||
for (;;)
|
||
{
|
||
ulTaskNotifyTake( pdTRUE, portMAX_DELAY);
|
||
|
||
LED_On(*CurrentOperationLED);
|
||
vTaskDelay( LED_LIGHTING_TIME );
|
||
LED_Off(*CurrentOperationLED);
|
||
}
|
||
}
|
||
/*****************************************************************************
|
||
* Function : init_led_task
|
||
* Description : none
|
||
* Input : void
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170313
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void init_uart_tasks(void)
|
||
{
|
||
// xTaskCreate( led_process_task, "Uart Led", 70, CurrentOperationLED, 1, &operation_led_handle);
|
||
|
||
xTaskCreate( PLC_process_task, NULL, 200, NULL, 3, NULL);
|
||
// xTaskCreate( MBUS_slave_detected_task, NULL, 70, NULL, 3, NULL);
|
||
|
||
// xTaskCreate( temp_saved_task, NULL, 200, NULL, 2, &temp_saved_handle);
|
||
|
||
xTaskCreate( XYDX485Data_process_task, "485 Task", 200, NULL, 3, NULL);
|
||
// xTaskCreate( RadioPortData_process_task, "485 Task", 200, NULL, 3, NULL);
|
||
|
||
// xTaskCreate( RS4852_process_task, "4852 Task", 200, NULL, 3, NULL);
|
||
|
||
}
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : temp_saved_task
|
||
* Description : none
|
||
* Input : void *ptr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170313
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : uarts_process_task
|
||
* Description : none
|
||
* Input : void * ptr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void uarts_process_task(void * ptr)
|
||
{
|
||
u16 need_delay;
|
||
|
||
struct st_uart_port * port_list[] = {&COM_PLC_port, &COM_MBUS_MASTER_port, &COM_485_port, &COM_RADIO_port,&RS4852_port};
|
||
|
||
mbus_gpio_init();
|
||
RS485_gpio_init();
|
||
|
||
|
||
vSemaphoreCreateBinary( uart_sync_Semaphore);
|
||
xSemaphoreTake(uart_sync_Semaphore, 0);
|
||
|
||
init_uart_port(&COM_PLC_port);
|
||
init_uart_port(&COM_485_port);
|
||
init_uart_port(&COM_RADIO_port);
|
||
init_uart_port(&COM_MBUS_MASTER_port);
|
||
AnalogUartInit(&RS4852_port);
|
||
|
||
|
||
|
||
mbus_port_Mutex = xSemaphoreCreateMutex();
|
||
mPortsQueueSet = xQueueCreateSet(3);
|
||
|
||
if( mPortsQueueSet != NULL )
|
||
{
|
||
xQueueAddToSet(COM_MBUS_MASTER_port.xSemaphore, mPortsQueueSet);
|
||
xQueueAddToSet(RS4852_port.xSemaphore, mPortsQueueSet);
|
||
xQueueAddToSet(COM_RADIO_port.xSemaphore, mPortsQueueSet);
|
||
}
|
||
|
||
mbus_switch_handle = xTimerCreate( "uart switch timer", MBUS_SWITCH_TIMEOUT, pdFALSE, 0, mbus_switch_timeOut_callback_function);
|
||
|
||
init_uart_tasks();
|
||
|
||
for (;;)
|
||
{
|
||
xSemaphoreTake( uart_sync_Semaphore, portMAX_DELAY );
|
||
need_delay = 0;
|
||
|
||
do
|
||
{
|
||
for (u8 i = 0; i < sizeof(port_list)/sizeof(struct st_uart_port*); i++)
|
||
{
|
||
if (port_list[i]->data.rx_timeout > 0)//rx timeout scan
|
||
{
|
||
need_delay++;
|
||
if (port_list[i]->data.rx_timeout <= xTaskGetTickCount())
|
||
{
|
||
need_delay--;
|
||
port_list[i]->data.rx_len = port_list[i]->data.rx_index;
|
||
port_list[i]->data.rx_index = 0;
|
||
port_list[i]->data.rx_timeout = 0;
|
||
|
||
// printf("\r\n *** gprs串口接收 len=%d %s Rx:*** \r\n", port_list[i]->data.rx_len,port_list[i]->string);
|
||
//printf_buf(port_list[i]->data.rxBuf, port_list[i]->data.rx_len);
|
||
|
||
//保存监控的数据
|
||
//CheckFrameStore(port_list[i]->string,port_list[i]->data.rxBuf, port_list[i]->data.rx_len);
|
||
|
||
// printf("\r\n==\r\n");
|
||
// for(u16 k = 0;k<port_list[i]->data.rx_len;k++)
|
||
// {
|
||
// printf("%02x",port_list[i]->data.rxBuf[k]);
|
||
// }
|
||
|
||
// printf("\r\n==================== %d \r\n",port_list[i]->data.rx_len);
|
||
|
||
xSemaphoreGive(port_list[i]->xSemaphore);
|
||
}
|
||
}
|
||
|
||
if ( port_list[i]->data.tx_timeout > 0)//tx timeout scan
|
||
{
|
||
need_delay++;
|
||
if (port_list[i]->data.tx_timeout <= xTaskGetTickCount())
|
||
{
|
||
need_delay--;
|
||
port_list[i]->data.rx_len = 0;
|
||
port_list[i]->data.rx_index = 0;
|
||
port_list[i]->data.rx_timeout = 0;
|
||
port_list[i]->data.tx_timeout = 0;
|
||
hal_InitCOM(port_list[i]);
|
||
printf("%s Tx timeout:", port_list[i]->string);
|
||
}
|
||
}
|
||
}
|
||
if (need_delay > 0)
|
||
{
|
||
vTaskDelay(SCAN_PORT_RERIOD);
|
||
}
|
||
}while(need_delay);
|
||
|
||
}
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : MBUS_slave_detected_task
|
||
* Description : none
|
||
* Input : void *ptr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170613
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void MBUS_slave_detected_task(void *ptr)
|
||
{
|
||
//检测MBUS 状态 低电平表明当前转换器处于读表主动状态
|
||
mbus_mode = MBUS_in_state();
|
||
|
||
for (;;)
|
||
{
|
||
vTaskDelay(20/portTICK_RATE_MS);
|
||
|
||
if (mbus_mode == MBUS_MODE_MASTER)
|
||
{
|
||
//如果转换器过载,则断开转换器从端MBUS
|
||
if (MBUS_OVERLOAD_in_state() == 0)
|
||
{
|
||
vTaskDelay(20/portTICK_RATE_MS);
|
||
|
||
if(is_overload_flag)
|
||
{
|
||
//在充电过程中
|
||
}
|
||
else
|
||
{
|
||
close_mbus_switch();
|
||
printf("mbus overload\r\n");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
//如果检测到转换器外部主端MBUS上电,表示水表采集器开始抄表,这个时候我们必须断开与表端的MBUS链接
|
||
if (MBUS_in_state() == 1)
|
||
{
|
||
vTaskDelay(50/portTICK_RATE_MS);
|
||
|
||
if (MBUS_in_state() == 1)
|
||
{
|
||
mbus_mode = MBUS_MODE_SLAVE;
|
||
close_mbus_switch();
|
||
printf("ext MBUS enter\r\n");
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MBUS_in_state() == 0)
|
||
{
|
||
vTaskDelay(50/portTICK_RATE_MS);
|
||
|
||
if (MBUS_in_state() == 0)
|
||
{
|
||
mbus_mode = MBUS_MODE_MASTER;
|
||
printf("ext MBUS exit\r\n");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : Control_XinTian_WaterMeterKey
|
||
* Description : none
|
||
* Input : u8 *addr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record 新天MBUS水表拉合闸
|
||
|
||
*****************************************************************************/
|
||
|
||
|
||
#ifdef AMT_VER
|
||
void Control_XinTian_WaterMeterKey(st_params * read_params,u8 key)
|
||
{
|
||
u8 TempBuff[50] = {0x00};
|
||
u8 Length = 0x00;
|
||
ST_J188_read_woter_ack * j188_ptr = NULL;
|
||
u8 *ptr;
|
||
QueueSetMemberHandle_t rxPortMember;
|
||
|
||
CreatXinTian_Protocol_ControlONOFFKey(TempBuff,&Length,read_params->meter_addr,key==ON_KEY?ON_KEY:0x99);
|
||
|
||
|
||
mbus_master_tx_begin();
|
||
|
||
MBUS_mater_Tx(TempBuff, Length);
|
||
SendOperationUartLedCmd( MBUS2TX_LED );
|
||
printf("MBUS TX:");
|
||
printf_buf(TempBuff, Length);
|
||
|
||
rxPortMember = xQueueSelectFromSet(mPortsQueueSet, MBUS_TIMEOUT);
|
||
if (rxPortMember != NULL)
|
||
{
|
||
SendOperationUartLedCmd( MBUS2RX_LED );
|
||
Clear485PortINValidCount();
|
||
}
|
||
|
||
if (rxPortMember == COM_MBUS_MASTER_port.xSemaphore)
|
||
{
|
||
xSemaphoreTake(COM_MBUS_MASTER_port.xSemaphore, 0);
|
||
|
||
ptr = search_j188_packet(COM_MBUS_MASTER_port.data.rxBuf, COM_MBUS_MASTER_port.data.rx_len);
|
||
j188_ptr = (ST_J188_read_woter_ack*)ptr;
|
||
//StringBuffOverthrow( j188_ptr->head.id,id,7);
|
||
if( (ptr) && (cmp_datas(j188_ptr->head.id, read_params->meter_addr, 7)) )
|
||
{
|
||
if ((j188_ptr->head.ctrl & 0xC0) == 0x80)// up
|
||
{
|
||
if (cmp_datas(j188_ptr->head.DI, DIA017, 2))
|
||
{
|
||
//if(key == ON_KEY)
|
||
u8 status = j188_ptr->data_block.current_sum[0]&0x03;
|
||
|
||
if(status == 0x00)//开阀门
|
||
{
|
||
//CreatChenDianGuoJi_Protocol_ControlWaterGasMeterKeyAckFrame( COM_PLC_port.data.txBuf,&Length,read_params,0xFFFF);
|
||
concent_gateopen();
|
||
printf("开阀成功!\r\n");
|
||
|
||
|
||
}
|
||
//else if(key == OFF_KEY)
|
||
else if(status == 0x02)//关阀门
|
||
{
|
||
//CreatChenDianGuoJi_Protocol_ControlWaterGasMeterKeyAckFrame( COM_PLC_port.data.txBuf,&Length,read_params,0x0000);
|
||
concent_gateclose();
|
||
printf("关阀成功!\r\n");
|
||
|
||
}
|
||
else
|
||
{
|
||
printf("阀控异常!!\r\n");
|
||
|
||
}
|
||
|
||
//port_send(&COM_PLC_port, COM_PLC_port.data.txBuf, get_645_packet_length(COM_PLC_port.data.txBuf));
|
||
//printf("repeat ack to station:");
|
||
//printf_buf(COM_PLC_port.data.txBuf, get_645_packet_length(COM_PLC_port.data.txBuf));
|
||
|
||
return ;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{//数据错误
|
||
|
||
CreatChenDianGuoJI_Protocol_WaterGasMeter645DataERRORACKFrame( TempBuff,&Length,read_params);
|
||
port_send(&COM_PLC_port, TempBuff, Length);
|
||
printf_buf(TempBuff, Length);
|
||
printf(" MBUS Ack Frame Check ERROR\r\n");
|
||
|
||
|
||
}
|
||
|
||
|
||
return ;
|
||
}
|
||
|
||
printf("MBUS Rx OutTime\r\n");
|
||
|
||
|
||
|
||
}
|
||
|
||
#endif
|
||
|
||
|
||
#ifdef COMMON_VER
|
||
void Control_XinTian_WaterMeterKey(st_params * read_params,u8 key)
|
||
{
|
||
u8 TempBuff[50] = {0x00};
|
||
u8 Length = 0x00;
|
||
ST_J188_read_woter_ack * j188_ptr = NULL;
|
||
u8 *ptr;
|
||
QueueSetMemberHandle_t rxPortMember;
|
||
|
||
CreatXinTian_Protocol_ControlONOFFKey(TempBuff,&Length,read_params->meter_addr,key==ON_KEY?ON_KEY:0x99);
|
||
|
||
|
||
mbus_master_tx_begin();
|
||
|
||
MBUS_mater_Tx(TempBuff, Length);
|
||
SendOperationUartLedCmd( MBUS2TX_LED );
|
||
printf("MBUS TX:");
|
||
printf_buf(TempBuff, Length);
|
||
|
||
rxPortMember = xQueueSelectFromSet(mPortsQueueSet, MBUS_TIMEOUT);
|
||
if (rxPortMember != NULL)
|
||
{
|
||
SendOperationUartLedCmd( MBUS2RX_LED );
|
||
Clear485PortINValidCount();
|
||
}
|
||
|
||
if (rxPortMember == COM_MBUS_MASTER_port.xSemaphore)
|
||
{
|
||
xSemaphoreTake(COM_MBUS_MASTER_port.xSemaphore, 0);
|
||
|
||
ptr = search_j188_packet(COM_MBUS_MASTER_port.data.rxBuf, COM_MBUS_MASTER_port.data.rx_len);
|
||
j188_ptr = (ST_J188_read_woter_ack*)ptr;
|
||
//StringBuffOverthrow( j188_ptr->head.id,id,7);
|
||
if( (ptr) && (cmp_datas(j188_ptr->head.id, read_params->meter_addr, 7)) )
|
||
{
|
||
if ((j188_ptr->head.ctrl & 0xC0) == 0x80)// up
|
||
{
|
||
if (cmp_datas(j188_ptr->head.DI, DIA017, 2))
|
||
{
|
||
//if(key == ON_KEY)
|
||
u8 status = j188_ptr->data_block.current_sum[0]&0x03;
|
||
|
||
if(status == 0x00)//开阀门
|
||
{
|
||
concent_gateopen();
|
||
|
||
printf("开阀成功!\r\n");
|
||
}
|
||
//else if(key == OFF_KEY)
|
||
else if(status == 0x01)//关阀门
|
||
{
|
||
concent_gateclose();
|
||
|
||
printf("关阀成功!\r\n");
|
||
}
|
||
else
|
||
{
|
||
printf("阀控异常!!\r\n");
|
||
|
||
}
|
||
return ;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{//数据错误
|
||
|
||
CreatChenDianGuoJI_Protocol_WaterGasMeter645DataERRORACKFrame( TempBuff,&Length,read_params);
|
||
port_send(&COM_PLC_port, TempBuff, Length);
|
||
printf_buf(TempBuff, Length);
|
||
printf(" MBUS Ack Frame Check ERROR\r\n");
|
||
|
||
|
||
}
|
||
return ;
|
||
}
|
||
|
||
printf("MBUS Rx OutTime\r\n");
|
||
|
||
}
|
||
|
||
#endif
|
||
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : PLC_process_task
|
||
* Description : none
|
||
* Input : void * ptr
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
* 表计协议为初始化为自动,协议是绑定了端口号与软件协议的,当flash中有抄成功的表,以存储的表计
|
||
协议抄表,若抄表成功,则修改 last_meter_protcl为抄成功表号,失败不处理,
|
||
若存储中没有表计号,则以last_meter_protcl为协议去抄,失败不处理,
|
||
*****************************************************************************/
|
||
|
||
|
||
void PLC_process_task(void *ptr)
|
||
{
|
||
vTaskDelay( 500 / portTICK_RATE_MS );
|
||
|
||
for (;;)
|
||
{
|
||
//此处可改为等待PLC与485两种信号,对信号做同样处理,但是对于485做上行,需要统一下行接口在哪里
|
||
xSemaphoreTake(COM_PLC_port.xSemaphore, portMAX_DELAY);
|
||
|
||
|
||
if(get_isupdatestate())
|
||
{
|
||
|
||
//
|
||
ST_645_head * head_645_ptr = (ST_645_head *)NULL;
|
||
head_645_ptr = (ST_645_head *)search_645_packet(COM_PLC_port.data.rxBuf, COM_PLC_port.data.rx_len);
|
||
|
||
if (head_645_ptr == NULL)
|
||
{
|
||
continue;
|
||
}
|
||
switch ( head_645_ptr->ctrl & 0xFF )
|
||
{
|
||
default:
|
||
break;
|
||
|
||
case 0x19:
|
||
if (check_13762_packet(&head_645_ptr->len + 1))
|
||
{
|
||
apl_process_1372(&head_645_ptr->len + 1, UPDATE_PLC);
|
||
break;
|
||
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
st_rtc_ext * time = (st_rtc_ext *)GetCurrentTime();
|
||
// printf("\r\n%02x-%02x-%02x %02x:%02x:%02x 移动模块->集中器 长度=%d 值=", time->year,time->month,time->day,time->hour,time->min,time->sec,COM_PLC_port.data.rx_len);
|
||
|
||
// if(COM_PLC_port.data.rx_len>100)
|
||
// {
|
||
// printf("%02x%02x%02x%02x%02x%02x\r\n",COM_PLC_port.data.rxBuf[0],COM_PLC_port.data.rxBuf[1],COM_PLC_port.data.rxBuf[2],COM_PLC_port.data.rxBuf[3],COM_PLC_port.data.rxBuf[4],COM_PLC_port.data.rxBuf[COM_PLC_port.data.rx_len-1]);
|
||
// }
|
||
// else
|
||
// {
|
||
// for(int i = 0;i<COM_PLC_port.data.rx_len;i++)
|
||
// {
|
||
// printf("%02x",COM_PLC_port.data.rxBuf[i]);
|
||
// }
|
||
//
|
||
// printf( "\r\n");
|
||
// printf( "\r\n");
|
||
// printf( "\r\n");
|
||
// printf( "\r\n");
|
||
|
||
// vTaskDelay(300/portTICK_RATE_MS);
|
||
|
||
// if(strstr(tmp,"OK\r"))
|
||
{
|
||
plc_uart_buff_set(COM_PLC_port.data.rxBuf,COM_PLC_port.data.rx_len);
|
||
memset(COM_PLC_port.data.rxBuf,0,COM_PLC_RX_BUFFER_SIZE);
|
||
COM_PLC_port.data.rx_len = 0;
|
||
COM_PLC_port.data.rx_index = 0;
|
||
COM_PLC_port.data.rx_timeout = 0;
|
||
}
|
||
|
||
xQueueReset((QueueHandle_t)COM_PLC_port.xSemaphore);
|
||
plc_buff_sem_give();
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
u8 send_mbus_buff[256];
|
||
u16 send_mbus_len = 0;
|
||
|
||
void send_to_mbus_set(u8 * buf,u16 len)
|
||
{
|
||
memmove(send_mbus_buff,buf,len);
|
||
send_mbus_len = len;
|
||
}
|
||
|
||
static bool is_pro_sucess = false;
|
||
|
||
bool get_pro_sucess_status()
|
||
{
|
||
return is_pro_sucess;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
void send_to_mbus(void *ptr)
|
||
{
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : plc_uart_Tx
|
||
* Description : none
|
||
* Input : u8 *buf
|
||
u16 length
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170314
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void plc_uart_Tx(u8 *buf, u16 length)
|
||
{
|
||
port_send(&COM_PLC_port, buf, length);
|
||
}
|
||
|
||
|
||
|
||
|
||
/* 485 2 Port Send Data*/
|
||
void RS4852_SendDataPacket(u8 *buf, u16 length)
|
||
{
|
||
port_send(&COM_485_port, buf, length);
|
||
}
|
||
|
||
void up_485_Tx(u8 *buf, u16 length)
|
||
{
|
||
|
||
}
|
||
|
||
void dwn_radio_Tx(u8 *buf, u16 length)
|
||
{
|
||
port_send(&COM_RADIO_port, buf, length);
|
||
}
|
||
|
||
|
||
/*****************************************************************************
|
||
* Function : hal_UartIntTx
|
||
* Description : none
|
||
* Input : u8 *pBuf
|
||
u16 length
|
||
* Output : None
|
||
* Return : void
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
/*
|
||
void hal_UartIntTx(u8 *pBuf, u16 length)
|
||
{
|
||
port_send(&COM_RADIO_port, pBuf, length);
|
||
}
|
||
*/
|
||
/*****************************************************************************
|
||
* Function : MBUS_mater_Tx
|
||
* Description : none
|
||
* Input : u8 *pBuf
|
||
u16 length
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170413
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
|
||
|
||
|
||
void mbus_master_tx_begin()
|
||
{
|
||
if (mbus_switch_state() == 1 && (mbus_mode == MBUS_MODE_MASTER) && (MBUS_OVERLOAD_in_state() == 1))
|
||
{
|
||
mbus_gpio_init();
|
||
printf("open switch 开始充电\r\n");
|
||
hal_sRF_ITConfig(MBUS_OVERLOAD_FLAG_LINE,DISABLE);
|
||
open_mbus_switch();
|
||
//vTaskDelay( MbusChargeTime*1000/portTICK_RATE_MS );
|
||
is_overload_flag = true;
|
||
//vTaskDelay( 1000/portTICK_RATE_MS );
|
||
//vTaskDelay( 1000/portTICK_RATE_MS );
|
||
vTaskDelay( MbusChargeTime*1000/portTICK_RATE_MS );
|
||
printf("充电%d秒完成\r\n",MbusChargeTime);
|
||
is_overload_flag = false;
|
||
|
||
EXTI_ClearITPendingBit(MBUS_OVERLOAD_FLAG_LINE);
|
||
hal_sRF_ITConfig(MBUS_OVERLOAD_FLAG_LINE,ENABLE);
|
||
}
|
||
xTimerReset(mbus_switch_handle, 0);
|
||
}
|
||
|
||
|
||
void time_reset()
|
||
{
|
||
xTimerReset(mbus_switch_handle, 0);
|
||
}
|
||
|
||
void mbus_master_tx_end()
|
||
{
|
||
close_mbus_switch();
|
||
printf("\r\n\r\n 关闭切换close switch\r\n\r\n");
|
||
|
||
}
|
||
|
||
|
||
void MBUS_mater_Tx(u8 *pBuf, u16 length)
|
||
{
|
||
/*
|
||
if (mbus_switch_state() == 1 && (mbus_mode == MBUS_MODE_MASTER) && (MBUS_OVERLOAD_in_state() == 1))
|
||
{
|
||
mbus_gpio_init();
|
||
printf("open switch\r\n");
|
||
hal_sRF_ITConfig(MBUS_OVERLOAD_FLAG_LINE,DISABLE);
|
||
open_mbus_switch();
|
||
vTaskDelay( MbusChargeTime*1000/portTICK_RATE_MS );
|
||
EXTI_ClearITPendingBit(MBUS_OVERLOAD_FLAG_LINE);
|
||
hal_sRF_ITConfig(MBUS_OVERLOAD_FLAG_LINE,ENABLE);
|
||
}
|
||
*/
|
||
xTimerReset(mbus_switch_handle, 0);
|
||
|
||
port_send(&COM_MBUS_MASTER_port,pBuf, length);
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : port_send
|
||
* Description : none
|
||
* Input : struct st_uart_port* port
|
||
u8 *buf
|
||
u16 length
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170412
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void port_send(struct st_uart_port* port, u8 *buf, u16 length)
|
||
{
|
||
if (port->init.com == COM_MBUS_MASTER_NO)
|
||
{
|
||
USART_ITConfig(COM_MBUS_MASTER_NO, USART_IT_RXNE, DISABLE);
|
||
port->init.com->CR1 &= ~(0x04);
|
||
|
||
port->data.tx_timeout = xTaskGetTickCount() + (MBUSM_BAUD_COFF*length + 100)/portTICK_RATE_MS;
|
||
hal_UartDMATx(port, buf, length);
|
||
|
||
}
|
||
else if (port->init.com == COM_485_NO)
|
||
{
|
||
port->init.com->CR1 &= ~(0x04);
|
||
port->data.tx_timeout = xTaskGetTickCount() + (RS485_BAUD_COFF*length + 100)/portTICK_RATE_MS;
|
||
hal_UartDMATx(port, buf, length);
|
||
}
|
||
else if (port->init.com == COM_PLC_NO)
|
||
{
|
||
port->data.tx_timeout = xTaskGetTickCount() + (PLC_BAUD_COFF*length + 100)/portTICK_RATE_MS;
|
||
hal_UartDMATx(port, buf, length);
|
||
}
|
||
else if (port->init.com == COM_RADIO_NO)
|
||
{
|
||
// memcpy(RS485_tx_buf, buf, length);
|
||
// COM_noDMA_tx_index = 0;
|
||
// COM_noDMA_len = length;
|
||
// COM_485_port.data.tx_timeout = xTaskGetTickCount() + (RS485_BAUD_COFF*length + 100)/portTICK_RATE_MS;;
|
||
// while(USART_GetITStatus(COM_RADIO_NO, USART_IT_TC) != RESET);
|
||
// USART_ITConfig(COM_RADIO_NO, USART_IT_TC, ENABLE);
|
||
port->data.tx_timeout = xTaskGetTickCount() + (COM_RADIO_BAUD*length + 100)/portTICK_RATE_MS;
|
||
hal_UartDMATx(port, buf, length);
|
||
}
|
||
else
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : UART5_IRQHandler
|
||
* Description : none
|
||
* Input : void
|
||
* Output : None
|
||
* Return : void
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170223
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
// void UART5_IRQHandler(void)
|
||
// {
|
||
// if (USART_GetITStatus(COM_RADIO_NO, USART_IT_TC) != RESET)
|
||
// {
|
||
// if (COM_noDMA_tx_index >= COM_noDMA_len)
|
||
// {
|
||
// u32 p =xTaskGetTickCount() ;
|
||
// USART_ITConfig(COM_RADIO_NO, USART_IT_TC, DISABLE);
|
||
// COM_noDMA_tx_index = 0;
|
||
// COM_485_port.data.tx_timeout = 0;
|
||
// }
|
||
// else
|
||
// {
|
||
// USART_SendData(COM_RADIO_NO, RS485_tx_buf[COM_noDMA_tx_index]);
|
||
// COM_noDMA_tx_index++;
|
||
// }
|
||
// }
|
||
// else if (USART_GetITStatus(COM_RADIO_NO, USART_IT_RXNE) != RESET)
|
||
// {
|
||
// uart_int_rx_frame(&COM_RADIO_port);
|
||
// }
|
||
// }
|
||
|
||
|
||
|
||
|
||
|
||
void StartDataBaudCompare( void )
|
||
{
|
||
TIM_SetCounter(COM_4852_BAUD_TIMER , COM_4852_BAUD_TIMER_PERIOD/2);//
|
||
TIM_ClearFlag(COM_4852_BAUD_TIMER, TIM_FLAG_Update);
|
||
|
||
TIM_ITConfig(COM_4852_BAUD_TIMER, TIM_IT_Update, ENABLE); //初始化时不允许更新中断
|
||
|
||
TIM_Cmd(COM_4852_BAUD_TIMER, ENABLE);
|
||
}
|
||
|
||
|
||
|
||
//该中断共用模拟串口接收中断
|
||
void RS485_OVERLOAD_FLAG_IRQHandler(void)
|
||
{
|
||
if(EXTI_GetITStatus(RS485_OVERLOAD_FLAG_LINE) != RESET)
|
||
{
|
||
EXTI_ClearITPendingBit(RS485_OVERLOAD_FLAG_LINE);
|
||
|
||
close_RS485_switch();
|
||
|
||
printf("overload close 12V switch\r\n");
|
||
}
|
||
else if(EXTI_GetITStatus(COM_4852_RX_LINE) != RESET)
|
||
{
|
||
EXTI_ClearITPendingBit(COM_4852_RX_LINE);
|
||
|
||
if ((RS4852_UNIT.Status == RS4852_STATUS_RXING) || (RS4852_UNIT.Status == RS4852_STATUS_RX_READY))
|
||
{
|
||
RS4852_UNIT.Status = RS4852_STATUS_RXING;
|
||
//hal_sRF_FSK_ITConfig(COM_4852_RX_LINE , DISABLE);
|
||
StartDataBaudCompare();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
///////////////////////////////////////////////////////////////////////////////////////////
|
||
///以下定义模拟串口 485 2 端口 相关函数
|
||
void AnalogUartInit(struct st_uart_port * port)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
EXTI_InitTypeDef EXTI_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||
|
||
vSemaphoreCreateBinary( port->xSemaphore );
|
||
if (port->xSemaphore)
|
||
{
|
||
xSemaphoreTake(port->xSemaphore, 0);
|
||
}
|
||
else
|
||
{
|
||
printf("create 4852 port xSemaphore failed\r\n");
|
||
}
|
||
|
||
|
||
RCC_APB2PeriphClockCmd(port->init.xom_rx_port_clk | port->init.com_tx_port_clk, ENABLE);
|
||
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStructure.GPIO_Pin = port->init.com_rx_pin;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//GPIO_Mode_IN_FLOATING;//
|
||
GPIO_Init( port->init.com_rx_port, &GPIO_InitStructure );
|
||
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStructure.GPIO_Pin = port->init.com_tx_pin;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//GPIO_Mode_Out_OD;
|
||
GPIO_Init( port->init.com_tx_port, &GPIO_InitStructure );
|
||
GPIO_SetBits(port->init.com_tx_port, port->init.com_tx_pin);
|
||
|
||
|
||
EXTI_ClearITPendingBit(COM_4852_RX_LINE);
|
||
hal_sRF_FSK_ITConfig(COM_4852_RX_LINE , ENABLE);
|
||
|
||
GPIO_EXTILineConfig(COM_4852_RX_PORT_SOURCE, COM_4852_RX_PIN_SOURCE);
|
||
|
||
EXTI_InitStructure.EXTI_Line = COM_4852_RX_LINE;
|
||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||
EXTI_Init(&EXTI_InitStructure);
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = port->init.com_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
|
||
|
||
|
||
|
||
RCC_APB1PeriphClockCmd(COM_4852_BAUD_TIMER_CLK, ENABLE);
|
||
|
||
TIM_TimeBaseStructure.TIM_Period = COM_4852_BAUD_TIMER_PERIOD; // period
|
||
TIM_TimeBaseStructure.TIM_Prescaler = COM_4852_BAUD_PRESC; // 时钟分频
|
||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||
TIM_TimeBaseInit(COM_4852_BAUD_TIMER, &TIM_TimeBaseStructure);
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = COM_4852_BAUD_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
|
||
TIM_ClearFlag(COM_4852_BAUD_TIMER, TIM_FLAG_Update);
|
||
|
||
TIM_ITConfig(COM_4852_BAUD_TIMER, TIM_IT_Update, DISABLE); //初始化时不允许更新中断
|
||
|
||
TIM_Cmd(COM_4852_BAUD_TIMER, ENABLE);
|
||
|
||
RS4852_UNIT.Status = RS4852_STATUS_RX_READY; //准备接收状态
|
||
|
||
|
||
}
|
||
|
||
void COM_4852_TX_bit(u8 bitVal)
|
||
{
|
||
if (bitVal == 0)
|
||
{
|
||
COM_4852_TX_BIT0;
|
||
}
|
||
else
|
||
{
|
||
COM_4852_TX_BIT1;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
void COM_4852_RX_stop(void)
|
||
{
|
||
TIM_Cmd(COM_4852_BAUD_TIMER, DISABLE);
|
||
hal_sRF_FSK_ITConfig(COM_4852_RX_LINE , DISABLE);
|
||
//GPIO_SetBits(IRDA_TX_PORT, IRDA_TX_PIN);
|
||
COM_4852_TX_BIT1;
|
||
RS4852_port.data.rx_len = 0;
|
||
RS4852_port.data.rx_index = 0;
|
||
}
|
||
|
||
|
||
void COM_4852_RX_Bit_Restart(void)
|
||
{
|
||
//IRDA_GPIO_RX_init();
|
||
RS4852_port.data.rx_len = 0;
|
||
RS4852_port.data.rx_index = 0;
|
||
RS4852_UNIT.Status = RS4852_STATUS_RX_READY;
|
||
}
|
||
|
||
void COM_4852_TXProcess(u8 *buf, u8 length)
|
||
{
|
||
RS4852_port.data.tx_len = length;
|
||
RS4852_port.data.tx_index = 0;
|
||
|
||
if ((RS4852_UNIT.Status == RS4852_STATUS_RXING) || (RS4852_UNIT.Status == RS4852_STATUS_TXING))
|
||
{
|
||
printf("4852 tx when rx\r\n");
|
||
}
|
||
else
|
||
{
|
||
COM_4852_RX_stop();
|
||
|
||
COM_4852_TX_BIT1;
|
||
RS4852_UNIT.Status = RS4852_STATUS_TXING ;
|
||
MemCpy(RS4852_port.data.txBuf, buf, length);
|
||
hal_sRF_FSK_ITConfig(COM_4852_RX_LINE , DISABLE);
|
||
|
||
TIM_ClearITPendingBit(COM_4852_BAUD_TIMER, TIM_IT_Update);
|
||
//baud_timer_init(IRDA_BAUD_PERIOD);
|
||
TIM_Cmd(COM_4852_BAUD_TIMER, ENABLE);
|
||
TIM_ITConfig(COM_4852_BAUD_TIMER, TIM_IT_Update, ENABLE); //初始化时不允许更新中断
|
||
//xTaskNotify(IRDA_task_handle, IRDA_TX_START, eSetBits);
|
||
printf("4852 start tx\r\n");
|
||
}
|
||
}
|
||
|
||
void COM_4852_BAUD_IRQHandler( void )
|
||
{
|
||
u8 start_bit = 0;
|
||
u8 end_bit = 1;
|
||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||
u8 check_bit;
|
||
|
||
static u8 rxByte = 0;
|
||
static u8 tx_bit_pos = 0;
|
||
static u8 rx_bit_pos = 0;
|
||
//BaseType_t pxHigherPriorityTaskWoken = pdFALSE;
|
||
//u8 status;
|
||
|
||
if (TIM_GetITStatus(COM_4852_BAUD_TIMER, TIM_IT_Update) != RESET)
|
||
{
|
||
TIM_ClearITPendingBit(COM_4852_BAUD_TIMER, TIM_IT_Update);
|
||
|
||
if (RS4852_UNIT.Status == RS4852_STATUS_TXING)
|
||
{
|
||
switch (tx_bit_pos)
|
||
{
|
||
case 0:
|
||
if (RS4852_port.data.tx_index >= RS4852_port.data.tx_len)
|
||
{
|
||
TIM_Cmd(COM_4852_BAUD_TIMER, DISABLE);
|
||
hal_sRF_FSK_ITConfig(COM_4852_RX_LINE , ENABLE);
|
||
RS4852_UNIT.Status = RS4852_STATUS_RX_READY;
|
||
tx_bit_pos = 0x00;
|
||
//xTaskNotifyFromISR(IRDA_task_handle, IRDA_TX_FINISH, eSetBits, &pxHigherPriorityTaskWoken);
|
||
}
|
||
else
|
||
{
|
||
COM_4852_TX_bit( start_bit );
|
||
tx_bit_pos++;
|
||
}
|
||
|
||
|
||
break;
|
||
|
||
case 1:
|
||
case 2:
|
||
case 3:
|
||
case 4:
|
||
case 5:
|
||
case 6:
|
||
case 7:
|
||
case 8:
|
||
COM_4852_TX_bit( (RS4852_port.data.txBuf[RS4852_port.data.tx_index] >> (tx_bit_pos - 1)) & 0x01);
|
||
tx_bit_pos++;
|
||
break;
|
||
|
||
case 9:
|
||
check_bit = 0;
|
||
|
||
for (u8 i = 0; i < 8; i++)
|
||
{
|
||
check_bit += ((RS4852_port.data.txBuf[RS4852_port.data.tx_index] >> i) & 0x01);
|
||
}
|
||
|
||
check_bit = check_bit % 2;
|
||
|
||
COM_4852_TX_bit(check_bit);
|
||
tx_bit_pos++;
|
||
break;
|
||
|
||
case 10:
|
||
COM_4852_TX_bit(end_bit);
|
||
RS4852_port.data.tx_index ++;
|
||
tx_bit_pos = 0;
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
|
||
}
|
||
}
|
||
else if( (RS4852_UNIT.Status == RS4852_STATUS_RXING))
|
||
{
|
||
switch(rx_bit_pos)
|
||
{
|
||
case 0:
|
||
if (COM_4852_RX_BIT == 0)
|
||
{
|
||
rxByte = 0;
|
||
rx_bit_pos++;
|
||
}
|
||
else
|
||
{
|
||
TIM_Cmd(COM_4852_BAUD_TIMER, DISABLE);
|
||
hal_sRF_FSK_ITConfig(COM_4852_RX_LINE , ENABLE);
|
||
rx_bit_pos = 0x00;
|
||
}
|
||
break;
|
||
|
||
case 1:
|
||
case 2:
|
||
case 3:
|
||
case 4:
|
||
case 5:
|
||
case 6:
|
||
case 7:
|
||
case 8:
|
||
rxByte += COM_4852_RX_BIT << (rx_bit_pos - 1);
|
||
rx_bit_pos++;
|
||
break;
|
||
|
||
case 9:
|
||
check_bit = 0;
|
||
|
||
for (u8 i = 0; i < 8; i++)
|
||
{
|
||
check_bit += ((rxByte >> i) & 0x01);
|
||
}
|
||
|
||
check_bit = check_bit % 2;
|
||
|
||
if (COM_4852_RX_BIT != check_bit)
|
||
{
|
||
rx_bit_pos = 0;
|
||
RS4852_port.data.rx_index = 0;
|
||
TIM_Cmd(COM_4852_BAUD_TIMER, DISABLE);
|
||
hal_sRF_FSK_ITConfig(COM_4852_RX_LINE , ENABLE);
|
||
}
|
||
else
|
||
{
|
||
rx_bit_pos++;
|
||
}
|
||
|
||
break;
|
||
|
||
case 10:
|
||
rx_bit_pos = 0;
|
||
|
||
if (COM_4852_RX_BIT == 1)//停止位正确
|
||
{
|
||
RS4852_UNIT.Status = RS4852_STATUS_RX_READY;
|
||
if (RS4852_port.data.rx_index >= COM_485_RX_BUFFER_SIZE)
|
||
{
|
||
RS4852_port.data.rx_index = 0;
|
||
}
|
||
RS4852_port.data.rxBuf[RS4852_port.data.rx_index++] = rxByte;
|
||
RS4852_port.data.rx_len = RS4852_port.data.rx_index;
|
||
|
||
if (RS4852_port.data.rx_index >= 1)
|
||
{
|
||
RS4852_port.data.rx_timeout = xTaskGetTickCount() + PORT_RX_TIMEOUT;
|
||
}
|
||
|
||
if ( RS4852_port.data.rx_index == 1 )
|
||
{
|
||
if ((RS4852_port.data.rxBuf[0] == 0x68) || (RS4852_port.data.rxBuf[0] == 0xEB) )
|
||
{
|
||
xSemaphoreGiveFromISR( uart_sync_Semaphore, &xHigherPriorityTaskWoken );
|
||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
||
}
|
||
else
|
||
{
|
||
RS4852_port.data.rx_index = 0;
|
||
RS4852_port.data.rx_timeout = 0;
|
||
}
|
||
}
|
||
|
||
}
|
||
else //停止位错误
|
||
{
|
||
RS4852_UNIT.Status = RS4852_STATUS_RX_READY;
|
||
RS4852_port.data.rx_index = 0;
|
||
TIM_Cmd(COM_4852_BAUD_TIMER, DISABLE);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
void RS4852_process_task(void *ptr)
|
||
{
|
||
for (;;)
|
||
{
|
||
xSemaphoreTake(RS4852_port.xSemaphore, portMAX_DELAY);
|
||
|
||
if(RS4852_UNIT.Status == RS4852_STATUS_RXING)
|
||
{
|
||
RS4852_UNIT.Status = RS4852_STATUS_RX_READY;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
////////////////////////////////以下是产品测试相关函数//////////////////////////////
|
||
//针对端口测试,测试架的底板应该返回取反后的数据
|
||
bool UartPort645Test(struct st_uart_port* port)
|
||
{
|
||
}
|
||
|
||
|
||
|
||
|
||
void TestMode_PLCTest( void )
|
||
{
|
||
u8 TempBuff[] = {0x68 ,0x72 ,0x48 ,0x08 ,0x16 ,0x00 ,0x00 ,0x68 ,0xD1 ,0x01 ,0x34 ,0xAE ,0x16};
|
||
QueueSetMemberHandle_t rxPortMember;
|
||
|
||
MemCpy(COM_PLC_port.data.txBuf,TempBuff,sizeof(TempBuff));
|
||
|
||
COM_PLC_port.init.uart_param.USART_BaudRate = 2400;
|
||
COM_PLC_port.init.uart_param.USART_Parity = USART_Parity_Even;
|
||
hal_InitCOM(&COM_PLC_port);
|
||
|
||
|
||
COM_RADIO_port.init.uart_param.USART_BaudRate = 2400;
|
||
COM_RADIO_port.init.uart_param.USART_Parity = USART_Parity_Even;
|
||
hal_InitCOM(&COM_RADIO_port);
|
||
|
||
port_send(&COM_PLC_port, COM_PLC_port.data.txBuf, sizeof(TempBuff));
|
||
|
||
rxPortMember = xQueueSelectFromSet(mPortsQueueSet, pdMS_TO_TICKS(500));
|
||
|
||
if(rxPortMember == COM_RADIO_port.xSemaphore)
|
||
{
|
||
xSemaphoreTake(COM_RADIO_port.xSemaphore, 0);
|
||
if(MemCmp(COM_RADIO_port.data.rxBuf,TempBuff,sizeof(TempBuff)) == 0x00)
|
||
{
|
||
printf("OK\r\n");
|
||
}
|
||
else
|
||
{
|
||
MemSet(COM_RADIO_port.data.rxBuf,0x00,sizeof(TempBuff));
|
||
printf("ERROR,PLC TX/RADIO RX 接触不良...\r\n");
|
||
return ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
printf("ERROR,PLC TX/RADIO RX 虚焊...\r\n");
|
||
return ;
|
||
}
|
||
|
||
|
||
port_send(&COM_RADIO_port, COM_RADIO_port.data.rxBuf, sizeof(TempBuff));
|
||
vTaskDelay(500/portTICK_RATE_MS);
|
||
|
||
if(MemCmp(COM_PLC_port.data.rxBuf,TempBuff,sizeof(TempBuff)) == 0x00)
|
||
{
|
||
printf("OK\r\n");
|
||
}
|
||
else
|
||
{
|
||
printf("ERROR,RADIO TX/PLC RX 虚焊...\r\n");
|
||
MemSet(COM_PLC_port.data.rxBuf,0x00,sizeof(TempBuff));
|
||
return ;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
void TestMode_485Test( void )
|
||
{
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
bool UartPort188Test(struct st_uart_port* port)
|
||
{
|
||
u8 TempBuff[] = {0x68, 0x01, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x81, 0x03, 0x22, 0x22, 0x9E, 0xAB, 0x16};
|
||
u8 AckBuff[] = {0x68 ,0x97 ,0x14 ,0x10 ,0x00 ,0x60 ,0x00 ,0x68 ,0x11 ,0x0E ,0x36 ,0x41 ,0x33 ,0x37 ,0xFF ,0xFF ,0x33 ,0x77 ,0x59 ,0x35 ,0x39 ,0x47 ,0x33 ,0x33 ,0x07 ,0x16};
|
||
|
||
MemSet(port->data.rxBuf,0x00,sizeof(AckBuff));
|
||
MemCpy(port->data.txBuf,TempBuff,sizeof(TempBuff));
|
||
if(port != &RS4852_port)
|
||
{
|
||
port_send(port, port->data.txBuf, sizeof(TempBuff));
|
||
}
|
||
else
|
||
{
|
||
COM_4852_TXProcess(port->data.txBuf, sizeof(TempBuff));
|
||
}
|
||
vTaskDelay(500/portTICK_RATE_MS);
|
||
|
||
if(MemCmp(port->data.rxBuf,AckBuff,sizeof(AckBuff)) == 0x00)
|
||
{
|
||
MemSet(port->data.rxBuf,0x00,sizeof(AckBuff));
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
MemSet(port->data.rxBuf,0x00,sizeof(TempBuff));
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
void PLCTest( void )
|
||
{
|
||
if(UartPort645Test(&COM_PLC_port) == false)
|
||
{
|
||
printf("ERROR\r\n");
|
||
}
|
||
else
|
||
{
|
||
printf("OK\r\n");
|
||
}
|
||
|
||
}
|
||
|
||
|
||
void RS4851Test( void )
|
||
{
|
||
//NVIC_DisableIRQ(COM_485_IRQn);
|
||
if(UartPort645Test(&COM_485_port) == false)
|
||
{
|
||
printf("ERROR\r\n");
|
||
}
|
||
else
|
||
{
|
||
printf("OK\r\n");
|
||
}
|
||
//NVIC_EnableIRQ(COM_485_IRQn);
|
||
}
|
||
|
||
|
||
void RS4852Test( void )
|
||
{
|
||
if(UartPort188Test(&RS4852_port) == false)
|
||
{
|
||
printf("ERROR\r\n");
|
||
}
|
||
else
|
||
{
|
||
printf("OK\r\n");
|
||
}
|
||
}
|
||
|
||
void TestMode_MBUSTest( void )
|
||
{
|
||
QueueSetMemberHandle_t rxPortMember;
|
||
u8 TempBuff[] = {0xFE ,0xFE ,0xFE ,0x68 ,0x10 ,0xAA ,0xAA ,0xAA ,0xAA ,0xAA ,0xAA ,0xAA ,0x01 ,0x03 ,0x90 ,0x1F ,0x00 ,0xD1 ,0x16};
|
||
// u8 AckBuff[] = {0x68 ,0x10 ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0x81 ,0x16 ,0x90 ,0x1F ,0xAA ,0x00 ,0x33 ,0x33 ,0x00 ,0x2C ,0xFF ,0xFF ,0xFF ,0xFF ,0x2C ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0x00 ,0x00 ,0x14 ,0x16};
|
||
|
||
//打开MBUS之前必须确定 1.MBUS断开 2.MBUS 处于主模式3.MBUS没有过载
|
||
if (mbus_switch_state() == 1 && (mbus_mode == MBUS_MODE_MASTER) && (MBUS_OVERLOAD_in_state() == 1))
|
||
{
|
||
mbus_gpio_init();
|
||
printf("open switch\r\n");
|
||
open_mbus_switch();
|
||
vTaskDelay( (2000 /portTICK_RATE_MS) );
|
||
}
|
||
xTimerReset(mbus_switch_handle, 0);
|
||
|
||
//MemSet(COM_MBUS_MASTER_port.data.rxBuf,0x00,sizeof(AckBuff));
|
||
MemCpy(COM_MBUS_MASTER_port.data.txBuf,TempBuff,sizeof(TempBuff));
|
||
|
||
port_send(&COM_MBUS_MASTER_port, COM_MBUS_MASTER_port.data.txBuf, sizeof(TempBuff));
|
||
|
||
rxPortMember = xQueueSelectFromSet(mPortsQueueSet, pdMS_TO_TICKS(500));
|
||
if(rxPortMember == COM_MBUS_MASTER_port.xSemaphore)
|
||
{
|
||
xSemaphoreTake(COM_MBUS_MASTER_port.xSemaphore, 0);
|
||
if(GetSum(COM_MBUS_MASTER_port.data.rxBuf,COM_MBUS_MASTER_port.data.rx_len-2) == COM_MBUS_MASTER_port.data.rxBuf[COM_MBUS_MASTER_port.data.rx_len-2])
|
||
// if(MemCmp(COM_MBUS_MASTER_port.data.rxBuf,AckBuff,sizeof(AckBuff)) == 0x00)
|
||
{
|
||
MemSet(COM_MBUS_MASTER_port.data.rxBuf,0x00,COM_MBUS_MASTER_port.data.rx_len);
|
||
printf("OK\r\n");
|
||
}
|
||
else
|
||
{
|
||
printf("ERROR,MBUS RX/TX 接触不良\r\n");
|
||
return ;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
printf("ERROR,MBUS RX/TX 虚焊\r\n");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
void RFPortTest( void )
|
||
{
|
||
if(UartPort188Test(&COM_RADIO_port) == false)
|
||
{
|
||
printf("ERROR\r\n");
|
||
}
|
||
else
|
||
{
|
||
printf("OK\r\n");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
bool ReadRS232ConcentratorDate(u8* year,u8* month)
|
||
{
|
||
QueueSetMemberHandle_t rxPortMember;
|
||
CreatReadChangDeConcentratorDate(COM_RADIO_port.data.txBuf, &COM_RADIO_port.data.tx_len);
|
||
port_send(&COM_RADIO_port,COM_RADIO_port.data.txBuf, COM_RADIO_port.data.tx_len);
|
||
|
||
rxPortMember = xQueueSelectFromSet(mPortsQueueSet, pdMS_TO_TICKS(500));
|
||
|
||
if(rxPortMember == COM_RADIO_port.xSemaphore)
|
||
{
|
||
xSemaphoreTake(COM_RADIO_port.xSemaphore, 0);
|
||
|
||
u8 tempbuff[] = {0xAA ,0x00 ,0x00 ,0x0A ,0x00 ,0x0F ,0x02 ,0x2F ,0x0A ,0x12 ,0x05 ,0x19 ,0x0F ,0x3B ,0x2A ,0xF8 ,0xFF};
|
||
printf("Receive Date Data True\r\n");
|
||
for(u8 index = 0; index < COM_RADIO_port.data.rx_len; index ++)
|
||
{
|
||
if(MemCmp(&COM_RADIO_port.data.rxBuf[index],&tempbuff[3],6) == 0x00)
|
||
{
|
||
*year = COM_RADIO_port.data.rxBuf[index+6];
|
||
*month = COM_RADIO_port.data.rxBuf[index+7];
|
||
return true;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//////////////////////////////////////////////////////////
|
||
bool amt_process(u8 * val,u8 len)
|
||
{
|
||
|
||
//充电30秒。
|
||
u32 timeout = MBUS_TIMEOUT;
|
||
|
||
QueueSetMemberHandle_t rxPortMember;
|
||
|
||
//因为涉及到延长30秒,特地加这个。
|
||
mbus_master_tx_begin();
|
||
|
||
//
|
||
// amt_dl_set_1();
|
||
rxPortMember = xQueueSelectFromSet(mPortsQueueSet, pdMS_TO_TICKS(0));
|
||
xSemaphoreTake(COM_MBUS_MASTER_port.xSemaphore, 0);
|
||
|
||
//发送
|
||
MBUS_mater_Tx(val, len);
|
||
|
||
|
||
// SendOperationUartLedCmd( MBUS2TX_LED );
|
||
printf("MBUS TX:");
|
||
printf_buf(val, len);
|
||
|
||
//等待数据
|
||
// xSemaphoreTake(amt_buff.xSemaphore, 30000/portTICK_RATE_MS);
|
||
// amt_sem_clear();
|
||
|
||
rxPortMember = xQueueSelectFromSet(mPortsQueueSet, timeout);
|
||
|
||
|
||
if (rxPortMember == COM_MBUS_MASTER_port.xSemaphore)
|
||
{
|
||
xSemaphoreTake(COM_MBUS_MASTER_port.xSemaphore, 0);
|
||
// read_params->meter_port = PORT_MBUS_MASTER;
|
||
// read_params->meter_protl = CurrentProtcl;
|
||
// return meter_ack_packet_process(read_params->meter_protl , COM_MBUS_MASTER_port.data.rxBuf, COM_MBUS_MASTER_port.data.rx_len, read_params, outbuf);
|
||
smt_set_value( COM_MBUS_MASTER_port.data.rxBuf, COM_MBUS_MASTER_port.data.rx_len);
|
||
mbus_master_tx_end();
|
||
return true;
|
||
}
|
||
|
||
mbus_master_tx_end();
|
||
|
||
return false;
|
||
|
||
}
|
||
|
||
|
||
//////////////////////////////////////////////////////////
|
||
void amt_process_cmd()
|
||
{
|
||
|
||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
||
//FE FE FE 68 10 66 20 00 32 22 00 00 01 03 90 1F 00 05 16
|
||
u8 sendval[19]={0xFE,0xFE,0xFE,0x68,0x10,0x66,0x20,0x00,0x32,0x22,0x00,0x00,0x01,0x03,0x90,0x1F,0x00,0x05,0x16};
|
||
amt_process(sendval,19);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/******************* (C) COPYRIGHT 2013 Robulink Technology Ltd.*****END OF FILE****/
|