简单列举一下电动车的一线通协议解析代码,自己记录用
/*** @brief : 一线通初始化内部函数** @return vd_bool_t*/
vd_bool_t isdn_inside_init(void) {drv_gpio_t drv_gpio;drv_gpio.pin = PLATFORM_ISDN_PIN;drv_gpio.mode = DRV_GPIO_MODE_INPUT;drv_gpio.pull = DRV_GPIO_NOPULL;drv_gpio_init(&drv_gpio);drv_gpio_requst_irq(drv_gpio.pin, DRV_GPIO_MODE_EXTI_IT_RISING, isdn_pin_isr);printf("isdn_init_successful\r");return vd_true;
}
/*** @brief : 一线通中断处理函数** @param pin:中断引脚* @param value:引脚电平* @return vd_void_t*/
static vd_void_t isdn_pin_isr(vd_uint8_t pin, vd_uint8_t value) {if (value == 1) {t1_time = drv_systick_get(); //触发高电平时刻drv_gpio_irq_mode(PLATFORM_ISDN_PIN, DRV_GPIO_MODE_EXTI_IT_FALLING); //高电平配置下降沿触发if ((t1_time - t2_time >= 10000) && start_signal == 0) {start_signal = 2; //起始信号} else if (t2_time != 0 && start_signal == 1) {low_time = t1_time - t2_time; //低电平持续时间}} else {t2_time = drv_systick_get(); //触发低电平时刻drv_gpio_irq_mode(PLATFORM_ISDN_PIN, DRV_GPIO_MODE_EXTI_IT_RISING); //低电平配置上升沿触发if (t1_time != 0 && start_signal == 1) {high_time = t2_time - t1_time; //高电平持续时间} else if (t1_time != 0 && start_signal == 2) {start_signal = 1; //开始接收数据high_time = low_time = 0; //高低电平持续时间清空}}if (high_time != NULL && low_time != NULL && start_signal == 1) {high_or_low = (low_time > high_time) ? LOW : HIGH; //高低电平时间比例drv_isdn_interaction(high_or_low); //字节组合函数high_time = low_time = 0; //时间清空}}
}/*** @brief : 字节组合函数** @param bit_value: 传入的位数* @return vd_bool_t*/
static vd_bool_t drv_isdn_interaction(vd_uint8_t bit_value) {vd_uint8_t byte_bit;byte_bit = bit_value;// isdn_sum[bit_num] = bit_value; //存入bitbyte |= byte_bit << (7 - bit_num);bit_num++;if (bit_num == 8) {bit_num = 0; //位数清零log_debug("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r");log_debug("receive byte : %d\n",byte);isdn_sum[byte_num] = byte; //存入字节byte = 0; //字节清零byte_num++; //字节数+1if (byte_num /12 == 1) {start_signal = 0; //起始信号清除protocol_push_queue(PLATFORM_ISDN0, isdn_sum, 12); //往队列里面丢数据memset(&isdn_sum,0,12);byte_num = 0;}}return vd_true;
}