jcs
/subtext
/amendments
/202
serial: Add config setting for port speed
jcs made amendment 202 over 2 years ago
--- db.c Thu Jul 7 17:30:23 2022
+++ db.c Wed Jul 13 10:14:30 2022
@@ -48,6 +48,9 @@ struct struct_field config_fields[] = {
{ "Modem Port", CONFIG_TYPE_SHORT,
offsetof(struct config, modem_port),
0, 2 },
+ { "Modem Port Speed", CONFIG_TYPE_LONG,
+ offsetof(struct config, modem_speed),
+ 300, 115200 },
{ "Modem Init String", CONFIG_TYPE_STRING,
offsetof(struct config, modem_init),
1, member_size(struct config, modem_init) },
@@ -253,6 +256,7 @@ db_migrate(struct db *tdb, short is_new)
sprintf(tdb->config.hostname, "bbs.example.com");
tdb->config.telnet_port = 23;
tdb->config.modem_port = 0;
+ tdb->config.modem_speed = 19200;
sprintf(tdb->config.modem_init, "ATQ0V1S0=2");
tdb->config.max_idle_minutes = 5;
tdb->config.max_login_seconds = 90;
@@ -356,7 +360,19 @@ db_migrate(struct db *tdb, short is_new)
sizeof(new_config));
break;
}
+ case 6: {
+ /* 6->7, added modem_speed */
+ struct config new_config = { 0 };
+
+ bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config,
+ sizeof(new_config));
+ new_config.modem_speed = 19200;
+
+ bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config,
+ sizeof(new_config));
+ break;
}
+ }
ver++;
}
@@ -601,7 +617,7 @@ db_cache_folders(struct db *tdb)
memcpy(folder_dir, tdb->folders[n].path, sizeof(folder_dir));
CtoPstr(folder_dir);
if (!FIsDir(folder_dir))
- panic("Folder %ld path %s does not exist",
+ warn("Folder %ld path \"%s\" does not exist",
tdb->folders[n].id, tdb->folders[n].path);
}
}
--- db.h Thu Jun 30 13:22:19 2022
+++ db.h Wed Jul 13 09:25:38 2022
@@ -23,7 +23,7 @@
#define DB_TYPE 'STDB'
-#define DB_CUR_VERS 6
+#define DB_CUR_VERS 7
#define DB_TRUE 0x100
#define DB_FALSE 0x000
@@ -76,6 +76,7 @@ struct config {
short blanker_idle_seconds;
short blanker_runtime_seconds;
unsigned long trusted_proxy_ip;
+ unsigned long modem_speed;
};
extern struct struct_field config_fields[];
--- serial.c Tue Jun 21 13:37:54 2022
+++ serial.c Wed Jul 13 10:04:04 2022
@@ -36,6 +36,18 @@
#include "subtext.h"
#include "util.h"
+/* more speeds defined in Inside Macintosh: Serial Driver, may not work */
+#ifndef baud14400
+#define baud14400 6
+#endif
+#ifndef baud28800
+#define baud28800 2
+#endif
+#ifndef baud38400
+#define baud38400 1
+#endif
+
+
/*
* The number of seconds after a RING that we'll allow a connection to
* establish and a session to start, before we hang up and reset the
@@ -80,6 +92,7 @@ serial_init(void)
Str32 in_port = "\p.AIn";
Str32 out_port = "\p.AOut";
SerShk flags = { 0 };
+ long baud;
short error;
if (db->config.modem_port == 0)
@@ -91,8 +104,51 @@ serial_init(void)
out_port[2] = 'B';
}
- logger_printf(logger, "[modem] Initializing %s port",
- (db->config.modem_port == 2 ? "printer" : "modem"));
+ switch (db->config.modem_speed) {
+ case 300:
+ baud = baud300;
+ break;
+ case 600:
+ baud = baud600;
+ break;
+ case 1200:
+ baud = baud1200;
+ break;
+ case 2400:
+ baud = baud2400;
+ break;
+ case 4800:
+ baud = baud4800;
+ break;
+ case 9600:
+ baud = baud9600;
+ break;
+ case 14400:
+ baud = baud14400;
+ break;
+ case 19200:
+ baud = baud19200;
+ break;
+ case 28800:
+ baud = baud28800;
+ break;
+ case 38400:
+ baud = baud38400;
+ break;
+ case 57600:
+ baud = baud57600;
+ break;
+ default:
+ logger_printf(logger,
+ "[modem] Unsupported port speed %ld, using 19200",
+ db->config.modem_speed);
+ db->config.modem_speed = 19200;
+ baud = baud19200;
+ }
+
+ logger_printf(logger, "[modem] Initializing %s port at %ld",
+ (db->config.modem_port == 2 ? "printer" : "modem"),
+ db->config.modem_speed);
if ((error = OpenDriver(out_port, &serial_out_refnum)) != 0)
panic("OpenDriver(%s) failed: %d", PtoCstr(out_port), error);
@@ -101,10 +157,10 @@ serial_init(void)
/* 8N1 */
if ((error = SerReset(serial_out_refnum,
- baud19200 + data8 + noParity + stop10)) != 0)
+ baud + data8 + noParity + stop10)) != 0)
panic("SerReset(out) failed: %d", error);
if ((error = SerReset(serial_in_refnum,
- baud19200 + data8 + noParity + stop10)) != 0)
+ baud + data8 + noParity + stop10)) != 0)
panic("SerReset(in) failed: %d", error);
SerSetBuf(serial_in_refnum, (Ptr)&serial_input_internal_buf,