Skip to content

Commit

Permalink
Основные изменения
Browse files Browse the repository at this point in the history
*Исправлена проблема с тестом unit_tstamp на ARMHF
*Исправлены проблема с тестом unit_checks под Windows
*Мелкие улучшения
 *Доработан CI
  • Loading branch information
alexs-sh committed May 17, 2019
1 parent 1c1355b commit d0ec1e0
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 103 deletions.
38 changes: 30 additions & 8 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ x86_64-linux:
script:
- sed -i 's/deb.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- sed -i 's/security.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- apt update -y && apt install -y ninja-build cmake git gcc g++
- apt update -y && apt install -y ninja-build cmake git gcc

- mkdir build
- cd build
- cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -Wall -Wextra -pedantic -Werror -Wno-unused-parameter -std=c99" -DCMAKE_FIND_ROOT_PATH=/tmp/output ..
- cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -Wall -Wextra -pedantic -Werror -Wno-unused-parameter -std=c99" ..
- ninja
- ninja test
tags:
Expand All @@ -52,7 +52,7 @@ x86_64-linux-memsan:
script:
- sed -i 's/deb.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- sed -i 's/security.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- apt update -y && apt install -y ninja-build cmake git gcc g++
- apt update -y && apt install -y ninja-build cmake git gcc

- mkdir build
- cd build
Expand All @@ -62,17 +62,33 @@ x86_64-linux-memsan:
tags:
- docker

x86_64-linux-valgrind:
image: debian:9
stage: build
script:
- sed -i 's/deb.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- sed -i 's/security.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- apt update -y && apt install -y ninja-build cmake git gcc valgrind

- mkdir build
- cd build
- cmake -G "Ninja" -DCMAKE_C_FLAGS="-g -O0" ..
- ninja
- find -executable -type f -name 'unit_*' -exec valgrind '{}' \;
tags:
- docker

x86_64-linux-coverage:
image: debian:9
stage: build
script:
- sed -i 's/deb.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- sed -i 's/security.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- apt update -y && apt install -y ninja-build cmake git gcc g++ gcovr
- apt update -y && apt install -y ninja-build cmake git gcc gcovr

- mkdir build
- cd build
- cmake -G "Ninja" -DTEKON_TESTS_COVERAGE=1 -DCMAKE_FIND_ROOT_PATH=/tmp/output ..
- cmake -G "Ninja" -DTEKON_TESTS_COVERAGE=1 ..
- ninja
- ninja test
- ../test/suite_msr.sh $(pwd)
Expand All @@ -89,12 +105,14 @@ armhf-linux:
script:
- sed -i 's/deb.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- sed -i 's/security.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- apt update -y && apt install -y ninja-build cmake git gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
- apt update -y && apt install -y ninja-build cmake git gcc-arm-linux-gnueabihf qemu

- mkdir build
- cd build
- cmake -G "Ninja" -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_FIND_ROOT_PATH=/usr/arm-linux-gnueabihf -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -Wall -Wextra -Wno-unused-parameter -std=c99" -DCMAKE_FIND_ROOT_PATH=/tmp/output ..
- cmake -G "Ninja" -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -Wall -Wextra -Wno-unused-parameter -std=c99" ..
- ninja

- find -executable -type f -name 'unit_*' -exec qemu-arm -L /usr/arm-linux-gnueabihf '{}' \;

tags:
- docker
Expand All @@ -105,12 +123,16 @@ x86_64-mingw:
script:
- sed -i 's/deb.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- sed -i 's/security.debian.org/mirror.yandex.ru/' /etc/apt/sources.list
- apt update && apt install -y ninja-build cmake git gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 build-essential autoconf automake libtool
- apt update && apt install -y ninja-build cmake git gcc-mingw-w64-x86-64 build-essential autoconf automake libtool wine

- mkdir build
- cd build
- cmake -G "Ninja" -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_LINKER=/usr/x86_64-w64-mingw32/bin/ld -DCMAKE_C_STANDARD_LIBRARIES="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lws2_32 -liphlpapi -lpsapi -luserenv" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-Bstatic -lwinpthread" ..
- ninja

- find -executable -type f -name 'unit_*' -exec wine '{}' \;

tags:
- docker


67 changes: 35 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,31 @@

# TEKON-UTILS

