## 2 Materials and Methods
### System Architecture
#### 2.2.2 Software Description  
The software application was developed in the C language and includes a configuration process that sets the prescaler resolution to 8 bits for timer 0, configures the watchdog timer timeout, and sets the input/output pins. To restore the last relay value, a read operation is performed from the electrically erasable programmable read-only memory (EEPROM). If the relay was previously opened, the system will send a command to reopen it. This feature is useful in the event of a voltage drop during board restart, as it ensures that the relay is set to the previous command. Figure 6 provides further details on this process. The next step, is to configure the EUSART (enhanced universal asynchronous receiver transceiver) module, where the baud rate is configured at 300 bps, along with other configurations (frequencies, asynchronous mode, enable the interrupts for reception). If the power is down, the modem needs some time (almost 70 s) to connect to the nearby mobile cell tower. For this, a waiting time delay of 70 s was introduced. Because this fail-safe mechanism is very important, firstly, a message which specifies that a problem has been detected and a voltage drop-out has occurred, is sent, alongside the state of the relay (if it is ON or OFF), so that the user will know for sure if the data from the EEPROM was successfully restored and if it is correct. Secondly, the code will enter into a continuous loop, also known as a while loop, that will check regularly if an SMS was received from the user. If it receives a message and it is not an accepted command, it will react immediately with 'invalid command'. If the request is valid, then, firstly it will send the command to the relay via RD1, and then, if the PIN was set, it will save it into the EEPROM. A feedback message will be sent confirming the command and the relay were set to the desired position. The available commands are made up on 4-byte buffers, and they are as follows: \"01 ON\" to turn on the relay, \"1 OFF\" to turn off the relay, and for the current status of the relay, the command is \"STAT\". The mobile phone number where the messages can be sent, is configurable from the source code. The new code can be flashed on the PIC microcontroller with the updated number. The panel-mounted control module is shown in Figure 7.  
This C-module has in total 12 functions, including the main function, and it uses a 68-byte buffer, used for storing the messages from the GSM modem along with some safety checks (in the case of the message being longer than 68 bytes, the buffer will be overwritten!) [22]. The development and integration of the system into SCADA (supervisory control and data acquisition) involved the following stages:  
* Replacement of the mobile terminal with the SCADA system implemented in the dispatch center;
* Installation of an RTU connected to the GSM modem at the station;
* Outfitting of SMBs (source management blocks) and PSPs with digital relays. A block diagram of the control system consisting of the PC unit on which the SCADA system is installed, the GSM modem that enables bidirectional transmission of information, and the RTU unit installed at the railway station, is shown in Figure 8[25]. In this implementation, the existing SCADA system at the dispatching point, was enhanced with a software package that collects data from the field, transmitted by the RTU, and generates corrective commands if the RTU has not already done so. The RTU developed for this implementation is described in Figure 9.  
Figure 6: Main code with configurations and fail-safe features. The remote terminal unit (RTU) is typically defined as a communication satellite within the SCADA system, and is installed at the railway station. The RTU collects data from sensors located in the field, stores them in its own memory, analyzes them, and initiates a command if necessary. Periodically, this information is sent to the SCADA system dispatch point, which can intervene with response commands.