协议测试初步通过,第一包数据返回过多
This commit is contained in:
parent
55e91c55ca
commit
032d541cf5
|
@ -40,13 +40,19 @@ extern "C"
|
|||
DI_2,
|
||||
DI_3,
|
||||
DI_4,
|
||||
DI_5,
|
||||
DI_6,
|
||||
DI_MAX,
|
||||
} gpio_di_e;
|
||||
typedef enum
|
||||
{
|
||||
DO_1,
|
||||
DO_2,
|
||||
DO_3,
|
||||
DO_4,
|
||||
DO_EN,
|
||||
DI_DO_MAX,
|
||||
} gpio_e;
|
||||
DO_MAX,
|
||||
} gpio_do_e;
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_GPIO_Init(void);
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
@ -92,6 +91,10 @@ extern uart_t hart2_uart2;
|
|||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define DI_CH5_Pin GPIO_PIN_2
|
||||
#define DI_CH5_GPIO_Port GPIOE
|
||||
#define DI_CH6_Pin GPIO_PIN_3
|
||||
#define DI_CH6_GPIO_Port GPIOE
|
||||
#define ETH_RESET_Pin GPIO_PIN_0
|
||||
#define ETH_RESET_GPIO_Port GPIOC
|
||||
#define LED3_R_Pin GPIO_PIN_1
|
||||
|
|
|
@ -54,6 +54,7 @@ osThreadId lwip_taskHandle;
|
|||
osThreadId led_taskHandle;
|
||||
osThreadId dac_taskHandle;
|
||||
osThreadId adc_taskHandle;
|
||||
osThreadId gpio_di_do_taskHandle;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
|
@ -64,6 +65,7 @@ void start_tcp_task(void const *argument);
|
|||
void start_led_toggle_task(void const *argument);
|
||||
void start_dac_task(void const *argument);
|
||||
void start_adc_task(void const *argument);
|
||||
void start_gpio_di_do_task(void const *argument);
|
||||
|
||||
extern void MX_LWIP_Init(void);
|
||||
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
||||
|
@ -128,6 +130,10 @@ void MX_FREERTOS_Init(void)
|
|||
osThreadDef(adc_task, start_adc_task, osPriorityBelowNormal, 0, 128);
|
||||
adc_taskHandle = osThreadCreate(osThread(adc_task), NULL);
|
||||
|
||||
/* definition and creation of gpio_di_do_task */
|
||||
osThreadDef(gpio_di_do_task, start_gpio_di_do_task, osPriorityNormal, 0, 128);
|
||||
gpio_di_do_taskHandle = osThreadCreate(osThread(gpio_di_do_task), NULL);
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
|
@ -240,6 +246,24 @@ void start_adc_task(void const *argument)
|
|||
/* USER CODE END start_adc_task */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_start_gpio_di_do_task */
|
||||
/**
|
||||
* @brief Function implementing the gpio_di_do_task thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_start_gpio_di_do_task */
|
||||
void start_gpio_di_do_task(void const *argument)
|
||||
{
|
||||
/* USER CODE BEGIN start_gpio_di_do_task */
|
||||
/* Infinite loop */
|
||||
for (;;)
|
||||
{
|
||||
osDelay(1);
|
||||
}
|
||||
/* USER CODE END start_gpio_di_do_task */
|
||||
}
|
||||
|
||||
/* Private application code --------------------------------------------------*/
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
|
|
|
@ -45,11 +45,11 @@ void MX_GPIO_Init(void)
|
|||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
|
@ -70,6 +70,12 @@ void MX_GPIO_Init(void)
|
|||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(HART2_RST_GPIO_Port, HART2_RST_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : PEPin PEPin */
|
||||
GPIO_InitStruct.Pin = DI_CH5_Pin | DI_CH6_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = ETH_RESET_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
|
@ -199,6 +205,12 @@ GPIO_PinState gpio_di_test(uint8_t gpio_num)
|
|||
case DI_4:
|
||||
state = HAL_GPIO_ReadPin(DI_CH4_GPIO_Port, DI_CH4_Pin);
|
||||
break;
|
||||
case DI_5:
|
||||
state = HAL_GPIO_ReadPin(DI_CH5_GPIO_Port, DI_CH5_Pin);
|
||||
break;
|
||||
case DI_6:
|
||||
state = HAL_GPIO_ReadPin(DI_CH6_GPIO_Port, DI_CH6_Pin);
|
||||
break;
|
||||
default:
|
||||
state = GPIO_PIN_RESET;
|
||||
break;
|
||||
|
|
|
@ -177,7 +177,8 @@ void SystemClock_Config(void)
|
|||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
||||
|
@ -268,8 +269,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM1)
|
||||
{
|
||||
if (htim->Instance == TIM1) {
|
||||
HAL_IncTick();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
|
|
|
@ -65,6 +65,7 @@ void MX_UART4_Init(void)
|
|||
/* USER CODE BEGIN UART4_Init 2 */
|
||||
//__HAL_UART_ENABLE_IT(&huart4, UART_IT_IDLE); // 使能IDLE中断
|
||||
/* USER CODE END UART4_Init 2 */
|
||||
|
||||
}
|
||||
/* UART5 init function */
|
||||
void MX_UART5_Init(void)
|
||||
|
@ -93,6 +94,7 @@ void MX_UART5_Init(void)
|
|||
// __HAL_UART_ENABLE_IT(&huart5, UART_IT_RXNE); // 接收中断
|
||||
// __HAL_UART_ENABLE_IT(&huart5, UART_IT_IDLE); // 空闲中断
|
||||
/* USER CODE END UART5_Init 2 */
|
||||
|
||||
}
|
||||
/* USART2 init function */
|
||||
|
||||
|
@ -122,6 +124,7 @@ void MX_USART2_UART_Init(void)
|
|||
// __HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE); // 接收中断
|
||||
// __HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE); // 使能IDLE中断
|
||||
/* USER CODE END USART2_Init 2 */
|
||||
|
||||
}
|
||||
/* USART3 init function */
|
||||
|
||||
|
@ -150,6 +153,7 @@ void MX_USART3_UART_Init(void)
|
|||
/* USER CODE BEGIN USART3_Init 2 */
|
||||
|
||||
/* USER CODE END USART3_Init 2 */
|
||||
|
||||
}
|
||||
/* USART6 init function */
|
||||
|
||||
|
@ -178,6 +182,7 @@ void MX_USART6_UART_Init(void)
|
|||
/* USER CODE BEGIN USART6_Init 2 */
|
||||
|
||||
/* USER CODE END USART6_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
|
@ -644,21 +649,21 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle)
|
|||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/**
|
||||
* @brief 使用DMA方式通过串口发送数据
|
||||
* @brief 使用DMAæ–¹å¼<EFBFBD>通过串å<EFBFBD>£å<EFBFBD>‘é?<EFBFBD>æ•°æ<EFBFBD>?
|
||||
*
|
||||
* 该函数使用DMA方式通过指定的串口发送指定长度的数据。
|
||||
* 该函数使用DMAæ–¹å¼<EFBFBD>通过指定的串å<EFBFBD>£å<EFBFBD>‘é€<EFBFBD>指定长度的数æ<EFBFBD>®ã€?
|
||||
*
|
||||
* @param huart UART_HandleTypeDef结构体指针,指向需要使用的串口句柄
|
||||
* @param buf 指向需要发送的数据缓冲区的指针
|
||||
* @param len 需要发送的数据长度
|
||||
* @param huart UART_HandleTypeDef结构体指针,指å<EFBFBD>‘éœ?è¦<EFBFBD>使用的串å<EFBFBD>£å<EFBFBD>¥æŸ„
|
||||
* @param buf 指å<EFBFBD>‘éœ?è¦<EFBFBD>å<EFBFBD>‘é€<EFBFBD>的数æ<EFBFBD>®ç¼“冲区的指针
|
||||
* @param len éœ?è¦<EFBFBD>å<EFBFBD>‘é€<EFBFBD>的数æ<EFBFBD>®é•¿åº¦
|
||||
*
|
||||
* @return 无返回值
|
||||
* @return æ— è¿”å›žå??
|
||||
*
|
||||
* @note 如果发送过程中出现错误,会调用Error_Handler函数处理错误
|
||||
* @note 如果å<EFBFBD>‘é?<EFBFBD>过程ä¸å‡ºçŽ°é”™è¯¯ï¼Œä¼šè°ƒç”¨Error_Handler函数处ç<EFBFBD>†é”™è¯¯
|
||||
*/
|
||||
void dma_usart_send(UART_HandleTypeDef *huart, uint8_t *buf, uint8_t len)
|
||||
{
|
||||
if (HAL_UART_Transmit_DMA(huart, buf, len) != HAL_OK) // 判断是否发送正常,如果出现异常则进入异常中断函数
|
||||
if (HAL_UART_Transmit_DMA(huart, buf, len) != HAL_OK) // åˆ¤æ–æ˜¯å<EFBFBD>¦å<EFBFBD>‘é?<3F>æ£å¸¸ï¼Œå¦‚æžœå‡ºçŽ°å¼‚å¸¸åˆ™è¿›å…¥å¼‚å¸¸ä¸æ–函æ•?
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -148,24 +148,7 @@
|
|||
<Name>-UB -O2254 -SF1800 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407VGTx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>4</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>0</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>0</BreakIfRCount>
|
||||
<Filename>../User/application/inc/communication_protocol.h</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<Breakpoint/>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
|
|
132
TEST2.ioc
132
TEST2.ioc
|
@ -117,7 +117,7 @@ ETH.IPParameters=MediaInterface
|
|||
ETH.MediaInterface=HAL_ETH_RMII_MODE
|
||||
FREERTOS.FootprintOK=true
|
||||
FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configENABLE_FPU,configMAX_PRIORITIES,FootprintOK
|
||||
FREERTOS.Tasks01=lwip_task,2,512,start_tcp_task,Default,NULL,Dynamic,NULL,NULL;led_task,-2,128,start_led_toggle_task,Default,NULL,Dynamic,NULL,NULL;dac_task,0,512,start_dac_task,Default,NULL,Dynamic,NULL,NULL;adc_task,-1,128,start_adc_task,Default,NULL,Dynamic,NULL,NULL
|
||||
FREERTOS.Tasks01=lwip_task,2,512,start_tcp_task,Default,NULL,Dynamic,NULL,NULL;led_task,-2,128,start_led_toggle_task,Default,NULL,Dynamic,NULL,NULL;dac_task,0,512,start_dac_task,Default,NULL,Dynamic,NULL,NULL;adc_task,-1,128,start_adc_task,Default,NULL,Dynamic,NULL,NULL;gpio_di_do_task,0,128,start_gpio_di_do_task,Default,NULL,Dynamic,NULL,NULL
|
||||
FREERTOS.configENABLE_FPU=1
|
||||
FREERTOS.configMAX_PRIORITIES=32
|
||||
FREERTOS.configMAX_TASK_NAME_LEN=24
|
||||
|
@ -163,65 +163,67 @@ Mcu.IP9=TIM3
|
|||
Mcu.IPNb=15
|
||||
Mcu.Name=STM32F407V(E-G)Tx
|
||||
Mcu.Package=LQFP100
|
||||
Mcu.Pin0=PH0-OSC_IN
|
||||
Mcu.Pin1=PH1-OSC_OUT
|
||||
Mcu.Pin10=PB2
|
||||
Mcu.Pin11=PE7
|
||||
Mcu.Pin12=PE12
|
||||
Mcu.Pin13=PE13
|
||||
Mcu.Pin14=PE14
|
||||
Mcu.Pin15=PB11
|
||||
Mcu.Pin16=PB12
|
||||
Mcu.Pin17=PB13
|
||||
Mcu.Pin18=PD8
|
||||
Mcu.Pin19=PD9
|
||||
Mcu.Pin2=PC0
|
||||
Mcu.Pin20=PD11
|
||||
Mcu.Pin21=PD12
|
||||
Mcu.Pin22=PD13
|
||||
Mcu.Pin23=PD14
|
||||
Mcu.Pin24=PD15
|
||||
Mcu.Pin25=PC6
|
||||
Mcu.Pin26=PC7
|
||||
Mcu.Pin27=PC8
|
||||
Mcu.Pin28=PC9
|
||||
Mcu.Pin29=PA8
|
||||
Mcu.Pin3=PC1
|
||||
Mcu.Pin30=PA11
|
||||
Mcu.Pin31=PA12
|
||||
Mcu.Pin32=PA13
|
||||
Mcu.Pin33=PA14
|
||||
Mcu.Pin34=PA15
|
||||
Mcu.Pin35=PC10
|
||||
Mcu.Pin36=PC11
|
||||
Mcu.Pin37=PC12
|
||||
Mcu.Pin38=PD0
|
||||
Mcu.Pin39=PD1
|
||||
Mcu.Pin4=PA1
|
||||
Mcu.Pin40=PD2
|
||||
Mcu.Pin41=PD3
|
||||
Mcu.Pin42=PD4
|
||||
Mcu.Pin43=PD5
|
||||
Mcu.Pin44=PD6
|
||||
Mcu.Pin45=PD7
|
||||
Mcu.Pin46=PB3
|
||||
Mcu.Pin47=PB4
|
||||
Mcu.Pin48=PB5
|
||||
Mcu.Pin49=PB6
|
||||
Mcu.Pin5=PA2
|
||||
Mcu.Pin50=PB7
|
||||
Mcu.Pin51=PE0
|
||||
Mcu.Pin52=PE1
|
||||
Mcu.Pin53=VP_FREERTOS_VS_CMSIS_V1
|
||||
Mcu.Pin54=VP_LWIP_VS_Enabled
|
||||
Mcu.Pin55=VP_SYS_VS_tim1
|
||||
Mcu.Pin56=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin57=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin6=PA7
|
||||
Mcu.Pin7=PC4
|
||||
Mcu.Pin8=PC5
|
||||
Mcu.Pin9=PB1
|
||||
Mcu.PinsNb=58
|
||||
Mcu.Pin0=PE2
|
||||
Mcu.Pin1=PE3
|
||||
Mcu.Pin10=PC5
|
||||
Mcu.Pin11=PB1
|
||||
Mcu.Pin12=PB2
|
||||
Mcu.Pin13=PE7
|
||||
Mcu.Pin14=PE12
|
||||
Mcu.Pin15=PE13
|
||||
Mcu.Pin16=PE14
|
||||
Mcu.Pin17=PB11
|
||||
Mcu.Pin18=PB12
|
||||
Mcu.Pin19=PB13
|
||||
Mcu.Pin2=PH0-OSC_IN
|
||||
Mcu.Pin20=PD8
|
||||
Mcu.Pin21=PD9
|
||||
Mcu.Pin22=PD11
|
||||
Mcu.Pin23=PD12
|
||||
Mcu.Pin24=PD13
|
||||
Mcu.Pin25=PD14
|
||||
Mcu.Pin26=PD15
|
||||
Mcu.Pin27=PC6
|
||||
Mcu.Pin28=PC7
|
||||
Mcu.Pin29=PC8
|
||||
Mcu.Pin3=PH1-OSC_OUT
|
||||
Mcu.Pin30=PC9
|
||||
Mcu.Pin31=PA8
|
||||
Mcu.Pin32=PA11
|
||||
Mcu.Pin33=PA12
|
||||
Mcu.Pin34=PA13
|
||||
Mcu.Pin35=PA14
|
||||
Mcu.Pin36=PA15
|
||||
Mcu.Pin37=PC10
|
||||
Mcu.Pin38=PC11
|
||||
Mcu.Pin39=PC12
|
||||
Mcu.Pin4=PC0
|
||||
Mcu.Pin40=PD0
|
||||
Mcu.Pin41=PD1
|
||||
Mcu.Pin42=PD2
|
||||
Mcu.Pin43=PD3
|
||||
Mcu.Pin44=PD4
|
||||
Mcu.Pin45=PD5
|
||||
Mcu.Pin46=PD6
|
||||
Mcu.Pin47=PD7
|
||||
Mcu.Pin48=PB3
|
||||
Mcu.Pin49=PB4
|
||||
Mcu.Pin5=PC1
|
||||
Mcu.Pin50=PB5
|
||||
Mcu.Pin51=PB6
|
||||
Mcu.Pin52=PB7
|
||||
Mcu.Pin53=PE0
|
||||
Mcu.Pin54=PE1
|
||||
Mcu.Pin55=VP_FREERTOS_VS_CMSIS_V1
|
||||
Mcu.Pin56=VP_LWIP_VS_Enabled
|
||||
Mcu.Pin57=VP_SYS_VS_tim1
|
||||
Mcu.Pin58=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin59=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin6=PA1
|
||||
Mcu.Pin7=PA2
|
||||
Mcu.Pin8=PA7
|
||||
Mcu.Pin9=PC4
|
||||
Mcu.PinsNb=60
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F407VGTx
|
||||
|
@ -508,6 +510,16 @@ PE14.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
|
|||
PE14.Locked=true
|
||||
PE14.PinState=GPIO_PIN_SET
|
||||
PE14.Signal=GPIO_Output
|
||||
PE2.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||
PE2.GPIO_Label=DI_CH5
|
||||
PE2.GPIO_PuPd=GPIO_PULLUP
|
||||
PE2.Locked=true
|
||||
PE2.Signal=GPIO_Input
|
||||
PE3.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||
PE3.GPIO_Label=DI_CH6
|
||||
PE3.GPIO_PuPd=GPIO_PULLUP
|
||||
PE3.Locked=true
|
||||
PE3.Signal=GPIO_Input
|
||||
PE7.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label
|
||||
PE7.GPIO_Label=LED3_Y
|
||||
PE7.GPIO_PuPd=GPIO_PULLUP
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
#define TCP_PORT_HART1 5001
|
||||
#define TCP_PORT_HART2 5002
|
||||
#define TCP_PORT_BLE1 5003
|
||||
#define TCP_PORT_BLE2 5004
|
||||
#define TCP_PORT_CONTROL 5005
|
||||
#define TCP_PORT_BLE1 6001
|
||||
#define TCP_PORT_BLE2 6002
|
||||
#define TCP_PORT_CONTROL 5003
|
||||
|
||||
extern void tcp_echo_init(void);
|
||||
extern void user_send_data_hart1(uint8_t *data, uint16_t len);
|
||||
|
|
|
@ -175,6 +175,11 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
|
|||
}
|
||||
else if (tcp_rx_data[3] == 0x02) // 读数字量指令
|
||||
{
|
||||
/*读操作,从寄存器读取数据,组包返回*/
|
||||
tx_data_len = 7 + user_communication_di->num;
|
||||
user_communication_di = &communication_data.di_data;
|
||||
user_read_gpio(user_communication_di, tcp_tx_data, tcp_rx_data);
|
||||
tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
|
||||
}
|
||||
else if (tcp_rx_data[3] == 0x03) // 写数字量指令
|
||||
{
|
||||
|
|
|
@ -17,13 +17,21 @@ void user_write_gpio(communication_do_t *do_data)
|
|||
}
|
||||
}
|
||||
}
|
||||
void user_read_gpio(uint8_t *const tx_data, uint8_t *const rx_data, uint16_t length)
|
||||
void user_read_gpio(communication_di_t *di_data, uint8_t *tx_data, const uint8_t *const rx_data)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t start_addr = rx_data[0]; // 读输入的起始地址
|
||||
uint8_t leng = rx_data[1]; // 读输入的数量
|
||||
for (i = 0; i < leng; i++)
|
||||
uint8_t start_addr = di_data->start_addr; // 读输入的起始地址
|
||||
uint8_t length = di_data->num; // 读输入的数量
|
||||
uint8_t tx_data_len = 7 + length; // 数据长度
|
||||
tx_data[0] = FRAME_HEAD; // 帧头
|
||||
tx_data[1] = COM_OK; // 状态
|
||||
tx_data[2] = rx_data[2]; // 设备号
|
||||
tx_data[3] = rx_data[3]; // 命令号
|
||||
tx_data[4] = length; // 数据长度
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
tx_data[i] = gpio_di_test(DI_1 + start_addr + i);
|
||||
tx_data[5 + i] = gpio_di_test(DI_1 + i + start_addr);
|
||||
}
|
||||
tx_data[5 + length] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
|
||||
tx_data[6 + length] = FRAME_TAIL; // 帧尾
|
||||
}
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
#include "communication_protocol.h"
|
||||
|
||||
void user_write_gpio(communication_do_t *do_data);
|
||||
void user_read_gpio(uint8_t *const tx_data, uint8_t *const rx_data, uint16_t length);
|
||||
void user_read_gpio(communication_di_t *di_data, uint8_t *tx_data, const uint8_t *const rx_data);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue