aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/SitesModule.cs
blob: 96d3aed49e4623d508b286c0018746857ba89269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using Tango.BL.Enumerations;
using Tango.MachineStudio.Common;
using Tango.MachineStudio.Sites.Views;
using Tango.SharedUI.Helpers;

namespace Tango.MachineStudio.Sites
{
    [StudioModule(20)]
    public class SitesModule : StudioModuleBase
    {
        public override string Name
        {
            get
            {
                return "Sites";
            }
        }

        public override string Description
        {
            get
            {
                return "Manage organizations sites and their common machine properties.";
            }
        }

        public override BitmapSource Image
        {
            get
            {
                return ResourceHelper.GetImageFromResources("Images/site.png");
            }
        }

        public override Type MainViewType
        {
            get
            {
                return typeof(MainView);
            }
        }

        public override Permissions Permission
        {
            get
            {
                return Permissions.RunRMLModule;
            }
        }

        public override void Dispose()
        {

        }
    }
}
omment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/**********************************************************

   File name      :Idle.c
   Title          :Idle task for cpu load measuring
   Project        :Hi-Mux 100
   Subsystem      :IDLE
   Date created   :12 November 1996
   Revision       :Rev 0.0
   Author         :Shay Mamon & Sharon Melamed
   History        :

   Description    :This module contains two tasks that works in the system
                   Idle time.
                    1) In initialization the tasks comute referance
                       load when the system is unloaded.
                    2) Computing the current load according to the referance load.

************************************************************/

/*******************  Include Files ************************/

#include "include.h"
#include <ti/sysbios/knl/Task.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>

#include "Modules/Control/Control.h"
#include "Modules/Control/MillisecTask.h"
#define MAX_PRIORITY 15
#define SECOND_MAX_PRIORITY 14
#define MIN_PRIORITY 0
#define SECOND_MIN_PRIORITY 1
#define TICKS_IN_SECOND 1000

/**********************************************************/

/*#define DEBUG*/

/*******************  Function Prototypes *****************/


void    idle_task (UArg arg0, UArg arg1);
void    IDLE_statistics_task(UArg arg0, UArg arg1);
static void    calculate_system_load (int current_load);

/**********************************************************/

/*******************   Globals  ***************************/

static uint32_t idle_counter;
static long next_interval;  /*by ticks*/
static bool first_time_after_init;
static int system_load;
static int load;
static int max_system_load;
static int max_load;
static uint32_t idle_load_table[101];
static uint32_t idle_sequence_table[11];
static uint32_t idle_max_sequence_table[11];
/**********************************************************/
Task_Handle IdleTaskHandle;
Task_Handle IdleStTaskHandle;
char IdleTaskName[11] = "timeKeeper";
char IdleStTaskName[11] = "timeManager";
/**********************************************************

  Name            :  IDLE_package_init

  Function        :  Initilize global vars

  Parameters      :  None

  Return value    :  None

  Note            :  None

  Description     :  Initilize global vars, sets the new interval and reset the samples number.

***********************************************************/
extern void IDLE_TASK_package_init(void)
{
    Task_Params taskParams;
    Error_Block eb;

    /* Make sure Error_Block is initialized */
    Error_init(&eb);
    Task_Params_init(&taskParams);

   system_load=0;
   max_load = 0;
   max_system_load = 0;
   first_time_after_init=TRUE;
   next_interval = 1000 /*10 mSec*/ /*TICKS_IN_SECOND*/;
   idle_counter=0;
   taskParams.instance->name = IdleTaskName;
   taskParams.priority = SECOND_MIN_PRIORITY;
   taskParams.stackSize = 512;
   IdleTaskHandle = Task_create((Task_FuncPtr)idle_task, &taskParams, &eb);
   Error_init(&eb);
   Task_Params_init(&taskParams);
   taskParams.instance->name = IdleStTaskName;
   taskParams.priority = MAX_PRIORITY;
   taskParams.stackSize = 512;
   IdleStTaskHandle = Task_create((Task_FuncPtr)IDLE_statistics_task, &taskParams, &eb);
   //if (IdleTaskHandle == NULL) {
   //    System_printf("netOpenHook: Failed to create tcpHandler Task\n");
   //}
}