Набор утилит для работы со счетчиками [Тэкон](https://kreit.ru/) через Ethernet
контроллер [К-104](https://kreit.ru/products/communication/k-104.html).
Набор утилит для работы со счетчиками [Тэкон](https://kreit.ru/) через Ethernet контроллер [К-104](https://kreit.ru/products/communication/k-104.html).
Позволяют выполнять чтение значений, чтение архивов, синхронизацию времени.
Для работы используется протокол описанный в [Т10.06.59РД](https://kreit.ru/files/prot17_6.pdf)
и [Т10.06.59РД-Д1](https://kreit.ru/files/prot_d1.pdf).

Для работы используется протокол описанный в [Т10.06.59РД](https://kreit.ru/files/prot17_6.pdf) и [Т10.06.59РД-Д1](https://kreit.ru/files/prot_d1.pdf).

## Быстрый старт

### Чтение параметров

```console
tekon_msr -a udp:10.0.0.3:51960@9 -p'3:0xF001:0:H 3:0xF017:0:D 3:0xF018:0:T'
9:3:0xf001 H 0x3840 OK 1557896484 18000
9:3:0xf017 D 2019-05-15 OK 1557896484 18000
9:3:0xf018 T 10:01:22 OK 1557896484 18000
tekon_msr -a udp:10.0.0.3:51960@9 -p'3:0xF001:0:H 3:0xF017:0:D 3:0xF018:0:T 3:0x801c:2:f'
9:3:0xf001:0 H 0x3840 OK 1558082153 18000
9:3:0xf017:0 D 2019-05-17 OK 1558082153 18000
9:3:0xf018:0 T 13:35:49 OK 1558082153 18000
9:3:0x801c:2 F 38.151833 OK 1558082153 18000
```
### Чтение архива

### Чтение архива
```console
tekon_arch -a udp:10.0.0.3:51960@9 -p 3:0x801C:0:12:F -i m:12 -d 3:0xF017:0xF018
9:3:0x801c F -nan OK 1546282800 18000 0
9:3:0x801c F -nan OK 1548961200 18000 1
9:3:0x801c F 38.151833 OK 1551380400 18000 2
9:3:0x801c:0 F -nan OK 1546282800 18000
9:3:0x801c:1 F -nan OK 1548961200 18000
9:3:0x801c:2 F 38.151833 OK 1551380400 18000
...
```

### Синхронизация времени

```console
tekon_sync -a udp:10.0.0.3:51960@9 -d 3:0xF017:0xF018 -p 00000001
```
Expand All @@ -45,8 +41,7 @@ tekon_sync -a udp:10.0.0.3:51960@9 -d 3:0xF017:0xF018 -p 00000001
* cmake
* make

### Пример сборки для Debian x86_64

### Debian x86_64
```console
apt install git cmake make gcc
git clone <repo>
Expand All @@ -58,8 +53,7 @@ make
make test
```

### Пример кросс-компиляции для Debian ARMv7

### Debian ARM
```console
apt install git cmake make gcc-arm-linux-gnueabihf
git clone <repo>
Expand All @@ -70,8 +64,7 @@ cmake -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_FIND_ROOT_PATH=/usr/arm
make
```

### Пример кросс-компиляции для Windows XP x86

### Windows XP x86
```console
apt install git cmake make gcc-mingw-w64-i686
git clone <repo>
Expand All @@ -82,6 +75,11 @@ cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAK
make
```

Все примеры выполнены в ОС Debian 9 x86_64.

git clone <repo> - вместо параметра <repo> следует подставить адрес репозитория,
например, https://github.com/alexs-sh/tekon-utils.git

## Применение

Утилиты для чтения получают данные с устройства и выводят их в stdout. Чтение
Expand All @@ -102,22 +100,21 @@ make
### Чтение значений

Формат вывода данных:
шлюз:адрес:параметр тип значение качество UTC TZ

шлюз:адрес:параметр:индекс тип значение качество UTC TZ
```console
9:3:0xf001 H 0x3840 OK 1557900053 18000
9:3:0xf001:0 H 0x3840 OK 1557900053 18000
```

### Чтение архива

Формат вывода данных:
шлюз:адрес:параметр тип значение качество UTC TZ индекс

шлюз:адрес:параметр:индекс тип значение качество UTC TZ
```console
9:3:0x801c F -nan OK 1546282800 18000 0
9:3:0x801c:0 F -nan OK 1546282800 18000
```


Чтение архива может выполнятся в 2-х вариантах:

* без метки времени
Expand All @@ -127,22 +124,28 @@ make
Чтение без меток времени. Все значения UTC равны -1.
```console
tekon_arch -a udp:10.0.0.3:51960@9 -p 3:0x801C:0:12:F
9:3:0x801c F -nan OK -1 18000 0
9:3:0x801c F -nan OK -1 18000 1
9:3:0x801c F 38.151833 OK -1 18000 2
9:3:0x801c:0 F -nan OK -1 18000
9:3:0x801c:1 F -nan OK -1 18000
9:3:0x801c:2 F 38.151833 OK -1 18000
...
```

Чтение с метками времени. Требует дополнительных параметров с описанием
интервала и адресов даты / времени. Переводит индексы Тэкон в UTC время.
```console
tekon_arch -a udp:10.0.0.3:51960@9 -p 3:0x801C:0:12:F -i m:12 -d 3:0xF017:0xF018
9:3:0x801c F -nan OK 1546282800 18000 0
9:3:0x801c F -nan OK 1548961200 18000 1
9:3:0x801c F 38.151833 OK 1551380400 18000 2
9:3:0x801c:0 F -nan OK 1546282800 18000
9:3:0x801c:1 F -nan OK 1548961200 18000
9:3:0x801c:2 F 38.151833 OK 1551380400 18000
...
```

Для месячных, суточных, часовых архивов метка времени относится к началу архива.

Для интервальных архивов метка времени относится к концу архива.

Более подробно см. [Т10.06.59РД-Д1](https://kreit.ru/files/prot_d1.pdf) стр.
31-33

### Синхронизация времени

Expand Down
39 changes: 21 additions & 18 deletions bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ pipelines:
- step:
name: build-x86_64-linux
script:
- echo "Skip"
- apt update -y && apt install -y ninja-build cmake git gcc g++
- apt update -y && apt install -y ninja-build cmake git gcc

- mkdir build
- cd build
Expand All @@ -32,20 +31,30 @@ pipelines:
- step:
name: build-x86_64-linux-memsan
script:
- echo "Skip"
- apt update -y && apt install -y ninja-build cmake git gcc g++
- apt update -y && apt install -y ninja-build cmake git gcc

- mkdir build
- cd build
- cmake -G "Ninja" -DCMAKE_C_FLAGS="-g -O0 -fsanitize=leak -fsanitize=address" ..
- ninja
- ninja test

- step:
name: build-x86_64-linux-valgrind
script:
- apt update -y && apt install -y ninja-build cmake git gcc valgrind

- mkdir build
- cd build
- cmake -G "Ninja" -DCMAKE_C_FLAGS="-g -O0" ..
- ninja

- find -executable -type f -name 'unit_*' -exec valgrind '{}' \;

- step:
name: build-x86_64-linux-coverage
script:
- echo "Skip"
- apt update -y && apt install -y ninja-build cmake git gcc g++ gcovr curl
- apt update -y && apt install -y ninja-build cmake git gcc gcovr curl

- mkdir build
- cd build
Expand All @@ -63,32 +72,26 @@ pipelines:
- step:
name: build-armhf-linux
script:
- apt update -y && apt install -y ninja-build cmake git gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
- apt update -y && apt install -y ninja-build cmake git gcc-arm-linux-gnueabihf qemu

- mkdir build
- cd build
- cmake -G "Ninja" -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_FIND_ROOT_PATH=/usr/arm-linux-gnueabihf -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -Wall -Wextra -Wno-unused-parameter -std=c99" -DCMAKE_FIND_ROOT_PATH=/tmp/output ..
- cmake -G "Ninja" -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -Wall -Wextra -Wno-unused-parameter -std=c99" ..
- ninja

- find -executable -type f -name 'unit_*' -exec qemu-arm -L /usr/arm-linux-gnueabihf '{}' \;

- step:
name: build-x86_64-mingw
script:
- apt update && apt install -y ninja-build cmake git gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 build-essential autoconf automake libtool
- apt update && apt install -y ninja-build cmake git gcc-mingw-w64-x86-64 build-essential autoconf automake libtool wine

- mkdir build
- cd build
- cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_LINKER=/usr/x86_64-w64-mingw32/bin/ld -DCMAKE_C_STANDARD_LIBRARIES="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lws2_32 -liphlpapi -lpsapi -luserenv" -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -Wall -Wextra -Wno-unused-parameter -std=c99 -DWINVER=0x0501" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-Bstatic -lwinpthread" ..
- ninja

- step:
name: build-i686-mingw
script:
- apt update && apt install -y ninja-build cmake git gcc-mingw-w64-i686 g++-mingw-w64-i686 build-essential autoconf automake libtool

- mkdir build
- cd build
- cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_LINKER=/usr/i686-w64-mingw32/bin/ld -DCMAKE_C_STANDARD_LIBRARIES="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lws2_32 -liphlpapi -lpsapi -luserenv" -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -Wall -Wextra -Wno-unused-parameter -std=c99 -DWINVER=0x0501" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-Bstatic -lwinpthread" ..
- ninja
- find -executable -type f -name 'unit_*' -exec wine '{}' \;

options:
docker: true
Expand Down
1 change: 0 additions & 1 deletion tekon/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern "C" {

#include "tekon/message.h"
#include <assert.h>
#include <errno.h>
#include <string.h>

int tekon_req_11(struct message * self, uint8_t gateway, uint8_t device, uint16_t address)
Expand Down
1 change: 0 additions & 1 deletion tekon/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ extern "C" {
#include "tekon/pack.h"
#include <assert.h>
#include <string.h>
#include <errno.h>

struct buffer_writer {
size_t avail;
Expand Down
6 changes: 3 additions & 3 deletions test/suite_arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ test_output()

# Проверка кол-ва слов
WD=$(wc -w ${OUT} | cut -f 1 -d' ')
EXPECT=84
EXPECT=72
if [ "$WD" -ne "$EXPECT" ]; then
fail "Invalid output. Got ${WD} words insted of ${EXPECT}"
fi
# Проверка по шаблону строки
PAT='2:3:0x801c F 0.000000 COM -1'
grep "${PAT}" /tmp/out > /dev/null && echo "Done" || fail "Invalid output. Can't find ${PAT}"
PAT='2:3:0x801c:([0-9])+ F 0.000000 COM'
grep -E "${PAT}" /tmp/out > /dev/null && echo "Done" || fail "Invalid output. Can't find ${PAT}"
}

echo "<-- ARCHIVE TEST SUITE -->"
Expand Down
Loading

0 comments on commit d0ec1e0

Please sign in to comment.