Package jmri.jmrix.loconet.soundloader
Class LoaderEngine
- java.lang.Object
-
- jmri.jmrix.loconet.soundloader.LoaderEngine
-
public class LoaderEngine extends java.lang.Object
Controls the actual LocoNet transfers to download sounds into a Digitrax SFX decoder.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
LoaderEngine.DelayException
-
Field Summary
Fields Modifier and Type Field Description (package private) static int
CMD_ADD
(package private) static int
CMD_START
(package private) LnTrafficController
controller
(package private) LocoNetSystemConnectionMemo
memo
(package private) static int
SENDDATASIZE
(package private) static int
SENDPAGESIZE
(package private) SpjFile
spjFile
(package private) static int
TYPE_SDF
(package private) static int
TYPE_WAV
-
Constructor Summary
Constructors Constructor Description LoaderEngine(LocoNetSystemConnectionMemo memo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
(package private) LocoNetMessage
getEraseMessage()
Get a message to erase the non-volatile sound memory(package private) LocoNetMessage
getExitMessage()
Get a message to exit the download process(package private) LocoNetMessage
getInitMessage()
Get a message to initialize the load sequence(package private) LocoNetMessage
getSendDataMessage(int type, int handle, byte[] contents)
Get a message to tell the PR2 to store length bytes of data (following)(package private) LocoNetMessage
getStartDataMessage(int type, int handle, int length)
Get a message to start the download of data(package private) void
initController()
(package private) LocoNetMessage
initTransfer(int type, int handle, java.lang.String name, byte[] contents)
Start a sequence to download a specific type of data.LocoNetMessage
nextTransfer()
Get the next message for an ongoing WAV download.void
notify(java.lang.String message)
Notify of status of download.void
protectedWait(int millis)
Provide a simple object wait.void
runDownload(SpjFile file)
Send the complete sequence to download to a decoder.(package private) void
sendAllWAV()
void
sendOneWav(int index)
(package private) void
sendSDF()
(package private) void
throttleOutbound(LocoNetMessage m)
Delay to prevent too much data being sent down.
-
-
-
Field Detail
-
CMD_START
static final int CMD_START
- See Also:
- Constant Field Values
-
CMD_ADD
static final int CMD_ADD
- See Also:
- Constant Field Values
-
TYPE_SDF
static final int TYPE_SDF
- See Also:
- Constant Field Values
-
TYPE_WAV
static final int TYPE_WAV
- See Also:
- Constant Field Values
-
SENDPAGESIZE
static final int SENDPAGESIZE
- See Also:
- Constant Field Values
-
SENDDATASIZE
static final int SENDDATASIZE
- See Also:
- Constant Field Values
-
controller
LnTrafficController controller
-
-
Constructor Detail
-
LoaderEngine
public LoaderEngine(LocoNetSystemConnectionMemo memo)
-
-
Method Detail
-
runDownload
public void runDownload(SpjFile file)
Send the complete sequence to download to a decoder.Intended to be run in a separate thread. Uses "notify" method for status updates; overload that to redirect the messages.
- Parameters:
file
- the spjfile to be used.
-
sendSDF
void sendSDF() throws LoaderEngine.DelayException
- Throws:
LoaderEngine.DelayException
-
sendAllWAV
void sendAllWAV() throws LoaderEngine.DelayException
- Throws:
LoaderEngine.DelayException
-
sendOneWav
public void sendOneWav(int index) throws LoaderEngine.DelayException
- Throws:
LoaderEngine.DelayException
-
notify
public void notify(java.lang.String message)
Notify of status of download.This implementation doesn't do much, but this is provided as a separate method to allow easy overloading.
- Parameters:
message
- string form of message.
-
throttleOutbound
void throttleOutbound(LocoNetMessage m) throws LoaderEngine.DelayException
Delay to prevent too much data being sent down. Works with the controller to ensure that too much data doesn't back up.- Parameters:
m
- Throttle message to send- Throws:
LoaderEngine.DelayException
- if too much time elapsed before send possible
-
protectedWait
public void protectedWait(int millis)
Provide a simple object wait.This handles interrupts, synchronization, etc.
- Parameters:
millis
- milliseconds to wait.
-
initTransfer
LocoNetMessage initTransfer(int type, int handle, java.lang.String name, byte[] contents)
Start a sequence to download a specific type of data. This returns the message to start the process. You then loop calling nextWavTransfer() until it says it's complete.- Parameters:
type
- Either TYPE_SDF or TYPE_WAV for the data typehandle
- Handle number for the following dataname
- Name of the transfercontents
- Data to download- Returns:
- Prepared message
-
nextTransfer
public LocoNetMessage nextTransfer()
Get the next message for an ongoing WAV download.You loop calling nextWavTransfer() until it says it's complete by returning null.
- Returns:
- message to send.
-
getStartDataMessage
LocoNetMessage getStartDataMessage(int type, int handle, int length)
Get a message to start the download of data- Parameters:
type
- Either TYPE_SDF or TYPE_WAV for the data typehandle
- Handle number for the following datalength
- Total length of the WAV data to load- Returns:
- Prepared message
-
getSendDataMessage
LocoNetMessage getSendDataMessage(int type, int handle, byte[] contents)
Get a message to tell the PR2 to store length bytes of data (following)- Parameters:
type
- Either TYPE_SDF or TYPE_WAV for the data typehandle
- Handle number for the following datacontents
- Data to download- Returns:
- Prepared message
-
getEraseMessage
LocoNetMessage getEraseMessage()
Get a message to erase the non-volatile sound memory- Returns:
- Prepared message
-
getInitMessage
LocoNetMessage getInitMessage()
Get a message to initialize the load sequence- Returns:
- Prepared message
-
getExitMessage
LocoNetMessage getExitMessage()
Get a message to exit the download process- Returns:
- Prepared message
-
initController
void initController()
-
dispose
public void dispose()
-
-