2015-07-08 07:30:09 +02:00
## How to Code your own plugin:
2015-07-02 12:56:16 +02:00
More information and a little Tutorial coming soon!
2015-07-08 07:30:09 +02:00
## 1. Plugin template
#### 1.1 General
2015-07-08 09:44:13 +02:00
You can find a little template plugin file in `plugins/template/template.py` But you can also take a look in all other plugins.
A plugin must be in an seperate folder with the same name of the .py file
2015-07-02 12:56:16 +02:00
2015-07-08 07:30:09 +02:00
#### 1.2 Plugin Init `.onLoad()`
2015-07-07 14:24:41 +02:00
This `.onLoad()` routine is called one time for initialize the plugin
2015-07-07 14:08:46 +02:00
2015-07-08 07:30:09 +02:00
#### 1.3 Plugin call `.run()`
2015-07-07 14:24:41 +02:00
This `.run()` routine is called every time an alarm comes in
2015-07-08 09:44:13 +02:00
Here are the information from BOSWatch available. See section `5. Process the data from BOSWatch`
2015-07-07 14:24:41 +02:00
2015-07-08 07:30:09 +02:00
## 2. Use Global Logging
#### 2.1 Init and Use
2015-07-07 14:24:41 +02:00
First you must import the logging module
```python
import logging # Global logger
```
Now you can send log messages with:
```python
logging.LOGLEVEL("MESSAGE")
```
2015-07-09 07:09:32 +02:00
You must replace the word `LOGLEVEL` with one if the following `debug` , `info` , `warning` or `error`
2015-07-07 14:24:41 +02:00
To use the right loglevel see next section `2.2 Choose right Loglevel`
2015-07-08 07:30:09 +02:00
#### 2.2 Choose right Loglevel
2015-07-07 14:24:41 +02:00
`debug`
2015-07-09 07:09:32 +02:00
all messages to find errors and for the internal program flow.
2015-07-07 14:24:41 +02:00
`info`
2015-07-09 07:09:32 +02:00
messages that serve only to inform the user.
2015-07-07 14:24:41 +02:00
`warning`
2015-07-09 07:09:32 +02:00
Warnings are notes and technical errors. Never leads to terminate BOSWatch.
2015-07-07 14:24:41 +02:00
`error`
2015-07-09 07:09:32 +02:00
An error that does not necessarily lead to end of BOSWatch, but an administrator intervention required.
2015-07-07 14:24:41 +02:00
`critical`
2015-07-09 07:09:32 +02:00
errors leading to the end of boswatch immediate - **in plugins not allowed** (Plugin cannot crash the entire program)
2015-07-07 14:24:41 +02:00
2015-07-08 07:30:09 +02:00
## 3. Use config file
#### 3.1 Own configuration in config.ini
2015-07-07 14:08:46 +02:00
First you must set a new Section in `config.ini`
A section is between brackets. Its recommended to give the section the same name as the plugin. `[SECTION_NAME]`
Now you can an set a unlimited number of options with its own value in these format: `OPTION = VALUE` .
Here is the sample from the template plugin:
```python
[template]
test1 = testString
test2 = 123456
```
2015-07-08 07:30:09 +02:00
#### 3.2 Read data from config.ini
2016-10-03 12:02:18 +02:00
To read yout configuration data you must import the `globalVars.py` where the global config-object is located:
2015-07-07 14:08:46 +02:00
```python
2016-10-03 11:56:27 +02:00
from includes import globalVars # Global variables
2015-07-07 14:08:46 +02:00
```
2015-07-08 07:30:09 +02:00
Now you can get your configuration data with:
2015-07-07 14:08:46 +02:00
```python
2016-10-03 12:02:18 +02:00
VALUE = globalVars.config.get("SECTION", "OPTION") #Gets any value
2015-07-07 14:08:46 +02:00
```
or better, use this:
```python
2016-10-03 12:02:18 +02:00
VALUE = globalVars.config.getint("SECTION", "OPTION") #Value must be an Integer
VALUE = globalVars.config.getfloat("SECTION", "OPTION") #Value must be an Float
VALUE = globalVars.config.getboolean("SECTION", "OPTION") #Value must be an Boolean
2015-07-07 14:08:46 +02:00
```
2015-07-08 07:30:09 +02:00
## 4. Global helper functions
2015-07-08 09:44:13 +02:00
#### 4.1 configHandler.py
First you must include the helper file
```python
from includes.helper import configHandler
```
##### 4.1.1 `.checkConfig(section)`
This function read all options from a config section and prints it to the debug log. The return value is `true` , also the section var is empty. In case of error a `false` is returned and error printed to log.
```python
if configHandler.checkConfig("template"): #check config file
########## User Plugin CODE ##########
pass
```
#### 4.2 timeHandler.py
2015-07-08 07:30:09 +02:00
First you must include the helper file
```python
from includes.helper import timeHandler
```
2015-07-08 09:44:13 +02:00
##### 4.2.1 `.curtime(format)`
2015-07-08 07:30:09 +02:00
```python
timeHandler.curtime() # returns a formated datetime string
```
you can give the function an format string. See https://docs.python.org/2/library/time.html#time.strftime
2015-07-07 14:24:41 +02:00
2015-07-08 07:30:09 +02:00
default (without format parameter) the function returns a date time with this format `%d.%m.%Y %H:%M:%S`
2015-07-08 09:44:13 +02:00
##### 4.2.2 `.getDate()`
2015-07-08 07:30:09 +02:00
```python
timeHandler.getDate() # returns the current date in format `%d.%m.%Y`
```
2015-07-08 09:44:13 +02:00
##### 4.2.3 `.getTime()`
2015-07-08 07:30:09 +02:00
```python
timeHandler.getTime() # returns the current time in format `%H:%M:%S`
```
2015-07-08 09:44:13 +02:00
##### 4.2.4 `.getTimestamp()`
2015-07-08 07:30:09 +02:00
```python
timeHandler.getTimestamp() # returns the current linux timestamp
```
2015-07-07 14:08:46 +02:00
2015-07-08 09:44:13 +02:00
#### 4.3 wildcardHandler.py
2015-07-08 07:30:09 +02:00
First you must include the helper file
```python
from includes.helper import wildcardHandler
```
2015-07-08 09:44:13 +02:00
##### 4.3.1 `.replaceWildcards(text,data)`
2015-07-08 07:30:09 +02:00
```python
wildcardHandler.replaceWildcards(text,data) # replace all standard wildcards
```
replace all the standard wildcards in the given text
the function needs the data[ ] var
defined wildcards:
**General:**
- `%TIME%` = Time (by script)
- `%DATE%` = Date (by script)
- `%DESCR%` = Description from csv-file
2015-10-12 22:03:04 +02:00
- `%BR%` = new line
- `%LPAR%` = "("
- `%RPAR%` = ")"
2015-07-08 07:30:09 +02:00
**FMS:**
- `%FMS%` = FMS Code
- `%STATUS%` = FMS Status
- `%DIR%` = Direction of the telegram (0/1)
- `%DIRT%` = Direction of the telegram (Text-String)
- `%TSI%` = Tactical Short Information (I-IV)
**ZVEI:**
- `%ZVEI%` = ZVEI 5-tone Code
**POCSAG:**
- `%RIC%` = Pocsag RIC
- `%FUNC%` = Pocsac function/Subric (1-4)
- `%FUNCCHAR%` = Pocsac function/Subric als character (a-d)
2016-11-06 09:17:53 +01:00
- `%FUNCTEXT%` = Pocsac function/Subric static massage definded in pocsag section
2015-07-08 07:30:09 +02:00
- `%MSG%` = Message of the Pocsag telegram
- `%BITRATE%` = Bitrate of the Pocsag telegram
## 5. Process the data from BOSWatch
2015-07-07 14:08:46 +02:00
Three parameters are passed during the alarm to the .run() method
2015-07-07 14:24:41 +02:00
2015-07-08 07:30:09 +02:00
#### 5.1 typ
Thats the function of the alarm. Possible values are `FMS` , `ZVEI` or `POC`
2015-07-07 14:24:41 +02:00
2015-07-08 07:30:09 +02:00
#### 5.2 freq
2015-07-07 14:08:46 +02:00
The reception frequency of the tuner in Hz
2015-07-07 14:24:41 +02:00
2015-07-08 07:30:09 +02:00
#### 5.3 data[ ]
2015-07-13 09:42:54 +02:00
You can get an information with `data["INFO"]`
2015-07-08 07:30:09 +02:00
In the data map are the folowing informations:
**ZVEI:**
- zvei
- description
2015-07-31 19:09:27 +02:00
- timestamp
2015-07-08 07:30:09 +02:00
**FMS:**
- fms
- status
- direction
- directionText
- tsi
- description
2015-07-31 19:09:27 +02:00
- timestamp
2015-07-08 07:30:09 +02:00
**POCSAG:**
- ric
- function
- functionChar
- msg
- bitrate
- description
2015-10-12 22:03:04 +02:00
- timestamp