Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 34.65 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /***********************************************************************************************
  2.  * Main forms program for mannequin-DIS translator program.
  3.  * Author: Josh Estes
  4.  * Usage: read data from a mannequin, translate data to DIS format, broadcast DIS data to other
  5.  *        simulators on the network.
  6.  **********************************************************************************************/
  7.  
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Text;
  14. using System.Windows.Forms;
  15. using LaerdalSimulatorAPI;
  16. using System.Net;
  17. using System.Net.Sockets;
  18. using System.Threading;
  19. using System.Timers;
  20.  
  21.  
  22. namespace SimpleWinFormsDemo
  23. {
  24.     public partial class MainForm : Form, INotifyPropertyChanged
  25.     {
  26.         // The object which will be used for communication with the manikin
  27.         IManikin manikin;
  28.  
  29.         /// The event that happens each time a property changes
  30.         public event PropertyChangedEventHandler PropertyChanged;
  31.  
  32.         // A manikin parameter which will represent the state of the pulse oximeter.
  33.         IParameterAppValue<int> pulseOximeter;
  34.         IParameterModelDouble heartRate;
  35.         IParameterModelDouble overrideHeartRate;
  36.         IParameterModelDouble PAPsystolic;
  37.         IParameterModelDouble overridePAPSystolic;
  38.  
  39.         // Parameters used for pausing and starting the session
  40.         IParameterAppEventBool pauseEvent;
  41.         IParameterAppEventBool startEvent;
  42.         //Timer parameterUpdateTimer;
  43.  
  44.         byte[] data, bytes;
  45.         UdpClient server;
  46.         IPEndPoint sender;
  47.  
  48.         //  hasControl defines whether or not the simulation has control of the entity
  49.         bool hasControl;
  50.  
  51.         // Starts the Reader program
  52.         Reader readingObj;
  53.         // Starts the Writer program
  54.         Writer w;
  55.  
  56.         UInt32 request = 0;
  57.  
  58.         /********************************************************************************************
  59.          * This method constructs the main window and initializes all of the gui components.  It also
  60.          * creates the UDP network and passes it on to the writer thread.  So we can write from this
  61.          * thread and the writer thread.
  62.          ********************************************************************************************/
  63.         public MainForm(IManikin manikin)
  64.         {
  65.             this.manikin = manikin;
  66.  
  67.             InitializeComponent();
  68.  
  69.             /***************************************************************************************
  70.              * This values are the default values for the Low Fidelity Variable Paramter (VP)
  71.              * record. All of these are enumerated lists.  Below is the given all the options
  72.              * and which is the initialized value.
  73.              *
  74.              * Weight by Age (weightList) is 3-bit enumeration with
  75.              * Field Value     Weight by Age
  76.              *     0           Not Specified
  77.              *     1           Underweight
  78.              *     2           Normal  *** Initial Value ***
  79.              *     3           Overweight
  80.              *     4           Obese
  81.              *     5           Morbidly Obese
  82.              *     6           Other
  83.              **************************************************************************************/
  84.             weightList.SelectedIndex = 2;
  85.             /***************************************************************************************
  86.              * Sex (sexList) is 2-bit enumeration with
  87.              * Field Value     Sex
  88.              *     0           Not Specified
  89.              *     1           Male     *** Initial Value ***
  90.              *     2           Female  
  91.              *     3           Indeterminate
  92.              **************************************************************************************/
  93.             sexList.SelectedIndex = 1;
  94.             /***************************************************************************************
  95.              * Consciousness (conList) is 3-bit enumeration with
  96.              * Field Value     Consciousness
  97.              *     0           Not Specified
  98.              *     1           Alert  *** Initial Value ***
  99.              *     2           Confused  
  100.              *     3           In-and-Out
  101.              *     4           Unconscious
  102.              **************************************************************************************/
  103.             conList.SelectedIndex = 1;
  104.             /***************************************************************************************
  105.              * Chest Rise (chestList) is 2-bit enumeration with
  106.              * Field Value     Chest Rise  
  107.              *     0           Not Specified
  108.              *     1           Normal  *** Initial Value ***
  109.              *     2           Paradoxical  
  110.              *     3           Labored
  111.              **************************************************************************************/
  112.             chestList.SelectedIndex = 1;
  113.             /***************************************************************************************
  114.              * Respirations (respList) is 3-bit enumeration with
  115.              * Field Value     Respirations  
  116.              *     0           Not Specified
  117.              *     1           Normal  *** Initial Value ***
  118.              *     2           Slow  
  119.              *     3           Rapid
  120.              *     4           Labored
  121.              **************************************************************************************/
  122.             respList.SelectedIndex = 1;
  123.             /***************************************************************************************
  124.              * Airway (airList) is 2-bit enumeration with
  125.              * Field Value     Airway  
  126.              *     0           Not Specified
  127.              *     1           Open  *** Initial Value ***
  128.              *     2           Blocked  
  129.              **************************************************************************************/
  130.             airList.SelectedIndex = 1;
  131.             /***************************************************************************************
  132.              * Pulse  (PulseList) is 2-bit enumeration with
  133.              * Field Value     Pulse    
  134.              *     0           Not Specified
  135.              *     1           Normal  *** Initial Value ***
  136.              *     2           Thready  
  137.              *     3           Fast
  138.              **************************************************************************************/
  139.             pulseList.SelectedIndex = 1;
  140.             /***************************************************************************************
  141.              * Heart Rate (hrList) is 3-bit enumeration with
  142.              * Field Value     Heart Rate    
  143.              *     0           Not Specified
  144.              *     1           Normal  *** Initial Value ***
  145.              *     2           Faint  
  146.              *     3           Low
  147.              *     4           High
  148.              *     5           Very High
  149.              **************************************************************************************/
  150.             hrList.SelectedIndex = 1;
  151.             /***************************************************************************************
  152.              * Blood Pressure (bpList) is 3-bit enumeration with
  153.              * Field Value     Blood Pressure    
  154.              *     0           Not Specified
  155.              *     1           Normal  *** Initial Value ***
  156.              *     2           Low  
  157.              *     3           Very Low
  158.              *     4           High
  159.              *     5           Very High
  160.              *     6           Stroke
  161.              **************************************************************************************/
  162.             bpList.SelectedIndex = 1;
  163.             /***************************************************************************************
  164.              * Fluid (fluidList) is 2-bit enumeration with
  165.              * Field Value     Fluid    
  166.              *     0           Not Specified
  167.              *     1           Normal  *** Initial Value ***
  168.              *     2           Low  
  169.              *     3           Very Low
  170.              **************************************************************************************/
  171.             fluidList.SelectedIndex = 1;
  172.             /***************************************************************************************
  173.              * O2 (Oxygen) Saturation (oxyLList) is 2-bit enumeration with
  174.              * Field Value     O2 Saturation      
  175.              *     0           Not Specified
  176.              *     1           Normal  *** Initial Value ***
  177.              *     2           Low  
  178.              *     3           Very Low
  179.              **************************************************************************************/
  180.             oxyLList.SelectedIndex = 1;
  181.             /***************************************************************************************
  182.              * Train-of-Four (tofList) is 3-bit enumeration with
  183.              * Field Value     Train-of-Four    
  184.              *     0           Not Specified
  185.              *     1           No Twitches  *** Initial Value ***
  186.              *     2           One Twitch  
  187.              *     3           Two Twitches
  188.              *     4           Three Twitches
  189.              *     5           Four Twitches
  190.              **************************************************************************************/
  191.             tofList.SelectedIndex = 0;
  192.  
  193.             // From the manikin, get the parameter representing the pulse oximeter
  194.             pulseOximeter = manikin.GetParameterAppValue<int>("PulseOximeter");
  195.  
  196.             // From the manikin, get the parameter representing the heart rate
  197.             heartRate = manikin.GetParameterModelDouble("heartRate");
  198.             overrideHeartRate = manikin.GetParameterModelDouble("override HeartRate");
  199.             heartRate.ValueChanged += new PropertyChangedEventHandler(OnHeartRateChanged);
  200.             //         heartRateLabel.DataBindings.Add("Text", this, "HeartRate");
  201.  
  202.             // Get the Pulmonary Arterial Pressure (Systolic) value from the manikin.
  203.             PAPsystolic = manikin.GetParameterModelDouble("PAPSystolic");
  204.             overridePAPSystolic = manikin.GetParameterModelDouble("override PAPSystolic");
  205.             PAPsystolic.ValueChanged += new PropertyChangedEventHandler(OnPAPSystolicChanged);
  206.  
  207.             // The events that pauses and starts the simulation
  208.             pauseEvent = manikin.GetParameterAppEventBool("Pause Simulation");
  209.             startEvent = manikin.GetParameterAppEventBool("Start Simulation");
  210.  
  211.             // allocates new byte array of length 160
  212.             bytes = new byte[160];
  213.             //creates a new UDPClient, which can read and write on port 9050
  214.             server = new UdpClient("255.255.255.255", 9050);
  215.             // Creates new IPEndPoint
  216.             sender = new IPEndPoint(IPAddress.Any, 0);
  217.             hasControl = true;
  218.  
  219.             // Creates an instance of the Reader class and puts it in a thread.
  220.             readingObj = new Reader(server, sender, this);
  221.             Thread readerThread = new Thread(readingObj.DoWork);
  222.             // Start the thread
  223.             readerThread.Start();
  224.             // Creates a new instance of Writer class.
  225.             w = new Writer(server, bytes, this);
  226.         }
  227.  
  228.         /// Gets/sets the heart rate from the Manikin
  229.         public double HeartRate
  230.         {
  231.             get
  232.             {
  233.                 return heartRate.Value;
  234.             }
  235.             set
  236.             {
  237.                 overrideHeartRate.Value = value;
  238.                 if (PropertyChanged != null)
  239.                     PropertyChanged(this, new PropertyChangedEventArgs("HeartRate"));
  240.             }
  241.         }
  242.  
  243.         //Gets and sets Systolic Pulmonary Arterial Pressure from the Manikin
  244.         public double PapSystolic
  245.         {
  246.             get
  247.             {
  248.                 return PAPsystolic.Value;
  249.             }
  250.             set
  251.             {
  252.                 overridePAPSystolic.Value = value;
  253.                 if (PropertyChanged != null)
  254.                     PropertyChanged(this, new PropertyChangedEventArgs("PapSystolic"));
  255.             }
  256.         }
  257.  
  258.  
  259.         /// Happens when the main window is about to be closed
  260.         protected override void OnClosing(CancelEventArgs e)
  261.         {
  262.             // When closing the connection should be terminated
  263.             manikin.Disconnect();
  264.             base.OnClosing(e);
  265.         }
  266.  
  267.         /// Happens when the heart rate changes on the server.  WHY TBD
  268.         void OnHeartRateChanged(object obj, PropertyChangedEventArgs args)
  269.         {
  270.             if (PropertyChanged != null)
  271.                 PropertyChanged(this, new PropertyChangedEventArgs("HeartRate"));
  272.         }
  273.  
  274.         // Calls an event when Pulmonary Arterial Pressure is changed
  275.         void OnPAPSystolicChanged(object obj, PropertyChangedEventArgs args)
  276.         {
  277.             if (PropertyChanged != null)
  278.                 PropertyChanged(this, new PropertyChangedEventArgs("PapSystolic"));
  279.         }
  280.  
  281.      
  282.      
  283.         // Used for GUI
  284.         private void MainForm_Load(object sender, EventArgs e)
  285.         {
  286.  
  287.         }
  288.  
  289.      
  290.  
  291.         /*****************************************************************************************
  292.          * This method brings in a binary string called bin and the number of bits (called numBits)
  293.          * the output should be.  It takes the binary string, pads it with the appropriate number
  294.          * of 0s and then returns the padded string in bin.
  295.          ****************************************************************************************/
  296.         private string format(string bin, int numBits)
  297.         {
  298.             string paddedBinString = "";
  299.             if (bin.Length != numBits)
  300.             {
  301.                 for (int i = 0; i < numBits - bin.Length; i++)
  302.                 {
  303.                     paddedBinString += "0";
  304.                 }
  305.                 return paddedBinString + bin;
  306.             }
  307.  
  308.             else
  309.                 return bin;
  310.         }
  311.  
  312.         // This method can be called from the writer class before it writes to make sure this simulation has control of the entity.
  313.         public bool getHasControl()
  314.         {
  315.             return hasControl;
  316.         }
  317.  
  318.         // Gets Heart Rate value from user and sets manikin
  319.         private void setHR()
  320.         {
  321.             HeartRate = Convert.ToUInt16(heartRateBox.Text);
  322.         }
  323.  
  324.         // Gets Pulmonary Arterial Pressure from user and sets manikin
  325.         private void setPap()
  326.         {
  327.             PapSystolic = Convert.ToUInt16(spap.Text);
  328.         }
  329.  
  330.         // TBD
  331.         private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
  332.         {
  333.  
  334.         }
  335.  
  336.         /****************************************************************************************
  337.          * This method is called whenever the user chooses to update the variable parameter
  338.          * (low fidelity) record.  First, if there is a current writing thread active, it is
  339.          * stopped, then data is compiled from the GUI, formed into a PDU and a new writing thread
  340.          * is started with the new data.
  341.          ****************************************************************************************/
  342.         private void updateVp_Click(object sender, EventArgs e)
  343.         {
  344.             if (hasControl)
  345.             {
  346.                 // Stop current writer thread
  347.                 w.requestStop();
  348.  
  349.  
  350.                 // data here is gathered from the drop down menus to populate the VP record
  351.                 // the method called format, takes in binary strings and returns the formatted string.
  352.  
  353.                 /************************************************************************
  354.                  * The VP record first section is the record type of 63 hex or 99 dec
  355.                  ************************************************************************/
  356.                 /***************************************************************************************
  357.                  * Race is 4-bit enumeration with
  358.                  * Field Value     Race    
  359.                  *     0           Not Specified
  360.                  *     1           TBD  *** Initial Value ***
  361.                  *     2           Other  
  362.                  **************************************************************************************/
  363.                 /***************************************************************************************
  364.                  * Species is 4-bit enumeration with
  365.                  * Field Value     Species      
  366.                  *     0           Not Specified
  367.                  *     1           TBD  *** Initial Value ***
  368.                  *     2           Other  
  369.                  **************************************************************************************/
  370.                 /***************************************************************************************
  371.                  * Breed  is 4-bit enumeration with
  372.                  * Field Value     Breed      
  373.                  *     0           Not Specified
  374.                  *     1           TBD  *** Initial Value ***
  375.                  *     2           Other  
  376.                  **************************************************************************************/
  377.                 /************************************************************************
  378.                  * The second section is Patient Basic Attribute with
  379.                  *    Variable Race = Race & Species values together are 11 hex or 17 dec
  380.                  *    Variable wt for Weight by Age
  381.                  *    Breed - TBD - should be 1 for TBD?
  382.                  *    Variable Sex = Sex
  383.                  ************************************************************************/
  384.                 byte[] basic = new byte[3];
  385.                 byte race = 17;
  386.  
  387.                 /***************************************************************************************
  388.                  * Clinical Event/ Observation  is 3-bit enumeration with
  389.                  * Field Value     Clinical Event/ Observation      
  390.                  *     0           Not Specified
  391.                  *     1           None  *** Initial Value ***
  392.                  *     2           Blunt Trauma  
  393.                  *     3           Penetrating Trauma
  394.                  *     4           Burn, Amputation
  395.                  *     5           Chemical Trauma
  396.                  *     6           Biological Traum
  397.                  *     7           Other
  398.                  **************************************************************************************/
  399.                 /***************************************************************************************
  400.                  * Location On Body 1 is 3-bit enumeration with
  401.                  * Field Value     Location On Body 1      
  402.                  *     0           Not Specified  *** Initial Value ***
  403.                  *     1           Head and Neck  
  404.                  *     2           Face  
  405.                  *     3           Chest
  406.                  *     4           Abdomen
  407.                  *     5           Extremities
  408.                  *     6           External
  409.                  *     7           Other
  410.                  **************************************************************************************/
  411.                 /***************************************************************************************
  412.                  * Location On Body 2 is 2-bit enumeration with
  413.                  * Field Value     Location On Body 2      
  414.                  *     0           Not Specified  *** Initial Value ***
  415.                  *     1           Right  
  416.                  *     2           Left  
  417.                  *     3           Other
  418.                  **************************************************************************************/
  419.                 /***************************************************************************************
  420.                  * Location On Body 3 is 2-bit enumeration with
  421.                  * Field Value     Location On Body 3      
  422.                  *     0           Not Specified  *** Initial Value ***
  423.                  *     1           Proximal  
  424.                  *     2           Distal  
  425.                  *     3           Other
  426.                  **************************************************************************************/
  427.                 /***************************************************************************************
  428.                  * Location On Body 4 is 3-bit enumeration with
  429.                  * Field Value     Location On Body 4      
  430.                  *     0           Not Specified  *** Initial Value ***
  431.                  *     1           Front  
  432.                  *     2           Back  
  433.                  *     3           Other
  434.                  **************************************************************************************/
  435.                 /***************************************************************************************
  436.                  * Bleeding is 2-bit enumeration with
  437.                  * Field Value     Bleeding      
  438.                  *     0           Not Specified  *** Initial Value ***
  439.                  *     1           Artenial  
  440.                  *     2           Venial  
  441.                  *     3           None
  442.                  **************************************************************************************/
  443.                 /***************************************************************************************
  444.                  * Skin is 2-bit enumeration with
  445.                  * Field Value     Skin        
  446.                  *     0           Not Specified  
  447.                  *     1           Normal  *** Initial Value ***
  448.                  *     2           Clammy
  449.                  *     3           Cold
  450.                  **************************************************************************************/
  451.                 /************************************************************************
  452.                  * The VP record 3th section is the Patient Visual Event Details
  453.                  * The section uses the following values
  454.                  *    Variable obs = Clinical Event/ Observation, Location On Body 1 & 2
  455.                  *        which together are 20 hex or 32 dec
  456.                  *    Variable loc = Location On Body 3, 4, & 5, Bleeding which together
  457.                  *        are 3 hex or 3 dec
  458.                  *    Variable skin = Skin which is 1
  459.                  *    The four byte is Padding with value of zero
  460.                  ************************************************************************/
  461.                 byte[] visEvent = new byte[4];
  462.                 byte obs = 32, loc = 3, skin = 1;
  463.  
  464.                 visEvent[0] = obs; visEvent[1] = loc; visEvent[2] = skin; visEvent[3] = 0;
  465.  
  466.                 /***************************************************************************************
  467.                  * Intervention Name is 4-bit enumeration with
  468.                  * Field Value     Intervention Name        
  469.                  *     0           Not Specified  
  470.                  *     1           TBD  
  471.                  *     2           None  *** Initial Value ***
  472.                  **************************************************************************************/
  473.                 /***************************************************************************************
  474.                  * Medication  is 4-bit enumeration with
  475.                  * Field Value     Medication        
  476.                  *     0           Not Specified  
  477.                  *     1           None   *** Initial Value ***
  478.                  *     2           Antibiotic
  479.                  *     3           Pain
  480.                  *     4           Fluid
  481.                  *     5           Blood
  482.                  *     6           ACLS Drawer
  483.                  *     7           Anesthetic
  484.                  *     8           Other
  485.                   **************************************************************************************/
  486.                 /***************************************************************************************
  487.                  * Dose is 2-bit enumeration with
  488.                  * Field Value     Dose        
  489.                  *     0           Not Specified  
  490.                  *     1           None  *** Initial Value ***
  491.                  *     2           TBD  
  492.                   **************************************************************************************/
  493.                 /***************************************************************************************
  494.                  * Route is 2-bit enumeration with
  495.                  * Field Value     Route        
  496.                  *     0           Not Specified  
  497.                  *     1           None  *** Initial Value ***
  498.                  *     2           TBD  
  499.                  **************************************************************************************/
  500.                 /***************************************************************************************
  501.                  * Frequency is 3-bit enumeration with
  502.                  * Field Value     Frequency      
  503.                  *     0           Not Specified  
  504.                  *     1           None  *** Initial Value ***
  505.                  *     2           TBD  
  506.                  **************************************************************************************/
  507.                 /***************************************************************************************
  508.                  * Appropriateness  is 1-bit enumeration with
  509.                  * Field Value     Appropriateness        
  510.                  *     0           Not Specified  *** Initial Value ***
  511.                  *     1           TBD  
  512.                  **************************************************************************************/
  513.                 /***************************************************************************************
  514.                  * Effectiveness  is 2-bit enumeration with
  515.                  * Field Value     Effectiveness        
  516.                  *     0           Not Specified  
  517.                  *     1           None  *** Initial Value ***
  518.                  *     2           TBD  
  519.                  **************************************************************************************/
  520.                 /************************************************************************
  521.                  * The VP record 5th section is the Intervention Details
  522.                  * The section uses the following values
  523.                  *    Variable intName = Intervention name and Medication values which  
  524.                  *        together are 21 hex or 33 dec
  525.                  *    Variable dose = Dose, Route, Frequency, & Appropriateness which
  526.                  *        together together are 54 hex or 84 dec
  527.                  *    Variable effect = Effectiveness which is 1
  528.                  *    The four byte is Padding with value of zero
  529.                  ************************************************************************/
  530.  
  531.                 byte[] inter = new byte[4];
  532.                 byte intName = 33, dose = 84, effect = 1;
  533.  
  534.                 inter[0] = intName; inter[1] = dose; inter[2] = effect; inter[3] = 0;
  535.  
  536.                 /************************************************************************
  537.                 * The VP record 4th section is the Patient Physiology Detail
  538.                 * This section uses values from the User and Manikin
  539.                 *    This code combines these variable for the record
  540.                 ************************************************************************/
  541.                 byte[] phys = new byte[4];
  542.                 string gen = format(Convert.ToString(sexList.SelectedIndex, 2), 2);
  543.                 string weigh = format(Convert.ToString(weightList.SelectedIndex, 2), 3);
  544.                 string con = format(Convert.ToString(conList.SelectedIndex, 2), 3);
  545.                 string c = format(Convert.ToString(chestList.SelectedIndex, 2), 2);
  546.                 string r = format(Convert.ToString(respList.SelectedIndex, 2), 3);
  547.                 string a = format(Convert.ToString(airList.SelectedIndex, 2), 3);
  548.                 string p = format(Convert.ToString(pulseList.SelectedIndex, 2), 2);
  549.                 string h = format(Convert.ToString(hrList.SelectedIndex, 2), 3);
  550.                 string b = format(Convert.ToString(bpList.SelectedIndex, 2), 4);
  551.                 string l = format(Convert.ToString(fluidList.SelectedIndex, 2), 2);
  552.                 string o = format(Convert.ToString(oxyLList.SelectedIndex, 2), 2);
  553.                 string t = format(Convert.ToString(tofList.SelectedIndex, 2), 8);
  554.  
  555.                 weigh = "00001" + weigh;
  556.                 gen = "000000" + gen;
  557.                 con += (c + r);
  558.                 a += (p + h);
  559.                 b += (l + o);
  560.  
  561.                 byte wt = Convert.ToByte(weigh, 2);
  562.                 byte sex = Convert.ToByte(gen, 2);
  563.                 byte cons = Convert.ToByte(con, 2);
  564.                 byte airway = Convert.ToByte(a, 2);
  565.                 byte blood = Convert.ToByte(b, 2);
  566.                 byte trainFour = Convert.ToByte(t, 2);
  567.  
  568.                 basic[0] = race;
  569.                 basic[1] = wt;
  570.                 basic[2] = sex;
  571.                 phys[0] = cons;
  572.                 phys[1] = airway;
  573.                 phys[2] = blood;
  574.                 phys[3] = trainFour;
  575.  
  576.                 // PDU Type is 1 because this is an entity state PDU
  577.                 byte pduType = 1;
  578.  
  579.                 //new entity state PDU is created
  580.                 EntityState es = new EntityState(basic, visEvent, phys, inter, pduType);
  581.                 data = es.createPDU();
  582.  
  583.                 //new writer thread is created
  584.                 w = new Writer(server, data, this);
  585.                 Thread writerThread = new Thread(w.DoWork);
  586.                 writerThread.Start();
  587.  
  588.             }
  589.  
  590.             else
  591.             {
  592.                 Console.WriteLine("Simulation does not have control of entity.");
  593.             }
  594.         }
  595.  
  596.         /****************************************************************************************************
  597.                  * This method is called when the user choses a transfer control request.
  598.                  ***************************************************************************************************/
  599.         private void button1_Click(object sender, EventArgs e)
  600.         {
  601.             request++;
  602.             byte tType = 1;
  603.  
  604.             // A new Transfer control request PDU is created
  605.             TransferControlReq t = new TransferControlReq(request, tType);
  606.             byte[] tcr = t.createTCR();
  607.             server.Send(tcr, tcr.Length);
  608.             for (int i = 0; i < 5; i++)
  609.             {
  610.                 // Check for ack every 1 second for 5 seconds.
  611.                 Thread.Sleep(1000);
  612.  
  613.                 // Check to see if reader received acknowledgment
  614.                 if (readingObj.getGotAck())
  615.                 {
  616.                     hasControl = false;
  617.                     readingObj.setGotAck(true);
  618.                     break;
  619.                 }
  620.             }
  621.         }
  622.  
  623.         // Will be used for Transfer Control (push)
  624.         private void button3_Click(object sender, EventArgs e)
  625.         {
  626.            
  627.         }
  628.  
  629.         /********************************************************************************************
  630.          * This method is called when the "update high fidelity" button is clicked on the main GUI.
  631.          * Here, we take all the data from the high fidelity parameters and use classes to turn it in
  632.          * to a DIS Attribute Record.  We then send it directly from this method, as opposed to using
  633.          * the writer class.
  634.          ********************************************************************************************/
  635.         private void updateAr_Click(object sender, EventArgs e)
  636.         {
  637.  
  638.             heartRateBox.Text = Convert.ToString(HeartRate);
  639.             spap.Text = Convert.ToString(PapSystolic);
  640.  
  641.  
  642.  
  643.             //Creates a new General Physical Record using values from main GUI, the record
  644.             //is then stored in a byte array
  645.             PhysRecord gen = new PhysRecord(Convert.ToUInt16(heightBox.Text), Convert.ToUInt16(weightBox.Text), Convert.ToUInt16(ageBox.Text));
  646.             byte[] general = gen.createPhysRecord();
  647.  
  648.             //This line creates a new Cardio object, it converts the text in the cardio boxes to an int, byte or float.
  649.             Cardio card = new Cardio(Convert.ToUInt16(asbp.Text), Convert.ToUInt16(adbp.Text), Convert.ToUInt16(mabp.Text),
  650.                                      Convert.ToUInt16(nsbp.Text), Convert.ToUInt16(ndbp.Text), Convert.ToUInt16(mnbp.Text),
  651.                                      Convert.ToSingle(temp.Text), Convert.ToSingle(ph.Text), Convert.ToUInt16(heartRateBox.Text),
  652.                                      Convert.ToUInt16(co.Text), Convert.ToByte(hematocrit.Text), Convert.ToByte(pos.Text),
  653.                                      Convert.ToByte(cvp.Text));
  654.             //This line creates a new cardio record
  655.             byte[] cardio = card.createCardio();
  656.  
  657.             //This line takes the text from the respiratory boxes and passes it to the Respiratory class to make a new object
  658.             Respiratory resp = new Respiratory(Convert.ToUInt16(aot.Text), Convert.ToUInt16(alot.Text), Convert.ToSingle(stv.Text),
  659.                                                Convert.ToSingle(tlv.Text), Convert.ToByte(rr.Text), Convert.ToByte(acdt.Text),
  660.                                                Convert.ToByte(alcdt.Text), Convert.ToByte(spap.Text), Convert.ToByte(dpap.Text),
  661.                                                Convert.ToByte(mpap.Text), Convert.ToByte(pcwp.Text), Convert.ToByte(ervp.Text),
  662.                                                Convert.ToByte(srvp.Text));
  663.             //This line creates a new repiratory record
  664.             byte[] respiratory = resp.createRespiratory();
  665.  
  666.             //The following lines pass the general, repiratory, and cardio records and use them to create an attribute PDU
  667.             Attribute att = new Attribute(general, cardio, respiratory);
  668.             byte[] attribute = att.createAttribute();
  669.  
  670.             //The following 2 lines send the Attribute PDU in its entirity along the network.
  671.             server.EnableBroadcast = true;
  672.             server.Send(attribute, attribute.Length);
  673.             setHR();
  674.             setPap();
  675.             Console.WriteLine("sent attribute");
  676.         }
  677.  
  678.     }
  679. }