/**********************************************************

  Name            :  idle_task

  Function        :  Task that runs on idle time

  Parameters      :  NONE

  Return value    :  None

  Note            :  None

  Description     :  This task contain one loop and each pass
                     on the loop inc counter by 1

***********************************************************/
 void idle_task (UArg arg0, UArg arg1)
{
   while(1)  idle_counter++;
}
/**********************************************************

  Name            :  IDLE_statistic_task

  Function        :  Calculate the presentege of idle time

  Parameters      :  NONE

  Return value    :  None

  Note            :  None

  Description     :  This task rize every x (according to user define) seconds and calculate
                     the presentege of idle time by comparing the idle conter
                     when the system is load and when the system is unload.

***********************************************************/
 void IDLE_statistics_task(UArg arg0, UArg arg1)
{
uint32_t current_load;
uint32_t prev_load = 0;
uint32_t old_idle_counter=0;
uint32_t delta_idle_counter = 0;
long time_interval;  /*by ticks*/
uint32_t unload_max_count=0;

   //taskPrioritySet (idle_task_id ,SECOND_MAX_PRIORITY);
   Task_setPri(IdleTaskHandle, SECOND_MAX_PRIORITY);
   Task_sleep(TICKS_IN_SECOND);                  /* stablize the idle_task */
   old_idle_counter=idle_counter;
   Task_sleep(TICKS_IN_SECOND);
   //taskPrioritySet (idle_task_id ,MIN_PRIORITY);
   Task_setPri(IdleTaskHandle, SECOND_MIN_PRIORITY);
   unload_max_count = idle_counter - old_idle_counter + ULONG_MAX;        /* compute circular counter */
   old_idle_counter=idle_counter;

   time_interval = next_interval;
   while(1)
   {
       Task_sleep(time_interval);
      delta_idle_counter = abs((uint32_t)(idle_counter - old_idle_counter + ULONG_MAX));   /* compute circular counter */

      current_load = ((100 - (((delta_idle_counter/time_interval)*TICKS_IN_SECOND)/ (unload_max_count/100)))%101);
      if(prev_load == (current_load / 10))
      {
        idle_sequence_table[prev_load]++;
      }
      else
      {
        if(idle_max_sequence_table[prev_load] < idle_sequence_table[prev_load])
        {
           idle_max_sequence_table[prev_load] = idle_sequence_table[prev_load];
        }
        idle_sequence_table[prev_load] = 0;
        idle_sequence_table[current_load/10] = 1;
      }
      calculate_system_load(current_load);
      old_idle_counter = idle_counter;
      time_interval = next_interval;
      load=current_load;
      prev_load = current_load / 10;
      idle_load_table[load]++;
      if(load > max_load) max_load = load;
      //REPORT_MSG(load,"Real time load");

      #ifdef DEBUG
      printf("c_ld=%d\n",load);
      #endif
   }
}
 void IdleTaskGetLoadTable (uint32_t *Buffer)
 {
     memcpy (Buffer,idle_load_table,sizeof(idle_load_table));
 }
 uint32_t MillisecCounter = 0;
 uint32_t ControlCounter = 0;
 Void mySwitchFxn(Task_Handle from, Task_Handle to)
 {
     if (to == Control_Task_Handle)
         ControlCounter++;
     if (to == Millisecond_Task_Handle)
         MillisecCounter++;
     //idle_counter
      // System_printf("mySwitchFxn: from = 0x%x, to = 0x%x", from, to);
 }
/**********************************************************

  Name            :  calculate_system_load

  Function        :  calculate the average system load

  Parameters      :  current load (int)

  Return value    :  None

  Note            :  the average resets when the number_of_load_samples = 0

  Description     :  The function calculate and change the system load variable

***********************************************************/

static void calculate_system_load (int current_load)
{
static int sum_of_previous_load=0;
static uint32_t number_of_load_samples;
   if (first_time_after_init)
   {
      first_time_after_init = FALSE;
      system_load = current_load;
      max_system_load = system_load;
      max_load = load;
      number_of_load_samples = 1;
      sum_of_previous_load = current_load;
   }
   else
   {
      sum_of_previous_load = sum_of_previous_load + current_load;
      number_of_load_samples = number_of_load_samples + 1;
      system_load = ( sum_of_previous_load / number_of_load_samples);
      if(system_load > max_system_load) max_system_load = system_load;
   }
}

