first commit

This commit is contained in:
Aleksey
2026-02-13 22:52:33 +03:00
commit 24e419b955
8 changed files with 1058 additions and 0 deletions

Binary file not shown.

Binary file not shown.

86
dps150/packets/base.py Normal file
View File

@@ -0,0 +1,86 @@
from construct import (
Byte,
Bytes,
Float32l,
Struct,
Computed,
this,
GreedyBytes,
)
# Base packet structure
# Format: [header, cmd, type, length, data..., checksum]
packet = Struct(
"header" / Byte,
"cmd" / Byte,
"type" / Byte,
"length" / Byte,
"data" / Bytes(this.length),
"checksum" / Byte,
"checksum_valid" / Computed(
lambda ctx: (ctx.type + ctx.length + sum(ctx.data)) % 0x100 == ctx.checksum
),
)
# Data structures for different response types
float_response = Struct(
"value" / Float32l,
)
float3_response = Struct(
"value1" / Float32l,
"value2" / Float32l,
"value3" / Float32l,
)
byte_response = Struct(
"value" / Byte,
)
# All data structure (type 255)
all_data = Struct(
"inputVoltage" / Float32l, # 0-4
"setVoltage" / Float32l, # 4-8
"setCurrent" / Float32l, # 8-12
"outputVoltage" / Float32l, # 12-16
"outputCurrent" / Float32l, # 16-20
"outputPower" / Float32l, # 20-24
"temperature" / Float32l, # 24-28
"group1setVoltage" / Float32l, # 28-32
"group1setCurrent" / Float32l, # 32-36
"group2setVoltage" / Float32l, # 36-40
"group2setCurrent" / Float32l, # 40-44
"group3setVoltage" / Float32l, # 44-48
"group3setCurrent" / Float32l, # 48-52
"group4setVoltage" / Float32l, # 52-56
"group4setCurrent" / Float32l, # 56-60
"group5setVoltage" / Float32l, # 60-64
"group5setCurrent" / Float32l, # 64-68
"group6setVoltage" / Float32l, # 68-72
"group6setCurrent" / Float32l, # 72-76
"overVoltageProtection" / Float32l, # 76-80
"overCurrentProtection" / Float32l, # 80-84
"overPowerProtection" / Float32l, # 84-88
"overTemperatureProtection" / Float32l, # 88-92
"lowVoltageProtection" / Float32l, # 92-96
"brightness" / Byte, # 96
"volume" / Byte, # 97
"metering" / Byte, # 98
"outputCapacity" / Float32l, # 99-103
"outputEnergy" / Float32l, # 103-107
"outputClosedRaw" / Byte, # 107
"protectionStateRaw" / Byte, # 108
"modeRaw" / Byte, # 109
"unknown1" / Byte, # 110
"upperLimitVoltage" / Float32l, # 111-115
"upperLimitCurrent" / Float32l, # 115-119
"unknownVoltage" / Float32l, # 119-123
"unknownCurrent" / Float32l, # 123-127
"unknown2" / Float32l, # 127-131
"unknown3" / Float32l, # 131-135
"unknown4" / Float32l, # 135-139
"extra" / GreedyBytes, # Any extra data
"meteringClosed" / Computed(lambda ctx: ctx.metering == 0),
"outputClosed" / Computed(lambda ctx: ctx.outputClosedRaw == 1),
)

52
dps150/packets/cmd.py Normal file
View File

@@ -0,0 +1,52 @@
HEADER_OUT = 241
HEADER_IN = 240
CMD_GET = 161
CMD_BAUD = 176
CMD_SET = 177
CMD_SESSION = 193
# float
VOLTAGE_SET = 193
CURRENT_SET = 194
GROUP1_VOLTAGE_SET = 197
GROUP1_CURRENT_SET = 198
GROUP2_VOLTAGE_SET = 199
GROUP2_CURRENT_SET = 200
GROUP3_VOLTAGE_SET = 201
GROUP3_CURRENT_SET = 202
GROUP4_VOLTAGE_SET = 203
GROUP4_CURRENT_SET = 204
GROUP5_VOLTAGE_SET = 205
GROUP5_CURRENT_SET = 206
GROUP6_VOLTAGE_SET = 207
GROUP6_CURRENT_SET = 208
OVP = 209
OCP = 210
OPP = 211
OTP = 212
LVP = 213
METERING_ENABLE = 216
OUTPUT_ENABLE = 219
# byte
BRIGHTNESS = 214
VOLUME = 215
MODEL_NAME = 222
HARDWARE_VERSION = 223
FIRMWARE_VERSION = 224
ALL = 255
PROTECTION_STATES = [
"",
"OVP",
"OCP",
"OPP",
"OTP",
"LVP",
"REP",
]