TCAS has solved this for airplanes. It wouldn't take much to modify the system for trains so that, in the least, it notifies when an unexpected train is nearby. A little more logic could allow it to verify which track each train is on.