#include "Key.h" /* ---------------------------------------------------------------------------- * @breif:发送按键信息给从机 * @input:NONE * @retval:NONE */ void Send_Key_Inf(void) { uint16_t crc16=0; //校验码 if(sending_flag[USART1_Locat] == 0) { //没有报文正在发送 if(Dealwith.Key1_REG != 0 || Dealwith.Key2_REG != 0) { //有按键按下 Txbuf[0] = SLAVE_ADDRESS; //装置地址 Txbuf[1] = MOD_WRITE_M_REGISTER; Txbuf[2] = (uint8_t)(ADR_KEY_START>>8); Txbuf[3] = (uint8_t)(ADR_KEY_START); Txbuf[4] = 0x00; Txbuf[5] = 0x02; Txbuf[6] = 0x04; Txbuf[7] = (uint8_t)(Dealwith.Key1_REG>>8); Txbuf[8] = (uint8_t)(Dealwith.Key1_REG); Txbuf[9] = (uint8_t)(Dealwith.Key2_REG>>8); Txbuf[10] = (uint8_t)(Dealwith.Key2_REG); crc16 = CRC16(Txbuf,11); Txbuf[11] = (uint8_t)(crc16); Txbuf[12] = (uint8_t)(crc16>>8); Txlen = 13; //发送数据 DMA_Usart1_Send(Txbuf,Txlen); } } }
时间: 2023-10-23 11:57:40 浏览: 104
这段代码是一个发送按键信息给从机的函数。根据代码的逻辑,当有按键按下时,将会发送相应的按键信息给从机。
函数中的变量`Txbuf`是用来存储待发送的数据帧的缓冲区。首先,函数会设置装置地址、功能码、起始地址和寄存器数量等信息,然后将按键值存储在`Txbuf`中相应的位置。
接下来,函数使用CRC16校验算法计算校验码,并将校验码存储在`Txbuf`的最后两个字节中。最后,通过DMA方式将数据发送出去。
请注意,此处的代码仅为发送部分的逻辑,整个通信过程还需要接收从机的响应并进行相应的处理。如果您需要完整的通信过程代码,还需要实现接收部分的逻辑。
如果您对具体的代码实现有任何疑问,请随时提问。
相关问题
jwt-cpp/jwt.h
jwt-cpp/jwt.h是一个用于创建和验证JSON Web令牌的C++头文件。它是Thalhammer/jwt-cpp库的一部分。该库提供了一组功能强大的工具,用于处理JWT(JSON Web Token)。
以下是jwt-cpp/jwt.h的一些主要特性和用法示例:
1. 创建JWT令牌:
```cpp
#include <jwt-cpp/jwt.h>
jwt::builder jwtBuilder;
jwtBuilder.set_issuer("example.com")
.set_subject("user123")
.set_expires_at(std::chrono::system_clock::now() + std::chrono::minutes{5})
.set_payload_claim("custom_claim", "custom_value");
std::string token = jwtBuilder.sign(jwt::algorithm::hs256{"secret_key"});
```
2. 验证JWT令牌:
```cpp
#include <jwt-cpp/jwt.h>
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMTIzIiwiaXNzIjoiZXhhbXBsZS5jb20iLCJleHAiOjE2MzIwMzQwMzAsImN1c3RvbV9jbGFpbSI6ImN1c3RvbV92YWx1ZSJ9.2X0Yzv8Xz7z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3z4z3
json-c/json_util.h
Sorry, as an AI language model, I am not able to provide an opinion on code or code libraries. However, I can provide you with information on what the json-c/json_util.h header file is and what it does.
The json-c/json_util.h header file is a part of the json-c library, which is a C library for JSON (JavaScript Object Notation) parsing and generation. The json_util.h header file provides utility functions for working with JSON data, such as functions for creating, deleting, and manipulating JSON objects and arrays.
Some of the functions provided by the json_util.h header file include:
- json_object *json_object_new_object(): Creates a new JSON object.
- void json_object_object_add(json_object *obj, const char *key, json_object *val): Adds a key-value pair to a JSON object.
- void json_object_array_add(json_object *array, json_object *val): Adds a value to a JSON array.
- json_object *json_object_object_get(json_object *obj, const char *key): Gets the value associated with a key in a JSON object.
- const char *json_object_get_string(json_object *obj): Gets the string value of a JSON object.
- int json_object_array_length(json_object *array): Gets the length of a JSON array.
Overall, the json_util.h header file provides a set of convenient functions for working with JSON data in C.
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)