Hi,
I am using Teensy 4.1 for a UDP networking project, down bellow is an UDP send function appended by me.
My goal is to combine two integer values with a space between them and send it via UDP.
Variable 'line' is from a UDP template, I dont want to/can not mess with it, otherwise my UDP part could collapse, I just it as a given that 'line' is a string type
I have been struggling for a long time to do all the sequence I have described above. In my last attempt I tired to divide integers into digits and assign them as chars, and using indexing assign these to a string elements. However, my compiler does not give me any errors, my UDP receiver receives empty packets, and my Serial.println(line) does not show me anything at all. It seems my 'line' variable disappears. Any ideas on converting two integers to a continuous string? P.S Chanel and Chanel_value global variables are tested, the carry right values.
static void sendLine() {
static String line;
for (int i = 0; i<4096; i++){
line[0] = char((Chanel[i]/1000)%10);
line[1] = char((Chanel[i]/100)%10);
line[2] = char((Chanel[i]/10)%10);
line[3] = char(Chanel[i]%10);
line[4] = ' ';
line[5] = char((Chanel_value[i]/1000000)%10);
line[6] = char((Chanel_value[i]/100000)%10);
line[7] = char((Chanel_value[i]/10000)%10);
line[8] = char((Chanel_value[i]/1000)%10);
line[9] = char((Chanel_value[i]/100)%10);
line[10] = char((Chanel_value[i]/10)%10);
line[11] = char(Chanel_value[i]%10);
Serial.println(line);
if (!udp.send({10, 10, 16, 110}, kPort,
reinterpret_cast<const uint8_t *>(line.c_str()),
line.length())) {
printf("[Error sending]\r\n");
}
printPrompt();
delayMicroseconds(10);
}
}