You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
int write_buff_c(char* buff, char c) {
|
|
size_t len = strlen(buff);
|
|
if (len + 1 < BUFF_SIZE) {
|
|
buff[len] = c;
|
|
buff[len + 1] = '\0'; // 문자열의 끝을 나타내는 null 문자를 추가해야 합니다.
|
|
return 1;
|
|
} else {
|
|
Serial.println("Not enough space in buffer! (write c)");
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
int write_buff(char* buff, String str) {
|
|
// check if last characters are not CRLF and append if not
|
|
if (!str.endsWith(CRLF)) {
|
|
str += CRLF;
|
|
}
|
|
|
|
const char* cstr = str.c_str();
|
|
size_t len = strlen(cstr);
|
|
if (strlen(buff) + len < BUFF_SIZE) {
|
|
strcat(buff, cstr);
|
|
numOf485++;
|
|
return 1;
|
|
} else {
|
|
Serial.println("Not enough space in buffer! (write)");
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
int write_buff_first(char* buff, String str) {
|
|
const char* cstr = str.c_str();
|
|
size_t len = strlen(cstr);
|
|
if (strlen(buff) + len < BUFF_SIZE) {
|
|
char temp[BUFF_SIZE];
|
|
strcpy(temp, buff); // copy existing content to temp buffer
|
|
strcpy(buff, cstr); // copy new string to buffer
|
|
strcat(buff, temp); // append old content to buffer
|
|
numOf485++;
|
|
return 1;
|
|
} else {
|
|
Serial.println("Not enough space in buffer! (prepend)");
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
String read_buff(char* buff) {
|
|
char* pos = strstr(buff, CRLF);
|
|
String output = "";
|
|
if (pos != nullptr) {
|
|
size_t len = pos - buff;
|
|
output = String(buff).substring(0, len);
|
|
//output += CRLF;
|
|
|
|
// Shift remaining string to the start
|
|
memmove(buff, pos + 2, strlen(pos + 2) + 1);
|
|
}
|
|
return output;
|
|
} |