#include "protocol_modbus_rtu.h"
#include "Rn8302_cal.h"
-static BYTE rs4851_probuf[1024];
+static BYTE rs485_2_probuf[1024];
uint16_t pLocalCnt = 0;
uint8_t pLocalTestData[100] = {0};
uint8_t pD645AckBuff[200] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
/*
- RS485-1¶Ë¿Ú¼ÓÔØ¹æÔ¼
+ RS485-2¶Ë¿Ú¼ÓÔØ¹æÔ¼
*/
-void Task_RS485_1_sProtocol()
+void Task_RS485_2_sProtocol()
{
BYTE *frame;
WORD len;
-#if 0
- /* RS485-1¼ÓÔØ698¹æÔ¼ */
- if (Port_Get_One_Rx_Frame(PORT_UART_IFACE_RS4851, &frame, &len)) // ²éѯ»ñÈ¡RS-4851¶Ë¿ÚFIFOÖеÄÊý¾Ý
+
+ /* RS485-2¼ÓÔØ698¹æÔ¼ */
+ if (Port_Get_One_Rx_Frame(PORT_UART_IFACE_RS4852, &frame, &len)) // ²éѯ»ñÈ¡RS-4851¶Ë¿ÚFIFOÖеÄÊý¾Ý
{
WORD txlen;
- if (Dlt698_45_protocol(frame, len, rs4851_probuf, sizeof(rs4851_probuf), &txlen) == TRUE)//Éý¼¶Îļþ
+ if (Dlt698_45_protocol(frame, len, rs485_2_probuf, sizeof(rs485_2_probuf), &txlen) == TRUE)//Éý¼¶Îļþ
{
- Port_tran_One_Frame(PORT_UART_IFACE_RS4851, rs4851_probuf, txlen); // RS-4851¶Ë¿Ú·¢ËÍÍêÕûµÄÒ»Ö¡Êý¾Ý
+ Port_tran_One_Frame(PORT_UART_IFACE_RS4852, rs485_2_probuf, txlen); // RS-4852¶Ë¿Ú·¢ËÍÍêÕûµÄÒ»Ö¡Êý¾Ý
}
- else if (protocol_Modbus_RTU(frame, len, rs4851_probuf, &txlen) == TRUE) // MODBUS¹æÔ¼´¦Àí
+ else if (protocol_Modbus_RTU(frame, len, rs485_2_probuf, &txlen) == TRUE) // MODBUS¹æÔ¼´¦Àí
{
- Port_tran_One_Frame(PORT_UART_IFACE_RS4851, rs4851_probuf, txlen);
+ Port_tran_One_Frame(PORT_UART_IFACE_RS4852, rs485_2_probuf, txlen);
}
else if( (*frame == 0xFE) &&
(*(frame+1) == 0xFE) &&
memcpy(pD645AckBuff, frame+4, len-4);
//send ack to host app
- Port_tran_One_Frame(PORT_UART_IFACE_RS4851, pD645AckBuff, len-4);
+ Port_tran_One_Frame(PORT_UART_IFACE_RS4852, pD645AckBuff, len-4);
}
}
- else if(Modbus_Protocol_Passthrouh_Analysis(frame,len))//͸´«µ½ Á½Â·ÏÂÐÐ485½Ó¿Ú
- {
- }
+// else if(Modbus_Protocol_Passthrouh_Analysis(frame,len))//͸´«µ½ Á½Â·ÏÂÐÐ485½Ó¿Ú
+// {
+// }
else if(Modbus_Protocol_Analysis(frame,len))//µÚÈý·½ºǫ́modbusÐÒé
{
}
}
}
-#else
-
-#endif
-
}
uint8_t send_bf=0;
uint32_t curr_level;
//USART2_RXD / GPD6
- curr_level = HAL_GPIO_ReadPin( GPIOD, 1<<6 )==GPIO_PIN_SET ? 1: 0;
+ curr_level = HAL_GPIO_ReadPin( GPIOD, GPIO_PIN_6 )==GPIO_PIN_SET ? 1: 0;
if( rx_start == 0 ){
if( last_level == 0 && curr_level == 1 ){
#endif
}
+#define TIME_BIT_P 2
+#define TIME_BIT_0 0
+#define TIME_BIT_1 1
+#define TIME_BIT_E -1
+
//¶Áȡһ¸öbit£¬ ·µ»Ø ´íÎó£º-1 £¬ 0£ºÊý¾Ý0 2/8 1£ºÊý¾Ý1 5/5£¬ 2£ºP 8/2
int32_t IRIG_B_Time_get_bit( void )
{
int h_time = 0;
int l_time = 0;
- int ret = -1;
+ int ret = TIME_BIT_E;
//¼ÆËã¸ßµçƽʱ¼ä
while( rd_n < wr_n && irig_b_rx_buf[rd_n&TIME_BUF_SIZE_MASK] == 1 ){
while( rd_n < wr_n && irig_b_rx_buf[rd_n&TIME_BUF_SIZE_MASK] == 0 ){
rd_n++;
l_time++;
+ if( h_time+l_time > 10 )
+ break;
}
if( h_time>0 && h_time + l_time >=9 && h_time + l_time <= 11 ){
- if( h_time <3 )
- ret = 0; // 2ms + 8ms - 0
- else if( h_time <6 )
- ret = 1; //5ms + 5ms - 1
+ if( h_time <4 )
+ ret = TIME_BIT_0; // 2ms + 8ms - 0
+ else if( h_time <7 )
+ ret = TIME_BIT_1; //5ms + 5ms - 1
else if( h_time <9 )
- ret = 2; //8ms + 2ms - P
+ ret = TIME_BIT_P; //8ms + 2ms - P
}
return ret;
}
+
//¶Áȡһ¸öByte£¬ Õý³££º·µ»Ø BCDÂ룬 ´íÎ󣺷µ»Ø-1
-int32_t IRIG_B_Time_get_byte( void )
+int32_t IRIG_B_Time_get_byte( uint8_t first )
{
uint8_t rx_byte = 0;
int32_t b;
- //P
- if( (b = IRIG_B_Time_get_bit()) != 2)
- return -1;
-
//Bit0
- if( (b = IRIG_B_Time_get_bit()) < 0 || b == 2)
- return -1;
- rx_byte |= b?1:0;
+ if( (b = IRIG_B_Time_get_bit()) == TIME_BIT_E || b == TIME_BIT_P)
+ return TIME_BIT_E;
+
+ if(b==TIME_BIT_1)
+ rx_byte |= 1;
//Bit1
- if( (b = IRIG_B_Time_get_bit()) < 0 || b == 2)
- return -1;
- rx_byte |= b?2:0;
+ if( (b = IRIG_B_Time_get_bit()) == TIME_BIT_E || b == TIME_BIT_P)
+ return TIME_BIT_E;
+
+ if(b==TIME_BIT_1)
+ rx_byte |= 2;
//Bit2
- if( (b = IRIG_B_Time_get_bit()) < 0 || b == 2)
- return -1;
- rx_byte |= b?4:0;
+ if( (b = IRIG_B_Time_get_bit()) == TIME_BIT_E || b == TIME_BIT_P)
+ return TIME_BIT_E;
+
+ if(b==TIME_BIT_1)
+ rx_byte |= 4;
//Bit3
- if( (b = IRIG_B_Time_get_bit()) < 0 || b == 2)
- return -1;
- rx_byte |= b?8:0;
+ if( (b = IRIG_B_Time_get_bit()) == TIME_BIT_E || b == TIME_BIT_P)
+ return TIME_BIT_E;
+
+ if(b==TIME_BIT_1)
+ rx_byte |= 8;
//0
if( (b = IRIG_B_Time_get_bit()) < 0 || b != 0)
return -1;
- rx_byte |= b?1:0;
+ //Bit4
+ if( (b = IRIG_B_Time_get_bit()) == TIME_BIT_E || b == TIME_BIT_P)
+ return TIME_BIT_E;
+
+ if(b==TIME_BIT_1)
+ rx_byte |= 0x10;
+
+ //Bit5
+ if( (b = IRIG_B_Time_get_bit()) == TIME_BIT_E || b == TIME_BIT_P)
+ return TIME_BIT_E;
+
+ if(b==TIME_BIT_1)
+ rx_byte |= 0x20;
+
+ //Bit6
+ if( (b = IRIG_B_Time_get_bit()) == TIME_BIT_E || b == TIME_BIT_P)
+ return TIME_BIT_E;
+
+ if(b==TIME_BIT_1)
+ rx_byte |= 0x40;
+
+ if( first == 0 ){
+ //Bit7
+ if( (b = IRIG_B_Time_get_bit()) == TIME_BIT_E || b == TIME_BIT_P)
+ return TIME_BIT_E;
+
+ if(b==TIME_BIT_1)
+ rx_byte |= 0x80;
+ }
+ return rx_byte;
}
+
void IRIG_B_Time_Init( void )
{
- //HAL_GPIO_WritePin( GPIOD, PIN(4), GPIO_PIN_RESET );
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+ //GPIO PD6
+ GPIO_InitStruct.Pin = GPIO_PIN_6;
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}
void IRIG_B_Time_Task( void )
{
#if 0
- uint8_t data[10];
- if( wr_n - rd_n >= 1000 ){
- //½âÎöÊý¾Ý
+
+ uint32_t sec;
+ uint32_t min;
+ uint32_t hour;
+ uint32_t day;
+ uint32_t year;
+
+ uint8_t data[10];
+ int32_t rx_byte[10];
+ while( wr_n - rd_n >= 1000 ){
- if( get_bit() == TIME_P ){ //P0
- for( int i=0; i<10; i++ ){
- get_bit() == TEIM_P
- data[i] = get_byte();
- }
- }
- }else if( rx_start == 0 ){
- rd_n = wr_n;
- }
+ if( IRIG_B_Time_get_bit() == TIME_BIT_P ){ //P0
+ if( IRIG_B_Time_get_bit() == TIME_BIT_P ){ //PR
+ rx_byte[0] = IRIG_B_Time_get_byte(1);
+ if( rx_byte[0] == TIME_BIT_E )
+ break;
+ if( IRIG_B_Time_get_bit() != TIME_BIT_P ) //P1
+ break;
+ if( (rx_byte[1] = IRIG_B_Time_get_byte(0)) == TIME_BIT_E )
+ break;
+ if( IRIG_B_Time_get_bit() != TIME_BIT_P ) //P2
+ break;
+ if( (rx_byte[2] = IRIG_B_Time_get_byte(0)) == TIME_BIT_E )
+ break;
+ if( IRIG_B_Time_get_bit() != TIME_BIT_P ) //P3
+ break;
+ if( (rx_byte[3] = IRIG_B_Time_get_byte(0)) == TIME_BIT_E )
+ break;
+ if( IRIG_B_Time_get_bit() != TIME_BIT_P ) //P4
+ break;
+ if( (rx_byte[4] = IRIG_B_Time_get_byte(0)) == TIME_BIT_E )
+ break;
+ if( IRIG_B_Time_get_bit() != TIME_BIT_P ) //P5
+ break;
+ if( (rx_byte[5] = IRIG_B_Time_get_byte(0)) == TIME_BIT_E )
+ break;
+ if( IRIG_B_Time_get_bit() != TIME_BIT_P ) //P6
+ break;
+ if( (rx_byte[6] = IRIG_B_Time_get_byte(0)) == TIME_BIT_E )
+ break;
+ if( IRIG_B_Time_get_bit() != TIME_BIT_P ) //P7
+ break;
+ if( (rx_byte[7] = IRIG_B_Time_get_byte(0)) == TIME_BIT_E )
+ break;
+ if( IRIG_B_Time_get_bit() != TIME_BIT_P ) //P8
+ break;
+ if( (rx_byte[8] = IRIG_B_Time_get_byte(0)) == TIME_BIT_E )
+ break;
+ if( IRIG_B_Time_get_bit() != TIME_BIT_P ) //P9
+ break;
+ if( (rx_byte[9] = IRIG_B_Time_get_byte(0)) == TIME_BIT_E )
+ break;
+ //»ñµÃһ֡ʱ¼äÊý¾Ý
+ sec = ((rx_byte[0]>>4)&0x0f)*10 + (rx_byte[0]&0x0f);
+ min = ((rx_byte[1]>>4)&0x0f)*10 + (rx_byte[1]&0x0f);
+ hour = ((rx_byte[2]>>4)&0x0f)*10 + (rx_byte[2]&0x0f);
+ day = ((rx_byte[3]>>4)&0x0f)*10 + (rx_byte[3]&0x0f) + (rx_byte[4]&0x0f)*100 ;
+ year = ((rx_byte[5]>>4)&0x0f)*10 + (rx_byte[5]&0x0f);
+ printf( "get time %d, %d, %d, %d\n", sec, hour, day, year );
+ }
+ }
+ }
#endif
}