PuTTY 收到空字符 '\0' 时的默认行为

PuTTY 收到空字符 '\0' 时的默认行为

我正在研究终端输出中有关接收空字符“\0”的一些意外行为。我发送了一个字符串,我期望它包含 2 个 \0,但这并未显示在 PuTTY 上。

根据这个问题这意味着 PuTTY 在正常情况下不会发送空值。然而,这个问题已经存在近 10 年了,我认为 PuTTY 在此期间已经收到更新。

我已经调查过PuTTY 用户手册并且主要找到了有关 PuTTY 面板的文档以及大量有关错误消息和连接性的文档。第三.3 章讨论了“改变你的字符集配置”,但主要涉及非拉丁字母,并且链接到第四章 第 10 节,即翻译面板。

我的问题很简单,当 PuTTY 需要接收 \0 字符时,它通常会做什么?它没有接收到吗?它是否接收到字符但未显示在终端中?

如果需要更多信息,请告诉我。

用于将数据发送到PuTTY的代码是C语言的,在STM32板上:

static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceFS);

  memset (buffer, '\0', 64);  // clear the buffer
  uint8_t len = (uint8_t)*Len;  //Converts Len as uint32_t to len as uint8_t
  memcpy(buffer, Buf, len);  // copy the data to the buffer
  memset(Buf, '\0', len);   // clear the Buf also
  //Code used to send message back

  /*In the full version, there will be another function outside of this file.
   * The buffer will be processed and a proper message will be sent.
   * Check that other file to see how it gets processed when we eventually implement it.
   */

  uint8_t transmit_message[64] = "TOWST_FIRMV_REEEEEEE_27\r\n"; //Do we have \r\n?
  //CDC_Transmit_FS(transmit_message, sizeof(transmit_message));
  //HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_10);
  //message_Received(buffer, len);
  process_Message(buffer, len);
  return (USBD_OK);
  /* USER CODE END 6 */
}

void process_Message(uint8_t* message, uint16_t Len){
    HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_10);
    uint8_t* inputCmd[5];
    uint8_t* inputMessage[8];
    uint8_t outputCmd[5];
    uint8_t outputData[8];

//  strcpy((char*) inputCmd, (const char*)message + COMMAND_CHAR);
//  strcpy((char*) inputMessage, (const char*)message + DATA_CHAR);
    if (strcmp(inputCmd, "FIRMV") == 0){
        memcpy(outputCmd, "FIRMV", COMMAND_LENGTH);
        memcpy(outputData, "01050A00", DATA_LENGTH);
    }
    else{
        memcpy(outputCmd, "REEEE", COMMAND_LENGTH);
        memcpy(outputData, "99999999", DATA_LENGTH);
    }

//  message_Received(message, Len);
    send_Message(outputCmd, outputData);
}

void send_Message(uint8_t* cmd, uint8_t* data){
    uint8_t outputMessage[25] = "TOWST_";  //Size of array is for future uses.
    strncpy((char*) outputMessage + 8, "FIRMV", 5);
    CDC_Transmit_FS(outputMessage, sizeof(outputMessage));
}

    //Expected output: 'TOWST_\0\0FIRMV' based on this post, which per my understanding suggests that strncpy will fill in unfilled memory with null chars. https://aticleworld.com/how-to-use-strncpy-and-how-to-write-your-own-strncpy 


相关内容