Injector Components - How to create your own
Posted: Fri Aug 23, 2013 5:12 pm
An Injector component is a component that works with a communications component (e.g. RS232, SPI, I2C) and adds a simulation only method to parse the incoming data to provide meaningful outgoing data.
An example of this is the GPS Injector which uses it's properties to generate a recurring stream of bytes which can then be parsed using the GPS component or any other injector enabled component such as RS232.
Another example is the AT Injector which basically waits for an incoming carriage return and then spits out an approximation of what the real return string would be.
Input: AT\n
Output: AT\nOK\n
Each injector deals only in bytes so the comms component makes what it will of this.
I have started to put together a DS1307 injector which provides the functionality of a real time clock and a few bytes of RAM.
Here is the breakdown of the component so you can see what it is doing and then hopefully be able to edit and regenerate to allow any type of component injector to be made.
Main Macros.
Main - Component test routine, this code will not make it into the exported component so use this place as a space to test out the component before export.
TxByte - Stores the incoming byte into the incoming circular buffer. This macro should detect an event to then parse the incoming data as a command. In the AT component we run the parse command macro when we receive a carriage return. In the example we run the parse macro when the "Stop" bytes have been received.
ParseCommand - Runs through the data in the incoming circular buffer and calls the AddReturn macros to populate any data into the outgoing circular buffer.
AddReturnByte - Adds a single byte into the outgoing circular buffer.
AddReturnString - As above but with an array of bytes.
RxByte - Pulls out the oldest value from the outgoing circular buffer so the comms component can collect it.
Consoles.
The console data is automatically populated via the TxByte and RxByte macros so this should be mostly taken care of for you. The Ev_Initialise macro calls the InitialiseInjector macro which sets up the console window and handle. The only thing to look out for is the console mode, the AT uses a text mode and the DS1307 uses a byte mode to allow the contents of the RAM to be easily available. The Communications component provides the high level console so the injector console can be a bit lower level if need be.
Injector Interface
To get new injectors to appear in the Injector selection property on the comms components you need to make sure that the component name in the settings manager is set to "InjectorXXXX" where XXXX is the customisable name of the injector. When creating a new injector component you will need to assign a new component GUID by going into the advanced tab of the setting manager and then clicking Edit and New.
Confused yet? Look at the examples below, they show the source for the DS1307 component and the AT component. These are really an advanced feature and it is not our intent that everyone should be able to write these, however they should be usable by pretty much anyone. It would be great if we can build up a library of supported simulation devices for the release and then beyond.
Also there are bound to be bugs especially in the DS1307 component which I have rushed a bit to get it out. Hopefully we can work on the these and get any major bugs or headaches ironed out.
I suggest anyone attempting this first goes through the component creation example on the Wiki as these go into a lot more detail then is covered here.
Exported Component Updates (since patchset 2) Injector Component Source Files
An example of this is the GPS Injector which uses it's properties to generate a recurring stream of bytes which can then be parsed using the GPS component or any other injector enabled component such as RS232.
Another example is the AT Injector which basically waits for an incoming carriage return and then spits out an approximation of what the real return string would be.
Input: AT\n
Output: AT\nOK\n
Each injector deals only in bytes so the comms component makes what it will of this.
I have started to put together a DS1307 injector which provides the functionality of a real time clock and a few bytes of RAM.
Here is the breakdown of the component so you can see what it is doing and then hopefully be able to edit and regenerate to allow any type of component injector to be made.
Main Macros.
Main - Component test routine, this code will not make it into the exported component so use this place as a space to test out the component before export.
TxByte - Stores the incoming byte into the incoming circular buffer. This macro should detect an event to then parse the incoming data as a command. In the AT component we run the parse command macro when we receive a carriage return. In the example we run the parse macro when the "Stop" bytes have been received.
ParseCommand - Runs through the data in the incoming circular buffer and calls the AddReturn macros to populate any data into the outgoing circular buffer.
AddReturnByte - Adds a single byte into the outgoing circular buffer.
AddReturnString - As above but with an array of bytes.
RxByte - Pulls out the oldest value from the outgoing circular buffer so the comms component can collect it.
Consoles.
The console data is automatically populated via the TxByte and RxByte macros so this should be mostly taken care of for you. The Ev_Initialise macro calls the InitialiseInjector macro which sets up the console window and handle. The only thing to look out for is the console mode, the AT uses a text mode and the DS1307 uses a byte mode to allow the contents of the RAM to be easily available. The Communications component provides the high level console so the injector console can be a bit lower level if need be.
Injector Interface
To get new injectors to appear in the Injector selection property on the comms components you need to make sure that the component name in the settings manager is set to "InjectorXXXX" where XXXX is the customisable name of the injector. When creating a new injector component you will need to assign a new component GUID by going into the advanced tab of the setting manager and then clicking Edit and New.
Confused yet? Look at the examples below, they show the source for the DS1307 component and the AT component. These are really an advanced feature and it is not our intent that everyone should be able to write these, however they should be usable by pretty much anyone. It would be great if we can build up a library of supported simulation devices for the release and then beyond.
Also there are bound to be bugs especially in the DS1307 component which I have rushed a bit to get it out. Hopefully we can work on the these and get any major bugs or headaches ironed out.
I suggest anyone attempting this first goes through the component creation example on the Wiki as these go into a lot more detail then is covered here.
Exported Component Updates (since patchset 2) Injector Component Source Files