diff --git a/build_all.sh b/build_all.sh index c281820..10f52d1 100755 --- a/build_all.sh +++ b/build_all.sh @@ -49,7 +49,7 @@ else echo "--- build boost, target host: ${TARGET_HOST} ----" fi -#${BASE_DIR}/build_boost.sh +${BASE_DIR}/build_boost.sh if [ "rk3576" = ${TARGET_HOST} ];then echo "--- cross build vsomeip, target host: ${TARGET_HOST} ----" @@ -70,7 +70,7 @@ else echo "--- build vsomeip, target host: ${TARGET_HOST} ----" fi -#${BASE_DIR}/build_vsomeip.sh +${BASE_DIR}/build_vsomeip.sh #${BASE_DIR}/build_example.sh ${BASE_DIR}/build_soa_server.sh diff --git a/source/soa_server/spi_server.cpp b/source/soa_server/spi_server.cpp index 6349059..ad97f54 100644 --- a/source/soa_server/spi_server.cpp +++ b/source/soa_server/spi_server.cpp @@ -75,8 +75,10 @@ void my_spi_server_thread_func(void* arg) { uint8_t buf[FRAME_LEN]; + uint8_t last_buf[FRAME_LEN] = {0}; int fd, ret; unsigned int frame_count = 0; + int data_changed = 0; /* 注册退出信号 */ signal(SIGINT, sigint_handler); @@ -137,17 +139,29 @@ void my_spi_server_thread_func(void* arg) { /* 6. 循环接收数据 */ while (keep_running) { memset(buf, 0, FRAME_LEN); - ret = read(fd, buf, FRAME_LEN); - if (ret < 0) { - perror("read"); - break; - } else if (ret == 0) { - /* 非阻塞模式可能返回0,但这里用了阻塞模式,一般不会出现 */ - //continue; - } - + struct spi_ioc_transfer tr = { + .tx_buf = (unsigned long)NULL, + .rx_buf = (unsigned long)buf, + .len = FRAME_LEN, + .speed_hz = SPI_SPEED, + .bits_per_word = SPI_BITS, + }; + ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); + if (ret < 0) { + perror("spi transfer"); + break; + } + ret = FRAME_LEN; /* transfer 成功则返回 FRAME_LEN */ + frame_count++; + + /* 判断数据是否有变化 */ + data_changed = (memcmp(last_buf, buf, FRAME_LEN) != 0); + if (!data_changed) + continue; + memcpy(last_buf, buf, FRAME_LEN); + printf("\n========== Frame #%u (%d bytes) ==========\n", frame_count, ret); printf("HEX : "); for (int i = 0; i < ret; i++)