pub struct Engine { /* private fields */ }Expand description
The protocol’s state machine (see the module docs).
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(host: &'static str, pacing: Pacing) -> Engine
pub fn new(host: &'static str, pacing: Pacing) -> Engine
An engine with no machine yet, for the host called host, paced
as pacing says.
Sourcepub fn set_answer_recover(&mut self, on: bool)
pub fn set_answer_recover(&mut self, on: bool)
Whether a cold boot’s “Try To Recover Memory?” (48SX, 48GX, 49G)
is answered NO for the user, and the 49G’s “Memory Clear” after it
dismissed (recover.rs): a host that keeps the user’s calculator
(off by default; key scripts and tests answer it themselves).
Sourcepub fn answering_recover(&self) -> bool
pub fn answering_recover(&self) -> bool
An answer to the boot’s question is still pending.
Sourcepub fn set_auto_save(&mut self, on: bool)
pub fn set_auto_save(&mut self, on: bool)
Whether the host keeps states: then the machine’s state comes out
as Output::Save once it changed and settled (off by default).
Sourcepub fn auto_saves(&self) -> u64
pub fn auto_saves(&self) -> u64
Saves handed to the host so far.
Sourcepub fn save_now(&mut self)
pub fn save_now(&mut self)
Hand out the owed save now, without the delay, if the machine has settled (a computing one is not saved: its last settled state is in the store). A host calls it before a boot, and stores what it gives before it reads or clears the slot: a model switch keeps the machine it leaves, a reboot of the same model restores the newest state, and a fresh start deletes the slot after this save, so the old machine never comes back.
Sourcepub fn admit<'a>(&self, msg: &'a Value) -> Result<&'a str>
pub fn admit<'a>(&self, msg: &'a Value) -> Result<&'a str>
The protocol version check and the command’s name, refused while a
send is typing if its Policy says so: what every command
passes first, also those a host serves itself.
Sourcepub fn refusal(&self, cmd: &str) -> Option<Error>
pub fn refusal(&self, cmd: &str) -> Option<Error>
Why cmd is refused now, or None (an unknown name never is):
the page holds the serial port and it is a write or a question to
the server; a send is typing and it is refused_while_typing; a
write runs and it uses the serial port.
Sourcepub fn command(
&mut self,
clock: &dyn Clock,
msg: &Value,
bytes: Option<Vec<u8>>,
reply: Option<u64>,
)
pub fn command( &mut self, clock: &dyn Clock, msg: &Value, bytes: Option<Vec<u8>>, reply: Option<u64>, )
One protocol message. bytes are its bytes field when the host
has them apart from the JSON (the Worker’s rom and state);
without them a state field is base64. With a reply tag the
reply comes out as Output::Reply after the events the command
caused (a send’s when it is done); without one an error comes out
as an error event.
Sourcepub fn answer(
&mut self,
clock: &dyn Clock,
reply: Option<u64>,
result: Result<Value>,
)
pub fn answer( &mut self, clock: &dyn Clock, reply: Option<u64>, result: Result<Value>, )
Answer a command the host served itself: the events so far, then
the reply (or, without a reply tag, an error event for an
error).
Sourcepub fn take_output(&mut self) -> Vec<Output>
pub fn take_output(&mut self) -> Vec<Output>
The replies and events so far, in order.
Sourcepub fn deadline(&self) -> Option<f64>
pub fn deadline(&self) -> Option<f64>
When Engine::timer is due on the host’s clock; None while
only a message can change anything (paused, idle with nothing to
watch).
Sourcepub fn timer(&mut self, clock: &dyn Clock)
pub fn timer(&mut self, clock: &dyn Clock)
The host’s timer fired: run what is due (a send’s turn, a pass, a wake, a look at the memory).
Sourcepub fn input(&mut self, clock: &dyn Clock)
pub fn input(&mut self, clock: &dyn Clock)
Bytes arrived for the machine from outside (the serial bridge): a sleeping CPU first runs the time that passed, then sees when the UART wakes it.
Sourcepub fn serial_open(&self) -> bool
pub fn serial_open(&self) -> bool
The page holds the serial port (serialOpen).
Sourcepub fn transferring(&self) -> bool
pub fn transferring(&self) -> bool
A write through the Kermit server runs (a /v1/memory write, a
server probe): it owns the calculator’s UART, so a host’s own serial
bridge leaves it alone until it ends.
Sourcepub fn cancel_send(&mut self, clock: &dyn Clock, why: &str)
pub fn cancel_send(&mut self, clock: &dyn Clock, why: &str)
Stop the send in progress; its reply is the error why.
Sourcepub fn emulator_mut(&mut self) -> Option<&mut Emulator>
pub fn emulator_mut(&mut self) -> Option<&mut Emulator>
The machine, for what a host does beside the protocol (the serial
bridge); None before a boot.
Sourcepub fn emulator(&self) -> Result<&Emulator>
pub fn emulator(&self) -> Result<&Emulator>
The machine, for the commands a host serves itself.
Sourcepub fn into_emulator(self) -> Option<Emulator>
pub fn into_emulator(self) -> Option<Emulator>
The machine, once the host is done with the engine.
Sourcepub fn start(&mut self, clock: &dyn Clock, emu: Emulator, rom_name: &str)
pub fn start(&mut self, clock: &dyn Clock, emu: Emulator, rom_name: &str)
Start running emu, a machine the host built (and perhaps ran)
from the ROM file rom_name.
Sourcepub fn poke(
&mut self,
clock: &dyn Clock,
address: u32,
nibbles: &[u8],
) -> Result<()>
pub fn poke( &mut self, clock: &dyn Clock, address: u32, nibbles: &[u8], ) -> Result<()>
Write nibbles from address on as CPU writes would (poke):
the display may show it, the user memory may have changed, a
sleeping CPU may see it.
Sourcepub fn exclusive<T>(
&mut self,
clock: &dyn Clock,
f: impl FnOnce(Machine) -> (Machine, Result<T, RunError>),
) -> Result<T>
pub fn exclusive<T>( &mut self, clock: &dyn Clock, f: impl FnOnce(Machine) -> (Machine, Result<T, RunError>), ) -> Result<T>
Run f on the machine outside the pacing, as fast as the host can
(a native key script), with every key released first; then follow
the wall clock again from where it left the machine. f gets the
machine and gives it back with its result. Refused during a send,
as keyScript.
Sourcepub fn boot(
&mut self,
clock: &dyn Clock,
model: &str,
rom: &[u8],
rom_name: &str,
) -> Result<Booted>
pub fn boot( &mut self, clock: &dyn Clock, model: &str, rom: &[u8], rom_name: &str, ) -> Result<Booted>
Build model (a preference: a ROM that only fits another model
boots that one) from rom and run it; the machine before keeps
running if this one cannot be built.
Sourcepub fn boot_restoring(
&mut self,
clock: &dyn Clock,
model: &str,
rom: &[u8],
rom_name: &str,
kept: Option<&[u8]>,
) -> Result<Booted>
pub fn boot_restoring( &mut self, clock: &dyn Clock, model: &str, rom: &[u8], rom_name: &str, kept: Option<&[u8]>, ) -> Result<Booted>
Engine::boot, then restore kept, the state the host kept for
this model, before the machine runs a cycle: the calculator is as
it was, with no “Try To Recover Memory?”. A state that does not
load (another ROM, another model, an older format) leaves the cold
boot, and restore_error says why. The machine it replaces is not
saved here: the host calls Engine::save_now and stores that
save before it reads or clears the slot, so the slot it reads is
the newest and a fresh start’s stays empty. An owed save left now
is dropped.
Sourcepub fn save_state(&self) -> Result<Vec<u8>>
pub fn save_state(&self) -> Result<Vec<u8>>
The whole machine state (saveState).
Sourcepub fn load_state(&mut self, clock: &dyn Clock, state: &[u8]) -> Result<()>
pub fn load_state(&mut self, clock: &dyn Clock, state: &[u8]) -> Result<()>
Restore a saved state of the same model and ROM (loadState);
the host’s queued and held keys go with the old machine
(Emulator::load_state). A state that does not load changes
nothing, the keys held included.