示例#1
0
        public void serve_client(TcpClient client, int ID)
        {
            write_to_msg_box("Client " + Convert.ToString(ID) + " Connected!!\n");
            NetworkStream stream = client.GetStream();
            // Array to store incoming data
            Byte[] bytes = new Byte[PACKET_LENGTH];
            // Object to store information about subject
            Subj S = new Subj(client, 0, ID);
            // Object to get confid values based on 2D Gaussian
            Screen_Prob_Map p_m = new Screen_Prob_Map(MONITOR_DIM_X, MONITOR_DIM_Y, 250, 100);
            int i;

            clear_chart(ID);

            try
            {
                while ((i = stream.Read(bytes, 0, PACKET_LENGTH)) != 0)
                {
                    // Convert byte array to float
                    float[] float_array = new float[NUM_FLOATS];
                    Console.Write("\n"+Convert.ToString(ID)+" - ");
                    for (int ii = 0; ii < float_array.Length; ii++)
                    {
                        float_array[ii] = BitConverter.ToSingle(bytes, ii * sizeof(float));
                        if (ii < 11)
                            Console.Write(float_array[ii] + " ");
                    }
                    Console.Write("\n");

                    // Process float array and get estimated gaze point
                    Point_Obj est_gaze_pt = process_float_data(float_array, S.get_ID());

                    // Log estimated gaze point
                    S.get_gaze_pts().Add(est_gaze_pt);

                    // Check if subject is distracted
                    S = check_if_distract(S, est_gaze_pt);
                    Console.WriteLine("{0} - NUM DISTRACT FRAMES: {1}", S.get_ID(), S.get_num_frames_distracted());
                    if (S.get_num_frames_distracted() > DISTRACT_WINDOW)
                    {
                        write_to_alert_box(1, S.get_ID());
                    }
                    else
                    {
                        write_to_alert_box(0, S.get_ID());
                    }

                    //write_pt_to_hist(est_gaze_pt, ID, Convert.ToInt32(float_array[0]));

                    write_pt_to_hist(est_gaze_pt, p_m, ID, Convert.ToInt32(float_array[0]));

                }

                stream.Close();
                client.Close();
                write_to_msg_box("Connection to Client " + Convert.ToString(S.get_ID()) + " Closed");

                // Set occupied flag back to 0 (need thread-safe call)
                mut.WaitOne();
                occupied_flags[ID] = 0; // atomic (?)
                write_to_msg_box("CLIENT FLAG ARRAY: " + occupied_flags[0].ToString() + " " + occupied_flags[1].ToString());
                mut.ReleaseMutex();

            }
            catch (Exception EE)
            {
                Console.WriteLine("EXCEPTION: {0}\n", EE.Message);
                //all_subj.Add(S);
                stream.Close();
                client.Close();
                write_to_msg_box("Connection to Client "+Convert.ToString(S.get_ID())+" Closed");

                // Set occupied flag back to 0 (need thread-safe call)
                mut.WaitOne();
                occupied_flags[ID] = 0; // atomic (?)
                write_to_msg_box("CLIENT FLAG ARRAY: " + occupied_flags[0].ToString() + " " + occupied_flags[1].ToString());
                mut.ReleaseMutex();

            }
            //all_subj.Add(S);

            // Set occupied flag back to 0 (need thread-safe call)
            //mut.WaitOne();
            //occupied_flags[ID] = 0; // atomic (?)
            //mut.ReleaseMutex();
        }
示例#2
0
        private void write_pt_to_hist(Point_Obj p, Screen_Prob_Map p_m, int ID, int frame_num)
        {
            if (((Chart)this.hist_chart_list[ID]).InvokeRequired)
            {
                ChartHistCallback cH = new ChartHistCallback(write_pt_to_hist);
                this.Invoke(cH, new object[] { p, p_m, ID, frame_num });
            }
            else
            {
                Chart chart = (Chart)this.hist_chart_list[ID];
                chart.ChartAreas[0].AxisX.Maximum = frame_num; // display points up to current frame

                if (p.get_x() < -MONITOR_DIM_X / 2 || p.get_x() > MONITOR_DIM_X / 2)
                {
                    chart.Series["Series1"].Points.AddXY(frame_num, 0.0F);
                }
                else if (p.get_y() < -MONITOR_DIM_Y / 2 || p.get_y() > MONITOR_DIM_Y / 2)
                {
                    chart.Series["Series1"].Points.AddXY(frame_num, 0.0F);
                }
                else
                {
                    //chart.Series["Series1"].Points.AddXY(frame_num, 0);
                    double D = p_m.look_up_value(Convert.ToInt32(p.get_x()) + MONITOR_DIM_X / 2, Convert.ToInt32(p.get_y()) + MONITOR_DIM_Y / 2);
                    //Console.WriteLine(D);
                    //Console.WriteLine("Adding Point "+D.ToString());
                    chart.Series["Series1"].Points.AddXY(frame_num, Convert.ToSingle(D));
                    //write_to_msg_box(frame_num.ToString() + " " + D.ToString());

                }

                if (frame_num > 100)
                {
                    chart.ChartAreas[0].AxisX.Minimum = chart.ChartAreas[0].AxisX.Maximum - 100;
                }

            }
        }