|
@@ -449,6 +449,8 @@ int main(int argc, char *argv[]) {
|
|
|
string play;
|
|
|
play.reserve(4096);
|
|
|
|
|
|
+ int zmodem = 0;
|
|
|
+
|
|
|
// int size = 0; // use buffer.size() instead
|
|
|
|
|
|
for (;;) {
|
|
@@ -478,11 +480,17 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
|
I'm thinking something like timeouts 30-50 seconds?
|
|
|
And as we get closer, 15-25 seconds.
|
|
|
+
|
|
|
+ if zmodem, buffer will always be empty -- we won't hold anything.
|
|
|
*/
|
|
|
|
|
|
if (buffer.size() == 0) {
|
|
|
// buffer is empty
|
|
|
- timeout.tv_sec = randrange(10, 20);
|
|
|
+ if (zmodem) {
|
|
|
+ timeout.tv_sec = 5;
|
|
|
+ } else {
|
|
|
+ timeout.tv_sec = randrange(10, 20);
|
|
|
+ };
|
|
|
timeout.tv_usec = 0;
|
|
|
time_idle = 1;
|
|
|
} else {
|
|
@@ -504,7 +512,7 @@ int main(int argc, char *argv[]) {
|
|
|
ZF_LOGI("TIMEOUT");
|
|
|
// This means timeout!
|
|
|
if (time_idle) {
|
|
|
- if (harry_level())
|
|
|
+ if (harry_level() && !zmodem)
|
|
|
harry_idle_event(STDOUT_FILENO);
|
|
|
} else {
|
|
|
ZF_LOGV("TIMEOUT buffer: %s", logrepr(buffer.c_str()));
|
|
@@ -547,48 +555,72 @@ int main(int argc, char *argv[]) {
|
|
|
ZF_LOGV("Read %d bytes", total);
|
|
|
buffer.append(read_buffer, total);
|
|
|
|
|
|
- // ZF_LOGV_MEM(buffer + size, total, "Read %d bytes:", total);
|
|
|
- // size += total;
|
|
|
- // ZF_LOGV_MEM(buffer, size, "Buffer now:");
|
|
|
-
|
|
|
- int pos = buffer.rfind("\r\n");
|
|
|
- // rstrnstr(buffer, size, "\r\n");
|
|
|
- // >= 0) {
|
|
|
- if (pos != string::npos) {
|
|
|
- // found something!
|
|
|
-
|
|
|
- pos += 2;
|
|
|
- // play = buffer.substr() wipes out play's reserve.
|
|
|
- // play = buffer.substr(0, pos);
|
|
|
- play.assign(buffer, 0, pos);
|
|
|
- ZF_LOGI("play %lu size, %lu cap", play.size(), play.capacity());
|
|
|
- // play.copy(buffer.data(), pos);
|
|
|
- //) = buffer.substr(0, pos);
|
|
|
- buffer.erase(0, pos);
|
|
|
-
|
|
|
- mangle(STDOUT_FILENO, play);
|
|
|
-
|
|
|
- // ZF_LOGD_MEM(buffer, pos, "mangle buffer %d bytes:", pos);
|
|
|
- // mangle(STDOUT_FILENO, buffer, pos);
|
|
|
- // memmove(buffer, buffer + pos, size - pos);
|
|
|
- // size -= pos;
|
|
|
- // } else {
|
|
|
- // ZF_LOGV("position of /r/n not found.");
|
|
|
+ if (zmodem) {
|
|
|
+ // Ok, we're zmodem mode -- is it time to exit?
|
|
|
+ int zend = buffer.find("\x1b[0m");
|
|
|
+ if (zend != string::npos)
|
|
|
+ zmodem = 0;
|
|
|
+ zend = buffer.find("\x1b[1;1H");
|
|
|
+ if (zend != string::npos)
|
|
|
+ zmodem = 0;
|
|
|
+ } else {
|
|
|
+ // Should we be in zmodem mode?
|
|
|
+ int zstart = buffer.find("**\x18"
|
|
|
+ "B0");
|
|
|
+ if (zstart != string::npos)
|
|
|
+ zmodem = 1;
|
|
|
}
|
|
|
|
|
|
- // Ok, we failed to find CR+NL. What's the buffer size at?
|
|
|
-
|
|
|
- if (buffer.size() > BSIZE) {
|
|
|
- // Ok, there's something going on, and it doesn't look good
|
|
|
- // unsure if I want to feed this into the console
|
|
|
- // my guess at this point would be zmodem xfer
|
|
|
- ZF_LOGI("Buffer %lu bytes, write only...", buffer.size());
|
|
|
+ if (zmodem) {
|
|
|
+ ZF_LOGI("Buffer %lu bytes, zmodem...", buffer.size());
|
|
|
|
|
|
write(STDOUT_FILENO, buffer.data(), buffer.size());
|
|
|
- console_receive(&console, buffer);
|
|
|
+ // console_receive(&console, buffer);
|
|
|
buffer.clear();
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // ZF_LOGV_MEM(buffer + size, total, "Read %d bytes:", total);
|
|
|
+ // size += total;
|
|
|
+ // ZF_LOGV_MEM(buffer, size, "Buffer now:");
|
|
|
+
|
|
|
+ int pos = buffer.rfind("\r\n");
|
|
|
+ // rstrnstr(buffer, size, "\r\n");
|
|
|
+ // >= 0) {
|
|
|
+ if (pos != string::npos) {
|
|
|
+ // found something!
|
|
|
+
|
|
|
+ pos += 2;
|
|
|
+ // play = buffer.substr() wipes out play's reserve.
|
|
|
+ // play = buffer.substr(0, pos);
|
|
|
+ play.assign(buffer, 0, pos);
|
|
|
+ ZF_LOGI("play %lu size, %lu cap", play.size(), play.capacity());
|
|
|
+ // play.copy(buffer.data(), pos);
|
|
|
+ //) = buffer.substr(0, pos);
|
|
|
+ buffer.erase(0, pos);
|
|
|
+
|
|
|
+ mangle(STDOUT_FILENO, play);
|
|
|
+
|
|
|
+ // ZF_LOGD_MEM(buffer, pos, "mangle buffer %d bytes:", pos);
|
|
|
+ // mangle(STDOUT_FILENO, buffer, pos);
|
|
|
+ // memmove(buffer, buffer + pos, size - pos);
|
|
|
+ // size -= pos;
|
|
|
+ // } else {
|
|
|
+ // ZF_LOGV("position of /r/n not found.");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Ok, we failed to find CR+NL. What's the buffer size at?
|
|
|
+
|
|
|
+ if (buffer.size() > BSIZE) {
|
|
|
+ // Ok, there's something going on, and it doesn't look good
|
|
|
+ // unsure if I want to feed this into the console
|
|
|
+ // my guess at this point would be zmodem xfer
|
|
|
+ ZF_LOGI("Buffer %lu bytes, write only...", buffer.size());
|
|
|
+
|
|
|
+ write(STDOUT_FILENO, buffer.data(), buffer.size());
|
|
|
+ console_receive(&console, buffer);
|
|
|
+ buffer.clear();
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
} else
|
|
|
break;
|
|
|
}
|