Skip to content

Software Programming

shein318 edited this page Jan 11, 2016 · 9 revisions

Overview

The implementation of the conceptual design is done with a moore machine. The implentation can be found here. It is made in the function decisionLoop(). The data is read periodically out of the database. It is checked if there is an alarm. Every state of the conceptual design get its own bool variable. Then the petri network is coded.

bool int = true; // set initialisation state

while(1){
// 1. read data out of the database
// 2. check if there is an alarm
// 3. write the alarm state in the database
// 4. implementation of the moore machine
// 5. in decision of what state the moore machine is, there are assignments made
}

Implementation of the petri-network

Every state gets its own bool variable. Every variable that is read of the database gets its own variable. After that a loop is programmed in which the action above documented happens. The excerpt of the implementation where the temperature is controlled follows. The whole code can be found here.

bool int = true; // set initialisation state
bool state0 = false;
bool state11 = false;
bool state12 = false;
bool state13 = false;
bool state14 = false;
...

while(1){
  // read Auto/Manual out of database
  // read current status out of database
  // read temperature out of database
  // read priority out of database
  ...

  // check temperature alarm
  if (((temp_in < temp_min) && (temp_in < temp_out)) || ((temp_in > temp_max) && (temp_in > temp_out)))
  {
    temp_alarm = true;
  }
  if (temp_in == temp_average)
  {
    temp_alarm = false;
  }
  ...

  // write the temperature alarm state in the database
  if (temp_alarm  && temp_alarm_changed)
  {
    // Temperature Alarm
    writeTemperatureState("2");
  } else {
    if ((temp_min < temp_in) && (temp_in < temp_max))
    {
      // Temparture OK
      writeTemperatureState("0");
    } else {
      // Temperature Warning
      writeTemperatureState("1");
    }
  }
  ...

  // Transition 0
  // At the beginning the Window will always be closed
  if (init && !win_open_bo && !state0)
  {
    init = false;
    state0 = true;
  } 

  // Transition 1.1
  if (state0 && (priority==0) && !state11)
  {
    state0 = false;
    state11 = true;		
  }

  // Transition 1.2
  if (state11 && (!wind_alarm && ((!autoMode_bo && manOpen_bo) || (autoMode_bo && humid_alarm))) && !state12)
  {
    state11 = false;
    state12 = true;
  }

  // Transition 1.3
  if (state12 && win_open_bo && !state13)
  {
    state12 = false;
    state13 = true;
  }

  // Transition 1.4
  if (state13 && (!wind_alarm || (!autoMode_bo && manClose_bo) || (autoMode_bo && (vol_alarm || !humid_alarm))) && !state14)
  {
    state13 = false;
    state14 = true;
  }

  // Transition 1.5
  if (state14 && !win_open_bo && !state11)
  {
    state14 = false;
    state11 = true;
  }

  // Transition 1.6
  if (state13 && (priority != 0) && !init)
  {
    state13 = false;
    init = true;
  }

  // Transition 1,7
  if (state11 && (priority != 0) && !init)
  {
    state11 = false;
    init = true;
  }
  ...

  // Assignments
  if(state12)
  {
    // if the machine is in state12, the raspberry sends a commando to open the window to the phytec
    sw_send(DST_MULITCAST, "PUT_Win/Open");
    sleep(5);
  }

  if (state14 || init)
  {
    // if the machine is in state12 or init, the raspberry sends a commando to open the window to the phytec
    sw_send(DST_MULITCAST, "PUT_Win/Close");
    sleep(5);
  }
}
...