/***********************************************************

  Name            :  IDLE_change_parameters

  Function        :  starts new statistic with new time interval

  Parameters      :  new time interval

  Return value    :  None

  Note            :  None

  Description     :  sets the new interval and reset the samples number.

***********************************************************/
extern void IDLE_change_parameters(uint32_t new_interval)
{
   next_interval = new_interval;
   memset(idle_load_table,0,sizeof(idle_load_table));
   memset(idle_max_sequence_table,0,sizeof(idle_max_sequence_table));
   memset(idle_sequence_table,0,sizeof(idle_sequence_table));

   first_time_after_init=TRUE;                  /* reset the avarage calculation */
}

/**********************************************************

  Name            :  IDEL_get_load

  Function        :  returns the system load

  Parameters      :  None

  Return value    :  system load

  Note            :  External function

  Description     :  Trivial
***********************************************************/

extern int IDLE_TASK_get_load(void)
{
   return system_load;
}
 /***********************************************************/
 extern int IDLE_TASK_get_current_load(void)
 {
  return load;
 }

/***********************************************************/
 /*export MN_uint32_t mn_get_load(char *pParams)
 {
    int i;

    MN_printf("\n\r\n\rSystem load\n\r-------------");
    for(i=0;i<10;i++)
    MN_printf("\n\r %3d-%-3d Max Continuous Load is %4d intervals = %5d mSec",
             i*10, (i * 10 + 9),idle_max_sequence_table[i], 10*next_interval*idle_max_sequence_table[i]);
    MN_printf("\n\r  %3d    Max Continuous Load is %4d intervals = %5d mSec",
              (i * 10),idle_max_sequence_table[i], 10*next_interval*idle_max_sequence_table[i]);
    MN_printf("\n\r\n\rSystem avarege load=%d , max avarege load = %d",system_load, max_system_load);

    return(RET_OK);
 }*/
/***********************************************************/
 /*export MN_uint32_t mn_get_curent_load(char *pParams)
 {
    MN_printf("\n\rload=%d,max load=%d", load, max_load);
    return(RET_OK);
 }
*/
/***********************************************************/
 /*export MN_uint32_t mn_get_load_table(char *pParams)
 {
    int i;
    uint32_t interval_count;
    uint32_t avarege;
    int total_avarege;
    interval_count = 0;
    total_avarege = 0;
    MN_printf("\n\ridle_load_table\n\r---------------\n\r");
    for ( i=0;i<=100;i++)
      {
        interval_count+=idle_load_table[i];
      }
    for ( i=0;i<=100;i++)
      {
        avarege = (100*idle_load_table[i])/interval_count;
        MN_printf("|%3d-%-7d(%-2d)", i, idle_load_table[i], avarege);
        total_avarege+=(idle_load_table[i]*i);
        taskDelay(2);
      }
      total_avarege = total_avarege/interval_count;
    MN_printf("\n\rTotal avarege = %ld",total_avarege);

    return(RET_OK);
 }
*/
/***********************************************************/
 /*export MN_uint32_t mn_change_interval(char *pParams)
 {

  MN_uint32_t          rc;
  MN_WORD             new_interval;
  MN_WORD             index;
  index = 0;
  rc = MN_ParseWord(pParams ,&index ,&new_interval);
  if(rc == RET_OK)
  {
     IDLE_change_parameters((long)new_interval);
  }
  else
  {
    MN_printf("\r\nrc = %d Illegal parameter" ,rc);
  }
  return(RET_OK);
 }*/
/***********************************************************/
/*extern uint32_t IDLE_TASK_monitor_init(void)
{
    MN_uint32_t rc=RET_OK;
    MN_WORD idleMenuEntry;

    rc|=MN_BindMenu("Idle_task menu","Monitor system load",&idleMenuEntry);

    rc|=MN_BindCommand("GetCurLoad",idleMenuEntry,mn_get_curent_load,"GetCurLoad - Get Curent System CPU load\r\nGetCurLoad <cr>");
    rc|=MN_BindCommand("GetLoad",idleMenuEntry,mn_get_load,"GetLoad - Get averege system load (since last time you changed interval or since initiation)\r\nGetLoad <cr>");
    rc|=MN_BindCommand("IdleTbl",idleMenuEntry,mn_get_load_table,"IdleTbl - Get load table(since last time you changed interval or since initiation)\r\nGetLoad <cr>");
    rc|=MN_BindCommand("ChangeInt",idleMenuEntry,mn_change_interval,"ChangeInt - change interval of system load chack\r\nChangeInterval <New Interval in Tics (~100 in second)>");

 return(RET_OK);
}
*/