// See the License for the specific language governing permissions and
// limitations under the License.
//! Handlers for UART connections to/from nodes
-use std::ops::Index;
+use std::{ops::Index, path::PathBuf};
use super::serial_handler::Handler;
use crate::hal::NodeId;
impl SerialConnections {
pub fn new() -> Self {
- let paths = ["/dev/ttyS2", "/dev/ttyS1", "/dev/ttyS4", "/dev/ttyS5"];
+ let paths = get_serial_devices();
let collection = paths.iter().enumerate().map(|(i, path)| {
let mut handler = Handler::new(
&self.handlers[index as usize]
}
}
+
+/// This is a quick and dirty way to detect which serial devices to load. At some point in time the
+/// mapping of ttySx devices to the uart ports changed to align them numerically with the nodes
+/// switched the numbering of
+fn get_serial_devices() -> [&'static str; 4] {
+ let device_type = PathBuf::from("/sys/class/tty/ttyS3/device/of_node/device_type");
+ if matches!(std::fs::read_to_string(device_type), Ok(str) if str == "uart3") {
+ ["/dev/ttyS2", "/dev/ttyS1", "/dev/ttyS4", "/dev/ttyS5"]
+ } else {
+ ["/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3", "/dev/ttyS4"]
+ }
+}