Compare commits
194 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcb4ccb462 | ||
|
|
e0cd14e904 | ||
|
|
7e41168606 | ||
|
|
6e9e988ff0 | ||
|
|
04c269d982 | ||
|
|
0dd77dbaa8 | ||
|
|
29524c2123 | ||
|
|
e2fb5e2673 | ||
|
|
751a0edca7 | ||
|
|
a8e62e086c | ||
|
|
35eb69bebb | ||
|
|
5c7c0699b2 | ||
|
|
7e31a60000 | ||
|
|
793bc877fc | ||
|
|
5ab6de21dc | ||
|
|
db5e242ad8 | ||
|
|
5be921a342 | ||
|
|
dd87d70876 | ||
|
|
52992f09ee | ||
|
|
6aa02d54c8 | ||
|
|
9dbf9137c7 | ||
|
|
c0a9a01b41 | ||
|
|
7b203b196f | ||
|
|
50c06e2cfe | ||
|
|
e4d4753181 | ||
|
|
04daf551fb | ||
|
|
4b51f0f235 | ||
|
|
5e4ccca663 | ||
|
|
6b0ec39759 | ||
|
|
1f7d845a32 | ||
|
|
6de5b719f3 | ||
|
|
90859ee6b8 | ||
|
|
78dd856a97 | ||
|
|
9897ccc563 | ||
|
|
701e5904c5 | ||
|
|
54ea17d345 | ||
|
|
327fed6f08 | ||
|
|
8fe1a1edf2 | ||
|
|
6fd8dc0432 | ||
|
|
f586336ae3 | ||
|
|
1527ee7d45 | ||
|
|
c543b38829 | ||
|
|
6d12d7120c | ||
|
|
c1d4ba772e | ||
|
|
a03d4113e7 | ||
|
|
8751b6325d | ||
|
|
ff02dd43a9 | ||
|
|
b772fb6323 | ||
|
|
f5acfce578 | ||
|
|
4b902e2544 | ||
|
|
217247b28e | ||
|
|
4828f5a727 | ||
|
|
062a3634a9 | ||
|
|
376cd0cf90 | ||
|
|
2a20893a58 | ||
|
|
f3dba112de | ||
|
|
b037d6bb64 | ||
|
|
6f7eacddff | ||
|
|
4185411315 | ||
|
|
2a1b5a5f6d | ||
|
|
246a4f96fe | ||
|
|
c7d235b367 | ||
|
|
c5c8fbc2a0 | ||
|
|
8adf591c4e | ||
|
|
aa893f7ede | ||
|
|
f8b1725e94 | ||
|
|
ae7e3d11d5 | ||
|
|
73b20a0766 | ||
|
|
d8cf961258 | ||
|
|
bccd19812d | ||
|
|
6954ff5432 | ||
|
|
6200f31b83 | ||
|
|
5408b3c2a9 | ||
|
|
bd0b3ebb26 | ||
|
|
895a9bc6b1 | ||
|
|
ff935fc920 | ||
|
|
3833421e5f | ||
|
|
ebdc357a47 | ||
|
|
7da617e8c2 | ||
|
|
0b86761d2c | ||
|
|
d697f7e37f | ||
|
|
db859e3ff5 | ||
|
|
94d22957bd | ||
|
|
1ebaf443cc | ||
|
|
a336f711b0 | ||
|
|
e6d3b47d4f | ||
|
|
eb479f8216 | ||
|
|
38cba4e8da | ||
|
|
bc6d45ecf2 | ||
|
|
097131d7fb | ||
|
|
2107ca50e4 | ||
|
|
178f603937 | ||
|
|
21687368c6 | ||
|
|
6054e900e6 | ||
|
|
3da5275624 | ||
|
|
3fda2cfe7a | ||
|
|
2bb651f95c | ||
|
|
e2442a26ee | ||
|
|
cbd2ab4a7a | ||
|
|
76f8e2c343 | ||
|
|
ab101c8622 | ||
|
|
f425abb52d | ||
|
|
dc5bfff655 | ||
|
|
eb59245118 | ||
|
|
d18fd27a24 | ||
|
|
6f09f523e4 | ||
|
|
e78d59c31a | ||
|
|
e7f3217d7b | ||
|
|
ab534ce60a | ||
|
|
933246eae8 | ||
|
|
5c38d1cf3e | ||
|
|
580085f717 | ||
|
|
9831d4aa78 | ||
|
|
a3561d5c58 | ||
|
|
2a524cd0ac | ||
|
|
254e010594 | ||
|
|
24025d6785 | ||
|
|
4c92e592d6 | ||
|
|
f192ddae81 | ||
|
|
1cd2446365 | ||
|
|
6d26102b8e | ||
|
|
8e9da8f255 | ||
|
|
72bdb6e363 | ||
|
|
6df942f488 | ||
|
|
1e323ac3b9 | ||
|
|
05bdbaf1f5 | ||
|
|
6cca25788e | ||
|
|
e929f87ea9 | ||
|
|
21a4102553 | ||
|
|
768645fc0a | ||
|
|
c670549dea | ||
|
|
147b2ca33e | ||
|
|
c645b82ed3 | ||
|
|
26bb8a0fea | ||
|
|
507ed13770 | ||
|
|
a0f53a0c52 | ||
|
|
13bbc81b7f | ||
|
|
7412ba2697 | ||
|
|
dce7b7e64b | ||
|
|
7627d6c369 | ||
|
|
9fc9adea1c | ||
|
|
46df07fe40 | ||
|
|
0aeb5555e7 | ||
|
|
181fe3c909 | ||
|
|
867d6a4ef8 | ||
|
|
d52216a73e | ||
|
|
d70b41a454 | ||
|
|
332c366561 | ||
|
|
b572ad97f8 | ||
|
|
aa307f8690 | ||
|
|
19223312b5 | ||
|
|
74bc5aa7a0 | ||
|
|
e66e8a96ff | ||
|
|
ce95360a64 | ||
|
|
7802aeaab1 | ||
|
|
37ce3566bf | ||
|
|
606bac100a | ||
|
|
be569d1802 | ||
|
|
3e21105b2d | ||
|
|
9946827431 | ||
|
|
90d03ca77f | ||
|
|
7727b17122 | ||
|
|
fbc4c8c502 | ||
|
|
5d6a4ea0a4 | ||
|
|
91ce486bde | ||
|
|
523139749e | ||
|
|
5b9f3b7aed | ||
|
|
af76243761 | ||
|
|
605dc4901c | ||
|
|
54fb950513 | ||
|
|
ff84278edf | ||
|
|
f15cf5d75e | ||
|
|
33070af111 | ||
|
|
53573184f3 | ||
|
|
decc4788a7 | ||
|
|
f9597c786e | ||
|
|
af8f5a7c24 | ||
|
|
a830a52863 | ||
|
|
037bac24de | ||
|
|
837c3cf802 | ||
|
|
75956c087c | ||
|
|
88528b4099 | ||
|
|
6176d34e84 | ||
|
|
f2dda26bbb | ||
|
|
402ecf67d7 | ||
|
|
a83a6c1c53 | ||
|
|
5beb13894c | ||
|
|
c3fa618ab2 | ||
|
|
7713ae8566 | ||
|
|
7ae860ec72 | ||
|
|
376008a735 | ||
|
|
feed10184b | ||
|
|
59ca29f6a8 | ||
|
|
644a3fa40b |
39
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report a bug
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Hardware information:**
|
||||
- Meter: [e.g. Aidon]
|
||||
- AMS reader: [e.g. Pow-U, ESP32 etc]
|
||||
- M-bus adapter (if applicable):
|
||||
|
||||
**Relevant firmware information:**
|
||||
- Version: [e.g. 1.5.0]
|
||||
- MQTT: [yes/no]
|
||||
- HAN GPIO: [e.g. GPIO5]
|
||||
- HAN baud and parity: [e.g. 2400 8E1]
|
||||
- Temperature sensors [e.g. 3xDS18B20]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
8
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Meter configuration
|
||||
url: https://github.com/gskjold/AmsToMqttBridge/wiki/Known-hardware-configurations
|
||||
about: Please check your meter configuration here first.
|
||||
- name: Frequently asked questions
|
||||
url: https://github.com/gskjold/AmsToMqttBridge/wiki/FAQ
|
||||
about: Please check frequently asked questions first.
|
||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
22
.github/ISSUE_TEMPLATE/support.md
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: Support
|
||||
about: Request support
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe your problem**
|
||||
A clear and concise description of what the problem is.
|
||||
|
||||
**Hardware information:**
|
||||
- Meter: [e.g. Aidon]
|
||||
- AMS reader: [e.g. Pow-U, ESP32 etc]
|
||||
- M-bus adapter (if applicable):
|
||||
|
||||
**Relevant firmware information:**
|
||||
- Version: [e.g. 1.5.0]
|
||||
- MQTT: [yes/no]
|
||||
- HAN GPIO: [e.g. GPIO5]
|
||||
- Temperature sensors [e.g. 3xDS18B20]
|
||||
2
.github/workflows/build.yml
vendored
@@ -41,7 +41,7 @@ jobs:
|
||||
python -m pip install --upgrade pip
|
||||
pip install -U platformio css_html_js_minify
|
||||
- name: Configure build targets
|
||||
run: echo "[platformio]\ndefault_envs = hw1esp12e, esp12e, esp32" > platformio-user.ini
|
||||
run: echo "[platformio]\ndefault_envs = esp8266, esp32" > platformio-user.ini
|
||||
- name: PlatformIO lib install
|
||||
run: pio lib install
|
||||
- name: PlatformIO run
|
||||
|
||||
2
.github/workflows/release.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
||||
- name: Get release version for code
|
||||
env:
|
||||
GITHUB_REF: ${{ github.ref }}
|
||||
run: echo ::set-env name=GITHUB_TAG::$(echo ${GITHUB_REF##*/})
|
||||
run: echo "GITHUB_TAG=$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
|
||||
- name: Cache Python dependencies
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
|
||||
2
.gitignore
vendored
@@ -12,3 +12,5 @@ platformio-user.ini
|
||||
/src/AmsToMqttBridge.ino.cpp
|
||||
/test
|
||||
/web/test.html
|
||||
/sdkconfig
|
||||
/.tmp
|
||||
|
||||
33
README.md
@@ -1,33 +1,12 @@
|
||||
# AMS <-> MQTT Bridge
|
||||
Orignally designed and coded by [@roarfred](https://github.com/roarfred), see the original repo at [roarfred/AmsToMqttBridge](https://github.com/roarfred/AmsToMqttBridge)
|
||||
# AMS MQTT Bridge
|
||||
This code is designed to decode data from electric smart meters installed in many countries in Europe these days. The data is presented in a graphical web interface and can also send the data to a MQTT broker which makes it suitable for home automation project. Originally it was only designed to work with Norwegian meters, but has since been adapter to read any IEC-62056-7-5 or IEC-62056-21 compliant meters.
|
||||
|
||||
This repository contains the code and schematics necessary to build a device to receive and convert data from AMS electrical meters installed in Norway. The code can be used on both ESP8266 and ESP32, both as custom build devices or built from readily available development modules. It reads data from the HAN port of the meter and sends this to a configured MQTT bus.
|
||||
|
||||
There is also a web interface available on runtime, showing meter data in real time.
|
||||
|
||||
<img src="webui.jpg" width="480">
|
||||
|
||||
## Hardware options
|
||||
Look in [hardware section](/hardware) for more details about supported hardware
|
||||
|
||||
## Release binaries
|
||||
|
||||
In the [Release section](https://github.com/gskjold/AmsToMqttBridge/releases) of this repository, you will find precompiled binaries for ESP8266 and ESP32 boards.
|
||||
Later development have added Energy usage graph for both day and month, as well as future energy price (Prices only available for ESP32). The code can run on any ESP8266 or ESP32 hardware which you can read more about in the [WiKi](https://github.com/gskjold/AmsToMqttBridge/wiki). If you don't have the knowledge to set up a ESP device yourself, have a look at the shop at [amsleser.no](https://amsleser.no/).
|
||||
|
||||
|
||||
### Flashing binaries with [esptool.py](https://github.com/espressif/esptool)
|
||||
|
||||
Linux:
|
||||
```esptool.py --port /dev/ttyUSB0 write_flash 0x0 firmware.bin```
|
||||
|
||||
Windows:
|
||||
```esptool.py --port COM1 write_flash 0x0 firmware.bin```
|
||||
|
||||
With ESP32 it is a bit more complicated:
|
||||
```esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x8000 partitions.bin 0x10000 firmware.bin```
|
||||
|
||||
Get the bootloader here: [Arduino ESP32 bootloader](https://github.com/espressif/arduino-esp32/tree/master/tools/sdk/bin) The default bootloader is [bootloader_dio_40m.bin](https://github.com/espressif/arduino-esp32/raw/master/tools/sdk/bin/bootloader_dio_40m.bin)
|
||||
<img src="webui.png">
|
||||
|
||||
Go to the [WiKi](https://github.com/gskjold/AmsToMqttBridge/wiki) for information on how to get your own device! And find the latest prebuilt firmware file at the [release section](https://github.com/gskjold/AmsToMqttBridge/releases).
|
||||
|
||||
## Building this project with PlatformIO
|
||||
To build this project, you need [PlatformIO](https://platformio.org/) installed.
|
||||
@@ -38,4 +17,4 @@ It is recommended to use Visual Studio Code with the PlatformIO plugin for devel
|
||||
|
||||
[PlatformIO vscode plugin](https://platformio.org/install/ide?install=vscode)
|
||||
|
||||
Copy the ```platformio-user.ini-example``` to ```platformio-user.ini``` and customize to your preference. The code will adapt to the platform and board set in your profile. If you are using the original board design by [@roarfred](https://github.com/roarfred) use build flag -D HW_ROARFRED=1
|
||||
For development purposes, copy the ```platformio-user.ini-example``` to ```platformio-user.ini``` and customize to your preference. The code will adapt to the platform and board set in your profile.
|
||||
|
||||
BIN
doc/Blue_Book_Edition_13-Excerpt.pdf
Normal file
32
doc/Denmark/Kamstrup_encrypted_OBIS.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
1.1.1.8.0.255 - Active+ Energy
|
||||
1.1.2.8.0.255 - Active- Energy
|
||||
1.1.3.8.0.255 - Reactive+ Energy
|
||||
1.1.4.8.0.255 - Reactive- Energy
|
||||
1.1.0.0.1.255 - Meter number 1
|
||||
1.1.1.7.0.255 - Active+ Instantaneous value
|
||||
1.1.2.7.0.255 - Active- Instantaneous value
|
||||
1.1.3.7.0.255 - Reactive+ Instantaneous value
|
||||
1.1.4.7.0.255 - Reactive- Instantaneous value
|
||||
0.1.1.0.0.255 - Current date/time
|
||||
1.1.32.7.0.255 - L1 Voltage Instantaneous value
|
||||
1.1.52.7.0.255 - L2 Voltage Instantaneous value
|
||||
1.1.72.7.0.255 - L3 Voltage Instantaneous value
|
||||
1.1.31.7.0.255 - L1 Current Instantaneous value
|
||||
1.1.51.7.0.255 - L2 Current Instantaneous value
|
||||
1.1.71.7.0.255 - L3 Current Instantaneous value
|
||||
1.1.21.7.0.255 - L1 Active+ Instantaneous value
|
||||
1.1.41.7.0.255 - L2 Active+ Instantaneous value
|
||||
1.1.61.7.0.255 - L3 Active+ Instantaneous value
|
||||
1.1.33.7.0.255 - L1 (cos.phi) (PF) Instantaneous value
|
||||
1.1.53.7.0.255 - L2 (cos.phi) (PF) Instantaneous value
|
||||
1.1.73.7.0.255 - L3 (cos.phi) (PF) Instantaneous value
|
||||
1.1.13.7.0.255 - Avegage (cos.phi) (PF) Inst. value
|
||||
1.1.22.7.0.255 - L1 Active- Instantaneous value
|
||||
1.1.42.7.0.255 - L2 Active- Instantaneous value
|
||||
1.1.62.7.0.255 - L3 Active- Instantaneous value
|
||||
1.1.22.8.0.255 - L1 Active- Energy
|
||||
1.1.42.8.0.255 - L2 Active- Energy
|
||||
1.1.62.8.0.255 - L3 Active- Energy
|
||||
1.1.21.8.0.255 - L1 Active+ Energy
|
||||
1.1.41.8.0.255 - L2 Active+ Energy
|
||||
1.1.61.8.0.255 - L3 Active+ Energy
|
||||
112
doc/Denmark/Kamstrup_encrypted_data.xml
Normal file
@@ -0,0 +1,112 @@
|
||||
<GatewayRequest>
|
||||
<NetworkId Value="231" />
|
||||
<PhysicalDeviceAddress Value="" />
|
||||
<DataNotification>
|
||||
<LongInvokeIdAndPriority Value="40000000" />
|
||||
<DateTime Value="" />
|
||||
<NotificationBody>
|
||||
<DataValue>
|
||||
<Structure Qty="41" >
|
||||
<String Value="Kamstrup_V0001" />
|
||||
<!--1.1.1.8.0.255-->
|
||||
<OctetString Value="0101010800FF" />
|
||||
<UInt32 Value="001194CA" />
|
||||
<!--1.1.2.8.0.255-->
|
||||
<OctetString Value="0101020800FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<!--1.1.3.8.0.255-->
|
||||
<OctetString Value="0101030800FF" />
|
||||
<UInt32 Value="0000127E" />
|
||||
<!--1.1.4.8.0.255-->
|
||||
<OctetString Value="0101040800FF" />
|
||||
<UInt32 Value="0009550E" />
|
||||
<!--1.1.0.0.1.255-->
|
||||
<OctetString Value="0101000001FF" />
|
||||
<UInt32 Value="0144ADE1" />
|
||||
<!--1.1.1.7.0.255-->
|
||||
<OctetString Value="0101010700FF" />
|
||||
<UInt32 Value="00000531" />
|
||||
<!--1.1.2.7.0.255-->
|
||||
<OctetString Value="0101020700FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<!--1.1.3.7.0.255-->
|
||||
<OctetString Value="0101030700FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<!--1.1.4.7.0.255-->
|
||||
<OctetString Value="0101040700FF" />
|
||||
<UInt32 Value="00000054" />
|
||||
<!--0.1.1.0.0.255-->
|
||||
<OctetString Value="0001010000FF" />
|
||||
<!--2020-05-12 10:24:50-->
|
||||
<OctetString Value="07E4050C020A1832FF800080" />
|
||||
<!--1.1.32.7.0.255-->
|
||||
<OctetString Value="0101200700FF" />
|
||||
<UInt16 Value="00E4" />
|
||||
<!--1.1.52.7.0.255-->
|
||||
<OctetString Value="0101340700FF" />
|
||||
<UInt16 Value="00E5" />
|
||||
<!--1.1.72.7.0.255-->
|
||||
<OctetString Value="0101480700FF" />
|
||||
<UInt16 Value="00E3" />
|
||||
<!--1.1.31.7.0.255-->
|
||||
<OctetString Value="01011F0700FF" />
|
||||
<UInt32 Value="0000004B" />
|
||||
<!--1.1.51.7.0.255-->
|
||||
<OctetString Value="0101330700FF" />
|
||||
<UInt32 Value="00000070" />
|
||||
<!--1.1.71.7.0.255-->
|
||||
<OctetString Value="0101470700FF" />
|
||||
<UInt32 Value="000001E4" />
|
||||
<!--1.1.21.7.0.255-->
|
||||
<OctetString Value="0101150700FF" />
|
||||
<UInt32 Value="00000070" />
|
||||
<!--1.1.41.7.0.255-->
|
||||
<OctetString Value="0101290700FF" />
|
||||
<UInt32 Value="000000B5" />
|
||||
<!--1.1.61.7.0.255-->
|
||||
<OctetString Value="01013D0700FF" />
|
||||
<UInt32 Value="0000040C" />
|
||||
<!--1.1.33.7.0.255-->
|
||||
<OctetString Value="0101210700FF" />
|
||||
<UInt16 Value="004D" />
|
||||
<!--1.1.53.7.0.255-->
|
||||
<OctetString Value="0101350700FF" />
|
||||
<UInt16 Value="004E" />
|
||||
<!--1.1.73.7.0.255-->
|
||||
<OctetString Value="0101490700FF" />
|
||||
<UInt16 Value="0062" />
|
||||
<!--1.1.13.7.0.255-->
|
||||
<OctetString Value="01010D0700FF" />
|
||||
<UInt16 Value="0063" />
|
||||
<!--1.1.22.7.0.255-->
|
||||
<OctetString Value="0101160700FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<!--1.1.42.7.0.255-->
|
||||
<OctetString Value="01012A0700FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<!--1.1.62.7.0.255-->
|
||||
<OctetString Value="01013E0700FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<!--1.1.22.8.0.255-->
|
||||
<OctetString Value="0101160800FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<!--1.1.42.8.0.255-->
|
||||
<OctetString Value="01012A0800FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<!--1.1.62.8.0.255-->
|
||||
<OctetString Value="01013E0800FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<!--1.1.21.8.0.255-->
|
||||
<OctetString Value="0101150800FF" />
|
||||
<UInt32 Value="000A8F97" />
|
||||
<!--1.1.41.8.0.255-->
|
||||
<OctetString Value="0101290800FF" />
|
||||
<UInt32 Value="0004C152" />
|
||||
<!--1.1.61.8.0.255-->
|
||||
<OctetString Value="01013D0800FF" />
|
||||
<UInt32 Value="000243DF" />
|
||||
</Structure>
|
||||
</DataValue>
|
||||
</NotificationBody>
|
||||
</DataNotification>
|
||||
</GatewayRequest>
|
||||
BIN
doc/Encrypted payload.png
Normal file
|
After Width: | Height: | Size: 1.9 MiB |
BIN
doc/Germany/Anleitung_M-Bus_Protokoll_V1.0.pdf
Normal file
BIN
doc/Green_Book_Edition_9-Excerpt.pdf
Normal file
BIN
doc/M-Bus_DOC48.PDF
Normal file
BIN
doc/Netherlands/Slimme_meter_15_a727fce1f1.pdf
Normal file
18
doc/Norway/Aidon_OBIS.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
1.1.0.2.129.255 - List version identifier
|
||||
0.0.96.1.0.255 - Meter ID
|
||||
0.0.96.1.7.255 - Meter Model
|
||||
1.0.1.7.0.255 - Active+ Instantaneous value
|
||||
1.0.2.7.0.255 - Active- Instantaneous value
|
||||
1.0.3.7.0.255 - Reactive+ Instantaneous value
|
||||
1.0.4.7.0.255 - Reactive- Instantaneous value
|
||||
1.0.31.7.0.255 - L1 Current Instantaneous value
|
||||
1.0.51.7.0.255 - L2 Current Instantaneous value
|
||||
1.0.71.7.0.255 - L3 Current Instantaneous value
|
||||
1.0.32.7.0.255 - L1 Voltage Instantaneous value
|
||||
1.0.52.7.0.255 - L2 Voltage Instantaneous value
|
||||
1.0.72.7.0.255 - L3 Voltage Instantaneous value
|
||||
0.0.1.0.0.255 - Current date/time
|
||||
1.0.1.8.0.255 - Active+ Energy
|
||||
1.0.2.8.0.255 - Active- Energy
|
||||
1.0.3.8.0.255 - Reactive+ Energy
|
||||
1.0.4.8.0.255 - Reactive- Energy
|
||||
119
doc/Norway/Aidon_data.xml
Normal file
@@ -0,0 +1,119 @@
|
||||
<GatewayRequest>
|
||||
<NetworkId Value="231" />
|
||||
<PhysicalDeviceAddress Value="" />
|
||||
<DataNotification>
|
||||
<LongInvokeIdAndPriority Value="40000000" />
|
||||
<DateTime Value="" />
|
||||
<NotificationBody>
|
||||
<DataValue>
|
||||
<Array Qty="0D" >
|
||||
<Structure Qty="02" >
|
||||
<!--1.1.0.2.129.255-->
|
||||
<OctetString Value="0101000281FF" />
|
||||
<String Value="AIDON_V0001" />
|
||||
</Structure>
|
||||
<Structure Qty="02" >
|
||||
<!--0.0.96.1.0.255-->
|
||||
<OctetString Value="0000600100FF" />
|
||||
<String Value="0000000000000000" />
|
||||
</Structure>
|
||||
<Structure Qty="02" >
|
||||
<!--0.0.96.1.7.255-->
|
||||
<OctetString Value="0000600107FF" />
|
||||
<String Value="6534" />
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.1.7.0.255-->
|
||||
<OctetString Value="0100010700FF" />
|
||||
<UInt32 Value="00000339" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="00" />
|
||||
<Enum Value="1B" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.2.7.0.255-->
|
||||
<OctetString Value="0100020700FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="00" />
|
||||
<Enum Value="1B" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.3.7.0.255-->
|
||||
<OctetString Value="0100030700FF" />
|
||||
<UInt32 Value="00000000" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="00" />
|
||||
<Enum Value="1D" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.4.7.0.255-->
|
||||
<OctetString Value="0100040700FF" />
|
||||
<UInt32 Value="00000251" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="00" />
|
||||
<Enum Value="1D" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.31.7.0.255-->
|
||||
<OctetString Value="01001F0700FF" />
|
||||
<Int16 Value="0012" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="FF" />
|
||||
<Enum Value="21" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.51.7.0.255-->
|
||||
<OctetString Value="0100330700FF" />
|
||||
<Int16 Value="0003" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="FF" />
|
||||
<Enum Value="21" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.71.7.0.255-->
|
||||
<OctetString Value="0100470700FF" />
|
||||
<Int16 Value="0016" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="FF" />
|
||||
<Enum Value="21" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.32.7.0.255-->
|
||||
<OctetString Value="0100200700FF" />
|
||||
<UInt16 Value="08FE" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="FF" />
|
||||
<Enum Value="23" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.52.7.0.255-->
|
||||
<OctetString Value="0100340700FF" />
|
||||
<UInt16 Value="08F8" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="FF" />
|
||||
<Enum Value="23" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
<Structure Qty="03" >
|
||||
<!--1.0.72.7.0.255-->
|
||||
<OctetString Value="0100480700FF" />
|
||||
<UInt16 Value="08F7" />
|
||||
<Structure Qty="02" >
|
||||
<Int8 Value="FF" />
|
||||
<Enum Value="23" />
|
||||
</Structure>
|
||||
</Structure>
|
||||
</Array>
|
||||
</DataValue>
|
||||
</NotificationBody>
|
||||
</DataNotification>
|
||||
</GatewayRequest>
|
||||
BIN
doc/Norway/Kaifa.png
Normal file
|
After Width: | Height: | Size: 442 KiB |
BIN
doc/Sweden/Aidon-RJ12.pdf
Normal file
BIN
doc/omnipower.technical.description.pdf
Normal file
30
frames/Aidon-Sweden.raw
Normal file
@@ -0,0 +1,30 @@
|
||||
7E A2 43 41 08 83 13 85 EB E6 E7 00 0F 40 00 00 00 00
|
||||
01 1B
|
||||
02 02 09 06 00 00 01 00 00 FF 09 0C 07 E5 0C 0A 05 10 39 00 FF 80 00 FF
|
||||
02 03 09 06 01 00 01 07 00 FF 06 00 00 07 E5 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 02 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 03 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1D
|
||||
02 03 09 06 01 00 04 07 00 FF 06 00 00 02 48 02 02 0F 00 16 1D
|
||||
02 03 09 06 01 00 1F 07 00 FF 10 00 09 02 02 0F FF 16 21
|
||||
02 03 09 06 01 00 33 07 00 FF 10 00 25 02 02 0F FF 16 21
|
||||
02 03 09 06 01 00 47 07 00 FF 10 00 2E 02 02 0F FF 16 21
|
||||
02 03 09 06 01 00 20 07 00 FF 12 08 E3 02 02 0F FF 16 23
|
||||
02 03 09 06 01 00 34 07 00 FF 12 08 D8 02 02 0F FF 16 23
|
||||
02 03 09 06 01 00 48 07 00 FF 12 08 DF 02 02 0F FF 16 23
|
||||
02 03 09 06 01 00 15 07 00 FF 06 00 00 00 D5 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 16 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 17 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1D
|
||||
02 03 09 06 01 00 18 07 00 FF 06 00 00 00 36 02 02 0F 00 16 1D
|
||||
02 03 09 06 01 00 29 07 00 FF 06 00 00 03 0C 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 2A 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 2B 07 00 FF 06 00 00 01 21 02 02 0F 00 16 1D
|
||||
02 03 09 06 01 00 2C 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1D
|
||||
02 03 09 06 01 00 3D 07 00 FF 06 00 00 03 F9 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 3E 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 3F 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1D
|
||||
02 03 09 06 01 00 40 07 00 FF 06 00 00 00 E9 02 02 0F 00 16 1D
|
||||
02 03 09 06 01 00 01 08 00 FF 06 03 C2 5A 64 02 02 0F 00 16 1E
|
||||
02 03 09 06 01 00 02 08 00 FF 06 00 00 00 00 02 02 0F 00 16 1E
|
||||
02 03 09 06 01 00 03 08 00 FF 06 00 04 5D 06 02 02 0F 00 16 20
|
||||
02 03 09 06 01 00 04 08 00 FF 06 00 B4 9D 89 02 02 0F 00 16 20
|
||||
1C 90 7E
|
||||
33
frames/Aidon-TN-3p.raw
Normal file
@@ -0,0 +1,33 @@
|
||||
T FF FF DA SA SA C HC HC LD LS LQ AT AI AI AI AI AD
|
||||
7E A0 2A 41 08 83 13 04 13 E6 E7 00 0F 40 00 00 00 00 01 01 02 03 09 06 01 00 01 07 00 FF 06 00 00 08 64 02 02 0F 00 16 1B E1
|
||||
7E A1 1E 41 08 83 13 EE EE E6 E7 00 0F 40 00 00 00 00 01 0D 02 02 09 06 01 01 00 02 81 FF 0A 0B 41 49 44 4F 4E 5F 56 30 30 30 31 02 02 09 06 00 00 60 01 00 FF 0A 10 37 33 35 39 39 39 32 38 39 30 34 39 37 39 39 37 02 02 09 06 00 00 60 01 07 FF 0A 04 36 35 33 34 02 03 09 06 01 00 01 07 00 FF 06 00 00 08 6C 02 02 0F 00 16 1B 02 03 09 06 01 00 02 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B 02 03 09 06 01 00 03 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1D 02 03 09 06 01 00 04 07 00 FF 06 00 00 02 09 02 02 0F 00 16 1D 02 03 09 06 01 00 1F 07 00 FF 10 00 41 02 02 0F FF 16 21 02 03 09 06 01 00 33 07 00 FF 10 00 13 02 02 0F FF 16 21 02 03 09 06 01 00 47 07 00 FF 10 00 0E 02 02 0F FF 16 21 02 03 09 06 01 00 20 07 00 FF 12 08 F2 02 02 0F FF 16 23 02 03 09 06 01 00 34 07 00 FF 12 08 D1 02 02 0F FF 16 23 02 03 09 06 01 00 48 07 00 FF 12 08 E8 02 02 0F FF 16 23 8B
|
||||
7E A1 8A 41 08 83 13 EB FD E6 E7 00 0F 40 00 00 00 00 01 12 02 02 09 06 01 01 00 02 81 FF 0A 0B 41 49 44 4F 4E 5F 56 30 30 30 31 02 02 09 06 00 00 60 01 00 FF 0A 10 37 33 35 39 39 39 32 38 39 30 34 39 37 39 39 37 02 02 09 06 00 00 60 01 07 FF 0A 04 36 35 33 34 02 03 09 06 01 00 01 07 00 FF 06 00 00 03 9A 02 02 0F 00 16 1B 02 03 09 06 01 00 02 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B 02 03 09 06 01 00 03 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1D 02 03 09 06 01 00 04 07 00 FF 06 00 00 02 0E 02 02 0F 00 16 1D 02 03 09 06 01 00 1F 07 00 FF 10 00 11 02 02 0F FF 16 21 02 03 09 06 01 00 33 07 00 FF 10 00 10 02 02 0F FF 16 21 02 03 09 06 01 00 47 07 00 FF 10 00 0E 02 02 0F FF 16 21 02 03 09 06 01 00 20 07 00 FF 12 08 F4 02 02 0F FF 16 23 02 03 09 06 01 00 34 07 00 FF 12 08 CD 02 02 0F FF 16 23 02 03 09 06 01 00 48 07 00 FF 12 08 DC 02 02 0F FF 16 23 02 02 09 06 00 00 01 00 00 FF 09 0C 07 E5 03 18 03 08 00 00 FF 00 00 00 02 03 09 06 01 00 01 08 00 FF 06 00 47 F0 34 02 02 0F 01 16 1E 02 03 09 06 01 00 02 08 00 FF 06 00 00 00 00 02 02 0F 01 16 1E 02 03 09 06 01 00 03 08 00 FF 06 00 00 21 9E 02 02 0F 01 16 20 02 03 09 06 01 00 04 08 00 FF 06 00 08 E0 21 02 02 0F 01 16 20 57
|
||||
|
||||
7E A1 8A 41 08 83 13 EB FD E6 E7 00
|
||||
0F
|
||||
40 00 00 00 00
|
||||
01 12
|
||||
02 02 09 06 01 01 00 02 81 FF 0A 0B 41 49 44 4F 4E 5F 56 30 30 30 31
|
||||
02 02 09 06 00 00 60 01 00 FF 0A 10 37 33 35 39 39 39 32 38 39 30 34 39 37 39 39 37
|
||||
02 02 09 06 00 00 60 01 07 FF 0A 04 36 35 33 34
|
||||
02 03 09 06 01 00 01 07 00 FF 06 00 00 09 6D 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 02 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B
|
||||
02 03 09 06 01 00 03 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1D
|
||||
02 03 09 06 01 00 04 07 00 FF 06 00 00 02 5B 02 02 0F 00 16 1D
|
||||
|
||||
Object with three values Value Object with two values
|
||||
| Obis code | | Scaling
|
||||
| | | | | Unit
|
||||
02 03 09 06 01 00 1F 07 00 FF 10 00 11 02 02 0F FF 16 21
|
||||
02 03 09 06 01 00 33 07 00 FF 10 00 03 02 02 0F FF 16 21
|
||||
02 03 09 06 01 00 47 07 00 FF 10 00 5A 02 02 0F FF 16 21
|
||||
02 03 09 06 01 00 20 07 00 FF 12 09 04 02 02 0F FF 16 23
|
||||
02 03 09 06 01 00 34 07 00 FF 12 09 02 02 02 0F FF 16 23
|
||||
02 03 09 06 01 00 48 07 00 FF 12 08 EC 02 02 0F FF 16 23
|
||||
02 02 09 06 00 00 01 00 00 FF 09 0C 07 E5 0A 1F 00 14 00 00 FF 00 00 00
|
||||
02 03 09 06 01 00 01 08 00 FF 06 00 56 9F 52 02 02 0F 01 16 1E
|
||||
02 03 09 06 01 00 02 08 00 FF 06 00 00 00 00 02 02 0F 01 16 1E
|
||||
02 03 09 06 01 00 03 08 00 FF 06 00 00 22 D0 02 02 0F 01 16 20
|
||||
02 03 09 06 01 00 04 08 00 FF 06 00 0A F5 EC 02 02 0F 01 16 20
|
||||
51 D7
|
||||
7E
|
||||
34
frames/Kaifa-TN-3p.raw
Normal file
@@ -0,0 +1,34 @@
|
||||
T FF FF DA SA SA C HC HC LD LS LQ AT AI AI AI AI AD
|
||||
7E A0 27 01 02 01 10 5A 87 E6 E7 00 0F 40 00 00 00 09 0C 07 E5 03 17 02 13 1A 3A FF 80 00 00
|
||||
02 01 // Frame type and size
|
||||
06 00 00 0B F3 // Active power
|
||||
5B 05 7E // CRC and end tag
|
||||
|
||||
T FF FF DA SA SA C HC HC LD LS LQ AT AI AI AI AI AD
|
||||
7E A0 78 01 02 01 10 C4 98 E6 E7 00 0F 40 00 00 00 09 0C 07 E5 03 17 02 13 1B 00 FF 80 00 00
|
||||
02 0D // Frame type and size
|
||||
09 07 4B 46 4D 5F 30 30 31 // List version
|
||||
09 10 XX XX XX XX XX XX XX XX XX XX 35 33 34 34 39 33 // Meter ID
|
||||
09 07 4D 41 33 30 34 48 34 // Meter type
|
||||
06 00 00 0C 21 // Active import
|
||||
06 00 00 00 00 // Active export
|
||||
06 00 00 00 00 // Reactive import
|
||||
06 00 00 01 9F // Reactive export
|
||||
06 00 00 0B F3 // I1
|
||||
06 00 00 05 0B // I2
|
||||
06 00 00 25 11 // I3
|
||||
06 00 00 09 44 // U1
|
||||
06 00 00 09 49 // U2
|
||||
06 00 00 09 39 // U3
|
||||
C9 95 7E // CRC and end tag
|
||||
|
||||
|
||||
7E A0 9A 01 02 01 10 AA A5 E6 E7 00 0F 40 00 00 00 09 0C 07 E5 03 17 02 13 00 0A FF 80 00 00
|
||||
02 12 09 07 4B 46 4D 5F 30 30 31
|
||||
09 10 XX XX XX XX XX XX XX XX XX XX 35 33 34 34 39 33
|
||||
09 07 4D 41 33 30 34 48 34
|
||||
06 00 00 09 99
|
||||
06 00 00 00 00 06 00 00 00 00 06 00 00 01 67 06 00 00 03 BF 06 00 00 05 05
|
||||
06 00 00 24 34 06 00 00 09 45 06 00 00 09 4F 06 00 00 09 3B
|
||||
09 0C 07 E5 03 17 02 13 00 0A FF 80 00 00 06 01 34 3B 5D 06 00 00 00 00 06 00 00 09 36 06 00 3C 7A 98 DA 15 7E
|
||||
7E A0 79 01 02 01 10 80 93 E6 E7 00 0F 40 00 00 00 09 0C 07 E1 09 0E 04 15 1F 14 FF 80 00 00 02 0D 09 07 4B 46 4D 5F 30 30 31 09 10 36 39 37 30 36 33 31 34 30 31 37 35 33 39 38 35 09 08 4D 41 33 30 34 48 33 45 06 00 00 04 0C 06 00 00 00 00 06 00 00 00 00 06 00 00 00 4E 06 00 00 07 C1 06 00 00 0C 9E 06 00 00 0D 7E 06 00 00 09 5F 06 00 00 00 00 06 00 00 09 66 87 96 7E
|
||||
51
frames/Kamstrup-1p.raw
Normal file
@@ -0,0 +1,51 @@
|
||||
7E A0 BA 2B 21 13 ED AA E6 E7 00 0F 00 00 00 00
|
||||
0C 07 E6 02 05 06 0D 00 0A FF 80 00 00
|
||||
02 19
|
||||
0A 0E 4B 61 6D 73 74 72 75 70 5F 56 30 30 30 31
|
||||
09 06 01 01 00 00 05 FF 0A 10 35 37 30 36 35 36 37 32 37 31 35 33 33 32 30 37
|
||||
09 06 01 01 60 01 01 FF 0A 12 36 38 36 31 31 31 31 42 4E 32 34 32 31 30 31 30 34 30
|
||||
09 06 01 01 01 07 00 FF 06 00 00 02 68
|
||||
09 06 01 01 02 07 00 FF 06 00 00 00 00
|
||||
09 06 01 01 03 07 00 FF 06 00 00 00 53
|
||||
09 06 01 01 04 07 00 FF 06 00 00 00 00
|
||||
09 06 01 01 1F 07 00 FF 06 00 00 01 22
|
||||
00 00 00 00
|
||||
09 06 01 01 20 07 00 FF 12 00 E2
|
||||
00 00 00 00
|
||||
05 D8 7E
|
||||
|
||||
7E A0 BA 2B 21 13 ED AA E6 E7 00 0F 00 00 00 00
|
||||
0C 07 E6 02 05 06 0D 00 14 FF 80 00 00
|
||||
02 19
|
||||
0A 0E 4B 61 6D 73 74 72 75 70 5F 56 30 30 30 31
|
||||
09 06 01 01 00 00 05 FF 0A 10 35 37 30 36 35 36 37 32 37 31 35 33 33 32 30 37
|
||||
09 06 01 01 60 01 01 FF 0A 12 36 38 36 31 31 31 31 42 4E 32 34 32 31 30 31 30 34 30
|
||||
09 06 01 01 01 07 00 FF 06 00 00 02 68
|
||||
09 06 01 01 02 07 00 FF 06 00 00 00 00
|
||||
09 06 01 01 03 07 00 FF 06 00 00 00 53
|
||||
09 06 01 01 04 07 00 FF 06 00 00 00 00
|
||||
09 06 01 01 1F 07 00 FF 06 00 00 01 23
|
||||
00 00 00 00
|
||||
09 06 01 01 20 07 00 FF 12 00 E1
|
||||
00 00 00 00
|
||||
8E 5E 7E
|
||||
|
||||
7E A1 04 2B 21 13 77 6E E6 E7 00 0F 00 00 00 00
|
||||
0C 07 E6 02 05 06 0D 00 19 FF 80 00 00
|
||||
02 23 0A 0E 4B 61 6D 73 74 72 75 70 5F 56 30 30 30 31
|
||||
09 06 01 01 00 00 05 FF 0A 10 35 37 30 36 35 36 37 32 37 31 35 33 33 32 30 37
|
||||
09 06 01 01 60 01 01 FF 0A 12 36 38 36 31 31 31 31 42 4E 32 34 32 31 30 31 30 34 30
|
||||
09 06 01 01 01 07 00 FF 06 00 00 02 6B
|
||||
09 06 01 01 02 07 00 FF 06 00 00 00 00
|
||||
09 06 01 01 03 07 00 FF 06 00 00 00 54
|
||||
09 06 01 01 04 07 00 FF 06 00 00 00 00
|
||||
09 06 01 01 1F 07 00 FF 06 00 00 01 25
|
||||
00 00 00 00
|
||||
09 06 01 01 20 07 00 FF 12 00 E1
|
||||
00 00 00 00
|
||||
09 06 00 01 01 00 00 FF 09 0C 07 E6 02 05 06 0D 00 19 FF 80 00 00
|
||||
09 06 01 01 01 08 00 FF 06 00 12 CF 93
|
||||
09 06 01 01 02 08 00 FF 06 00 00 00 00
|
||||
09 06 01 01 03 08 00 FF 06 00 00 8C CE
|
||||
09 06 01 01 04 08 00 FF 06 00 05 E5 04
|
||||
7F E9 7E
|
||||
51
frames/Kamstup-Encrypted.raw
Normal file
@@ -0,0 +1,51 @@
|
||||
# After decode:
|
||||
7E
|
||||
A1 E9 // Frame type and size
|
||||
41 03 13 C6 37 E6 E7 00
|
||||
DB // Encrypted
|
||||
08 4B 41 4D 45 01 AC 4D 6E // System title
|
||||
82 // Prefix for 2-byte length
|
||||
01 D0 // Length 464
|
||||
30 // Security tag 0011 0000, 0=Compression off, 0=Unicast, 1=Encryption, 0=Authentication, 0000= Security Suite ID
|
||||
00 00 A3 2F // Frame counter
|
||||
|
||||
// Decrypted frame below
|
||||
0F 00 00 00 00
|
||||
0C 07 E4 05 0C 02 0A 19 00 FF 80 00 80 // Package timestamp
|
||||
|
||||
02 41
|
||||
0A 0E 4B 61 6D 73 74 72 75 70 5F 56 30 30 30 31 - List ID
|
||||
09 06 01 01 01 08 00 FF 06 00 11 94 CA - Active+ Energy
|
||||
09 06 01 01 02 08 00 FF 06 00 00 00 00 - Active- Energy
|
||||
09 06 01 01 03 08 00 FF 06 00 00 12 7E - Reactive+ Energy
|
||||
09 06 01 01 04 08 00 FF 06 00 09 55 0E - Reactive- Energy
|
||||
09 06 01 01 00 00 01 FF 06 01 44 AD E1 - Electricity ID?
|
||||
09 06 01 01 01 07 00 FF 06 00 00 05 CC - Active+ Instantaneous value
|
||||
09 06 01 01 02 07 00 FF 06 00 00 00 00 - Active- Instantaneous value
|
||||
09 06 01 01 03 07 00 FF 06 00 00 00 00 - Reactive+ Instantaneous value
|
||||
09 06 01 01 04 07 00 FF 06 00 00 00 17 - Reactive- Instantaneous value
|
||||
09 06 00 01 01 00 00 FF 09 0C 07 E4 05 0C 02 0A 19 00 FF 80 00 80 - Current date/time
|
||||
09 06 01 01 20 07 00 FF 12 00 E5 - L1 Voltage Instantaneous value
|
||||
09 06 01 01 34 07 00 FF 12 00 E5 - L2 Voltage Instantaneous value
|
||||
09 06 01 01 48 07 00 FF 12 00 E3 - L3 Voltage Instantaneous value
|
||||
09 06 01 01 1F 07 00 FF 06 00 00 00 4B - L1 Current Instantaneous value
|
||||
09 06 01 01 33 07 00 FF 06 00 00 00 AA - L2 Current Instantaneous value
|
||||
09 06 01 01 47 07 00 FF 06 00 00 01 E4 - L3 Current Instantaneous value
|
||||
09 06 01 01 15 07 00 FF 06 00 00 00 71 - L1 Active+ Instantaneous value
|
||||
09 06 01 01 29 07 00 FF 06 00 00 01 54 - L2 Active+ Instantaneous value
|
||||
09 06 01 01 3D 07 00 FF 06 00 00 04 07 - L3 Active+ Instantaneous value
|
||||
09 06 01 01 21 07 00 FF 12 00 4D - L1 (cos.phi) (PF) Instantaneous value
|
||||
09 06 01 01 35 07 00 FF 12 00 5F - L2 (cos.phi) (PF) Instantaneous value
|
||||
09 06 01 01 49 07 00 FF 12 00 62 - L3 (cos.phi) (PF) Instantaneous value
|
||||
09 06 01 01 0D 07 00 FF 12 00 63 - Avegage (cos.phi) (PF) Inst. value
|
||||
09 06 01 01 16 07 00 FF 06 00 00 00 00 - L1 Active- Instantaneous value
|
||||
09 06 01 01 2A 07 00 FF 06 00 00 00 00 - L2 Active- Instantaneous value
|
||||
09 06 01 01 3E 07 00 FF 06 00 00 00 00 - L3 Active- Instantaneous value
|
||||
09 06 01 01 16 08 00 FF 06 00 00 00 00 - L1 Active- Energy
|
||||
09 06 01 01 2A 08 00 FF 06 00 00 00 00 - L2 Active- Energy
|
||||
09 06 01 01 3E 08 00 FF 06 00 00 00 00 - L3 Active- Energy
|
||||
09 06 01 01 15 08 00 FF 06 00 0A 8F 97 - L1 Active+ Energy
|
||||
09 06 01 01 29 08 00 FF 06 00 04 C1 53 - L2 Active+ Energy
|
||||
09 06 01 01 3D 08 00 FF 06 00 02 43 E0 - L3 Active+ Energy
|
||||
|
||||
5B C3 CD 5E 79 18 18 DA 9F 97 85 FF 5A 84 7E
|
||||
18
frames/Kamstup-TN-3p.raw
Normal file
@@ -0,0 +1,18 @@
|
||||
7E A0 E2 2B 21 13 23 9A E6 E7 00 0F 00 00 00 00
|
||||
0C 07 E5 0B 11 03 0B 32 00 FF 80 00 00
|
||||
|
||||
02 19
|
||||
0A 0E 4B 61 6D 73 74 72 75 70 5F 56 30 30 30 31 - List ID
|
||||
09 06 01 01 00 00 05 FF 0A 10 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX - Meter ID
|
||||
09 06 01 01 60 01 01 FF 0A 12 36 38 34 31 31 33 31 42 4E 32 34 33 31 30 31 30 34 30 - Meter model
|
||||
09 06 01 01 01 07 00 FF 06 00 00 05 E6 - Active+
|
||||
09 06 01 01 02 07 00 FF 06 00 00 00 00 - Active-
|
||||
09 06 01 01 03 07 00 FF 06 00 00 00 00 - Reactive+
|
||||
09 06 01 01 04 07 00 FF 06 00 00 01 92 - Reactive-
|
||||
09 06 01 01 1F 07 00 FF 06 00 00 00 A1 - L1 current
|
||||
09 06 01 01 33 07 00 FF 06 00 00 00 C1 - L2 current
|
||||
09 06 01 01 47 07 00 FF 06 00 00 01 8E - L3 current
|
||||
09 06 01 01 20 07 00 FF 12 00 EB - L1 voltage
|
||||
09 06 01 01 34 07 00 FF 12 00 EC - L2 voltage
|
||||
09 06 01 01 48 07 00 FF 12 00 EC - L3 voltage
|
||||
EF 5F 7E
|
||||
45
frames/austria.raw
Normal file
@@ -0,0 +1,45 @@
|
||||
// HDLC header
|
||||
68
|
||||
01 01 // Format (0x00) and total length (257)
|
||||
|
||||
68 // Start
|
||||
53 // Control field
|
||||
FF // Address (Broadcast address)
|
||||
|
||||
// LLC
|
||||
00 // Control information field
|
||||
01 // Source SAP
|
||||
67 // Destination SAP
|
||||
|
||||
DB // Encrypted
|
||||
08 53 41 47 59 05 E6 D9 FD // System title
|
||||
81 // Prefix for 1-byte length
|
||||
F8 // Length (248), starting from 0xDB and including end byte
|
||||
20 // Security tag 0010 0000, 0=Compression off, 0=Unicast, 1=Encryption, 0=No auth, 0000= Security Suite ID
|
||||
00 72 00 76 // Frame counter
|
||||
|
||||
|
||||
68 01 01 68
|
||||
53 FF 10 01 67
|
||||
DB
|
||||
08 53 41 47 59 05 E6 D9 FD
|
||||
81 F8
|
||||
20
|
||||
00 01 A0 E0
|
||||
0F 80 3E 37 71
|
||||
0C 07 E5 0C 1B 01 0E 00 2D 00 FF C4 02 // Frame timestamp
|
||||
02 23 // 35 items
|
||||
09 0C 07 E5 0C 1B 01 0E 00 2D 00 FF C4 02 // Meter timestamp
|
||||
09 06 01 00 01 08 00 FF 06 00 43 3D 0A 02 02 0F 00 16 1E
|
||||
09 06 01 00 02 08 00 FF 06 00 00 01 03 02 02 0F 00 16 1E
|
||||
09 06 01 00 01 07 00 FF 06 00 00 01 FE 02 02 0F 00 16 1B
|
||||
09 06 01 00 02 07 00 FF 06 00 00 00 00 02 02 0F 00 16 1B
|
||||
09 06 01 00 20 07 00 FF 12 09 34 02 02 0F FF 16 23
|
||||
09 06 01 00 34 07 00 FF 12 09 34 02 02 0F FF 16 23
|
||||
09 06 01 00 48 07 00 FF 12 09 2D 02 02 0F FF 16 23
|
||||
09 06 01 00 1F 07 00 FF 12 00 63 02 02 0F FE 16 21
|
||||
09 06 01 00 33 07 00 FF 12 00 3F 02 02 0F FE 16 21
|
||||
09 06 01 00 47 07 00 FF 12 00 54 02 02 0F FE 16 21
|
||||
09 06 01 00 0D 07 00 FF 10 03 CF 02 02 0F FD 16 FF // Power factor
|
||||
09 0C 31 37 38 32 31 30 30 31 35 31 36 35 // Meter ID
|
||||
01 67
|
||||
32
frames/decoding.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
T = Tag
|
||||
FF = Frame format (4 bit type, 1 bit segmentation, 11 bit frame length)
|
||||
DA = Destination Address (1-4 bytes, LSB=1 terminates)
|
||||
SA = Source address (1-4 bytes, LSB=1 terminates)
|
||||
C = Control (1 byte)
|
||||
HC = HCS (2 bytes)
|
||||
|
||||
LD = LLC Destination
|
||||
LS = LLC Remote
|
||||
LQ = LLC Quality
|
||||
|
||||
AT = Tag (0x0F = unencrypted, 0xDB = encrypted) Not really documented that well...
|
||||
AI = Invoke ID and priority (4 bytes)
|
||||
AD = Date and time
|
||||
AS = System title
|
||||
CT = Cipher frame tag ? Undocumented
|
||||
CL = Lenght of Cipher frame. Length of payload will be this number - 5 (control and counter in start) - 12 (GCM tag appended after payload)
|
||||
CC = Security control
|
||||
CO = Invocation counter
|
||||
|
||||
Security control bits
|
||||
01234567
|
||||
00110000 (0x30)
|
||||
0 = read acces
|
||||
1 = write access
|
||||
2 = Authenticated req
|
||||
3 = Encrypted req
|
||||
4 = Digitally signed req
|
||||
5 = Authenticated res
|
||||
6 = Encrypted res
|
||||
7 = Digitally signed res
|
||||
|
||||
@@ -1,45 +1 @@
|
||||
# Hardware options
|
||||
|
||||
There are currently two possible hardware options for this project, both in need of external power supply. A self powered board is under development by a member of the community and is currently being tested.
|
||||
|
||||
## Hardware v1 by [@roarfred](https://github.com/roarfred)
|
||||
Composed from a ESP12E (or F) chip, this ESP8266 based board is designed specifically for this project with an on board M-bus chip.
|
||||
|
||||
Building this project will require some skills in ordering and assembling electronic circuits as well as programming. No detailed instructions are available.
|
||||
|
||||

|
||||
|
||||
*The completed board mounted in a [3D printed enclosure](/Enclosure)*
|
||||
|
||||
## HAN reader 2.0 by [@dakarym](https://github.com/dakarym)
|
||||
A board that does not require external power source. This have only been successfully tested on Aidon as far as I know. It draws too much power for Kamstrup, but it may work with Kaifa. The design is almost
|
||||
completely built with SMD components, so advanced soldering skills are required to make this one.
|
||||
|
||||
[View his design here](https://github.com/dakarym/AmsToMqttBridge/tree/master/PCB)
|
||||
|
||||
## Assembly of readily available modules
|
||||
You can also use a ESP based development board and combine this with a M-Bus module. Here are a few boards that have been tested, each one has a dedicated firmware file in the releases section.
|
||||
|
||||
### ESP8266 based boards
|
||||
|
||||
[Wemos D1 mini](https://docs.wemos.cc/en/latest/d1/d1_mini.html)
|
||||
- M-Bus connected to GPIO5 (D1)
|
||||
- Jump GPIO4 (D2) to GND to force AP mode during boot
|
||||
- Dallas temp sensor connected to GPIO14 (D5)
|
||||
|
||||
### ESP32 based boards
|
||||
|
||||
[Wemos Lolin D32](https://docs.wemos.cc/en/latest/d32/d32.html)
|
||||
- M-Bus connected to GPIO16
|
||||
- Jump GPIO4 to GND to force AP mode during boot
|
||||
- Dallas temp sensor connected to GPIO14
|
||||
|
||||
[Adafruit HUZZAH32](https://www.adafruit.com/product/3405)
|
||||
- M-Bus connected to GPIO16
|
||||
|
||||
|
||||
Combine one of above board with an M-Bus module. Connect 3.3v and GND together between the boards and connect the TX pin from the M-Bus board to the dedicated M-Bus pin on the ESP board.
|
||||
|
||||
[TSS721 M-BUS module board](https://www.aliexpress.com/item/TSS721/32751482255.html)
|
||||
|
||||

|
||||
[See Hardware page in Wiki](https://github.com/gskjold/AmsToMqttBridge/wiki)
|
||||
|
||||
BIN
hardware/img/pow-k-kamstrup.jpg
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
hardware/img/pow-u-universal.jpg
Normal file
|
After Width: | Height: | Size: 91 KiB |
BIN
images/dashboard.png
Normal file
|
After Width: | Height: | Size: 136 KiB |
BIN
images/dayplot.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
images/future-energy-price.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
images/main-header.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
images/monthplot.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
images/real-time-calculation.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
images/sensor-displays.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
images/status-bar.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
images/tempsensors.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
@@ -1,197 +0,0 @@
|
||||
/*
|
||||
* Simple sketch to simulate reading data from a Kamstrup
|
||||
* AMS Meter.
|
||||
*
|
||||
* Created 24. October 2017 by Roar Fredriksen
|
||||
* Modified 06. November 2017 by Ruben Andreassen
|
||||
*/
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <HanReader.h>
|
||||
#include <Kamstrup.h>
|
||||
|
||||
// The HAN Port reader
|
||||
HanReader hanReader;
|
||||
|
||||
// WiFi and MQTT endpoints
|
||||
const char* ssid = "ssid";
|
||||
const char* password = "password";
|
||||
const char* mqtt_server = "ip or dns";
|
||||
const char* mqtt_topic = "sensors/out/espams";
|
||||
const char* device_name = "espams";
|
||||
|
||||
bool enableDebug = false;
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
|
||||
void setup() {
|
||||
//setupDebugPort(); //Comment out this line if you dont need debugging on Serial1
|
||||
setupWiFi();
|
||||
setupMqtt();
|
||||
|
||||
// initialize the HanReader
|
||||
// (passing no han port, as we are feeding data manually, but provide Serial for debugging)
|
||||
if (enableDebug) {
|
||||
hanReader.setup(&Serial, 2400, SERIAL_8N1, &Serial1);
|
||||
} else {
|
||||
hanReader.setup(&Serial, 2400, SERIAL_8N1, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void setupMqtt()
|
||||
{
|
||||
client.setServer(mqtt_server, 1883);
|
||||
}
|
||||
|
||||
void setupDebugPort()
|
||||
{
|
||||
enableDebug = true;
|
||||
// Initialize the Serial port for debugging
|
||||
Serial1.begin(115200);
|
||||
while (!Serial1) {}
|
||||
Serial1.setDebugOutput(true);
|
||||
Serial1.println("Serial1");
|
||||
Serial1.println("Serial debugging port initialized");
|
||||
}
|
||||
|
||||
|
||||
void setupWiFi()
|
||||
{
|
||||
// Initialize wifi
|
||||
if (enableDebug) {
|
||||
Serial1.print("Connecting to ");
|
||||
Serial1.println(ssid);
|
||||
}
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
if (enableDebug) Serial1.print(".");
|
||||
}
|
||||
|
||||
if (enableDebug) {
|
||||
Serial1.println("");
|
||||
Serial1.println("WiFi connected");
|
||||
Serial1.println("IP address: ");
|
||||
Serial1.println(WiFi.localIP());
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
loopMqtt();
|
||||
|
||||
// Read one byte from the port, and see if we got a full package
|
||||
if (hanReader.read())
|
||||
{
|
||||
// Get the list identifier
|
||||
int listSize = hanReader.getListSize();
|
||||
|
||||
if (enableDebug) {
|
||||
Serial1.println("");
|
||||
Serial1.print("List size: ");
|
||||
Serial1.print(listSize);
|
||||
Serial1.print(": ");
|
||||
}
|
||||
|
||||
// Only care for the ACtive Power Imported, which is found in the first list
|
||||
if (listSize == (int)Kamstrup::List1 || listSize == (int)Kamstrup::List2)
|
||||
{
|
||||
// Define a json object to keep the data
|
||||
StaticJsonBuffer<MQTT_MAX_PACKET_SIZE> jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.createObject();
|
||||
|
||||
// Any generic useful info here
|
||||
root["dn"] = device_name;
|
||||
root["up"] = millis();
|
||||
|
||||
// Add a sub-structure to the json object,
|
||||
// to keep the data from the meter itself
|
||||
JsonObject& data = root.createNestedObject("data");
|
||||
|
||||
data["ls"] = listSize;
|
||||
|
||||
data["lvi"] = hanReader.getString((int)Kamstrup_List1::ListVersionIdentifier);
|
||||
data["mid"] = hanReader.getString((int)Kamstrup_List1::MeterID);
|
||||
data["mt"] = hanReader.getString((int)Kamstrup_List1::MeterType);
|
||||
data["t"] = hanReader.getPackageTime();
|
||||
|
||||
data["aip"] = hanReader.getInt((int)Kamstrup_List1::ActiveImportPower); //power
|
||||
data["aep"] = hanReader.getInt((int)Kamstrup_List1::ActiveExportPower);
|
||||
data["rip"] = hanReader.getInt((int)Kamstrup_List1::ReactiveImportPower);
|
||||
data["rep"] = hanReader.getInt((int)Kamstrup_List1::ReactiveExportPower);
|
||||
|
||||
data["al1"] = (float)hanReader.getInt((int)Kamstrup_List1::CurrentL1) / 100.0;
|
||||
data["al2"] = (float)hanReader.getInt((int)Kamstrup_List1::CurrentL2) / 100.0;
|
||||
data["al3"] = (float)hanReader.getInt((int)Kamstrup_List1::CurrentL3) / 100.0;
|
||||
|
||||
data["vl1"] = hanReader.getInt((int)Kamstrup_List1::VoltageL1);
|
||||
data["vl2"] = hanReader.getInt((int)Kamstrup_List1::VoltageL2);
|
||||
data["vl3"] = hanReader.getInt((int)Kamstrup_List1::VoltageL3);
|
||||
|
||||
if (listSize == (int)Kamstrup::List2)
|
||||
{
|
||||
data["cl"] = hanReader.getTime((int)Kamstrup_List2::MeterClock);
|
||||
data["caie"] = hanReader.getInt((int)Kamstrup_List2::CumulativeActiveImportEnergy);
|
||||
data["caee"] = hanReader.getInt((int)Kamstrup_List2::CumulativeActiveExportEnergy);
|
||||
data["crie"] = hanReader.getInt((int)Kamstrup_List2::CumulativeReactiveImportEnergy);
|
||||
data["cree"] = hanReader.getInt((int)Kamstrup_List2::CumulativeReactiveExportEnergy);
|
||||
}
|
||||
|
||||
if (enableDebug) {
|
||||
root.printTo(Serial1);
|
||||
Serial1.println("JSON length");
|
||||
Serial1.println(root.measureLength());
|
||||
Serial1.println("");
|
||||
}
|
||||
|
||||
// Publish the json to the MQTT server
|
||||
char msg[MQTT_MAX_PACKET_SIZE];
|
||||
root.printTo(msg, MQTT_MAX_PACKET_SIZE);
|
||||
bool result = client.publish(mqtt_topic, msg);
|
||||
|
||||
if (enableDebug) {
|
||||
Serial1.println("MQTT publish result:");
|
||||
Serial1.println(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Ensure the MQTT lirary gets some attention too
|
||||
void loopMqtt()
|
||||
{
|
||||
if (!client.connected()) {
|
||||
reconnectMqtt();
|
||||
}
|
||||
client.loop();
|
||||
}
|
||||
|
||||
void reconnectMqtt() {
|
||||
// Loop until we're reconnected
|
||||
while (!client.connected()) {
|
||||
if (enableDebug) Serial1.print("Attempting MQTT connection...");
|
||||
// Attempt to connect
|
||||
if (client.connect("ESP8266Client")) {
|
||||
if (enableDebug) Serial1.println("connected");
|
||||
// Once connected, publish an announcement...
|
||||
// client.publish("sensors", "hello world");
|
||||
// ... and resubscribe
|
||||
// client.subscribe("inTopic");
|
||||
}
|
||||
else {
|
||||
if (enableDebug) {
|
||||
Serial1.print("failed, rc=");
|
||||
Serial1.print(client.state());
|
||||
Serial1.println(" try again in 5 seconds");
|
||||
}
|
||||
// Wait 5 seconds before retrying
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
# Setup
|
||||
|
||||
1. Copy AmsToMqttBridge\Code\Arduino\HanReader\src to Arduino\libraries
|
||||
2. Download the following libraries and put them in Arduino\libraries
|
||||
- ESP8266WiFi
|
||||
- PubSubClient
|
||||
- ArduinoJson
|
||||
3. **Set MQTT_MAX_PACKET_SIZE in PubSubClient.h to at least 512 (i used 1024)**
|
||||
4. Edit the following variables in the project:
|
||||
- ssid
|
||||
- password
|
||||
- mqtt_server
|
||||
- mqtt_topic
|
||||
- device_name
|
||||
|
||||
## Output example:
|
||||
### List 1
|
||||
```
|
||||
{
|
||||
"dn": "espams",
|
||||
"up": 1475902,
|
||||
"data": {
|
||||
"ls": 25,
|
||||
"lvi": "Kamstrup_V0001",
|
||||
"mid": "5706567274389702",
|
||||
"mt": "6841121BN243101040",
|
||||
"t": 1510088840,
|
||||
"aip": 3499,
|
||||
"aep": 0,
|
||||
"rip": 0,
|
||||
"rep": 424,
|
||||
"al1": 10.27,
|
||||
"al2": 6.37,
|
||||
"al3": 11.79,
|
||||
"vl1": 231,
|
||||
"vl2": 226,
|
||||
"vl3": 231
|
||||
}
|
||||
}
|
||||
```
|
||||
### List 2
|
||||
```
|
||||
{
|
||||
"dn": "espams",
|
||||
"up": 1041212,
|
||||
"data": {
|
||||
"ls": 35,
|
||||
"lvi": "Kamstrup_V0001",
|
||||
"mid": "5706567274389702",
|
||||
"mt": "6841121BN243101040",
|
||||
"t": 1510088405,
|
||||
"aip": 4459,
|
||||
"aep": 0,
|
||||
"rip": 0,
|
||||
"rep": 207,
|
||||
"al1": 14.72,
|
||||
"al2": 6.39,
|
||||
"al3": 15.02,
|
||||
"vl1": 231,
|
||||
"vl2": 227,
|
||||
"vl3": 231,
|
||||
"cl": 1510088405,
|
||||
"caie": 588500,
|
||||
"caee": 0,
|
||||
"crie": 93,
|
||||
"cree": 80831
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### List 1 and 2 fields
|
||||
- dn = Device Name
|
||||
- up = MS since last reboot
|
||||
- ls = List Size
|
||||
- lvi = List Version Identifier
|
||||
- mid = Meter ID
|
||||
- mt = Meter Type
|
||||
- t = Time
|
||||
- aie = Active Import Power
|
||||
- aep = Active Export Power
|
||||
- rip = Reactive Import Power
|
||||
- rep = Reactive Export Power
|
||||
- al1 = Current L1
|
||||
- al2 = Current L2
|
||||
- al3 = Current L3
|
||||
- cl1 = Voltage L1
|
||||
- cl2 = Voltage L2
|
||||
- cl3 = Voltage L3
|
||||
|
||||
### List 2 additional fields
|
||||
- cl = Meter Clock
|
||||
- caie = Cumulative Active Import Energy
|
||||
- caee = Cumulative Active Export Energy
|
||||
- crie = Cumulative Reactive Import Energy
|
||||
- cree = Cumulative Reactive Export Energy
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Simple sketch to read MBus data from electrical meter
|
||||
* As the protocol requires "Even" parity, and this is
|
||||
* only supported on the hardware port of the ESP8266,
|
||||
* we'll have to use Serial1 for debugging.
|
||||
*
|
||||
* This means you'll have to program the ESP using the
|
||||
* regular RX/TX port, and then you must remove the FTDI
|
||||
* and connect the MBus signal from the meter to the
|
||||
* RS pin. The FTDI/RX can be moved to Pin2 for debugging
|
||||
*
|
||||
* Created 14. september 2017 by Roar Fredriksen
|
||||
*/
|
||||
|
||||
#include "HanReader.h"
|
||||
#include "Kaifa.h"
|
||||
|
||||
// The HAN Port reader
|
||||
HanReader hanReader;
|
||||
|
||||
void setup() {
|
||||
setupDebugPort();
|
||||
|
||||
// initialize the HanReader
|
||||
// (passing Serial as the HAN port and Serial1 for debugging)
|
||||
hanReader.setup(&Serial, &Serial1);
|
||||
}
|
||||
|
||||
void setupDebugPort()
|
||||
{
|
||||
// Initialize the Serial1 port for debugging
|
||||
// (This port is fixed to Pin2 of the ESP8266)
|
||||
Serial1.begin(115200);
|
||||
while (!Serial1) {}
|
||||
Serial1.setDebugOutput(true);
|
||||
Serial1.println("Serial1");
|
||||
Serial1.println("Serial debugging port initialized");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Read one byte from the port, and see if we got a full package
|
||||
if (hanReader.read())
|
||||
{
|
||||
// Get the list identifier
|
||||
int listSize = hanReader.getListSize();
|
||||
|
||||
Serial1.println("");
|
||||
Serial1.print("List size: ");
|
||||
Serial1.print(listSize);
|
||||
Serial1.print(": ");
|
||||
|
||||
// Only care for the ACtive Power Imported, which is found in the first list
|
||||
if (listSize == (int)Kaifa::List1)
|
||||
{
|
||||
int power = hanReader.getInt((int)Kaifa_List1::ActivePowerImported);
|
||||
Serial1.print("Power consumtion is right now: ");
|
||||
Serial1.print(power);
|
||||
Serial1.println(" W");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
* Simple sketch to read MBus data from electrical meter
|
||||
* As the protocol requires "Even" parity, and this is
|
||||
* only supported on the hardware port of the ESP8266,
|
||||
* we'll have to use Serial1 for debugging.
|
||||
*
|
||||
* This means you'll have to program the ESP using the
|
||||
* regular RX/TX port, and then you must remove the FTDI
|
||||
* and connect the MBus signal from the meter to the
|
||||
* RS pin. The FTDI/RX can be moved to Pin2 for debugging
|
||||
*
|
||||
* Created 14. september 2017 by Roar Fredriksen
|
||||
*/
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include "HanReader.h"
|
||||
#include "Kaifa.h"
|
||||
|
||||
// The HAN Port reader
|
||||
HanReader hanReader;
|
||||
|
||||
// WiFi and MQTT endpoints
|
||||
const char* ssid = "Roar_Etne";
|
||||
const char* password = "**********";
|
||||
const char* mqtt_server = "192.168.10.203";
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
|
||||
void setup() {
|
||||
setupDebugPort();
|
||||
setupWiFi();
|
||||
setupMqtt();
|
||||
|
||||
// initialize the HanReader
|
||||
// (passing Serial as the HAN port and Serial1 for debugging)
|
||||
hanReader.setup(&Serial, &Serial1);
|
||||
}
|
||||
|
||||
void setupMqtt()
|
||||
{
|
||||
client.setServer(mqtt_server, 1883);
|
||||
}
|
||||
|
||||
void setupDebugPort()
|
||||
{
|
||||
// Initialize the Serial1 port for debugging
|
||||
// (This port is fixed to Pin2 of the ESP8266)
|
||||
Serial1.begin(115200);
|
||||
while (!Serial1) {}
|
||||
Serial1.setDebugOutput(true);
|
||||
Serial1.println("Serial1");
|
||||
Serial1.println("Serial debugging port initialized");
|
||||
}
|
||||
|
||||
void setupWiFi()
|
||||
{
|
||||
// Initialize wifi
|
||||
Serial1.print("Connecting to ");
|
||||
Serial1.println(ssid);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial1.print(".");
|
||||
}
|
||||
|
||||
Serial1.println("");
|
||||
Serial1.println("WiFi connected");
|
||||
Serial1.println("IP address: ");
|
||||
Serial1.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
loopMqtt();
|
||||
|
||||
// Read one byt from the port, and see if we got a full package
|
||||
if (hanReader.read())
|
||||
{
|
||||
// Get the list identifier
|
||||
int listSize = hanReader.getListSize();
|
||||
|
||||
Serial1.println("");
|
||||
Serial1.print("List size: ");
|
||||
Serial1.print(listSize);
|
||||
Serial1.print(": ");
|
||||
|
||||
// Only care for the ACtive Power Imported, which is found in the first list
|
||||
if (listSize == (int)Kaifa::List1 || listSize == (int)Kaifa::List2 || listSize == (int)Kaifa::List3)
|
||||
{
|
||||
if (listSize == (int)Kaifa::List1)
|
||||
{
|
||||
Serial1.println(" (list #1 has no ID)");
|
||||
}
|
||||
else
|
||||
{
|
||||
String id = hanReader.getString((int)Kaifa_List2::ListVersionIdentifier);
|
||||
Serial1.println(id);
|
||||
}
|
||||
|
||||
// Get the timestamp (as unix time) from the package
|
||||
time_t time = hanReader.getPackageTime();
|
||||
Serial.print("Time of the package is: ");
|
||||
Serial.println(time);
|
||||
|
||||
// Define a json object to keep the data
|
||||
StaticJsonBuffer<500> jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.createObject();
|
||||
|
||||
// Any generic useful info here
|
||||
root["id"] = "espdebugger";
|
||||
root["up"] = millis();
|
||||
root["t"] = time;
|
||||
|
||||
// Add a sub-structure to the json object,
|
||||
// to keep the data from the meter itself
|
||||
JsonObject& data = root.createNestedObject("data");
|
||||
|
||||
// Based on the list number, get all details
|
||||
// according to OBIS specifications for the meter
|
||||
if (listSize == (int)Kaifa::List1)
|
||||
{
|
||||
data["P"] = hanReader.getInt((int)Kaifa_List1::ActivePowerImported);
|
||||
}
|
||||
else if (listSize == (int)Kaifa::List2)
|
||||
{
|
||||
data["lv"] = hanReader.getString((int)Kaifa_List2::ListVersionIdentifier);
|
||||
data["id"] = hanReader.getString((int)Kaifa_List2::MeterID);
|
||||
data["type"] = hanReader.getString((int)Kaifa_List2::MeterType);
|
||||
data["P"] = hanReader.getInt((int)Kaifa_List2::ActiveImportPower);
|
||||
data["Q"] = hanReader.getInt((int)Kaifa_List2::ReactiveImportPower);
|
||||
data["I1"] = hanReader.getInt((int)Kaifa_List2::CurrentL1);
|
||||
data["I2"] = hanReader.getInt((int)Kaifa_List2::CurrentL2);
|
||||
data["I3"] = hanReader.getInt((int)Kaifa_List2::CurrentL3);
|
||||
data["U1"] = hanReader.getInt((int)Kaifa_List2::VoltageL1);
|
||||
data["U2"] = hanReader.getInt((int)Kaifa_List2::VoltageL2);
|
||||
data["U3"] = hanReader.getInt((int)Kaifa_List2::VoltageL3);
|
||||
}
|
||||
else if (listSize == (int)Kaifa::List3)
|
||||
{
|
||||
data["lv"] = hanReader.getString((int)Kaifa_List3::ListVersionIdentifier);;
|
||||
data["id"] = hanReader.getString((int)Kaifa_List3::MeterID);
|
||||
data["type"] = hanReader.getString((int)Kaifa_List3::MeterType);
|
||||
data["P"] = hanReader.getInt((int)Kaifa_List3::ActiveImportPower);
|
||||
data["Q"] = hanReader.getInt((int)Kaifa_List3::ReactiveImportPower);
|
||||
data["I1"] = hanReader.getInt((int)Kaifa_List3::CurrentL1);
|
||||
data["I2"] = hanReader.getInt((int)Kaifa_List3::CurrentL2);
|
||||
data["I3"] = hanReader.getInt((int)Kaifa_List3::CurrentL3);
|
||||
data["U1"] = hanReader.getInt((int)Kaifa_List3::VoltageL1);
|
||||
data["U2"] = hanReader.getInt((int)Kaifa_List3::VoltageL2);
|
||||
data["U3"] = hanReader.getInt((int)Kaifa_List3::VoltageL3);
|
||||
data["tPI"] = hanReader.getInt((int)Kaifa_List3::CumulativeActiveImportEnergy);
|
||||
data["tPO"] = hanReader.getInt((int)Kaifa_List3::CumulativeActiveExportEnergy);
|
||||
data["tQI"] = hanReader.getInt((int)Kaifa_List3::CumulativeReactiveImportEnergy);
|
||||
data["tQO"] = hanReader.getInt((int)Kaifa_List3::CumulativeReactiveExportEnergy);
|
||||
}
|
||||
|
||||
// Write the json to the debug port
|
||||
root.printTo(Serial1);
|
||||
Serial1.println();
|
||||
|
||||
// Publish the json to the MQTT server
|
||||
char msg[1024];
|
||||
root.printTo(msg, 1024);
|
||||
client.publish("sensors/out/espdebugger", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the MQTT lirary gets some attention too
|
||||
void loopMqtt()
|
||||
{
|
||||
if (!client.connected()) {
|
||||
reconnectMqtt();
|
||||
}
|
||||
client.loop();
|
||||
}
|
||||
|
||||
void reconnectMqtt() {
|
||||
// Loop until we're reconnected
|
||||
while (!client.connected()) {
|
||||
Serial1.print("Attempting MQTT connection...");
|
||||
// Attempt to connect
|
||||
if (client.connect("ESP8266Client")) {
|
||||
Serial1.println("connected");
|
||||
// Once connected, publish an announcement...
|
||||
// client.publish("sensors", "hello world");
|
||||
// ... and resubscribe
|
||||
// client.subscribe("inTopic");
|
||||
}
|
||||
else {
|
||||
Serial1.print("failed, rc=");
|
||||
Serial1.print(client.state());
|
||||
Serial1.println(" try again in 5 seconds");
|
||||
// Wait 5 seconds before retrying
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
name=HANreader
|
||||
version=1.0.1
|
||||
author=roarfred
|
||||
maintainer=roarfred <not@important.com>
|
||||
sentence=HAN support
|
||||
paragraph=HAN support
|
||||
category=Sensors
|
||||
url=https://github.com/roarfred/AmsToMqttBridge
|
||||
architectures=*
|
||||
depends=Timezone
|
||||
@@ -1,19 +0,0 @@
|
||||
Arduino Compatible Cross Platform C++ Library Project : For more information see http://www.visualmicro.com
|
||||
|
||||
This project works exactly the same way as an Arduino library.
|
||||
|
||||
Add this project to any solution that contains an Arduino project and #include <headers.h> in code as you would any normal Arduino library headers.
|
||||
|
||||
To enable intellisense and to support live build discovery outside of the "standard" Arduino library locations, ensure that the library is added as a shared project reference to the master Arduino project. To do this, right click the master project "References" node and then click "Add Reference". A window will open and the library will appear on the "Shared Projects" tab. Click the checkbox next to the library name to add the reference. If this library is moved the shared referencemust be removed and re-added.
|
||||
|
||||
VS2017 has a bug, workround: After moving existing source code within a "library or shared project", close and re-open the solution.
|
||||
|
||||
Visual Studio will display intellisense for libraries based on the platform/board that has been specified for the currently active "Startup Project" of the current solution.
|
||||
|
||||
|
||||
IMPORTANT: The arduino.cc Library Rules must be followed when adding code or restructing libraries.
|
||||
|
||||
|
||||
|
||||
|
||||
blog: http://www.visualmicro.com/post/2017/01/16/Arduino-Cross-Platform-Library-Development.aspx
|
||||
@@ -1,304 +0,0 @@
|
||||
// Aidon.h
|
||||
|
||||
#ifndef _AIDON_h
|
||||
#define _AIDON_h
|
||||
|
||||
enum class Aidon
|
||||
{
|
||||
List1 = 0x01,
|
||||
List1PhaseShort = 0x09,
|
||||
List1PhaseLong = 0x0E,
|
||||
List3PhaseShort = 0x0D,
|
||||
List3PhaseLong = 0x12,
|
||||
List3PhaseITShort = 0x0C,
|
||||
List3PhaseITLong = 0x11,
|
||||
};
|
||||
|
||||
enum class Aidon_List1
|
||||
{
|
||||
ListSize,
|
||||
IGN_0,
|
||||
ActiveImportPower_OBIS,
|
||||
ActiveImportPower,
|
||||
IGN_1,
|
||||
ActiveImportPowerInt8,
|
||||
ActiveImportPowerEnum
|
||||
};
|
||||
|
||||
|
||||
enum class Aidon_List1Phase
|
||||
{
|
||||
ListSize,
|
||||
IGN_0,
|
||||
ListVersionIdentifier_OBIS,
|
||||
ListVersionIdentifier,
|
||||
IGN_1,
|
||||
MeterID_OBIS,
|
||||
MeterID,
|
||||
IGN_2,
|
||||
MeterType_OBIS,
|
||||
MeterType,
|
||||
IGN_3,
|
||||
ActiveImportPower_OBIS,
|
||||
ActiveImportPower,
|
||||
IGN_4,
|
||||
ActiveImportPowerInt8,
|
||||
ActiveImportPowerEnum,
|
||||
IGN_5,
|
||||
ActiveExportPower_OBIS,
|
||||
ActiveExportPower,
|
||||
IGN_6,
|
||||
ActiveExportPowerInt8,
|
||||
ActiveExportPowerEnum,
|
||||
IGN_7,
|
||||
ReactiveImportPower_OBIS,
|
||||
ReactiveImportPower,
|
||||
IGN_8,
|
||||
ReactiveImportPowerInt8,
|
||||
ReactiveImportPowerEnum,
|
||||
IGN_9,
|
||||
ReactiveExportPower_OBIS,
|
||||
ReactiveExportPower,
|
||||
IGN_10,
|
||||
ReactiveExportPowerInt8,
|
||||
ReactiveExportPowerEnum,
|
||||
IGN_11,
|
||||
CurrentL1_OBIS,
|
||||
CurrentL1,
|
||||
IGN_12,
|
||||
CurrentL1Int8,
|
||||
CurrentL1Enum,
|
||||
IGN_13,
|
||||
VoltageL1_OBIS,
|
||||
VoltageL1,
|
||||
IGN_14,
|
||||
VoltageL1Int8,
|
||||
VoltageL1Enum,
|
||||
IGN_15,
|
||||
Timestamp_OBIS,
|
||||
Timestamp,
|
||||
IGN_16,
|
||||
CumulativeActiveImportEnergy_OBIS,
|
||||
CumulativeActiveImportEnergy,
|
||||
IGN_17,
|
||||
CumulativeActiveImportEnergyInt8,
|
||||
CumulativeActiveImportEnergyEnum,
|
||||
IGN_18,
|
||||
CumulativeActiveExportEnergy_OBIS,
|
||||
CumulativeActiveExportEnergy,
|
||||
IGN_19,
|
||||
CumulativeActiveExportEnergyInt8,
|
||||
CumulativeActiveExportEnergyEnum,
|
||||
IGN_20,
|
||||
CumulativeReactiveImportEnergy_OBIS,
|
||||
CumulativeReactiveImportEnergy,
|
||||
IGN_21,
|
||||
CumulativeReactiveImportEnergyInt8,
|
||||
CumulativeReactiveImportEnergyEnum,
|
||||
IGN_22,
|
||||
CumulativeReactiveExportEnergy_OBIS,
|
||||
CumulativeReactiveExportEnergy,
|
||||
IGN_23,
|
||||
CumulativeReactiveExportEnergyInt8,
|
||||
CumulativeReactiveExportEnergyEnum
|
||||
};
|
||||
|
||||
enum class Aidon_List3Phase
|
||||
{
|
||||
ListSize,
|
||||
IGN_0,
|
||||
ListVersionIdentifier_OBIS,
|
||||
ListVersionIdentifier,
|
||||
IGN_1,
|
||||
MeterID_OBIS,
|
||||
MeterID,
|
||||
IGN_2,
|
||||
MeterType_OBIS,
|
||||
MeterType,
|
||||
IGN_3,
|
||||
ActiveImportPower_OBIS,
|
||||
ActiveImportPower,
|
||||
IGN_4,
|
||||
ActiveImportPowerInt8,
|
||||
ActiveImportPowerEnum,
|
||||
IGN_5,
|
||||
ActiveExportPower_OBIS,
|
||||
ActiveExportPower,
|
||||
IGN_6,
|
||||
ActiveExportPowerInt8,
|
||||
ActiveExportPowerEnum,
|
||||
IGN_7,
|
||||
ReactiveImportPower_OBIS,
|
||||
ReactiveImportPower,
|
||||
IGN_8,
|
||||
ReactiveImportPowerInt8,
|
||||
ReactiveImportPowerEnum,
|
||||
IGN_9,
|
||||
ReactiveExportPower_OBIS,
|
||||
ReactiveExportPower,
|
||||
IGN_10,
|
||||
ReactiveExportPowerInt8,
|
||||
ReactiveExportPowerEnum,
|
||||
IGN_11,
|
||||
CurrentL1_OBIS,
|
||||
CurrentL1,
|
||||
IGN_12,
|
||||
CurrentL1Int8,
|
||||
CurrentL1Enum,
|
||||
IGN_13,
|
||||
CurrentL2_OBIS,
|
||||
CurrentL2,
|
||||
IGN_14,
|
||||
CurrentL2Int8,
|
||||
CurrentL2Enum,
|
||||
IGN_15,
|
||||
CurrentL3_OBIS,
|
||||
CurrentL3,
|
||||
IGN_16,
|
||||
CurrentL3Int8,
|
||||
CurrentL3Enum,
|
||||
IGN_17,
|
||||
VoltageL1_OBIS,
|
||||
VoltageL1,
|
||||
IGN_18,
|
||||
VoltageL1Int8,
|
||||
VoltageL1Enum,
|
||||
IGN_19,
|
||||
VoltageL2_OBIS,
|
||||
VoltageL2,
|
||||
IGN_20,
|
||||
VoltageL2Int8,
|
||||
VoltageL2Enum,
|
||||
IGN_21,
|
||||
VoltageL3_OBIS,
|
||||
VoltageL3,
|
||||
IGN_22,
|
||||
VoltageL3Int8,
|
||||
VoltageL3Enum,
|
||||
IGN_23,
|
||||
Timestamp_OBIS,
|
||||
Timestamp,
|
||||
IGN_24,
|
||||
CumulativeActiveImportEnergy_OBIS,
|
||||
CumulativeActiveImportEnergy,
|
||||
IGN_25,
|
||||
CumulativeActiveImportEnergyInt8,
|
||||
CumulativeActiveImportEnergyEnum,
|
||||
IGN_26,
|
||||
CumulativeActiveExportEnergy_OBIS,
|
||||
CumulativeActiveExportEnergy,
|
||||
IGN_27,
|
||||
CumulativeActiveExportEnergyInt8,
|
||||
CumulativeActiveExportEnergyEnum,
|
||||
IGN_28,
|
||||
CumulativeReactiveImportEnergy_OBIS,
|
||||
CumulativeReactiveImportEnergy,
|
||||
IGN_29,
|
||||
CumulativeReactiveImportEnergyInt8,
|
||||
CumulativeReactiveImportEnergyEnum,
|
||||
IGN_30,
|
||||
CumulativeReactiveExportEnergy_OBIS,
|
||||
CumulativeReactiveExportEnergy,
|
||||
IGN_31,
|
||||
CumulativeReactiveExportEnergyInt8,
|
||||
CumulativeReactiveExportEnergyEnum
|
||||
};
|
||||
|
||||
enum class Aidon_List3PhaseIT
|
||||
{
|
||||
ListSize,
|
||||
IGN_0,
|
||||
ListVersionIdentifier_OBIS,
|
||||
ListVersionIdentifier,
|
||||
IGN_1,
|
||||
MeterID_OBIS,
|
||||
MeterID,
|
||||
IGN_2,
|
||||
MeterType_OBIS,
|
||||
MeterType,
|
||||
IGN_3,
|
||||
ActiveImportPower_OBIS,
|
||||
ActiveImportPower,
|
||||
IGN_4,
|
||||
ActiveImportPowerInt8,
|
||||
ActiveImportPowerEnum,
|
||||
IGN_5,
|
||||
ActiveExportPower_OBIS,
|
||||
ActiveExportPower,
|
||||
IGN_6,
|
||||
ActiveExportPowerInt8,
|
||||
ActiveExportPowerEnum,
|
||||
IGN_7,
|
||||
ReactiveImportPower_OBIS,
|
||||
ReactiveImportPower,
|
||||
IGN_8,
|
||||
ReactiveImportPowerInt8,
|
||||
ReactiveImportPowerEnum,
|
||||
IGN_9,
|
||||
ReactiveExportPower_OBIS,
|
||||
ReactiveExportPower,
|
||||
IGN_10,
|
||||
ReactiveExportPowerInt8,
|
||||
ReactiveExportPowerEnum,
|
||||
IGN_11,
|
||||
CurrentL1_OBIS,
|
||||
CurrentL1,
|
||||
IGN_12,
|
||||
CurrentL1Int8,
|
||||
CurrentL1Enum,
|
||||
IGN_13,
|
||||
CurrentL3_OBIS,
|
||||
CurrentL3,
|
||||
IGN_14,
|
||||
CurrentL3Int8,
|
||||
CurrentL3Enum,
|
||||
IGN_15,
|
||||
VoltageL1_OBIS,
|
||||
VoltageL1,
|
||||
IGN_16,
|
||||
VoltageL1Int8,
|
||||
VoltageL1Enum,
|
||||
IGN_17,
|
||||
VoltageL2_OBIS,
|
||||
VoltageL2,
|
||||
IGN_18,
|
||||
VoltageL2Int8,
|
||||
VoltageL2Enum,
|
||||
IGN_19,
|
||||
VoltageL3_OBIS,
|
||||
VoltageL3,
|
||||
IGN_20,
|
||||
VoltageL3Int8,
|
||||
VoltageL3Enum,
|
||||
IGN_21,
|
||||
Timestamp_OBIS,
|
||||
Timestamp,
|
||||
IGN_22,
|
||||
CumulativeActiveImportEnergy_OBIS,
|
||||
CumulativeActiveImportEnergy,
|
||||
IGN_23,
|
||||
CumulativeActiveImportEnergyInt8,
|
||||
CumulativeActiveImportEnergyEnum,
|
||||
IGN_24,
|
||||
CumulativeActiveExportEnergy_OBIS,
|
||||
CumulativeActiveExportEnergy,
|
||||
IGN_25,
|
||||
CumulativeActiveExportEnergyInt8,
|
||||
CumulativeActiveExportEnergyEnum,
|
||||
IGN_26,
|
||||
CumulativeReactiveImportEnergy_OBIS,
|
||||
CumulativeReactiveImportEnergy,
|
||||
IGN_27,
|
||||
CumulativeReactiveImportEnergyInt8,
|
||||
CumulativeReactiveImportEnergyEnum,
|
||||
IGN_28,
|
||||
CumulativeReactiveExportEnergy_OBIS,
|
||||
CumulativeReactiveExportEnergy,
|
||||
IGN_29,
|
||||
CumulativeReactiveExportEnergyInt8,
|
||||
CumulativeReactiveExportEnergyEnum
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#include "Crc16.h"
|
||||
|
||||
Crc16Class::Crc16Class()
|
||||
{
|
||||
unsigned short value;
|
||||
unsigned short temp;
|
||||
for (unsigned short i = 0; i < 256; ++i)
|
||||
{
|
||||
value = 0;
|
||||
temp = i;
|
||||
for (byte j = 0; j < 8; ++j)
|
||||
{
|
||||
if (((value ^ temp) & 0x0001) != 0)
|
||||
{
|
||||
value = (ushort)((value >> 1) ^ polynomial);
|
||||
}
|
||||
else
|
||||
{
|
||||
value >>= 1;
|
||||
}
|
||||
temp >>= 1;
|
||||
}
|
||||
table[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned short Crc16Class::ComputeChecksum(byte *data, int start, int length)
|
||||
{
|
||||
ushort fcs = 0xffff;
|
||||
for (int i = start; i < (start + length); i++)
|
||||
{
|
||||
byte index = (fcs ^ data[i]) & 0xff;
|
||||
fcs = (ushort)((fcs >> 8) ^ table[index]);
|
||||
}
|
||||
fcs ^= 0xffff;
|
||||
return fcs;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef _CRC16_h
|
||||
#define _CRC16_h
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
class Crc16Class
|
||||
{
|
||||
public:
|
||||
Crc16Class();
|
||||
unsigned short ComputeChecksum(byte *data, int start, int length);
|
||||
protected:
|
||||
private:
|
||||
const unsigned short polynomial = 0x8408;
|
||||
unsigned short table[256];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,208 +0,0 @@
|
||||
#include "DlmsReader.h"
|
||||
|
||||
DlmsReader::DlmsReader()
|
||||
{
|
||||
//this->Clear();
|
||||
}
|
||||
|
||||
void DlmsReader::Clear()
|
||||
{
|
||||
this->position = 0;
|
||||
this->dataLength = 0;
|
||||
this->destinationAddressLength = 0;
|
||||
this->sourceAddressLength = 0;
|
||||
this->frameFormatType = 0;
|
||||
}
|
||||
|
||||
bool DlmsReader::Read(byte data, Print* debugger)
|
||||
{
|
||||
if (position == 0 && data != 0x7E)
|
||||
{
|
||||
// we haven't started yet, wait for the start flag (no need to capture any data yet)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have completed reading of one package, so clear and be ready for the next
|
||||
if (dataLength > 0 && position >= dataLength + 2) {
|
||||
if(debugger != NULL) {
|
||||
debugger->printf("Preparing for next frame\n");
|
||||
}
|
||||
Clear();
|
||||
}
|
||||
|
||||
// Check if we're about to run into a buffer overflow
|
||||
if (position >= DLMS_READER_BUFFER_SIZE) {
|
||||
if(debugger != NULL) {
|
||||
debugger->printf("Buffer overflow\n");
|
||||
debugPrint(buffer, 0, position, debugger);
|
||||
}
|
||||
Clear();
|
||||
}
|
||||
|
||||
// Check if this is a second start flag, which indicates the previous one was a stop from the last package
|
||||
if (position == 1 && data == 0x7E)
|
||||
{
|
||||
// just return, we can keep the one byte we had in the buffer
|
||||
return false;
|
||||
}
|
||||
|
||||
// We have started, so capture every byte
|
||||
buffer[position++] = data;
|
||||
|
||||
if (position == 1)
|
||||
{
|
||||
// This was the start flag, we're not done yet
|
||||
return false;
|
||||
}
|
||||
else if (position == 2)
|
||||
{
|
||||
// Capture the Frame Format Type
|
||||
frameFormatType = (byte)(data & 0xF0);
|
||||
if (!IsValidFrameFormat(frameFormatType)) {
|
||||
if(debugger != NULL) {
|
||||
debugger->printf("Incorrect frame format %02X\n", frameFormatType);
|
||||
debugPrint(buffer, 0, position, debugger);
|
||||
}
|
||||
Clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (position == 3)
|
||||
{
|
||||
// Capture the length of the data package
|
||||
dataLength = ((buffer[1] & 0x0F) << 8) | buffer[2];
|
||||
return false;
|
||||
}
|
||||
else if (destinationAddressLength == 0)
|
||||
{
|
||||
// Capture the destination address
|
||||
destinationAddressLength = GetAddress(3, destinationAddress, 0, DLMS_READER_MAX_ADDRESS_SIZE);
|
||||
if (destinationAddressLength > 3) {
|
||||
if(debugger != NULL) {
|
||||
debugger->printf("Destination address length incorrect\n");
|
||||
debugPrint(buffer, 0, position, debugger);
|
||||
}
|
||||
Clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (sourceAddressLength == 0)
|
||||
{
|
||||
// Capture the source address
|
||||
sourceAddressLength = GetAddress(3 + destinationAddressLength, sourceAddress, 0, DLMS_READER_MAX_ADDRESS_SIZE);
|
||||
if (sourceAddressLength > 3) {
|
||||
if(debugger != NULL) {
|
||||
debugger->printf("Source address length incorrect\n");
|
||||
debugPrint(buffer, 0, position, debugger);
|
||||
}
|
||||
Clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (position == 4 + destinationAddressLength + sourceAddressLength + 2)
|
||||
{
|
||||
// Verify the header checksum
|
||||
ushort headerChecksum = GetChecksum(position - 3);
|
||||
if (headerChecksum != Crc16.ComputeChecksum(buffer, 1, position - 3)) {
|
||||
if(debugger != NULL) {
|
||||
debugger->printf("Header checksum is incorrect %02X\n", headerChecksum);
|
||||
debugPrint(buffer, 0, position, debugger);
|
||||
}
|
||||
Clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (position == dataLength + 1)
|
||||
{
|
||||
// Verify the data package checksum
|
||||
ushort checksum = this->GetChecksum(position - 3);
|
||||
if (checksum != Crc16.ComputeChecksum(buffer, 1, position - 3)) {
|
||||
if(debugger != NULL) {
|
||||
debugger->printf("Frame checksum is incorrect %02X\n", checksum);
|
||||
debugPrint(buffer, 0, position, debugger);
|
||||
}
|
||||
Clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (position == dataLength + 2)
|
||||
{
|
||||
// We're done, check the stop flag and signal we're done
|
||||
if (data == 0x7E)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
if(debugger != NULL) {
|
||||
debugger->printf("Received incorrect end marker %02X\n", data);
|
||||
debugPrint(buffer, 0, position, debugger);
|
||||
}
|
||||
Clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DlmsReader::IsValidFrameFormat(byte frameFormatType)
|
||||
{
|
||||
return frameFormatType == 0xA0;
|
||||
}
|
||||
|
||||
int DlmsReader::GetRawData(byte *dataBuffer, int start, int length)
|
||||
{
|
||||
if (dataLength > 0 && position == dataLength + 2)
|
||||
{
|
||||
int headerLength = 3 + destinationAddressLength + sourceAddressLength + 2;
|
||||
int bytesWritten = 0;
|
||||
for (int i = headerLength + 1; i < dataLength - 1; i++)
|
||||
{
|
||||
dataBuffer[i + start - headerLength - 1] = buffer[i];
|
||||
bytesWritten++;
|
||||
}
|
||||
return bytesWritten;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DlmsReader::GetAddress(int addressPosition, byte* addressBuffer, int start, int length)
|
||||
{
|
||||
int addressBufferPos = start;
|
||||
for (int i = addressPosition; i < position; i++)
|
||||
{
|
||||
addressBuffer[addressBufferPos++] = buffer[i];
|
||||
|
||||
// LSB=1 means this was the last address byte
|
||||
if ((buffer[i] & 0x01) == 0x01)
|
||||
break;
|
||||
|
||||
// See if we've reached last byte, try again when we've got more data
|
||||
else if (i == position - 1)
|
||||
return 0;
|
||||
}
|
||||
return addressBufferPos - start;
|
||||
}
|
||||
|
||||
ushort DlmsReader::GetChecksum(int checksumPosition)
|
||||
{
|
||||
return (ushort)(buffer[checksumPosition + 2] << 8 |
|
||||
buffer[checksumPosition + 1]);
|
||||
}
|
||||
|
||||
void DlmsReader::debugPrint(byte *buffer, int start, int length, Print* debugger) {
|
||||
for (int i = start; i < start + length; i++) {
|
||||
if (buffer[i] < 0x10)
|
||||
debugger->print("0");
|
||||
debugger->print(buffer[i], HEX);
|
||||
debugger->print(" ");
|
||||
if ((i - start + 1) % 16 == 0)
|
||||
debugger->println("");
|
||||
else if ((i - start + 1) % 4 == 0)
|
||||
debugger->print(" ");
|
||||
|
||||
yield(); // Let other get some resources too
|
||||
}
|
||||
debugger->println("");
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef _DLMSREADER_h
|
||||
#define _DLMSREADER_h
|
||||
|
||||
#include "Crc16.h"
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define DLMS_READER_BUFFER_SIZE 512
|
||||
#define DLMS_READER_MAX_ADDRESS_SIZE 5
|
||||
|
||||
class DlmsReader
|
||||
{
|
||||
public:
|
||||
DlmsReader();
|
||||
bool Read(byte data, Print* Debug);
|
||||
int GetRawData(byte *buffer, int start, int length);
|
||||
|
||||
protected:
|
||||
Crc16Class Crc16;
|
||||
|
||||
private:
|
||||
byte buffer[DLMS_READER_BUFFER_SIZE];
|
||||
int position;
|
||||
int dataLength;
|
||||
byte frameFormatType;
|
||||
byte destinationAddress[DLMS_READER_MAX_ADDRESS_SIZE];
|
||||
byte destinationAddressLength;
|
||||
byte sourceAddress[DLMS_READER_MAX_ADDRESS_SIZE];
|
||||
byte sourceAddressLength;
|
||||
|
||||
void Clear();
|
||||
int GetAddress(int addressPosition, byte* buffer, int start, int length);
|
||||
unsigned short GetChecksum(int checksumPosition);
|
||||
bool IsValidFrameFormat(byte frameFormatType);
|
||||
void WriteBuffer();
|
||||
void debugPrint(byte *buffer, int start, int length, Print* debugger);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,384 +0,0 @@
|
||||
#include "HanReader.h"
|
||||
#include "mbedtls/gcm.h"
|
||||
|
||||
HanReader::HanReader() {
|
||||
// Central European Time (Frankfurt, Paris)
|
||||
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; // Central European Summer Time
|
||||
TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central European Standard Time
|
||||
localZone = new Timezone(CEST, CET);
|
||||
}
|
||||
|
||||
void HanReader::setup(Stream *hanPort, RemoteDebug *debug)
|
||||
{
|
||||
han = hanPort;
|
||||
bytesRead = 0;
|
||||
debugger = debug;
|
||||
|
||||
if (debug) debug->println("MBUS serial setup complete");
|
||||
}
|
||||
|
||||
void HanReader::setup(Stream *hanPort){
|
||||
setup(hanPort, NULL);
|
||||
}
|
||||
|
||||
void HanReader::setEncryptionKey(uint8_t* encryption_key) {
|
||||
memcpy(this->encryption_key, encryption_key, 16);
|
||||
}
|
||||
|
||||
void HanReader::setAuthenticationKey(uint8_t* authentication_key) {
|
||||
memcpy(this->authentication_key, authentication_key, 16);
|
||||
}
|
||||
|
||||
|
||||
bool HanReader::read(byte data) {
|
||||
if (reader.Read(data, debugger->isActive(RemoteDebug::DEBUG) ? debugger : NULL)) {
|
||||
bytesRead = reader.GetRawData(buffer, 0, 512);
|
||||
if (debugger->isActive(RemoteDebug::INFO)) {
|
||||
printI("Got valid DLMS data (%d bytes)", bytesRead);
|
||||
if (debugger->isActive(RemoteDebug::DEBUG)) {
|
||||
debugPrint(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Data should start with E6 E7 00 0F
|
||||
and continue with four bytes for the InvokeId
|
||||
*/
|
||||
if (bytesRead < 9) {
|
||||
printW("Invalid HAN data: Less than 9 bytes received");
|
||||
return false;
|
||||
}
|
||||
else if (
|
||||
buffer[0] != 0xE6
|
||||
|| buffer[1] != 0xE7
|
||||
|| buffer[2] != 0x00
|
||||
//|| buffer[3] != 0x0F
|
||||
)
|
||||
{
|
||||
printW("Invalid HAN data: Start should be E6 E7 00");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Have not found any documentation supporting this, but 0x0F for all norwegian meters.
|
||||
// Danish meters with encryption has 0xDB, so lets assume this has something to do with that.
|
||||
switch(buffer[3]) {
|
||||
case 0x0F:
|
||||
dataHeader = 8;
|
||||
break;
|
||||
case 0xDB:
|
||||
printI("Decrypting frame");
|
||||
if(!decryptFrame()) return false;
|
||||
if (debugger->isActive(RemoteDebug::DEBUG)) {
|
||||
printD("Data after decryption:");
|
||||
debugPrint(buffer, 0, bytesRead);
|
||||
}
|
||||
dataHeader = 26;
|
||||
break;
|
||||
}
|
||||
|
||||
listSize = getInt(0, buffer, 0, bytesRead);
|
||||
printI("HAN data is valid, listSize: %d", listSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t headersize = 3;
|
||||
const size_t footersize = 0;
|
||||
|
||||
mbedtls_gcm_context m_ctx;
|
||||
|
||||
bool HanReader::decryptFrame() {
|
||||
uint8_t system_title[8];
|
||||
memcpy(system_title, buffer + headersize + 2, 8);
|
||||
if (debugger->isActive(RemoteDebug::DEBUG)) {
|
||||
printD("System title:");
|
||||
debugPrint(system_title, 0, 8);
|
||||
}
|
||||
|
||||
uint8_t initialization_vector[12];
|
||||
memcpy(initialization_vector, system_title, 8);
|
||||
memcpy(initialization_vector + 8, buffer + headersize + 14, 4);
|
||||
if (debugger->isActive(RemoteDebug::DEBUG)) {
|
||||
printD("Initialization vector:");
|
||||
debugPrint(initialization_vector, 0, 12);
|
||||
}
|
||||
|
||||
uint8_t additional_authenticated_data[17];
|
||||
memcpy(additional_authenticated_data, buffer + headersize + 13, 1);
|
||||
memcpy(additional_authenticated_data + 1, authentication_key, 16);
|
||||
if (debugger->isActive(RemoteDebug::DEBUG)) {
|
||||
printD("Additional authenticated data:");
|
||||
debugPrint(additional_authenticated_data, 0, 12);
|
||||
}
|
||||
|
||||
uint8_t authentication_tag[12];
|
||||
memcpy(authentication_tag, buffer + headersize + bytesRead - headersize - footersize - 12, 12);
|
||||
if (debugger->isActive(RemoteDebug::DEBUG)) {
|
||||
printD("Authentication tag:");
|
||||
debugPrint(authentication_tag, 0, 12);
|
||||
}
|
||||
|
||||
uint8_t cipher_text[bytesRead - headersize - footersize - 18 - 12];
|
||||
memcpy(cipher_text, buffer + headersize + 18, bytesRead - headersize - footersize - 12 - 18);
|
||||
|
||||
mbedtls_gcm_init(&m_ctx);
|
||||
int success = mbedtls_gcm_setkey(&m_ctx, MBEDTLS_CIPHER_ID_AES, encryption_key, sizeof(encryption_key)*8);
|
||||
if (0 != success ) {
|
||||
printE("Setkey failed: " + String(success));
|
||||
return false;
|
||||
}
|
||||
success = mbedtls_gcm_auth_decrypt(&m_ctx, sizeof(cipher_text), initialization_vector, sizeof(initialization_vector),
|
||||
additional_authenticated_data, sizeof(additional_authenticated_data), authentication_tag, sizeof(authentication_tag),
|
||||
cipher_text, buffer + headersize + 18);
|
||||
if (0 != success) {
|
||||
printE("authdecrypt failed: " + String(success));
|
||||
return false;
|
||||
}
|
||||
mbedtls_gcm_free(&m_ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HanReader::debugPrint(byte *buffer, int start, int length) {
|
||||
for (int i = start; i < start + length; i++) {
|
||||
if (buffer[i] < 0x10)
|
||||
debugger->print("0");
|
||||
debugger->print(buffer[i], HEX);
|
||||
debugger->print(" ");
|
||||
if ((i - start + 1) % 16 == 0)
|
||||
debugger->println("");
|
||||
else if ((i - start + 1) % 4 == 0)
|
||||
debugger->print(" ");
|
||||
|
||||
yield(); // Let other get some resources too
|
||||
}
|
||||
debugger->println("");
|
||||
}
|
||||
|
||||
bool HanReader::read() {
|
||||
while(han->available()) {
|
||||
if(read(han->read())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int HanReader::getListSize() {
|
||||
return listSize;
|
||||
}
|
||||
|
||||
time_t HanReader::getPackageTime() {
|
||||
int packageTimePosition = dataHeader
|
||||
+ (compensateFor09HeaderBug ? 1 : 0);
|
||||
|
||||
return getTime(buffer, packageTimePosition, bytesRead);
|
||||
}
|
||||
|
||||
time_t HanReader::getTime(int objectId) {
|
||||
return getTime(objectId, buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
int32_t HanReader::getInt(int objectId) {
|
||||
return getInt(objectId, buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
uint32_t HanReader::getUint(int objectId) {
|
||||
return getUint32(objectId, buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
String HanReader::getString(int objectId) {
|
||||
return getString(objectId, buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
int HanReader::getBuffer(byte* buf) {
|
||||
for (int i = 0; i < bytesRead; i++) {
|
||||
buf[i] = buffer[i];
|
||||
}
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
int HanReader::findValuePosition(int dataPosition, byte *buffer, int start, int length) {
|
||||
// The first byte after the header gives the length
|
||||
// of the extended header information (variable)
|
||||
int headerSize = dataHeader + (compensateFor09HeaderBug ? 1 : 0);
|
||||
int firstData = headerSize + buffer[headerSize] + 1;
|
||||
|
||||
for (int i = start + firstData; i<length; i++) {
|
||||
if (dataPosition-- == 0)
|
||||
return i;
|
||||
else if (buffer[i] == 0x00) // null
|
||||
i += 0;
|
||||
else if (buffer[i] == 0x0A) // String
|
||||
i += buffer[i + 1] + 1;
|
||||
else if (buffer[i] == 0x09) // byte array
|
||||
i += buffer[i + 1] + 1;
|
||||
else if (buffer[i] == 0x01) // array (1 byte for reading size)
|
||||
i += 1;
|
||||
else if (buffer[i] == 0x02) // struct (1 byte for reading size)
|
||||
i += 1;
|
||||
else if (buffer[i] == 0x10) // int16 value (2 bytes)
|
||||
i += 2;
|
||||
else if (buffer[i] == 0x12) // uint16 value (2 bytes)
|
||||
i += 2;
|
||||
else if (buffer[i] == 0x06) // uint32 value (4 bytes)
|
||||
i += 4;
|
||||
else if (buffer[i] == 0x0F) // int8 value (1 bytes)
|
||||
i += 1;
|
||||
else if (buffer[i] == 0x16) // enum (1 bytes)
|
||||
i += 1;
|
||||
else {
|
||||
printW("Unknown data type found: 0x%s", String(buffer[i], HEX).c_str());
|
||||
return 0; // unknown data type found
|
||||
}
|
||||
}
|
||||
|
||||
printD("Passed the end of the data. Length was: %d", length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
time_t HanReader::getTime(int dataPosition, byte *buffer, int start, int length) {
|
||||
// TODO: check if the time is represented always as a 12 byte string (0x09 0x0C)
|
||||
int timeStart = findValuePosition(dataPosition, buffer, start, length);
|
||||
timeStart += 1;
|
||||
return getTime(buffer, start + timeStart, length - timeStart);
|
||||
}
|
||||
|
||||
time_t HanReader::getTime(byte *buffer, int start, int length) {
|
||||
int pos = start;
|
||||
int dataLength = buffer[pos++];
|
||||
|
||||
if (dataLength == 0x0C) {
|
||||
int year = buffer[pos] << 8 |
|
||||
buffer[pos + 1];
|
||||
|
||||
int month = buffer[pos + 2];
|
||||
int day = buffer[pos + 3];
|
||||
int hour = buffer[pos + 5];
|
||||
int minute = buffer[pos + 6];
|
||||
int second = buffer[pos + 7];
|
||||
|
||||
tmElements_t tm;
|
||||
tm.Year = year - 1970;
|
||||
tm.Month = month;
|
||||
tm.Day = day;
|
||||
tm.Hour = hour;
|
||||
tm.Minute = minute;
|
||||
tm.Second = second;
|
||||
return localZone->toUTC(makeTime(tm));
|
||||
} else if(dataLength == 0) {
|
||||
return (time_t)0L;
|
||||
} else {
|
||||
printW("Unknown time length: %d", dataLength);
|
||||
// Date format not supported
|
||||
return (time_t)0L;
|
||||
}
|
||||
}
|
||||
|
||||
int HanReader::getInt(int dataPosition, byte *buffer, int start, int length) {
|
||||
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
|
||||
|
||||
if (valuePosition > 0) {
|
||||
switch (buffer[valuePosition++]) {
|
||||
case 0x01:
|
||||
case 0x02:
|
||||
case 0x16:
|
||||
return getUint8(dataPosition, buffer, start, length);
|
||||
case 0x0F:
|
||||
return getInt8(dataPosition, buffer, start, length);
|
||||
case 0x12:
|
||||
return getUint16(dataPosition, buffer, start, length);
|
||||
case 0x10:
|
||||
return getInt16(dataPosition, buffer, start, length);
|
||||
case 0x06:
|
||||
return getUint32(dataPosition, buffer, start, length);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int8_t HanReader::getInt8(int dataPosition, byte *buffer, int start, int length) {
|
||||
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
|
||||
if (valuePosition > 0 && buffer[valuePosition++] == 0x0F) {
|
||||
return buffer[valuePosition];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int16_t HanReader::getInt16(int dataPosition, byte *buffer, int start, int length) {
|
||||
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
|
||||
if (valuePosition > 0 && buffer[valuePosition++] == 0x10) {
|
||||
return buffer[valuePosition] << 8 | buffer[valuePosition+1];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t HanReader::getUint8(int dataPosition, byte *buffer, int start, int length) {
|
||||
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
|
||||
if (valuePosition > 0) {
|
||||
switch(buffer[valuePosition++]) {
|
||||
case 0x01:
|
||||
case 0x02:
|
||||
case 0x16:
|
||||
return buffer[valuePosition];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t HanReader::getUint16(int dataPosition, byte *buffer, int start, int length) {
|
||||
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
|
||||
if (valuePosition > 0 && buffer[valuePosition++] == 0x12) {
|
||||
return buffer[valuePosition] << 8 | buffer[valuePosition+1];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t HanReader::getUint32(int dataPosition, byte *buffer, int start, int length) {
|
||||
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
|
||||
if (valuePosition > 0) {
|
||||
if(buffer[valuePosition++] != 0x06)
|
||||
return 0;
|
||||
uint32_t value = 0;
|
||||
for (int i = valuePosition; i < valuePosition + 4; i++) {
|
||||
value = value << 8 | buffer[i];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
String HanReader::getString(int dataPosition, byte *buffer, int start, int length) {
|
||||
int valuePosition = findValuePosition(dataPosition, buffer, start, length);
|
||||
if (valuePosition > 0) {
|
||||
String value = String("");
|
||||
for (int i = valuePosition + 2; i < valuePosition + buffer[valuePosition + 1] + 2; i++) {
|
||||
value += String((char)buffer[i]);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return String("");
|
||||
}
|
||||
|
||||
void HanReader::printD(String fmt, int arg) {
|
||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||
}
|
||||
|
||||
void HanReader::printI(String fmt, int arg) {
|
||||
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||
}
|
||||
|
||||
void HanReader::printW(String fmt, int arg) {
|
||||
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||
}
|
||||
|
||||
void HanReader::printW(String fmt, const char* arg) {
|
||||
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||
}
|
||||
|
||||
void HanReader::printE(String fmt, int arg) {
|
||||
if(debugger->isActive(RemoteDebug::ERROR)) debugger->printf(String("(HanReader)" + fmt + "\n").c_str(), arg);
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
#ifndef _HANREADER_h
|
||||
#define _HANREADER_h
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include "DlmsReader.h"
|
||||
#include <Timezone.h>
|
||||
#include "RemoteDebug.h"
|
||||
|
||||
class HanReader
|
||||
{
|
||||
public:
|
||||
uint dataHeader = 8;
|
||||
bool compensateFor09HeaderBug = false;
|
||||
|
||||
HanReader();
|
||||
void setup(Stream *hanPort);
|
||||
void setup(Stream *hanPort, RemoteDebug *debug);
|
||||
bool read();
|
||||
bool read(byte data);
|
||||
int getListSize();
|
||||
time_t getPackageTime();
|
||||
int32_t getInt(int objectId); // Use this for uint8, int8, uint16, int16
|
||||
uint32_t getUint(int objectId); // Only for uint32
|
||||
String getString(int objectId);
|
||||
time_t getTime(int objectId);
|
||||
int getBuffer(byte* buf);
|
||||
|
||||
void setEncryptionKey(uint8_t* encryption_key);
|
||||
void setAuthenticationKey(uint8_t* authentication_key);
|
||||
|
||||
private:
|
||||
RemoteDebug* debugger;
|
||||
Stream *han;
|
||||
byte buffer[512];
|
||||
int bytesRead;
|
||||
DlmsReader reader;
|
||||
int listSize;
|
||||
Timezone *localZone;
|
||||
uint8_t encryption_key[16];
|
||||
uint8_t authentication_key[16];
|
||||
|
||||
int findValuePosition(int dataPosition, byte *buffer, int start, int length);
|
||||
|
||||
time_t getTime(int dataPosition, byte *buffer, int start, int length);
|
||||
time_t getTime(byte *buffer, int start, int length);
|
||||
int getInt(int dataPosition, byte *buffer, int start, int length);
|
||||
int8_t getInt8(int dataPosition, byte *buffer, int start, int length);
|
||||
uint8_t getUint8(int dataPosition, byte *buffer, int start, int length);
|
||||
int16_t getInt16(int dataPosition, byte *buffer, int start, int length);
|
||||
uint16_t getUint16(int dataPosition, byte *buffer, int start, int length);
|
||||
uint32_t getUint32(int dataPosition, byte *buffer, int start, int length);
|
||||
String getString(int dataPosition, byte *buffer, int start, int length);
|
||||
|
||||
time_t toUnixTime(int year, int month, int day, int hour, int minute, int second);
|
||||
|
||||
bool decryptFrame();
|
||||
|
||||
void debugPrint(byte *buffer, int start, int length);
|
||||
|
||||
void printD(String fmt, int arg=0);
|
||||
void printI(String fmt, int arg=0);
|
||||
void printW(String fmt, int arg=0);
|
||||
void printW(String fmt, const char* arg);
|
||||
void printE(String fmt, int arg=0);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,57 +0,0 @@
|
||||
#ifndef _KAIFA_h
|
||||
#define _KAIFA_h
|
||||
|
||||
enum class Kaifa {
|
||||
List1 = 0x01,
|
||||
List1PhaseShort = 0x09,
|
||||
List3PhaseShort = 0x0D,
|
||||
List1PhaseLong = 0x0E,
|
||||
List3PhaseLong = 0x12
|
||||
};
|
||||
|
||||
enum class Kaifa_List1 {
|
||||
ListSize,
|
||||
ActivePowerImported
|
||||
};
|
||||
|
||||
enum class Kaifa_List3Phase {
|
||||
ListSize,
|
||||
ListVersionIdentifier,
|
||||
MeterID,
|
||||
MeterType,
|
||||
ActiveImportPower,
|
||||
ActiveExportPower,
|
||||
ReactiveImportPower,
|
||||
ReactiveExportPower,
|
||||
CurrentL1,
|
||||
CurrentL2,
|
||||
CurrentL3,
|
||||
VoltageL1,
|
||||
VoltageL2,
|
||||
VoltageL3,
|
||||
MeterClock,
|
||||
CumulativeActiveImportEnergy,
|
||||
CumulativeActiveExportEnergy,
|
||||
CumulativeReactiveImportEnergy,
|
||||
CumulativeReactiveExportEnergy
|
||||
};
|
||||
|
||||
enum class Kaifa_List1Phase {
|
||||
ListSize,
|
||||
ListVersionIdentifier,
|
||||
MeterID,
|
||||
MeterType,
|
||||
ActiveImportPower,
|
||||
ActiveExportPower,
|
||||
ReactiveImportPower,
|
||||
ReactiveExportPower,
|
||||
CurrentL1,
|
||||
VoltageL1,
|
||||
MeterClock,
|
||||
CumulativeActiveImportEnergy,
|
||||
CumulativeActiveExportEnergy,
|
||||
CumulativeReactiveImportEnergy,
|
||||
CumulativeReactiveExportEnergy
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,127 +0,0 @@
|
||||
// Kamstrup.h
|
||||
|
||||
#ifndef _KAMSTRUP_h
|
||||
#define _KAMSTRUP_h
|
||||
|
||||
enum class Kamstrup
|
||||
{
|
||||
List1PhaseShort = 0x11,
|
||||
List1PhaseLong = 0x1B,
|
||||
List3PhaseShort = 0x19,
|
||||
List3PhaseLong = 0x23,
|
||||
List3PhaseITShort = 0x17,
|
||||
List3PhaseITLong = 0x21
|
||||
};
|
||||
|
||||
enum class Kamstrup_List3Phase
|
||||
{
|
||||
ListSize,
|
||||
ListVersionIdentifier,
|
||||
MeterID_OBIS,
|
||||
MeterID,
|
||||
MeterType_OBIS,
|
||||
MeterType,
|
||||
ActiveImportPower_OBIS,
|
||||
ActiveImportPower,
|
||||
ActiveExportPower_OBIS,
|
||||
ActiveExportPower,
|
||||
ReactiveImportPower_OBIS,
|
||||
ReactiveImportPower,
|
||||
ReactiveExportPower_OBIS,
|
||||
ReactiveExportPower,
|
||||
CurrentL1_OBIS,
|
||||
CurrentL1,
|
||||
CurrentL2_OBIS,
|
||||
CurrentL2,
|
||||
CurrentL3_OBIS,
|
||||
CurrentL3,
|
||||
VoltageL1_OBIS,
|
||||
VoltageL1,
|
||||
VoltageL2_OBIS,
|
||||
VoltageL2,
|
||||
VoltageL3_OBIS,
|
||||
VoltageL3,
|
||||
MeterClock_OBIS,
|
||||
MeterClock,
|
||||
CumulativeActiveImportEnergy_OBIS,
|
||||
CumulativeActiveImportEnergy,
|
||||
CumulativeActiveExportEnergy_OBIS,
|
||||
CumulativeActiveExportEnergy,
|
||||
CumulativeReactiveImportEnergy_OBIS,
|
||||
CumulativeReactiveImportEnergy,
|
||||
CumulativeReactiveExportEnergy_OBIS,
|
||||
CumulativeReactiveExportEnergy
|
||||
};
|
||||
|
||||
enum class Kamstrup_List1Phase
|
||||
{
|
||||
ListSize,
|
||||
ListVersionIdentifier,
|
||||
MeterID_OBIS,
|
||||
MeterID,
|
||||
MeterType_OBIS,
|
||||
MeterType,
|
||||
ActiveImportPower_OBIS,
|
||||
ActiveImportPower,
|
||||
ActiveExportPower_OBIS,
|
||||
ActiveExportPower,
|
||||
ReactiveImportPower_OBIS,
|
||||
ReactiveImportPower,
|
||||
ReactiveExportPower_OBIS,
|
||||
ReactiveExportPower,
|
||||
CurrentL1_OBIS,
|
||||
CurrentL1,
|
||||
VoltageL1_OBIS,
|
||||
VoltageL1,
|
||||
MeterClock_OBIS,
|
||||
MeterClock,
|
||||
CumulativeActiveImportEnergy_OBIS,
|
||||
CumulativeActiveImportEnergy,
|
||||
CumulativeActiveExportEnergy_OBIS,
|
||||
CumulativeActiveExportEnergy,
|
||||
CumulativeReactiveImportEnergy_OBIS,
|
||||
CumulativeReactiveImportEnergy,
|
||||
CumulativeReactiveExportEnergy_OBIS,
|
||||
CumulativeReactiveExportEnergy
|
||||
};
|
||||
|
||||
enum class Kamstrup_List3PhaseIT
|
||||
{
|
||||
ListSize,
|
||||
ListVersionIdentifier,
|
||||
MeterID_OBIS,
|
||||
MeterID,
|
||||
MeterType_OBIS,
|
||||
MeterType,
|
||||
ActiveImportPower_OBIS,
|
||||
ActiveImportPower,
|
||||
ActiveExportPower_OBIS,
|
||||
ActiveExportPower,
|
||||
ReactiveImportPower_OBIS,
|
||||
ReactiveImportPower,
|
||||
ReactiveExportPower_OBIS,
|
||||
ReactiveExportPower,
|
||||
CurrentL1_OBIS,
|
||||
CurrentL1,
|
||||
CurrentL3_OBIS,
|
||||
CurrentL3,
|
||||
VoltageL1_OBIS,
|
||||
VoltageL1,
|
||||
VoltageL2_OBIS,
|
||||
VoltageL2,
|
||||
VoltageL3_OBIS,
|
||||
VoltageL3,
|
||||
MeterClock_OBIS,
|
||||
MeterClock,
|
||||
CumulativeActiveImportEnergy_OBIS,
|
||||
CumulativeActiveImportEnergy,
|
||||
CumulativeActiveExportEnergy_OBIS,
|
||||
CumulativeActiveExportEnergy,
|
||||
CumulativeReactiveImportEnergy_OBIS,
|
||||
CumulativeReactiveImportEnergy,
|
||||
CumulativeReactiveExportEnergy_OBIS,
|
||||
CumulativeReactiveExportEnergy
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
#ifndef _OMNIPOWER_h
|
||||
#define _OMNIPOWER_h
|
||||
|
||||
enum class Omnipower {
|
||||
DLMS = 0x41
|
||||
};
|
||||
|
||||
enum class Omnipower_DLMS {
|
||||
ListSize,
|
||||
ListVersionIdentifier,
|
||||
CumulativeActiveImportEnergy_OBIS,
|
||||
CumulativeActiveImportEnergy,
|
||||
CumulativeActiveExportEnergy_OBIS,
|
||||
CumulativeActiveExportEnergy,
|
||||
CumulativeReactiveImportEnergy_OBIS,
|
||||
CumulativeReactiveImportEnergy,
|
||||
CumulativeReactiveExportEnergy_OBIS,
|
||||
CumulativeReactiveExportEnergy,
|
||||
MeterNumber_OBIS,
|
||||
MeterNumber,
|
||||
ActiveImportPower_OBIS,
|
||||
ActiveImportPower,
|
||||
ActiveExportPower_OBIS,
|
||||
ActiveExportPower,
|
||||
ReactiveImportPower_OBIS,
|
||||
ReactiveImportPower,
|
||||
ReactiveExportPower_OBIS,
|
||||
ReactiveExportPower,
|
||||
MeterClock_OBIS,
|
||||
MeterClock,
|
||||
VoltageL1_OBIS,
|
||||
VoltageL1,
|
||||
VoltageL2_OBIS,
|
||||
VoltageL2,
|
||||
VoltageL3_OBIS,
|
||||
VoltageL3,
|
||||
CurrentL1_OBIS,
|
||||
CurrentL1,
|
||||
CurrentL2_OBIS,
|
||||
CurrentL2,
|
||||
CurrentL3_OBIS,
|
||||
CurrentL3,
|
||||
ActiveImportPowerL1_OBIS,
|
||||
ActiveImportPowerL1,
|
||||
ActiveImportPowerL2_OBIS,
|
||||
ActiveImportPowerL2,
|
||||
ActiveImportPowerL3_OBIS,
|
||||
ActiveImportPowerL3,
|
||||
PowerFactorL1_OBIS,
|
||||
PowerFactorL1,
|
||||
PowerFactorL2_OBIS,
|
||||
PowerFactorL2,
|
||||
PowerFactorL3_OBIS,
|
||||
PowerFactorL3,
|
||||
PowerFactor_OBIS,
|
||||
PowerFactor,
|
||||
ActiveExportPowerL1_OBIS,
|
||||
ActiveExportPowerL1,
|
||||
ActiveExportPowerL2_OBIS,
|
||||
ActiveExportPowerL2,
|
||||
ActiveExportPowerL3_OBIS,
|
||||
ActiveExportPowerL3,
|
||||
CumulativeActiveExportEnergyL1_OBIS,
|
||||
CumulativeActiveExportEnergyL1,
|
||||
CumulativeActiveExportEnergyL2_OBIS,
|
||||
CumulativeActiveExportEnergyL2,
|
||||
CumulativeActiveExportEnergyL3_OBIS,
|
||||
CumulativeActiveExportEnergyL3,
|
||||
CumulativeActiveImportEnergyL1_OBIS,
|
||||
CumulativeActiveImportEnergyL1,
|
||||
CumulativeActiveImportEnergyL2_OBIS,
|
||||
CumulativeActiveImportEnergyL2,
|
||||
CumulativeActiveImportEnergyL3_OBIS,
|
||||
CumulativeActiveImportEnergyL3
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,18 +0,0 @@
|
||||
# A GitHub Manifesto
|
||||
### Notes on contributing to my repositories
|
||||
Jack Christensen
|
||||
Jan 2018
|
||||
|
||||
Surely Git and GitHub are wonderful tools. They make coding and collaboration so much easier. I'm equally impressed with the open source movement, and with the Arduino ecosystem in particular.
|
||||
|
||||
I'm just one guy, mostly a hobbyist. Posting my projects to GitHub is my way of giving back a little to the community. It's very gratifying that some of my code has received a modicum of popularity.
|
||||
|
||||
Like many things, this has been somewhat of a double-edged sword. Especially since I tend to be a pretty busy guy with many varied interests.
|
||||
|
||||
First, I am always interested in bug reports. Please raise an issue in the appropriate repository and please please please include a good, concise description of the issue and a Short, Self Contained, Correct (Compilable), Example (see [sscce.org](http://www.sscce.org/)). I will need to be able to reproduce the issue, with minimal hardware, and without installing a dozen other libraries. I work exclusively with the AVR architecture so most times I will not be able to reproduce issues on other platforms. (There have been one or two occasions where relatively simple changes have been made to accommodate another platform; I am not necessarily averse to these.)
|
||||
|
||||
Second, bug reports should always be for problems with *my* code. I will not use GitHub to help you with *your* code, even if you happen to be using one of my libraries. Please use the [Arduino forum](https://forum.arduino.cc/) or other such venue instead.
|
||||
|
||||
Finally, pull requests can be problematic, especially if they represent enhancements rather than fixes. I seldom intend my code to be all things to all people. This is mostly a hobby activity and I have very limited bandwidth. Reviewing and managing PRs requires time that I do not often have. Sometimes a PR will take a library in a direction that I'm not interested in. Sometimes a PR will be counter to my original design intent. No doubt the author of a PR thinks that their new feature is the best thing since canned beer, but if I don't happen to share that opinion, then I'll decline it. OTOH, I am certainly capable of making stupid mistakes and missing absolutely fundamental things, and I do appreciate it when these are pointed out.
|
||||
|
||||
All this to say, that if I do decline a request, please do not take it personally. Feel free to consider it my problem, not yours. At the end of the day, it's my code, and I reserve the right to decline issues or PRs for any reason, or for no reason at all. But here is the beauty of open source. You can always fork the repository and have your way with it.
|
||||
@@ -1,675 +0,0 @@
|
||||
### GNU GENERAL PUBLIC LICENSE
|
||||
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
<https://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this
|
||||
license document, but changing it is not allowed.
|
||||
|
||||
### Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom
|
||||
to share and change all versions of a program--to make sure it remains
|
||||
free software for all its users. We, the Free Software Foundation, use
|
||||
the GNU General Public License for most of our software; it applies
|
||||
also to any other work released this way by its authors. You can apply
|
||||
it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you
|
||||
have certain responsibilities if you distribute copies of the
|
||||
software, or if you modify it: responsibilities to respect the freedom
|
||||
of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the
|
||||
manufacturer can do so. This is fundamentally incompatible with the
|
||||
aim of protecting users' freedom to change the software. The
|
||||
systematic pattern of such abuse occurs in the area of products for
|
||||
individuals to use, which is precisely where it is most unacceptable.
|
||||
Therefore, we have designed this version of the GPL to prohibit the
|
||||
practice for those products. If such problems arise substantially in
|
||||
other domains, we stand ready to extend this provision to those
|
||||
domains in future versions of the GPL, as needed to protect the
|
||||
freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish
|
||||
to avoid the special danger that patents applied to a free program
|
||||
could make it effectively proprietary. To prevent this, the GPL
|
||||
assures that patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
### TERMS AND CONDITIONS
|
||||
|
||||
#### 0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds
|
||||
of works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of
|
||||
an exact copy. The resulting work is called a "modified version" of
|
||||
the earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user
|
||||
through a computer network, with no transfer of a copy, is not
|
||||
conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices" to
|
||||
the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
#### 1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work for
|
||||
making modifications to it. "Object code" means any non-source form of
|
||||
a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can
|
||||
regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same
|
||||
work.
|
||||
|
||||
#### 2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey,
|
||||
without conditions so long as your license otherwise remains in force.
|
||||
You may convey covered works to others for the sole purpose of having
|
||||
them make modifications exclusively for you, or provide you with
|
||||
facilities for running those works, provided that you comply with the
|
||||
terms of this License in conveying all material for which you do not
|
||||
control copyright. Those thus making or running the covered works for
|
||||
you must do so exclusively on your behalf, under your direction and
|
||||
control, on terms that prohibit them from making any copies of your
|
||||
copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the
|
||||
conditions stated below. Sublicensing is not allowed; section 10 makes
|
||||
it unnecessary.
|
||||
|
||||
#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such
|
||||
circumvention is effected by exercising rights under this License with
|
||||
respect to the covered work, and you disclaim any intention to limit
|
||||
operation or modification of the work as a means of enforcing, against
|
||||
the work's users, your or third parties' legal rights to forbid
|
||||
circumvention of technological measures.
|
||||
|
||||
#### 4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
#### 5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these
|
||||
conditions:
|
||||
|
||||
- a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
- b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under
|
||||
section 7. This requirement modifies the requirement in section 4
|
||||
to "keep intact all notices".
|
||||
- c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
- d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
#### 6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms of
|
||||
sections 4 and 5, provided that you also convey the machine-readable
|
||||
Corresponding Source under the terms of this License, in one of these
|
||||
ways:
|
||||
|
||||
- a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
- b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the Corresponding
|
||||
Source from a network server at no charge.
|
||||
- c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
- d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
- e) Convey the object code using peer-to-peer transmission,
|
||||
provided you inform other peers where the object code and
|
||||
Corresponding Source of the work are being offered to the general
|
||||
public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal,
|
||||
family, or household purposes, or (2) anything designed or sold for
|
||||
incorporation into a dwelling. In determining whether a product is a
|
||||
consumer product, doubtful cases shall be resolved in favor of
|
||||
coverage. For a particular product received by a particular user,
|
||||
"normally used" refers to a typical or common use of that class of
|
||||
product, regardless of the status of the particular user or of the way
|
||||
in which the particular user actually uses, or expects or is expected
|
||||
to use, the product. A product is a consumer product regardless of
|
||||
whether the product has substantial commercial, industrial or
|
||||
non-consumer uses, unless such uses represent the only significant
|
||||
mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to
|
||||
install and execute modified versions of a covered work in that User
|
||||
Product from a modified version of its Corresponding Source. The
|
||||
information must suffice to ensure that the continued functioning of
|
||||
the modified object code is in no case prevented or interfered with
|
||||
solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or
|
||||
updates for a work that has been modified or installed by the
|
||||
recipient, or for the User Product in which it has been modified or
|
||||
installed. Access to a network may be denied when the modification
|
||||
itself materially and adversely affects the operation of the network
|
||||
or violates the rules and protocols for communication across the
|
||||
network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
#### 7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders
|
||||
of that material) supplement the terms of this License with terms:
|
||||
|
||||
- a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
- b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
- c) Prohibiting misrepresentation of the origin of that material,
|
||||
or requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
- d) Limiting the use for publicity purposes of names of licensors
|
||||
or authors of the material; or
|
||||
- e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
- f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions
|
||||
of it) with contractual assumptions of liability to the recipient,
|
||||
for any liability that these contractual assumptions directly
|
||||
impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions; the
|
||||
above requirements apply either way.
|
||||
|
||||
#### 8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license
|
||||
from a particular copyright holder is reinstated (a) provisionally,
|
||||
unless and until the copyright holder explicitly and finally
|
||||
terminates your license, and (b) permanently, if the copyright holder
|
||||
fails to notify you of the violation by some reasonable means prior to
|
||||
60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
#### 9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or run
|
||||
a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
#### 10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
#### 11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims owned
|
||||
or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within the
|
||||
scope of its coverage, prohibits the exercise of, or is conditioned on
|
||||
the non-exercise of one or more of the rights that are specifically
|
||||
granted under this License. You may not convey a covered work if you
|
||||
are a party to an arrangement with a third party that is in the
|
||||
business of distributing software, under which you make payment to the
|
||||
third party based on the extent of your activity of conveying the
|
||||
work, and under which the third party grants, to any of the parties
|
||||
who would receive the covered work from you, a discriminatory patent
|
||||
license (a) in connection with copies of the covered work conveyed by
|
||||
you (or copies made from those copies), or (b) primarily for and in
|
||||
connection with specific products or compilations that contain the
|
||||
covered work, unless you entered into that arrangement, or that patent
|
||||
license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
#### 12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under
|
||||
this License and any other pertinent obligations, then as a
|
||||
consequence you may not convey it at all. For example, if you agree to
|
||||
terms that obligate you to collect a royalty for further conveying
|
||||
from those to whom you convey the Program, the only way you could
|
||||
satisfy both those terms and this License would be to refrain entirely
|
||||
from conveying the Program.
|
||||
|
||||
#### 13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
#### 14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in
|
||||
detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies that a certain numbered version of the GNU General Public
|
||||
License "or any later version" applies to it, you have the option of
|
||||
following the terms and conditions either of that numbered version or
|
||||
of any later version published by the Free Software Foundation. If the
|
||||
Program does not specify a version number of the GNU General Public
|
||||
License, you may choose any version ever published by the Free
|
||||
Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions
|
||||
of the GNU General Public License can be used, that proxy's public
|
||||
statement of acceptance of a version permanently authorizes you to
|
||||
choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
#### 15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
|
||||
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
||||
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
|
||||
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
|
||||
CORRECTION.
|
||||
|
||||
#### 16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
|
||||
CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
|
||||
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
|
||||
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
|
||||
LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
|
||||
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
|
||||
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
#### 17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
### How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these
|
||||
terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to
|
||||
attach them to the start of each source file to most effectively state
|
||||
the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper
|
||||
mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands \`show w' and \`show c' should show the
|
||||
appropriate parts of the General Public License. Of course, your
|
||||
program's commands might be different; for a GUI interface, you would
|
||||
use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. For more information on this, and how to apply and follow
|
||||
the GNU GPL, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your
|
||||
program into proprietary programs. If your program is a subroutine
|
||||
library, you may consider it more useful to permit linking proprietary
|
||||
applications with the library. If this is what you want to do, use the
|
||||
GNU Lesser General Public License instead of this License. But first,
|
||||
please read <https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
@@ -1,196 +0,0 @@
|
||||
# Arduino Timezone Library
|
||||
https://github.com/JChristensen/Timezone
|
||||
README file
|
||||
Jack Christensen
|
||||
Mar 2012
|
||||
|
||||
## License
|
||||
Arduino Timezone Library Copyright (C) 2018 Jack Christensen GNU GPL v3.0
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License v3.0 as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/gpl.html>
|
||||
|
||||
## Introduction
|
||||
The **Timezone** library is designed to work in conjunction with the [Arduino Time library](https://github.com/PaulStoffregen/Time), which must also be installed on your system. This documentation assumes some familiarity with the Time library.
|
||||
|
||||
The primary aim of the **Timezone** library is to convert Universal Coordinated Time (UTC) to the correct local time, whether it is daylight saving time (a.k.a. summer time) or standard time. The time source could be a GPS receiver, an NTP server, or a Real-Time Clock (RTC) set to UTC. But whether a hardware RTC or other time source is even present is immaterial, since the Time library can function as a software RTC without additional hardware (although its accuracy is dependent on the accuracy of the microcontroller's system clock.)
|
||||
|
||||
The **Timezone** library implements two objects to facilitate time zone conversions:
|
||||
- A **TimeChangeRule** object describes when local time changes to daylight (summer) time, or to standard time, for a particular locale.
|
||||
- A **Timezone** object uses **TimeChangeRule**s to perform conversions and related functions. It can also write its **TimeChangeRule**s to EEPROM, or read them from EEPROM. Multiple time zones can be represented by defining multiple **Timezone** objects.
|
||||
|
||||
## Examples
|
||||
The following example sketches are included with the **Timezone** library:
|
||||
|
||||
- **Clock:** A simple self-adjusting clock for a single time zone. **TimeChangeRule**s may be optionally read from EEPROM.
|
||||
- **HardwareRTC:** A self-adjusting clock for one time zone using an external real-time clock, either a DS1307 or DS3231 (e.g. Chronodot) which is set to UTC.
|
||||
- **WorldClock:** A self-adjusting clock for multiple time zones.
|
||||
- **WriteRules:** A sketch to write **TimeChangeRule**s to EEPROM.
|
||||
- **Change_TZ_1:** Changes between time zones by modifying the TimeChangeRules.
|
||||
- **Change_TZ_2:** Changes between time zones by selecting from an array of Timezone objects.
|
||||
|
||||
## Coding TimeChangeRules
|
||||
Normally these will be coded in pairs for a given time zone: One rule to describe when daylight (summer) time starts, and one to describe when standard time starts.
|
||||
|
||||
As an example, here in the Eastern US time zone, Eastern Daylight Time (EDT) starts on the 2nd Sunday in March at 02:00 local time. Eastern Standard Time (EST) starts on the 1st Sunday in November at 02:00 local time.
|
||||
|
||||
Define a **TimeChangeRule** as follows:
|
||||
|
||||
`TimeChangeRule myRule = {abbrev, week, dow, month, hour, offset};`
|
||||
|
||||
Where:
|
||||
|
||||
**abbrev** is a character string abbreviation for the time zone; it must be no longer than five characters.
|
||||
|
||||
**week** is the week of the month that the rule starts.
|
||||
|
||||
**dow** is the day of the week that the rule starts.
|
||||
|
||||
**hour** is the hour in local time that the rule starts (0-23).
|
||||
|
||||
**offset** is the UTC offset _in minutes_ for the time zone being defined.
|
||||
|
||||
For convenience, the following symbolic names can be used:
|
||||
|
||||
**week:** First, Second, Third, Fourth, Last
|
||||
**dow:** Sun, Mon, Tue, Wed, Thu, Fri, Sat
|
||||
**month:** Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
|
||||
|
||||
For the Eastern US time zone, the **TimeChangeRule**s could be defined as follows:
|
||||
|
||||
```c++
|
||||
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; //UTC - 4 hours
|
||||
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; //UTC - 5 hours
|
||||
```
|
||||
|
||||
## Coding Timezone objects
|
||||
There are three ways to define **Timezone** objects.
|
||||
|
||||
By first defining **TimeChangeRule**s (as above) and giving the daylight time rule and the standard time rule (assuming usEDT and usEST defined as above):
|
||||
`Timezone usEastern(usEDT, usEST);`
|
||||
|
||||
For a time zone that does not change to daylight/summer time, pass a single rule to the constructor. For example:
|
||||
`Timezone usAZ(usMST, usMST);`
|
||||
|
||||
By reading rules previously stored in EEPROM. This reads both the daylight and standard time rules previously stored at EEPROM address 100:
|
||||
`Timezone usPacific(100);`
|
||||
|
||||
Note that **TimeChangeRule**s require 12 bytes of storage each, so the pair of rules associated with a Timezone object requires 24 bytes total. This could possibly change in future versions of the library. The size of a **TimeChangeRule** can be checked with `sizeof(usEDT)`.
|
||||
|
||||
## Timezone library methods
|
||||
Note that the `time_t` data type is defined by the Arduino Time library <TimeLib.h>. See the Time library documentation [here](https://playground.arduino.cc/Code/Time) and [here](https://www.pjrc.com/teensy/td_libs_Time.html) for additional details.
|
||||
|
||||
### time_t toLocal(time_t utc);
|
||||
##### Description
|
||||
Converts the given UTC time to local time, standard or daylight as appropriate.
|
||||
##### Syntax
|
||||
`myTZ.toLocal(utc);`
|
||||
##### Parameters
|
||||
***utc:*** Universal Coordinated Time *(time_t)*
|
||||
##### Returns
|
||||
Local time *(time_t)*
|
||||
##### Example
|
||||
```c++
|
||||
time_t eastern, utc;
|
||||
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; //UTC - 4 hours
|
||||
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; //UTC - 5 hours
|
||||
Timezone usEastern(usEDT, usEST);
|
||||
utc = now(); //current time from the Time Library
|
||||
eastern = usEastern.toLocal(utc);
|
||||
```
|
||||
|
||||
### time_t toLocal(time_t utc, TimeChangeRule **tcr);
|
||||
##### Description
|
||||
As above, converts the given UTC time to local time, and also returns a pointer to the **TimeChangeRule** that was applied to do the conversion. This could then be used, for example, to include the time zone abbreviation as part of a time display. The caller must take care not to alter the pointed **TimeChangeRule**, as this will then result in incorrect conversions.
|
||||
##### Syntax
|
||||
`myTZ.toLocal(utc, &tcr);`
|
||||
##### Parameters
|
||||
***utc:*** Universal Coordinated Time *(time_t)*
|
||||
***tcr:*** Address of a pointer to a **TimeChangeRule** _(\*\*TimeChangeRule)_
|
||||
##### Returns
|
||||
Local time *(time_t)*
|
||||
Pointer to **TimeChangeRule** _(\*\*TimeChangeRule)_
|
||||
##### Example
|
||||
```c++
|
||||
time_t eastern, utc;
|
||||
TimeChangeRule *tcr;
|
||||
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; //UTC - 4 hours
|
||||
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; //UTC - 5 hours
|
||||
Timezone usEastern(usEDT, usEST);
|
||||
utc = now(); //current time from the Time Library
|
||||
eastern = usEastern.toLocal(utc, &tcr);
|
||||
Serial.print("The time zone is: ");
|
||||
Serial.println(tcr -> abbrev);
|
||||
```
|
||||
|
||||
### bool utcIsDST(time_t utc);
|
||||
### bool locIsDST(time_t local);
|
||||
##### Description
|
||||
These functions determine whether a given UTC time or a given local time is within the daylight saving (summer) time interval, and return true or false accordingly.
|
||||
##### Syntax
|
||||
`utcIsDST(utc);`
|
||||
`locIsDST(local);`
|
||||
##### Parameters
|
||||
***utc:*** Universal Coordinated Time *(time_t)*
|
||||
***local:*** Local Time *(time_t)*
|
||||
##### Returns
|
||||
true or false *(bool)*
|
||||
##### Example
|
||||
`if (usEastern.utcIsDST(utc)) { /*do something*/ }`
|
||||
|
||||
### void readRules(int address);
|
||||
### void writeRules(int address);
|
||||
##### Description
|
||||
These functions read or write a **Timezone** object's two **TimeChangeRule**s from or to EEPROM.
|
||||
##### Syntax
|
||||
`myTZ.readRules(address);`
|
||||
`myTZ.writeRules(address);`
|
||||
##### Parameters
|
||||
***address:*** The beginning EEPROM address to write to or read from *(int)*
|
||||
##### Returns
|
||||
None.
|
||||
##### Example
|
||||
`usEastern.writeRules(100); //write rules beginning at EEPROM address 100`
|
||||
|
||||
### void setRules(TimeChangeRule dstStart, TimeChangeRule stdStart);
|
||||
##### Description
|
||||
This function reads or updates the daylight and standard time rules from RAM. Can be used to change TimeChangeRules dynamically while a sketch runs.
|
||||
##### Syntax
|
||||
`myTZ.setRules(dstStart, stdStart);`
|
||||
##### Parameters
|
||||
***dstStart:*** A TimeChangeRule denoting the start of daylight saving (summer) time.
|
||||
***stdStart:*** A TimeChangeRule denoting the start of standard time.
|
||||
##### Returns
|
||||
None.
|
||||
##### Example
|
||||
```c++
|
||||
TimeChangeRule EDT = {"EDT", Second, Sun, Mar, 2, -240};
|
||||
TimeChangeRule EST = {"EST", First, Sun, Nov, 2, -300};
|
||||
Timezone ET(EDT, EST);
|
||||
...
|
||||
tz.setRules(EDT, EST);
|
||||
|
||||
```
|
||||
### time_t toUTC(time_t local);
|
||||
##### Description
|
||||
Converts the given local time to UTC time.
|
||||
|
||||
**WARNING:** This function is provided for completeness, but should seldom be needed and should be used sparingly and carefully.
|
||||
|
||||
Ambiguous situations occur after the Standard-to-DST and the DST-to-Standard time transitions. When changing to DST, there is one hour of local time that does not exist, since the clock moves forward one hour. Similarly, when changing to standard time, there is one hour of local time that occurs twice since the clock moves back one hour.
|
||||
|
||||
This function does not test whether it is passed an erroneous time value during the Local-to-DST transition that does not exist. If passed such a time, an incorrect UTC time value will be returned.
|
||||
|
||||
If passed a local time value during the DST-to-Local transition that occurs twice, it will be treated as the earlier time, i.e. the time that occurs before the transition.
|
||||
|
||||
Calling this function with local times during a transition interval should be avoided!
|
||||
##### Syntax
|
||||
`myTZ.toUTC(local);`
|
||||
##### Parameters
|
||||
***local:*** Local Time *(time_t)*
|
||||
##### Returns
|
||||
UTC *(time_t)*
|
||||
@@ -1,119 +0,0 @@
|
||||
// Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and
|
||||
// licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// Arduino Timezone Library example sketch.
|
||||
// Demonstrates changing timezone "on the fly".
|
||||
// Uses a pushbutton switch to change between the four continental US time zones.
|
||||
// The current timezone setting is saved in EEPROM so it is remembered if
|
||||
// the power is cycled.
|
||||
// Tested with Arduino 1.8.5 and an Arduino Uno.
|
||||
//
|
||||
// Jack Christensen 02Jan2018
|
||||
|
||||
#include <avr/eeprom.h>
|
||||
#include <JC_Button.h> // http://github.com/JChristensen/JC_Button
|
||||
#include <Streaming.h> // http://arduiniana.org/libraries/streaming/
|
||||
#include <Timezone.h> // http://github.com/JChristensen/Timezone
|
||||
|
||||
const uint8_t BUTTON_PIN(8); // connect a button from this pin to ground
|
||||
Button btn(BUTTON_PIN);
|
||||
|
||||
uint8_t tzIndex; //index to the arrays below
|
||||
EEMEM uint8_t ee_tzIndex; //copy of tzIndex persisted in EEPROM
|
||||
const char* dstNames[] = {"EDT", "CDT", "MDT", "PDT"};
|
||||
const char* stdNames[] = {"EST", "CST", "MST", "PST"};
|
||||
const int dstOffsets[] = {-240, -300, -360, -420};
|
||||
const int stdOffsets[] = {-300, -360, -420, -480};
|
||||
|
||||
TimeChangeRule dstRule = {"EDT", Second, Sun, Mar, 2, -240};
|
||||
TimeChangeRule stdRule = {"EST", First, Sun, Nov, 2, -300};
|
||||
Timezone tz(dstRule, stdRule);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// set the system time to UTC
|
||||
// warning: assumes that compileTime() returns US EST
|
||||
// adjust the following line accordingly if you're in another time zone
|
||||
setTime(compileTime() + 300 * 60);
|
||||
|
||||
// get tzIndex from eeprom and ensure that it's valid
|
||||
tzIndex = eeprom_read_byte( &ee_tzIndex );
|
||||
if ( tzIndex >= sizeof(stdOffsets) / sizeof(stdOffsets[0]) )
|
||||
{
|
||||
tzIndex = 0;
|
||||
eeprom_write_byte( &ee_tzIndex, tzIndex);
|
||||
}
|
||||
|
||||
btn.begin();
|
||||
Serial.begin(115200);
|
||||
changeTZ();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// print the time if it's changed
|
||||
static time_t tLast;
|
||||
time_t t = now();
|
||||
if (t != tLast)
|
||||
{
|
||||
tLast = t;
|
||||
printDateTime(t);
|
||||
Serial << " UTC ";
|
||||
TimeChangeRule* tcr; //pointer to current time change rule, used to get TZ abbrev
|
||||
printDateTime(tz.toLocal(t, &tcr));
|
||||
Serial << " " << tcr -> abbrev;
|
||||
Serial << endl;
|
||||
}
|
||||
|
||||
// change the time zone if button pressed
|
||||
btn.read();
|
||||
if (btn.wasPressed())
|
||||
{
|
||||
if ( ++tzIndex >= sizeof(stdOffsets) / sizeof(stdOffsets[0]) ) tzIndex = 0;
|
||||
changeTZ();
|
||||
}
|
||||
}
|
||||
|
||||
void changeTZ()
|
||||
{
|
||||
Serial << "tzIndex " << tzIndex << endl;
|
||||
eeprom_update_byte( &ee_tzIndex, tzIndex );
|
||||
dstRule.offset = dstOffsets[tzIndex];
|
||||
stdRule.offset = stdOffsets[tzIndex];
|
||||
strcpy(dstRule.abbrev, dstNames[tzIndex]);
|
||||
strcpy(stdRule.abbrev, stdNames[tzIndex]);
|
||||
tz.setRules(dstRule, stdRule);
|
||||
}
|
||||
|
||||
void printDateTime(time_t t)
|
||||
{
|
||||
Serial << ((day(t)<10) ? "0" : "") << _DEC(day(t));
|
||||
Serial << monthShortStr(month(t)) << _DEC(year(t)) << ' ';
|
||||
Serial << ((hour(t)<10) ? "0" : "") << _DEC(hour(t)) << ':';
|
||||
Serial << ((minute(t)<10) ? "0" : "") << _DEC(minute(t)) << ':';
|
||||
Serial << ((second(t)<10) ? "0" : "") << _DEC(second(t));
|
||||
}
|
||||
|
||||
// function to return the compile date and time as a time_t value
|
||||
time_t compileTime()
|
||||
{
|
||||
const time_t FUDGE(10); //fudge factor to allow for upload time, etc. (seconds, YMMV)
|
||||
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
char compMon[4], *m;
|
||||
|
||||
strncpy(compMon, compDate, 3);
|
||||
compMon[3] = '\0';
|
||||
m = strstr(months, compMon);
|
||||
|
||||
tmElements_t tm;
|
||||
tm.Month = ((m - months) / 3 + 1);
|
||||
tm.Day = atoi(compDate + 4);
|
||||
tm.Year = atoi(compDate + 7) - 1970;
|
||||
tm.Hour = atoi(compTime);
|
||||
tm.Minute = atoi(compTime + 3);
|
||||
tm.Second = atoi(compTime + 6);
|
||||
|
||||
time_t t = makeTime(tm);
|
||||
return t + FUDGE; //add fudge factor to allow for compile time
|
||||
}
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
// Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and
|
||||
// licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// Arduino Timezone Library example sketch.
|
||||
// Demonstrates changing time zones using an array of Timezone objects.
|
||||
// Uses a pushbutton switch to change between the four US continental time zones.
|
||||
// Tested with Arduino 1.8.5 and an Arduino Uno.
|
||||
//
|
||||
// Jack Christensen 02Jan2018
|
||||
|
||||
#include <JC_Button.h> // http://github.com/JChristensen/JC_Button
|
||||
#include <Streaming.h> // http://arduiniana.org/libraries/streaming/
|
||||
#include <Timezone.h> // http://github.com/JChristensen/Timezone
|
||||
|
||||
const uint8_t BUTTON_PIN(8); // connect a button from this pin to ground
|
||||
Button btn(BUTTON_PIN);
|
||||
|
||||
//Continental US Time Zones
|
||||
TimeChangeRule EDT = { "EDT", Second, Sun, Mar, 2, -240 }; //Daylight time = UTC - 4 hours
|
||||
TimeChangeRule EST = { "EST", First, Sun, Nov, 2, -300 }; //Standard time = UTC - 5 hours
|
||||
Timezone Eastern(EDT, EST);
|
||||
TimeChangeRule CDT = { "CDT", Second, Sun, Mar, 2, -300 }; //Daylight time = UTC - 5 hours
|
||||
TimeChangeRule CST = { "CST", First, Sun, Nov, 2, -360 }; //Standard time = UTC - 6 hours
|
||||
Timezone Central(CDT, CST);
|
||||
TimeChangeRule MDT = { "MDT", Second, Sun, Mar, 2, -360 }; //Daylight time = UTC - 6 hours
|
||||
TimeChangeRule MST = { "MST", First, Sun, Nov, 2, -420 }; //Standard time = UTC - 7 hours
|
||||
Timezone Mountain(MDT, MST);
|
||||
TimeChangeRule PDT = { "PDT", Second, Sun, Mar, 2, -420 }; //Daylight time = UTC - 7 hours
|
||||
TimeChangeRule PST = { "PST", First, Sun, Nov, 2, -480 }; //Standard time = UTC - 8 hours
|
||||
Timezone Pacific(PDT, PST);
|
||||
Timezone* timezones[] = { &Eastern, &Central, &Mountain, &Pacific };
|
||||
Timezone* tz; //pointer to the time zone
|
||||
uint8_t tzIndex; //indexes the timezones[] array
|
||||
TimeChangeRule* tcr; //pointer to the time change rule, use to get TZ abbrev
|
||||
|
||||
void setup()
|
||||
{
|
||||
// set the system time to UTC
|
||||
// warning: assumes that compileTime() returns US EST
|
||||
// adjust the following line accordingly if you're in another time zone
|
||||
setTime(compileTime() + 300 * 60);
|
||||
|
||||
btn.begin();
|
||||
Serial.begin(115200);
|
||||
tz = timezones[tzIndex];
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// print the time if it's changed
|
||||
static time_t tLast;
|
||||
time_t t = now();
|
||||
if (t != tLast)
|
||||
{
|
||||
tLast = t;
|
||||
printDateTime(t);
|
||||
Serial << " UTC ";
|
||||
TimeChangeRule* tcr; //pointer to current time change rule, used to get TZ abbrev
|
||||
printDateTime((*tz).toLocal(t, &tcr));
|
||||
Serial << " " << tcr -> abbrev;
|
||||
Serial << endl;
|
||||
}
|
||||
|
||||
// change the time zone if button pressed
|
||||
btn.read();
|
||||
if (btn.wasPressed())
|
||||
{
|
||||
if ( ++tzIndex >= sizeof(timezones) / sizeof(timezones[0]) ) tzIndex = 0;
|
||||
Serial << "tzIndex " << tzIndex << endl;
|
||||
tz = timezones[tzIndex];
|
||||
}
|
||||
}
|
||||
|
||||
void printDateTime(time_t t)
|
||||
{
|
||||
Serial << ((day(t)<10) ? "0" : "") << _DEC(day(t));
|
||||
Serial << monthShortStr(month(t)) << _DEC(year(t)) << ' ';
|
||||
Serial << ((hour(t)<10) ? "0" : "") << _DEC(hour(t)) << ':';
|
||||
Serial << ((minute(t)<10) ? "0" : "") << _DEC(minute(t)) << ':';
|
||||
Serial << ((second(t)<10) ? "0" : "") << _DEC(second(t));
|
||||
}
|
||||
|
||||
// function to return the compile date and time as a time_t value
|
||||
time_t compileTime()
|
||||
{
|
||||
const time_t FUDGE(10); //fudge factor to allow for upload time, etc. (seconds, YMMV)
|
||||
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
char compMon[4], *m;
|
||||
|
||||
strncpy(compMon, compDate, 3);
|
||||
compMon[3] = '\0';
|
||||
m = strstr(months, compMon);
|
||||
|
||||
tmElements_t tm;
|
||||
tm.Month = ((m - months) / 3 + 1);
|
||||
tm.Day = atoi(compDate + 4);
|
||||
tm.Year = atoi(compDate + 7) - 1970;
|
||||
tm.Hour = atoi(compTime);
|
||||
tm.Minute = atoi(compTime + 3);
|
||||
tm.Second = atoi(compTime + 6);
|
||||
|
||||
time_t t = makeTime(tm);
|
||||
return t + FUDGE; //add fudge factor to allow for compile time
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
// Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and
|
||||
// licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// Arduino Timezone Library example sketch.
|
||||
// Self-adjusting clock for one time zone.
|
||||
// TimeChangeRules can be hard-coded or read from EEPROM, see comments.
|
||||
// Jack Christensen Mar 2012
|
||||
|
||||
#include <Timezone.h> // https://github.com/JChristensen/Timezone
|
||||
|
||||
// US Eastern Time Zone (New York, Detroit)
|
||||
TimeChangeRule myDST = {"EDT", Second, Sun, Mar, 2, -240}; // Daylight time = UTC - 4 hours
|
||||
TimeChangeRule mySTD = {"EST", First, Sun, Nov, 2, -300}; // Standard time = UTC - 5 hours
|
||||
Timezone myTZ(myDST, mySTD);
|
||||
|
||||
// If TimeChangeRules are already stored in EEPROM, comment out the three
|
||||
// lines above and uncomment the line below.
|
||||
//Timezone myTZ(100); // assumes rules stored at EEPROM address 100
|
||||
|
||||
TimeChangeRule *tcr; // pointer to the time change rule, use to get TZ abbrev
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
setTime(myTZ.toUTC(compileTime()));
|
||||
//setTime(01, 55, 00, 11, 3, 2012); //another way to set the time (hr,min,sec,day,mnth,yr)
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
time_t utc = now();
|
||||
time_t local = myTZ.toLocal(utc, &tcr);
|
||||
Serial.println();
|
||||
printDateTime(utc, "UTC");
|
||||
printDateTime(local, tcr -> abbrev);
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// Function to return the compile date and time as a time_t value
|
||||
time_t compileTime()
|
||||
{
|
||||
const time_t FUDGE(10); // fudge factor to allow for compile time (seconds, YMMV)
|
||||
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
char chMon[4], *m;
|
||||
tmElements_t tm;
|
||||
|
||||
strncpy(chMon, compDate, 3);
|
||||
chMon[3] = '\0';
|
||||
m = strstr(months, chMon);
|
||||
tm.Month = ((m - months) / 3 + 1);
|
||||
|
||||
tm.Day = atoi(compDate + 4);
|
||||
tm.Year = atoi(compDate + 7) - 1970;
|
||||
tm.Hour = atoi(compTime);
|
||||
tm.Minute = atoi(compTime + 3);
|
||||
tm.Second = atoi(compTime + 6);
|
||||
time_t t = makeTime(tm);
|
||||
return t + FUDGE; // add fudge factor to allow for compile time
|
||||
}
|
||||
|
||||
// format and print a time_t value, with a time zone appended.
|
||||
void printDateTime(time_t t, const char *tz)
|
||||
{
|
||||
char buf[32];
|
||||
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
|
||||
strcpy(m, monthShortStr(month(t)));
|
||||
sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
|
||||
hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);
|
||||
Serial.println(buf);
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
// Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and
|
||||
// licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// Arduino Timezone Library example sketch.
|
||||
// Self-adjusting clock for one time zone using an external real-time
|
||||
// clock, either a DS1307 or DS3231 (e.g. Chronodot).
|
||||
// Assumes the RTC is set to UTC.
|
||||
// TimeChangeRules can be hard-coded or read from EEPROM, see comments.
|
||||
// Check out the Chronodot at http://www.macetech.com/store/
|
||||
//
|
||||
// Jack Christensen Aug 2012
|
||||
|
||||
#include <DS1307RTC.h> // https://github.com/PaulStoffregen/DS1307RTC
|
||||
#include <Timezone.h> // https://github.com/JChristensen/Timezone
|
||||
|
||||
// US Eastern Time Zone (New York, Detroit)
|
||||
TimeChangeRule myDST = {"EDT", Second, Sun, Mar, 2, -240}; //Daylight time = UTC - 4 hours
|
||||
TimeChangeRule mySTD = {"EST", First, Sun, Nov, 2, -300}; //Standard time = UTC - 5 hours
|
||||
Timezone myTZ(myDST, mySTD);
|
||||
|
||||
// If TimeChangeRules are already stored in EEPROM, comment out the three
|
||||
// lines above and uncomment the line below.
|
||||
//Timezone myTZ(100); //assumes rules stored at EEPROM address 100
|
||||
|
||||
TimeChangeRule *tcr; //pointer to the time change rule, use to get TZ abbrev
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
setSyncProvider(RTC.get); // the function to get the time from the RTC
|
||||
if(timeStatus()!= timeSet)
|
||||
Serial.println("Unable to sync with the RTC");
|
||||
else
|
||||
Serial.println("RTC has set the system time");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
time_t utc = now();
|
||||
time_t local = myTZ.toLocal(utc, &tcr);
|
||||
Serial.println();
|
||||
printDateTime(utc, "UTC");
|
||||
printDateTime(local, tcr -> abbrev);
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// format and print a time_t value, with a time zone appended.
|
||||
void printDateTime(time_t t, const char *tz)
|
||||
{
|
||||
char buf[32];
|
||||
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
|
||||
strcpy(m, monthShortStr(month(t)));
|
||||
sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
|
||||
hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);
|
||||
Serial.println(buf);
|
||||
}
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
// Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and
|
||||
// licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// Arduino Timezone Library example sketch.
|
||||
// Self-adjusting clock for multiple time zones.
|
||||
// Jack Christensen Mar 2012
|
||||
//
|
||||
// For time zone information:
|
||||
// http://www.timeanddate.com/worldclock/
|
||||
|
||||
#include <Timezone.h> // https://github.com/JChristensen/Timezone
|
||||
|
||||
// Australia Eastern Time Zone (Sydney, Melbourne)
|
||||
TimeChangeRule aEDT = {"AEDT", First, Sun, Oct, 2, 660}; // UTC + 11 hours
|
||||
TimeChangeRule aEST = {"AEST", First, Sun, Apr, 3, 600}; // UTC + 10 hours
|
||||
Timezone ausET(aEDT, aEST);
|
||||
|
||||
// Moscow Standard Time (MSK, does not observe DST)
|
||||
TimeChangeRule msk = {"MSK", Last, Sun, Mar, 1, 180};
|
||||
Timezone tzMSK(msk);
|
||||
|
||||
// Central European Time (Frankfurt, Paris)
|
||||
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; // Central European Summer Time
|
||||
TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central European Standard Time
|
||||
Timezone CE(CEST, CET);
|
||||
|
||||
// United Kingdom (London, Belfast)
|
||||
TimeChangeRule BST = {"BST", Last, Sun, Mar, 1, 60}; // British Summer Time
|
||||
TimeChangeRule GMT = {"GMT", Last, Sun, Oct, 2, 0}; // Standard Time
|
||||
Timezone UK(BST, GMT);
|
||||
|
||||
// UTC
|
||||
TimeChangeRule utcRule = {"UTC", Last, Sun, Mar, 1, 0}; // UTC
|
||||
Timezone UTC(utcRule);
|
||||
|
||||
// US Eastern Time Zone (New York, Detroit)
|
||||
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; // Eastern Daylight Time = UTC - 4 hours
|
||||
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; // Eastern Standard Time = UTC - 5 hours
|
||||
Timezone usET(usEDT, usEST);
|
||||
|
||||
// US Central Time Zone (Chicago, Houston)
|
||||
TimeChangeRule usCDT = {"CDT", Second, Sun, Mar, 2, -300};
|
||||
TimeChangeRule usCST = {"CST", First, Sun, Nov, 2, -360};
|
||||
Timezone usCT(usCDT, usCST);
|
||||
|
||||
// US Mountain Time Zone (Denver, Salt Lake City)
|
||||
TimeChangeRule usMDT = {"MDT", Second, Sun, Mar, 2, -360};
|
||||
TimeChangeRule usMST = {"MST", First, Sun, Nov, 2, -420};
|
||||
Timezone usMT(usMDT, usMST);
|
||||
|
||||
// Arizona is US Mountain Time Zone but does not use DST
|
||||
Timezone usAZ(usMST);
|
||||
|
||||
// US Pacific Time Zone (Las Vegas, Los Angeles)
|
||||
TimeChangeRule usPDT = {"PDT", Second, Sun, Mar, 2, -420};
|
||||
TimeChangeRule usPST = {"PST", First, Sun, Nov, 2, -480};
|
||||
Timezone usPT(usPDT, usPST);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
// set the system time to UTC
|
||||
// warning: assumes that compileTime() returns US EDT
|
||||
// adjust the following line accordingly if you're in another time zone
|
||||
setTime(compileTime() + 240 * 60);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
time_t utc = now();
|
||||
Serial.println();
|
||||
printDateTime(ausET, utc, "Sydney");
|
||||
printDateTime(tzMSK, utc, " Moscow");
|
||||
printDateTime(CE, utc, "Paris");
|
||||
printDateTime(UK, utc, " London");
|
||||
printDateTime(UTC, utc, " Universal Coordinated Time");
|
||||
printDateTime(usET, utc, " New York");
|
||||
printDateTime(usCT, utc, " Chicago");
|
||||
printDateTime(usMT, utc, " Denver");
|
||||
printDateTime(usAZ, utc, " Phoenix");
|
||||
printDateTime(usPT, utc, " Los Angeles");
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// Function to return the compile date and time as a time_t value
|
||||
time_t compileTime()
|
||||
{
|
||||
const time_t FUDGE(10); // fudge factor to allow for compile time (seconds, YMMV)
|
||||
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
char chMon[4], *m;
|
||||
tmElements_t tm;
|
||||
|
||||
strncpy(chMon, compDate, 3);
|
||||
chMon[3] = '\0';
|
||||
m = strstr(months, chMon);
|
||||
tm.Month = ((m - months) / 3 + 1);
|
||||
|
||||
tm.Day = atoi(compDate + 4);
|
||||
tm.Year = atoi(compDate + 7) - 1970;
|
||||
tm.Hour = atoi(compTime);
|
||||
tm.Minute = atoi(compTime + 3);
|
||||
tm.Second = atoi(compTime + 6);
|
||||
time_t t = makeTime(tm);
|
||||
return t + FUDGE; // add fudge factor to allow for compile time
|
||||
}
|
||||
|
||||
// given a Timezone object, UTC and a string description, convert and print local time with time zone
|
||||
void printDateTime(Timezone tz, time_t utc, const char *descr)
|
||||
{
|
||||
char buf[40];
|
||||
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
|
||||
TimeChangeRule *tcr; // pointer to the time change rule, use to get the TZ abbrev
|
||||
|
||||
time_t t = tz.toLocal(utc, &tcr);
|
||||
strcpy(m, monthShortStr(month(t)));
|
||||
sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
|
||||
hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tcr -> abbrev);
|
||||
Serial.print(buf);
|
||||
Serial.print(' ');
|
||||
Serial.println(descr);
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and
|
||||
// licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// Arduino Timezone Library example sketch.
|
||||
// Write TimeChangeRules to EEPROM.
|
||||
// Jack Christensen Mar 2012
|
||||
|
||||
#include <Timezone.h> // https://github.com/JChristensen/Timezone
|
||||
|
||||
// US Eastern Time Zone (New York, Detroit)
|
||||
TimeChangeRule usEdt = {"EDT", Second, Sun, Mar, 2, -240}; // UTC - 4 hours
|
||||
TimeChangeRule usEst = {"EST", First, Sun, Nov, 2, -300}; // UTC - 5 hours
|
||||
Timezone usEastern(usEdt, usEst);
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(13, OUTPUT);
|
||||
usEastern.writeRules(100); // write rules to EEPROM address 100
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// fast blink to indicate EEPROM write is complete
|
||||
digitalWrite(13, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(13, LOW);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
// Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and
|
||||
// licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
|
||||
//
|
||||
// Arduino Timezone Library example sketch.
|
||||
// Sketch to verify operation of Timezone library.
|
||||
// Jack Christensen 14Nov2018
|
||||
|
||||
#include <Timezone.h> // https://github.com/JChristensen/Timezone
|
||||
#include <TimeLib.h> // https://github.com/PaulStoffregen/Time
|
||||
|
||||
// New Zealand Time Zone
|
||||
TimeChangeRule nzSTD = {"NZST", First, Sun, Apr, 3, 720}; // UTC + 12 hours
|
||||
TimeChangeRule nzDST = {"NZDT", Last, Sun, Sep, 2, 780}; // UTC + 13 hours
|
||||
Timezone nz(nzDST, nzSTD);
|
||||
|
||||
// US Eastern Time Zone (New York, Detroit)
|
||||
TimeChangeRule etDST = {"EDT", Second, Sun, Mar, 2, -240}; // Daylight time = UTC - 4 hours
|
||||
TimeChangeRule etSTD = {"EST", First, Sun, Nov, 2, -300}; // Standard time = UTC - 5 hours
|
||||
Timezone et(etDST, etSTD);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
// New Zealand
|
||||
printTimes( 1, 4, 2018, nzSTD.hour, nzDST.offset, nz); // day, month, year, hour, offset, tz
|
||||
printTimes(30, 9, 2018, nzDST.hour, nzSTD.offset, nz);
|
||||
printTimes( 7, 4, 2019, nzSTD.hour, nzDST.offset, nz);
|
||||
printTimes(29, 9, 2019, nzDST.hour, nzSTD.offset, nz);
|
||||
printTimes( 5, 4, 2020, nzSTD.hour, nzDST.offset, nz);
|
||||
printTimes(27, 9, 2020, nzDST.hour, nzSTD.offset, nz);
|
||||
|
||||
// US Eastern
|
||||
printTimes(11, 3, 2018, etDST.hour, etSTD.offset, et); // day, month, year, hour, offset, tz
|
||||
printTimes( 4, 11, 2018, etSTD.hour, etDST.offset, et);
|
||||
printTimes(10, 3, 2019, etDST.hour, etSTD.offset, et);
|
||||
printTimes( 3, 11, 2019, etSTD.hour, etDST.offset, et);
|
||||
printTimes( 8, 3, 2020, etDST.hour, etSTD.offset, et);
|
||||
printTimes( 1, 11, 2020, etSTD.hour, etDST.offset, et);
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
|
||||
// print corresponding UTC and local times "n" seconds before and after the time change.
|
||||
// h is the hour to change the clock using the *current* time (i.e. before the change).
|
||||
// offset is the utc offset in minutes for the time *after* the change.
|
||||
void printTimes(uint8_t d, uint8_t m, int y, uint8_t h, int offset, Timezone tz)
|
||||
{
|
||||
const time_t n(3); // number of times to print before and after the time change
|
||||
tmElements_t tm;
|
||||
tm.Hour = h;
|
||||
tm.Minute = 0;
|
||||
tm.Second = 0;
|
||||
tm.Day = d;
|
||||
tm.Month = m;
|
||||
tm.Year = y - 1970; // offset from 1970
|
||||
time_t utc = makeTime(tm) - offset * SECS_PER_MIN - n;
|
||||
|
||||
Serial.print(F("\n-------- "));
|
||||
Serial.print(monthShortStr(m));
|
||||
Serial.print('-');
|
||||
Serial.print(y);
|
||||
Serial.print(F(" time change --------\n"));
|
||||
|
||||
for (uint16_t i=0; i<n*2; i++)
|
||||
{
|
||||
TimeChangeRule *tcr; // pointer to the time change rule, use to get TZ abbrev
|
||||
time_t local = tz.toLocal(utc, &tcr);
|
||||
printDateTime(utc, "UTC = ");
|
||||
printDateTime(local, tcr -> abbrev);
|
||||
Serial.println();
|
||||
++utc;
|
||||
}
|
||||
}
|
||||
|
||||
// format and print a time_t value, with a time zone appended.
|
||||
void printDateTime(time_t t, const char *tz)
|
||||
{
|
||||
char buf[32];
|
||||
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
|
||||
strcpy(m, monthShortStr(month(t)));
|
||||
sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
|
||||
hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);
|
||||
Serial.print(buf);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
TimeChangeRule KEYWORD1
|
||||
Timezone KEYWORD1
|
||||
toLocal KEYWORD2
|
||||
toUTC KEYWORD2
|
||||
utcIsDST KEYWORD2
|
||||
locIsDST KEYWORD2
|
||||
setRules KEYWORD2
|
||||
readRules KEYWORD2
|
||||
writeRules KEYWORD2
|
||||
@@ -1,10 +0,0 @@
|
||||
name=Timezone
|
||||
version=1.2.4
|
||||
author=Jack Christensen <jack.christensen@outlook.com>
|
||||
maintainer=Jack Christensen <jack.christensen@outlook.com>
|
||||
sentence=Arduino library to facilitate time zone conversions and automatic daylight saving (summer) time adjustments.
|
||||
paragraph=The primary aim of the Timezone library is to convert Universal Coordinated Time (UTC) to the correct local time, whether it is daylight saving time (a.k.a. summer time) or standard time.
|
||||
category=Timing
|
||||
url=https://github.com/JChristensen/Timezone
|
||||
architectures=*
|
||||
depends=Time
|
||||
@@ -1,243 +0,0 @@
|
||||
/*----------------------------------------------------------------------*
|
||||
* Arduino Timezone Library *
|
||||
* Jack Christensen Mar 2012 *
|
||||
* *
|
||||
* Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and *
|
||||
* licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html *
|
||||
*----------------------------------------------------------------------*/
|
||||
|
||||
#include "Timezone.h"
|
||||
|
||||
#ifdef __AVR__
|
||||
#include <avr/eeprom.h>
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Create a Timezone object from the given time change rules. *
|
||||
*----------------------------------------------------------------------*/
|
||||
Timezone::Timezone(TimeChangeRule dstStart, TimeChangeRule stdStart)
|
||||
: m_dst(dstStart), m_std(stdStart)
|
||||
{
|
||||
initTimeChanges();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Create a Timezone object for a zone that does not observe *
|
||||
* daylight time. *
|
||||
*----------------------------------------------------------------------*/
|
||||
Timezone::Timezone(TimeChangeRule stdTime)
|
||||
: m_dst(stdTime), m_std(stdTime)
|
||||
{
|
||||
initTimeChanges();
|
||||
}
|
||||
|
||||
#ifdef __AVR__
|
||||
/*----------------------------------------------------------------------*
|
||||
* Create a Timezone object from time change rules stored in EEPROM *
|
||||
* at the given address. *
|
||||
*----------------------------------------------------------------------*/
|
||||
Timezone::Timezone(int address)
|
||||
{
|
||||
readRules(address);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Convert the given UTC time to local time, standard or *
|
||||
* daylight time, as appropriate. *
|
||||
*----------------------------------------------------------------------*/
|
||||
time_t Timezone::toLocal(time_t utc)
|
||||
{
|
||||
// recalculate the time change points if needed
|
||||
if (year(utc) != year(m_dstUTC)) calcTimeChanges(year(utc));
|
||||
|
||||
if (utcIsDST(utc))
|
||||
return utc + m_dst.offset * SECS_PER_MIN;
|
||||
else
|
||||
return utc + m_std.offset * SECS_PER_MIN;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Convert the given UTC time to local time, standard or *
|
||||
* daylight time, as appropriate, and return a pointer to the time *
|
||||
* change rule used to do the conversion. The caller must take care *
|
||||
* not to alter this rule. *
|
||||
*----------------------------------------------------------------------*/
|
||||
time_t Timezone::toLocal(time_t utc, TimeChangeRule **tcr)
|
||||
{
|
||||
// recalculate the time change points if needed
|
||||
if (year(utc) != year(m_dstUTC)) calcTimeChanges(year(utc));
|
||||
|
||||
if (utcIsDST(utc)) {
|
||||
*tcr = &m_dst;
|
||||
return utc + m_dst.offset * SECS_PER_MIN;
|
||||
}
|
||||
else {
|
||||
*tcr = &m_std;
|
||||
return utc + m_std.offset * SECS_PER_MIN;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Convert the given local time to UTC time. *
|
||||
* *
|
||||
* WARNING: *
|
||||
* This function is provided for completeness, but should seldom be *
|
||||
* needed and should be used sparingly and carefully. *
|
||||
* *
|
||||
* Ambiguous situations occur after the Standard-to-DST and the *
|
||||
* DST-to-Standard time transitions. When changing to DST, there is *
|
||||
* one hour of local time that does not exist, since the clock moves *
|
||||
* forward one hour. Similarly, when changing to standard time, there *
|
||||
* is one hour of local times that occur twice since the clock moves *
|
||||
* back one hour. *
|
||||
* *
|
||||
* This function does not test whether it is passed an erroneous time *
|
||||
* value during the Local -> DST transition that does not exist. *
|
||||
* If passed such a time, an incorrect UTC time value will be returned. *
|
||||
* *
|
||||
* If passed a local time value during the DST -> Local transition *
|
||||
* that occurs twice, it will be treated as the earlier time, i.e. *
|
||||
* the time that occurs before the transistion. *
|
||||
* *
|
||||
* Calling this function with local times during a transition interval *
|
||||
* should be avoided! *
|
||||
*----------------------------------------------------------------------*/
|
||||
time_t Timezone::toUTC(time_t local)
|
||||
{
|
||||
// recalculate the time change points if needed
|
||||
if (year(local) != year(m_dstLoc)) calcTimeChanges(year(local));
|
||||
|
||||
if (locIsDST(local))
|
||||
return local - m_dst.offset * SECS_PER_MIN;
|
||||
else
|
||||
return local - m_std.offset * SECS_PER_MIN;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Determine whether the given UTC time_t is within the DST interval *
|
||||
* or the Standard time interval. *
|
||||
*----------------------------------------------------------------------*/
|
||||
bool Timezone::utcIsDST(time_t utc)
|
||||
{
|
||||
// recalculate the time change points if needed
|
||||
if (year(utc) != year(m_dstUTC)) calcTimeChanges(year(utc));
|
||||
|
||||
if (m_stdUTC == m_dstUTC) // daylight time not observed in this tz
|
||||
return false;
|
||||
else if (m_stdUTC > m_dstUTC) // northern hemisphere
|
||||
return (utc >= m_dstUTC && utc < m_stdUTC);
|
||||
else // southern hemisphere
|
||||
return !(utc >= m_stdUTC && utc < m_dstUTC);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Determine whether the given Local time_t is within the DST interval *
|
||||
* or the Standard time interval. *
|
||||
*----------------------------------------------------------------------*/
|
||||
bool Timezone::locIsDST(time_t local)
|
||||
{
|
||||
// recalculate the time change points if needed
|
||||
if (year(local) != year(m_dstLoc)) calcTimeChanges(year(local));
|
||||
|
||||
if (m_stdUTC == m_dstUTC) // daylight time not observed in this tz
|
||||
return false;
|
||||
else if (m_stdLoc > m_dstLoc) // northern hemisphere
|
||||
return (local >= m_dstLoc && local < m_stdLoc);
|
||||
else // southern hemisphere
|
||||
return !(local >= m_stdLoc && local < m_dstLoc);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Calculate the DST and standard time change points for the given *
|
||||
* given year as local and UTC time_t values. *
|
||||
*----------------------------------------------------------------------*/
|
||||
void Timezone::calcTimeChanges(int yr)
|
||||
{
|
||||
m_dstLoc = toTime_t(m_dst, yr);
|
||||
m_stdLoc = toTime_t(m_std, yr);
|
||||
m_dstUTC = m_dstLoc - m_std.offset * SECS_PER_MIN;
|
||||
m_stdUTC = m_stdLoc - m_dst.offset * SECS_PER_MIN;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Initialize the DST and standard time change points. *
|
||||
*----------------------------------------------------------------------*/
|
||||
void Timezone::initTimeChanges()
|
||||
{
|
||||
m_dstLoc = 0;
|
||||
m_stdLoc = 0;
|
||||
m_dstUTC = 0;
|
||||
m_stdUTC = 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Convert the given time change rule to a time_t value *
|
||||
* for the given year. *
|
||||
*----------------------------------------------------------------------*/
|
||||
time_t Timezone::toTime_t(TimeChangeRule r, int yr)
|
||||
{
|
||||
uint8_t m = r.month; // temp copies of r.month and r.week
|
||||
uint8_t w = r.week;
|
||||
if (w == 0) // is this a "Last week" rule?
|
||||
{
|
||||
if (++m > 12) // yes, for "Last", go to the next month
|
||||
{
|
||||
m = 1;
|
||||
++yr;
|
||||
}
|
||||
w = 1; // and treat as first week of next month, subtract 7 days later
|
||||
}
|
||||
|
||||
// calculate first day of the month, or for "Last" rules, first day of the next month
|
||||
tmElements_t tm;
|
||||
tm.Hour = r.hour;
|
||||
tm.Minute = 0;
|
||||
tm.Second = 0;
|
||||
tm.Day = 1;
|
||||
tm.Month = m;
|
||||
tm.Year = yr - 1970;
|
||||
time_t t = makeTime(tm);
|
||||
|
||||
// add offset from the first of the month to r.dow, and offset for the given week
|
||||
t += ( (r.dow - weekday(t) + 7) % 7 + (w - 1) * 7 ) * SECS_PER_DAY;
|
||||
// back up a week if this is a "Last" rule
|
||||
if (r.week == 0) t -= 7 * SECS_PER_DAY;
|
||||
return t;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Read or update the daylight and standard time rules from RAM. *
|
||||
*----------------------------------------------------------------------*/
|
||||
void Timezone::setRules(TimeChangeRule dstStart, TimeChangeRule stdStart)
|
||||
{
|
||||
m_dst = dstStart;
|
||||
m_std = stdStart;
|
||||
initTimeChanges(); // force calcTimeChanges() at next conversion call
|
||||
}
|
||||
|
||||
#ifdef __AVR__
|
||||
/*----------------------------------------------------------------------*
|
||||
* Read the daylight and standard time rules from EEPROM at *
|
||||
* the given address. *
|
||||
*----------------------------------------------------------------------*/
|
||||
void Timezone::readRules(int address)
|
||||
{
|
||||
eeprom_read_block((void *) &m_dst, (void *) address, sizeof(m_dst));
|
||||
address += sizeof(m_dst);
|
||||
eeprom_read_block((void *) &m_std, (void *) address, sizeof(m_std));
|
||||
initTimeChanges(); // force calcTimeChanges() at next conversion call
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* Write the daylight and standard time rules to EEPROM at *
|
||||
* the given address. *
|
||||
*----------------------------------------------------------------------*/
|
||||
void Timezone::writeRules(int address)
|
||||
{
|
||||
eeprom_write_block((void *) &m_dst, (void *) address, sizeof(m_dst));
|
||||
address += sizeof(m_dst);
|
||||
eeprom_write_block((void *) &m_std, (void *) address, sizeof(m_std));
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,61 +0,0 @@
|
||||
/*----------------------------------------------------------------------*
|
||||
* Arduino Timezone Library *
|
||||
* Jack Christensen Mar 2012 *
|
||||
* *
|
||||
* Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and *
|
||||
* licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html *
|
||||
*----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TIMEZONE_H_INCLUDED
|
||||
#define TIMEZONE_H_INCLUDED
|
||||
#if ARDUINO >= 100
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
#include <TimeLib.h> // https://github.com/PaulStoffregen/Time
|
||||
|
||||
// convenient constants for TimeChangeRules
|
||||
enum week_t {Last, First, Second, Third, Fourth};
|
||||
enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
|
||||
enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
|
||||
|
||||
// structure to describe rules for when daylight/summer time begins,
|
||||
// or when standard time begins.
|
||||
struct TimeChangeRule
|
||||
{
|
||||
char abbrev[6]; // five chars max
|
||||
uint8_t week; // First, Second, Third, Fourth, or Last week of the month
|
||||
uint8_t dow; // day of week, 1=Sun, 2=Mon, ... 7=Sat
|
||||
uint8_t month; // 1=Jan, 2=Feb, ... 12=Dec
|
||||
uint8_t hour; // 0-23
|
||||
int offset; // offset from UTC in minutes
|
||||
};
|
||||
|
||||
class Timezone
|
||||
{
|
||||
public:
|
||||
Timezone(TimeChangeRule dstStart, TimeChangeRule stdStart);
|
||||
Timezone(TimeChangeRule stdTime);
|
||||
Timezone(int address);
|
||||
time_t toLocal(time_t utc);
|
||||
time_t toLocal(time_t utc, TimeChangeRule **tcr);
|
||||
time_t toUTC(time_t local);
|
||||
bool utcIsDST(time_t utc);
|
||||
bool locIsDST(time_t local);
|
||||
void setRules(TimeChangeRule dstStart, TimeChangeRule stdStart);
|
||||
void readRules(int address);
|
||||
void writeRules(int address);
|
||||
|
||||
private:
|
||||
void calcTimeChanges(int yr);
|
||||
void initTimeChanges();
|
||||
time_t toTime_t(TimeChangeRule r, int yr);
|
||||
TimeChangeRule m_dst; // rule for start of dst or summer time for any year
|
||||
TimeChangeRule m_std; // rule for start of standard time for any year
|
||||
time_t m_dstUTC; // dst start for given/current year, given in UTC
|
||||
time_t m_stdUTC; // std time start for given/current year, given in UTC
|
||||
time_t m_dstLoc; // dst start for given/current year, given in local time
|
||||
time_t m_stdLoc; // std time start for given/current year, given in local time
|
||||
};
|
||||
#endif
|
||||
57
lib/mbedtls/.gitignore
vendored
@@ -1,57 +0,0 @@
|
||||
# Random seed file created by test scripts and sample programs
|
||||
seedfile
|
||||
|
||||
# CMake build artifacts:
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CTestTestfile.cmake
|
||||
cmake_install.cmake
|
||||
Testing
|
||||
# CMake generates *.dir/ folders for in-tree builds (used by MSVC projects), ignore all of those:
|
||||
*.dir/
|
||||
# MSVC files generated by CMake:
|
||||
/*.sln
|
||||
/*.vcxproj
|
||||
/*.filters
|
||||
|
||||
# Test coverage build artifacts:
|
||||
Coverage
|
||||
*.gcno
|
||||
*.gcda
|
||||
|
||||
# generated by scripts/memory.sh
|
||||
massif-*
|
||||
|
||||
# MSVC build artifacts:
|
||||
*.exe
|
||||
*.pdb
|
||||
*.ilk
|
||||
*.lib
|
||||
|
||||
# Python build artifacts:
|
||||
*.pyc
|
||||
|
||||
# CMake generates *.dir/ folders for in-tree builds (used by MSVC projects), ignore all of those:
|
||||
*.dir/
|
||||
|
||||
# Microsoft CMake extension for Visual Studio Code generates a build directory by default
|
||||
/build/
|
||||
|
||||
# Visual Studio artifacts
|
||||
/visualc/VS2010/.localhistory/
|
||||
/visualc/VS2010/.vs/
|
||||
/visualc/VS2010/Debug/
|
||||
/visualc/VS2010/Release/
|
||||
/visualc/VS2010/*.vcxproj.filters
|
||||
/visualc/VS2010/*.vcxproj.user
|
||||
|
||||
# Generated documentation:
|
||||
/apidoc
|
||||
|
||||
# Editor navigation files:
|
||||
/GPATH
|
||||
/GRTAGS
|
||||
/GSYMS
|
||||
/GTAGS
|
||||
/TAGS
|
||||
/tags
|
||||
@@ -1,3 +0,0 @@
|
||||
default:\
|
||||
:langmap=c\:.c.h.function:\
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
[BASIC]
|
||||
# We're ok with short funtion argument names.
|
||||
# [invalid-name]
|
||||
argument-rgx=[a-z_][a-z0-9_]*$
|
||||
|
||||
# Allow filter and map.
|
||||
# [bad-builtin]
|
||||
bad-functions=input
|
||||
|
||||
# We prefer docstrings, but we don't require them on all functions.
|
||||
# Require them only on long functions (for some value of long).
|
||||
# [missing-docstring]
|
||||
docstring-min-length=10
|
||||
|
||||
# Allow longer methods than the default.
|
||||
# [invalid-name]
|
||||
method-rgx=[a-z_][a-z0-9_]{2,35}$
|
||||
|
||||
# Allow module names containing a dash (but no underscore or uppercase letter).
|
||||
# They are whole programs, not meant to be included by another module.
|
||||
# [invalid-name]
|
||||
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|[a-z][-0-9a-z]+)$
|
||||
|
||||
# Some functions don't need docstrings.
|
||||
# [missing-docstring]
|
||||
no-docstring-rgx=(run_)?main$
|
||||
|
||||
# We're ok with short local or global variable names.
|
||||
# [invalid-name]
|
||||
variable-rgx=[a-z_][a-z0-9_]*$
|
||||
|
||||
[DESIGN]
|
||||
# Allow more than the default 7 attributes.
|
||||
# [too-many-instance-attributes]
|
||||
max-attributes=15
|
||||
|
||||
[FORMAT]
|
||||
# Allow longer modules than the default recommended maximum.
|
||||
# [too-many-lines]
|
||||
max-module-lines=2000
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
# * locally-disabled, locally-enabled: If we disable or enable a message
|
||||
# locally, it's by design. There's no need to clutter the Pylint output
|
||||
# with this information.
|
||||
# * logging-format-interpolation: Pylint warns about things like
|
||||
# ``log.info('...'.format(...))``. It insists on ``log.info('...', ...)``.
|
||||
# This is of minor utility (mainly a performance gain when there are
|
||||
# many messages that use formatting and are below the log level).
|
||||
# Some versions of Pylint (including 1.8, which is the version on
|
||||
# Ubuntu 18.04) only recognize old-style format strings using '%',
|
||||
# and complain about something like ``log.info('{}', foo)`` with
|
||||
# logging-too-many-args (Pylint supports new-style formatting if
|
||||
# declared globally with logging_format_style under [LOGGING] but
|
||||
# this requires Pylint >=2.2).
|
||||
# * no-else-return: Allow the perfectly reasonable idiom
|
||||
# if condition1:
|
||||
# return value1
|
||||
# else:
|
||||
# return value2
|
||||
# * unnecessary-pass: If we take the trouble of adding a line with "pass",
|
||||
# it's because we think the code is clearer that way.
|
||||
disable=locally-disabled,locally-enabled,logging-format-interpolation,no-else-return,unnecessary-pass
|
||||
|
||||
[REPORTS]
|
||||
# Don't diplay statistics. Just the facts.
|
||||
reports=no
|
||||
|
||||
[VARIABLES]
|
||||
# Allow unused variables if their name starts with an underscore.
|
||||
# [unused-argument]
|
||||
dummy-variables-rgx=_.*
|
||||
1
lib/mbedtls/3rdparty/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/Makefile
|
||||
11
lib/mbedtls/3rdparty/CMakeLists.txt
vendored
@@ -1,11 +0,0 @@
|
||||
list (APPEND thirdparty_src)
|
||||
list (APPEND thirdparty_lib)
|
||||
list (APPEND thirdparty_inc)
|
||||
list (APPEND thirdparty_def)
|
||||
|
||||
add_subdirectory(everest)
|
||||
|
||||
set(thirdparty_src ${thirdparty_src} PARENT_SCOPE)
|
||||
set(thirdparty_lib ${thirdparty_lib} PARENT_SCOPE)
|
||||
set(thirdparty_inc ${thirdparty_inc} PARENT_SCOPE)
|
||||
set(thirdparty_def ${thirdparty_def} PARENT_SCOPE)
|
||||
2
lib/mbedtls/3rdparty/Makefile.inc
vendored
@@ -1,2 +0,0 @@
|
||||
THIRDPARTY_DIR = $(dir $(lastword $(MAKEFILE_LIST)))
|
||||
include $(THIRDPARTY_DIR)/everest/Makefile.inc
|
||||
2
lib/mbedtls/3rdparty/everest/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*.o
|
||||
Makefile
|
||||
31
lib/mbedtls/3rdparty/everest/CMakeLists.txt
vendored
@@ -1,31 +0,0 @@
|
||||
list (APPEND everest_src)
|
||||
list (APPEND everest_inc)
|
||||
list (APPEND everest_def)
|
||||
|
||||
set(everest_src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/library/everest.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/library/x25519.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/library/Hacl_Curve25519_joined.c
|
||||
)
|
||||
|
||||
list(APPEND everest_inc ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/everest ${CMAKE_CURRENT_SOURCE_DIR}/include/everest/kremlib)
|
||||
|
||||
execute_process(COMMAND ${MBEDTLS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/config.py -f ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/config.h get MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED RESULT_VARIABLE result)
|
||||
|
||||
if(${result} EQUAL 0)
|
||||
|
||||
if(INSTALL_MBEDTLS_HEADERS)
|
||||
|
||||
install(DIRECTORY include/everest
|
||||
DESTINATION include
|
||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
|
||||
DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
|
||||
endif(INSTALL_MBEDTLS_HEADERS)
|
||||
|
||||
endif()
|
||||
|
||||
set(thirdparty_src ${thirdparty_src} ${everest_src} PARENT_SCOPE)
|
||||
set(thirdparty_inc ${thirdparty_inc} ${everest_inc} PARENT_SCOPE)
|
||||
set(thirdparty_def ${thirdparty_def} ${everest_def} PARENT_SCOPE)
|
||||
6
lib/mbedtls/3rdparty/everest/Makefile.inc
vendored
@@ -1,6 +0,0 @@
|
||||
THIRDPARTY_INCLUDES+=-I../3rdparty/everest/include -I../3rdparty/everest/include/everest -I../3rdparty/everest/include/everest/kremlib
|
||||
|
||||
THIRDPARTY_CRYPTO_OBJECTS+= \
|
||||
../3rdparty/everest/library/everest.o \
|
||||
../3rdparty/everest/library/x25519.o \
|
||||
../3rdparty/everest/library/Hacl_Curve25519_joined.o
|
||||
5
lib/mbedtls/3rdparty/everest/README.md
vendored
@@ -1,5 +0,0 @@
|
||||
The files in this directory stem from [Project Everest](https://project-everest.github.io/) and are distributed under the Apache 2.0 license.
|
||||
|
||||
This is a formally verified implementation of Curve25519-based handshakes. The C code is automatically derived from the (verified) [original implementation](https://github.com/project-everest/hacl-star/tree/master/code/curve25519) in the [F* language](https://github.com/fstarlang/fstar) by [KreMLin](https://github.com/fstarlang/kremlin). In addition to the improved safety and security of the implementation, it is also significantly faster than the default implementation of Curve25519 in mbedTLS.
|
||||
|
||||
The caveat is that not all platforms are supported, although the version in `everest/library/legacy` should work on most systems. The main issue is that some platforms do not provide a 128-bit integer type and KreMLin therefore has to use additional (also verified) code to simulate them, resulting in less of a performance gain overall. Explictly supported platforms are currently `x86` and `x86_64` using gcc or clang, and Visual C (2010 and later).
|
||||
@@ -1,21 +0,0 @@
|
||||
/* Copyright (c) INRIA and Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache 2.0 License. */
|
||||
|
||||
/* This file was generated by KreMLin <https://github.com/FStarLang/kremlin>
|
||||
* KreMLin invocation: /mnt/e/everest/verify/kremlin/krml -fc89 -fparentheses -fno-shadow -header /mnt/e/everest/verify/hdrcLh -minimal -fbuiltin-uint128 -fc89 -fparentheses -fno-shadow -header /mnt/e/everest/verify/hdrcLh -minimal -I /mnt/e/everest/verify/hacl-star/code/lib/kremlin -I /mnt/e/everest/verify/kremlin/kremlib/compat -I /mnt/e/everest/verify/hacl-star/specs -I /mnt/e/everest/verify/hacl-star/specs/old -I . -ccopt -march=native -verbose -ldopt -flto -tmpdir x25519-c -I ../bignum -bundle Hacl.Curve25519=* -minimal -add-include "kremlib.h" -skip-compilation x25519-c/out.krml -o x25519-c/Hacl_Curve25519.c
|
||||
* F* version: 059db0c8
|
||||
* KreMLin version: 916c37ac
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __Hacl_Curve25519_H
|
||||
#define __Hacl_Curve25519_H
|
||||
|
||||
|
||||
#include "kremlib.h"
|
||||
|
||||
void Hacl_Curve25519_crypto_scalarmult(uint8_t *mypublic, uint8_t *secret, uint8_t *basepoint);
|
||||
|
||||
#define __Hacl_Curve25519_H_DEFINED
|
||||
#endif
|
||||
@@ -1,234 +0,0 @@
|
||||
/*
|
||||
* Interface to code from Project Everest
|
||||
*
|
||||
* Copyright 2016-2018 INRIA and Microsoft Corporation
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of Mbed TLS (https://tls.mbed.org).
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_EVEREST_H
|
||||
#define MBEDTLS_EVEREST_H
|
||||
|
||||
#include "everest/x25519.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Defines the source of the imported EC key.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
MBEDTLS_EVEREST_ECDH_OURS, /**< Our key. */
|
||||
MBEDTLS_EVEREST_ECDH_THEIRS, /**< The key of the peer. */
|
||||
} mbedtls_everest_ecdh_side;
|
||||
|
||||
typedef struct {
|
||||
mbedtls_x25519_context ctx;
|
||||
} mbedtls_ecdh_context_everest;
|
||||
|
||||
|
||||
/**
|
||||
* \brief This function sets up the ECDH context with the information
|
||||
* given.
|
||||
*
|
||||
* This function should be called after mbedtls_ecdh_init() but
|
||||
* before mbedtls_ecdh_make_params(). There is no need to call
|
||||
* this function before mbedtls_ecdh_read_params().
|
||||
*
|
||||
* This is the first function used by a TLS server for ECDHE
|
||||
* ciphersuites.
|
||||
*
|
||||
* \param ctx The ECDH context to set up.
|
||||
* \param grp_id The group id of the group to set up the context for.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
int mbedtls_everest_setup( mbedtls_ecdh_context_everest *ctx, int grp_id );
|
||||
|
||||
/**
|
||||
* \brief This function frees a context.
|
||||
*
|
||||
* \param ctx The context to free.
|
||||
*/
|
||||
void mbedtls_everest_free( mbedtls_ecdh_context_everest *ctx );
|
||||
|
||||
/**
|
||||
* \brief This function generates a public key and a TLS
|
||||
* ServerKeyExchange payload.
|
||||
*
|
||||
* This is the second function used by a TLS server for ECDHE
|
||||
* ciphersuites. (It is called after mbedtls_ecdh_setup().)
|
||||
*
|
||||
* \note This function assumes that the ECP group (grp) of the
|
||||
* \p ctx context has already been properly set,
|
||||
* for example, using mbedtls_ecp_group_load().
|
||||
*
|
||||
* \see ecp.h
|
||||
*
|
||||
* \param ctx The ECDH context.
|
||||
* \param olen The number of characters written.
|
||||
* \param buf The destination buffer.
|
||||
* \param blen The length of the destination buffer.
|
||||
* \param f_rng The RNG function.
|
||||
* \param p_rng The RNG context.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_everest_make_params( mbedtls_ecdh_context_everest *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int( *f_rng )( void *, unsigned char *, size_t ),
|
||||
void *p_rng );
|
||||
|
||||
/**
|
||||
* \brief This function parses and processes a TLS ServerKeyExhange
|
||||
* payload.
|
||||
*
|
||||
* This is the first function used by a TLS client for ECDHE
|
||||
* ciphersuites.
|
||||
*
|
||||
* \see ecp.h
|
||||
*
|
||||
* \param ctx The ECDH context.
|
||||
* \param buf The pointer to the start of the input buffer.
|
||||
* \param end The address for one Byte past the end of the buffer.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_everest_read_params( mbedtls_ecdh_context_everest *ctx,
|
||||
const unsigned char **buf, const unsigned char *end );
|
||||
|
||||
/**
|
||||
* \brief This function parses and processes a TLS ServerKeyExhange
|
||||
* payload.
|
||||
*
|
||||
* This is the first function used by a TLS client for ECDHE
|
||||
* ciphersuites.
|
||||
*
|
||||
* \see ecp.h
|
||||
*
|
||||
* \param ctx The ECDH context.
|
||||
* \param buf The pointer to the start of the input buffer.
|
||||
* \param end The address for one Byte past the end of the buffer.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_everest_read_params( mbedtls_ecdh_context_everest *ctx,
|
||||
const unsigned char **buf, const unsigned char *end );
|
||||
|
||||
/**
|
||||
* \brief This function sets up an ECDH context from an EC key.
|
||||
*
|
||||
* It is used by clients and servers in place of the
|
||||
* ServerKeyEchange for static ECDH, and imports ECDH
|
||||
* parameters from the EC key information of a certificate.
|
||||
*
|
||||
* \see ecp.h
|
||||
*
|
||||
* \param ctx The ECDH context to set up.
|
||||
* \param key The EC key to use.
|
||||
* \param side Defines the source of the key: 1: Our key, or
|
||||
* 0: The key of the peer.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_everest_get_params( mbedtls_ecdh_context_everest *ctx, const mbedtls_ecp_keypair *key,
|
||||
mbedtls_everest_ecdh_side side );
|
||||
|
||||
/**
|
||||
* \brief This function generates a public key and a TLS
|
||||
* ClientKeyExchange payload.
|
||||
*
|
||||
* This is the second function used by a TLS client for ECDH(E)
|
||||
* ciphersuites.
|
||||
*
|
||||
* \see ecp.h
|
||||
*
|
||||
* \param ctx The ECDH context.
|
||||
* \param olen The number of Bytes written.
|
||||
* \param buf The destination buffer.
|
||||
* \param blen The size of the destination buffer.
|
||||
* \param f_rng The RNG function.
|
||||
* \param p_rng The RNG context.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_everest_make_public( mbedtls_ecdh_context_everest *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int( *f_rng )( void *, unsigned char *, size_t ),
|
||||
void *p_rng );
|
||||
|
||||
/**
|
||||
* \brief This function parses and processes a TLS ClientKeyExchange
|
||||
* payload.
|
||||
*
|
||||
* This is the third function used by a TLS server for ECDH(E)
|
||||
* ciphersuites. (It is called after mbedtls_ecdh_setup() and
|
||||
* mbedtls_ecdh_make_params().)
|
||||
*
|
||||
* \see ecp.h
|
||||
*
|
||||
* \param ctx The ECDH context.
|
||||
* \param buf The start of the input buffer.
|
||||
* \param blen The length of the input buffer.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_everest_read_public( mbedtls_ecdh_context_everest *ctx,
|
||||
const unsigned char *buf, size_t blen );
|
||||
|
||||
/**
|
||||
* \brief This function derives and exports the shared secret.
|
||||
*
|
||||
* This is the last function used by both TLS client
|
||||
* and servers.
|
||||
*
|
||||
* \note If \p f_rng is not NULL, it is used to implement
|
||||
* countermeasures against side-channel attacks.
|
||||
* For more information, see mbedtls_ecp_mul().
|
||||
*
|
||||
* \see ecp.h
|
||||
*
|
||||
* \param ctx The ECDH context.
|
||||
* \param olen The number of Bytes written.
|
||||
* \param buf The destination buffer.
|
||||
* \param blen The length of the destination buffer.
|
||||
* \param f_rng The RNG function.
|
||||
* \param p_rng The RNG context.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_everest_calc_secret( mbedtls_ecdh_context_everest *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int( *f_rng )( void *, unsigned char *, size_t ),
|
||||
void *p_rng );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_EVEREST_H */
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2018 INRIA and Microsoft Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of Mbed TLS (https://tls.mbed.org) and
|
||||
* originated from Project Everest (https://project-everest.github.io/)
|
||||
*/
|
||||
|
||||
#ifndef __KREMLIB_H
|
||||
#define __KREMLIB_H
|
||||
|
||||
#include "kremlin/internal/target.h"
|
||||
#include "kremlin/internal/types.h"
|
||||
#include "kremlin/c_endianness.h"
|
||||
|
||||
#endif /* __KREMLIB_H */
|
||||
@@ -1,124 +0,0 @@
|
||||
/* Copyright (c) INRIA and Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache 2.0 License. */
|
||||
|
||||
/* This file was generated by KreMLin <https://github.com/FStarLang/kremlin>
|
||||
* KreMLin invocation: ../krml -fc89 -fparentheses -fno-shadow -header /mnt/e/everest/verify/hdrB9w -minimal -fparentheses -fcurly-braces -fno-shadow -header copyright-header.txt -minimal -tmpdir dist/uint128 -skip-compilation -extract-uints -add-include <inttypes.h> -add-include <stdbool.h> -add-include "kremlin/internal/types.h" -bundle FStar.UInt128=* extracted/prims.krml extracted/FStar_Pervasives_Native.krml extracted/FStar_Pervasives.krml extracted/FStar_Mul.krml extracted/FStar_Squash.krml extracted/FStar_Classical.krml extracted/FStar_StrongExcludedMiddle.krml extracted/FStar_FunctionalExtensionality.krml extracted/FStar_List_Tot_Base.krml extracted/FStar_List_Tot_Properties.krml extracted/FStar_List_Tot.krml extracted/FStar_Seq_Base.krml extracted/FStar_Seq_Properties.krml extracted/FStar_Seq.krml extracted/FStar_Math_Lib.krml extracted/FStar_Math_Lemmas.krml extracted/FStar_BitVector.krml extracted/FStar_UInt.krml extracted/FStar_UInt32.krml extracted/FStar_Int.krml extracted/FStar_Int16.krml extracted/FStar_Preorder.krml extracted/FStar_Ghost.krml extracted/FStar_ErasedLogic.krml extracted/FStar_UInt64.krml extracted/FStar_Set.krml extracted/FStar_PropositionalExtensionality.krml extracted/FStar_PredicateExtensionality.krml extracted/FStar_TSet.krml extracted/FStar_Monotonic_Heap.krml extracted/FStar_Heap.krml extracted/FStar_Map.krml extracted/FStar_Monotonic_HyperHeap.krml extracted/FStar_Monotonic_HyperStack.krml extracted/FStar_HyperStack.krml extracted/FStar_Monotonic_Witnessed.krml extracted/FStar_HyperStack_ST.krml extracted/FStar_HyperStack_All.krml extracted/FStar_Date.krml extracted/FStar_Universe.krml extracted/FStar_GSet.krml extracted/FStar_ModifiesGen.krml extracted/LowStar_Monotonic_Buffer.krml extracted/LowStar_Buffer.krml extracted/Spec_Loops.krml extracted/LowStar_BufferOps.krml extracted/C_Loops.krml extracted/FStar_UInt8.krml extracted/FStar_Kremlin_Endianness.krml extracted/FStar_UInt63.krml extracted/FStar_Exn.krml extracted/FStar_ST.krml extracted/FStar_All.krml extracted/FStar_Dyn.krml extracted/FStar_Int63.krml extracted/FStar_Int64.krml extracted/FStar_Int32.krml extracted/FStar_Int8.krml extracted/FStar_UInt16.krml extracted/FStar_Int_Cast.krml extracted/FStar_UInt128.krml extracted/C_Endianness.krml extracted/FStar_List.krml extracted/FStar_Float.krml extracted/FStar_IO.krml extracted/C.krml extracted/FStar_Char.krml extracted/FStar_String.krml extracted/LowStar_Modifies.krml extracted/C_String.krml extracted/FStar_Bytes.krml extracted/FStar_HyperStack_IO.krml extracted/C_Failure.krml extracted/TestLib.krml extracted/FStar_Int_Cast_Full.krml
|
||||
* F* version: 059db0c8
|
||||
* KreMLin version: 916c37ac
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __FStar_UInt128_H
|
||||
#define __FStar_UInt128_H
|
||||
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include "kremlin/internal/types.h"
|
||||
|
||||
uint64_t FStar_UInt128___proj__Mkuint128__item__low(FStar_UInt128_uint128 projectee);
|
||||
|
||||
uint64_t FStar_UInt128___proj__Mkuint128__item__high(FStar_UInt128_uint128 projectee);
|
||||
|
||||
typedef FStar_UInt128_uint128 FStar_UInt128_t;
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_add(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128
|
||||
FStar_UInt128_add_underspec(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_add_mod(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_sub(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128
|
||||
FStar_UInt128_sub_underspec(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_sub_mod(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_logand(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_logxor(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_logor(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_lognot(FStar_UInt128_uint128 a);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_shift_left(FStar_UInt128_uint128 a, uint32_t s);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_shift_right(FStar_UInt128_uint128 a, uint32_t s);
|
||||
|
||||
bool FStar_UInt128_eq(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
bool FStar_UInt128_gt(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
bool FStar_UInt128_lt(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
bool FStar_UInt128_gte(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
bool FStar_UInt128_lte(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_eq_mask(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_gte_mask(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_uint64_to_uint128(uint64_t a);
|
||||
|
||||
uint64_t FStar_UInt128_uint128_to_uint64(FStar_UInt128_uint128 a);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Plus_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Plus_Question_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Plus_Percent_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Subtraction_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Subtraction_Question_Hat)(
|
||||
FStar_UInt128_uint128 x0,
|
||||
FStar_UInt128_uint128 x1
|
||||
);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Subtraction_Percent_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Amp_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Hat_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Bar_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Less_Less_Hat)(FStar_UInt128_uint128 x0, uint32_t x1);
|
||||
|
||||
extern FStar_UInt128_uint128
|
||||
(*FStar_UInt128_op_Greater_Greater_Hat)(FStar_UInt128_uint128 x0, uint32_t x1);
|
||||
|
||||
extern bool (*FStar_UInt128_op_Equals_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern bool
|
||||
(*FStar_UInt128_op_Greater_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern bool (*FStar_UInt128_op_Less_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern bool
|
||||
(*FStar_UInt128_op_Greater_Equals_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
extern bool
|
||||
(*FStar_UInt128_op_Less_Equals_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_mul32(uint64_t x, uint32_t y);
|
||||
|
||||
FStar_UInt128_uint128 FStar_UInt128_mul_wide(uint64_t x, uint64_t y);
|
||||
|
||||
#define __FStar_UInt128_H_DEFINED
|
||||
#endif
|
||||
@@ -1,280 +0,0 @@
|
||||
/* Copyright (c) INRIA and Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache 2.0 License. */
|
||||
|
||||
/* This file was generated by KreMLin <https://github.com/FStarLang/kremlin>
|
||||
* KreMLin invocation: ../krml -fc89 -fparentheses -fno-shadow -header /mnt/e/everest/verify/hdrB9w -minimal -fparentheses -fcurly-braces -fno-shadow -header copyright-header.txt -minimal -tmpdir dist/minimal -skip-compilation -extract-uints -add-include <inttypes.h> -add-include <stdbool.h> -add-include "kremlin/internal/compat.h" -add-include "kremlin/internal/types.h" -bundle FStar.UInt64+FStar.UInt32+FStar.UInt16+FStar.UInt8=* extracted/prims.krml extracted/FStar_Pervasives_Native.krml extracted/FStar_Pervasives.krml extracted/FStar_Mul.krml extracted/FStar_Squash.krml extracted/FStar_Classical.krml extracted/FStar_StrongExcludedMiddle.krml extracted/FStar_FunctionalExtensionality.krml extracted/FStar_List_Tot_Base.krml extracted/FStar_List_Tot_Properties.krml extracted/FStar_List_Tot.krml extracted/FStar_Seq_Base.krml extracted/FStar_Seq_Properties.krml extracted/FStar_Seq.krml extracted/FStar_Math_Lib.krml extracted/FStar_Math_Lemmas.krml extracted/FStar_BitVector.krml extracted/FStar_UInt.krml extracted/FStar_UInt32.krml extracted/FStar_Int.krml extracted/FStar_Int16.krml extracted/FStar_Preorder.krml extracted/FStar_Ghost.krml extracted/FStar_ErasedLogic.krml extracted/FStar_UInt64.krml extracted/FStar_Set.krml extracted/FStar_PropositionalExtensionality.krml extracted/FStar_PredicateExtensionality.krml extracted/FStar_TSet.krml extracted/FStar_Monotonic_Heap.krml extracted/FStar_Heap.krml extracted/FStar_Map.krml extracted/FStar_Monotonic_HyperHeap.krml extracted/FStar_Monotonic_HyperStack.krml extracted/FStar_HyperStack.krml extracted/FStar_Monotonic_Witnessed.krml extracted/FStar_HyperStack_ST.krml extracted/FStar_HyperStack_All.krml extracted/FStar_Date.krml extracted/FStar_Universe.krml extracted/FStar_GSet.krml extracted/FStar_ModifiesGen.krml extracted/LowStar_Monotonic_Buffer.krml extracted/LowStar_Buffer.krml extracted/Spec_Loops.krml extracted/LowStar_BufferOps.krml extracted/C_Loops.krml extracted/FStar_UInt8.krml extracted/FStar_Kremlin_Endianness.krml extracted/FStar_UInt63.krml extracted/FStar_Exn.krml extracted/FStar_ST.krml extracted/FStar_All.krml extracted/FStar_Dyn.krml extracted/FStar_Int63.krml extracted/FStar_Int64.krml extracted/FStar_Int32.krml extracted/FStar_Int8.krml extracted/FStar_UInt16.krml extracted/FStar_Int_Cast.krml extracted/FStar_UInt128.krml extracted/C_Endianness.krml extracted/FStar_List.krml extracted/FStar_Float.krml extracted/FStar_IO.krml extracted/C.krml extracted/FStar_Char.krml extracted/FStar_String.krml extracted/LowStar_Modifies.krml extracted/C_String.krml extracted/FStar_Bytes.krml extracted/FStar_HyperStack_IO.krml extracted/C_Failure.krml extracted/TestLib.krml extracted/FStar_Int_Cast_Full.krml
|
||||
* F* version: 059db0c8
|
||||
* KreMLin version: 916c37ac
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __FStar_UInt64_FStar_UInt32_FStar_UInt16_FStar_UInt8_H
|
||||
#define __FStar_UInt64_FStar_UInt32_FStar_UInt16_FStar_UInt8_H
|
||||
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include "kremlin/internal/compat.h"
|
||||
#include "kremlin/internal/types.h"
|
||||
|
||||
extern Prims_int FStar_UInt64_n;
|
||||
|
||||
extern Prims_int FStar_UInt64_v(uint64_t x0);
|
||||
|
||||
extern uint64_t FStar_UInt64_uint_to_t(Prims_int x0);
|
||||
|
||||
extern uint64_t FStar_UInt64_add(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_add_underspec(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_add_mod(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_sub(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_sub_underspec(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_sub_mod(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_mul(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_mul_underspec(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_mul_mod(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_mul_div(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_div(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_rem(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_logand(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_logxor(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_logor(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_lognot(uint64_t x0);
|
||||
|
||||
extern uint64_t FStar_UInt64_shift_right(uint64_t x0, uint32_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_shift_left(uint64_t x0, uint32_t x1);
|
||||
|
||||
extern bool FStar_UInt64_eq(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern bool FStar_UInt64_gt(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern bool FStar_UInt64_gte(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern bool FStar_UInt64_lt(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern bool FStar_UInt64_lte(uint64_t x0, uint64_t x1);
|
||||
|
||||
extern uint64_t FStar_UInt64_minus(uint64_t x0);
|
||||
|
||||
extern uint32_t FStar_UInt64_n_minus_one;
|
||||
|
||||
uint64_t FStar_UInt64_eq_mask(uint64_t a, uint64_t b);
|
||||
|
||||
uint64_t FStar_UInt64_gte_mask(uint64_t a, uint64_t b);
|
||||
|
||||
extern Prims_string FStar_UInt64_to_string(uint64_t x0);
|
||||
|
||||
extern uint64_t FStar_UInt64_of_string(Prims_string x0);
|
||||
|
||||
extern Prims_int FStar_UInt32_n;
|
||||
|
||||
extern Prims_int FStar_UInt32_v(uint32_t x0);
|
||||
|
||||
extern uint32_t FStar_UInt32_uint_to_t(Prims_int x0);
|
||||
|
||||
extern uint32_t FStar_UInt32_add(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_add_underspec(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_add_mod(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_sub(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_sub_underspec(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_sub_mod(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_mul(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_mul_underspec(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_mul_mod(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_mul_div(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_div(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_rem(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_logand(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_logxor(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_logor(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_lognot(uint32_t x0);
|
||||
|
||||
extern uint32_t FStar_UInt32_shift_right(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_shift_left(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern bool FStar_UInt32_eq(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern bool FStar_UInt32_gt(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern bool FStar_UInt32_gte(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern bool FStar_UInt32_lt(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern bool FStar_UInt32_lte(uint32_t x0, uint32_t x1);
|
||||
|
||||
extern uint32_t FStar_UInt32_minus(uint32_t x0);
|
||||
|
||||
extern uint32_t FStar_UInt32_n_minus_one;
|
||||
|
||||
uint32_t FStar_UInt32_eq_mask(uint32_t a, uint32_t b);
|
||||
|
||||
uint32_t FStar_UInt32_gte_mask(uint32_t a, uint32_t b);
|
||||
|
||||
extern Prims_string FStar_UInt32_to_string(uint32_t x0);
|
||||
|
||||
extern uint32_t FStar_UInt32_of_string(Prims_string x0);
|
||||
|
||||
extern Prims_int FStar_UInt16_n;
|
||||
|
||||
extern Prims_int FStar_UInt16_v(uint16_t x0);
|
||||
|
||||
extern uint16_t FStar_UInt16_uint_to_t(Prims_int x0);
|
||||
|
||||
extern uint16_t FStar_UInt16_add(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_add_underspec(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_add_mod(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_sub(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_sub_underspec(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_sub_mod(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_mul(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_mul_underspec(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_mul_mod(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_mul_div(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_div(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_rem(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_logand(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_logxor(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_logor(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_lognot(uint16_t x0);
|
||||
|
||||
extern uint16_t FStar_UInt16_shift_right(uint16_t x0, uint32_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_shift_left(uint16_t x0, uint32_t x1);
|
||||
|
||||
extern bool FStar_UInt16_eq(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern bool FStar_UInt16_gt(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern bool FStar_UInt16_gte(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern bool FStar_UInt16_lt(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern bool FStar_UInt16_lte(uint16_t x0, uint16_t x1);
|
||||
|
||||
extern uint16_t FStar_UInt16_minus(uint16_t x0);
|
||||
|
||||
extern uint32_t FStar_UInt16_n_minus_one;
|
||||
|
||||
uint16_t FStar_UInt16_eq_mask(uint16_t a, uint16_t b);
|
||||
|
||||
uint16_t FStar_UInt16_gte_mask(uint16_t a, uint16_t b);
|
||||
|
||||
extern Prims_string FStar_UInt16_to_string(uint16_t x0);
|
||||
|
||||
extern uint16_t FStar_UInt16_of_string(Prims_string x0);
|
||||
|
||||
extern Prims_int FStar_UInt8_n;
|
||||
|
||||
extern Prims_int FStar_UInt8_v(uint8_t x0);
|
||||
|
||||
extern uint8_t FStar_UInt8_uint_to_t(Prims_int x0);
|
||||
|
||||
extern uint8_t FStar_UInt8_add(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_add_underspec(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_add_mod(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_sub(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_sub_underspec(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_sub_mod(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_mul(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_mul_underspec(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_mul_mod(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_mul_div(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_div(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_rem(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_logand(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_logxor(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_logor(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_lognot(uint8_t x0);
|
||||
|
||||
extern uint8_t FStar_UInt8_shift_right(uint8_t x0, uint32_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_shift_left(uint8_t x0, uint32_t x1);
|
||||
|
||||
extern bool FStar_UInt8_eq(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern bool FStar_UInt8_gt(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern bool FStar_UInt8_gte(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern bool FStar_UInt8_lt(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern bool FStar_UInt8_lte(uint8_t x0, uint8_t x1);
|
||||
|
||||
extern uint8_t FStar_UInt8_minus(uint8_t x0);
|
||||
|
||||
extern uint32_t FStar_UInt8_n_minus_one;
|
||||
|
||||
uint8_t FStar_UInt8_eq_mask(uint8_t a, uint8_t b);
|
||||
|
||||
uint8_t FStar_UInt8_gte_mask(uint8_t a, uint8_t b);
|
||||
|
||||
extern Prims_string FStar_UInt8_to_string(uint8_t x0);
|
||||
|
||||
extern uint8_t FStar_UInt8_of_string(Prims_string x0);
|
||||
|
||||
typedef uint8_t FStar_UInt8_byte;
|
||||
|
||||
#define __FStar_UInt64_FStar_UInt32_FStar_UInt16_FStar_UInt8_H_DEFINED
|
||||
#endif
|
||||