
Estoy investigando algún comportamiento inesperado en la salida de una terminal con respecto a la recepción de un carácter nulo '\0'. Estoy enviando una cadena que espero que contenga 2 \0, pero no se muestra en PuTTY.
De acuerdo aesta preguntase da a entender que PuTTY no envía datos nulos en circunstancias normales. Sin embargo, esa pregunta se acerca a los 10 años y supongo que PuTTY recibió actualizaciones durante ese período.
He mirado en elManual de usuario de PuTTYy he encontrado principalmente documentación sobre los paneles de PuTTY y mucha sobre mensajes de error y conectividad.Capítulo 3.3analiza "Alteración de la configuración del juego de caracteres", pero se relaciona principalmente con alfabetos no latinos y enlaza conCapítulo 4.10, que es el panel de traducción.
Mi pregunta es simplemente,¿Qué hace normalmente PuTTY cuando necesita recibir un carácter \0? ¿No lo recibe? ¿Recibe el carácter pero no se muestra en la terminal?
Por favor, avíseme si se requiere más información.
El código utilizado para enviar datos a PuTTY está en C, en una placa 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