|
6 | 6 |
|
7 | 7 | from reactivex import Observable, Observer
|
8 | 8 |
|
9 |
| -from . import calcCrc8, calcCrc16, is_delta, is_river |
| 9 | +from . import calcCrc8, calcCrc16, is_delta, is_river, is_river_mini |
10 | 10 |
|
11 | 11 |
|
12 | 12 | class Serial(TypedDict):
|
@@ -69,6 +69,8 @@ def _to_float(d: bytes) -> float:
|
69 | 69 | def _to_int(d: bytes):
|
70 | 70 | return int.from_bytes(d, "little")
|
71 | 71 |
|
| 72 | +def _to_hex_debug(d: bytes): |
| 73 | + return " ".join("0x{:02x}".format(x) for x in d) |
72 | 74 |
|
73 | 75 | def _to_int_ex(div: int = 1):
|
74 | 76 | def f(d: bytes):
|
@@ -299,8 +301,8 @@ def parse_inverter(d: bytes, product: int):
|
299 | 301 | return parse_inverter_delta(d)
|
300 | 302 | if is_river(product):
|
301 | 303 | return parse_inverter_river(d)
|
302 |
| - # if is_river_mini(product): |
303 |
| - # return parse_pd_river_mini(d) |
| 304 | + if is_river_mini(product): |
| 305 | + return parse_inverter_river_mini(d) |
304 | 306 | return {}
|
305 | 307 |
|
306 | 308 |
|
@@ -364,6 +366,43 @@ def parse_inverter_river(d: bytes):
|
364 | 366 | ("fan_config", 1, _to_int),
|
365 | 367 | ])
|
366 | 368 |
|
| 369 | +def parse_inverter_river_mini(d: bytes): |
| 370 | + return _parse_dict(d, [ |
| 371 | + ("ac_error", 4, _to_int), |
| 372 | + ("ac_version", 4, _to_ver_reversed), |
| 373 | + ("in_type", 1, _to_int), |
| 374 | + ("in_power", 2, _to_int), |
| 375 | + ("ac_out_power", 2, _to_int), |
| 376 | + ("ac_type", 1, _to_int), |
| 377 | + ("ac_out_voltage", 4, _to_int_ex(div=1000)), |
| 378 | + ("ac_out_current", 4, _to_int_ex(div=1000)), |
| 379 | + ("ac_out_freq", 1, _to_int), |
| 380 | + ("ac_in_voltage", 4, _to_int_ex(div=1000)), |
| 381 | + ("ac_in_current", 4, _to_int_ex(div=1000)), |
| 382 | + ("ac_in_freq", 1, _to_int), |
| 383 | + ("ac_out_temp", 1, _to_int), |
| 384 | + ("dc_in_voltage", 4, _to_int_ex(div=1000)), |
| 385 | + ("dc_in_current", 4, _to_int_ex(div=1000)), |
| 386 | + ("ac_in_temp", 1, _to_int), |
| 387 | + ("fan_state", 1, _to_int), |
| 388 | + ("ac_out_state", 1, _to_int), |
| 389 | + ("ac_out_xboost", 1, _to_int), |
| 390 | + ("ac_out_voltage_config", 4, _to_int_ex(div=1000)), |
| 391 | + ("ac_out_freq_config", 1, _to_int), |
| 392 | + ("ac_in_slow", 1, _to_int), |
| 393 | + ("battery_main_level", 1, _to_int), |
| 394 | + ("battery_main_voltage", 4, _to_int_ex(div=1000)), |
| 395 | + ("battery_current", 4, _to_int), |
| 396 | + ("battery_main_temp", 1, _to_int), |
| 397 | + ("_open_bms_idx", 1, _to_int), |
| 398 | + ("battery_capacity_remain", 4, _to_int), |
| 399 | + ("battery_capacity_full", 4, _to_int), |
| 400 | + ("battery_cycles", 4, _to_int), |
| 401 | + ("battery_level_max", 1, _to_int), |
| 402 | + ("battery_main_level_f32", 4, _to_float), |
| 403 | + ("ac_out_timeout", 2, _to_int), |
| 404 | + ]) |
| 405 | + |
367 | 406 |
|
368 | 407 | def parse_lcd_timeout(d: bytes):
|
369 | 408 | return int.from_bytes(d[1:3], "little")
|
@@ -412,8 +451,8 @@ def parse_pd(d: bytes, product: int):
|
412 | 451 | return parse_pd_delta(d)
|
413 | 452 | if is_river(product):
|
414 | 453 | return parse_pd_river(d)
|
415 |
| - # if is_river_mini(product): |
416 |
| - # return parse_pd_river_mini(d) |
| 454 | + if is_river_mini(product): |
| 455 | + return parse_pd_river_mini(d) |
417 | 456 | return {}
|
418 | 457 |
|
419 | 458 |
|
@@ -498,49 +537,47 @@ def parse_pd_river(d: bytes):
|
498 | 537 | ])
|
499 | 538 |
|
500 | 539 |
|
501 |
| -# def parse_pd_river_mini(d: bytes): |
502 |
| -# return _parse_dict(d, [ |
503 |
| -# ("model", 1, _to_int), |
504 |
| -# ("pd_error", 4, _to_int), |
505 |
| -# ("pd_version", 4, _to_ver_reversed), |
506 |
| -# ("wifi_version", 4, _to_ver_reversed), |
507 |
| -# ("wifi_autorecovery", 1,), |
508 |
| -# ("soc_sum", 1, _to_int), |
509 |
| -# ("watts_out_sum", 2, _to_int), |
510 |
| -# ("watts_in_sum", 2, _to_int), |
511 |
| -# ("remain_time", 4, _to_int), |
512 |
| -# ("beep", 1, _to_int), |
513 |
| -# ("dc_out", 1, _to_int), |
514 |
| -# ("usb1_watts", 1, _to_int), |
515 |
| -# ("usb2_watts", 1, _to_int), |
516 |
| -# ("usbqc1_watts", 1, _to_int), |
517 |
| -# ("usbqc2_watts", 1, _to_int), |
518 |
| -# ("typec1_watts", 1, _to_int), |
519 |
| -# ("typec2_watts", 1, _to_int), |
520 |
| -# ("typec1_temp", 1, _to_int), |
521 |
| -# ("typec2_temp", 1, _to_int), |
522 |
| -# ("dc_out_watts", 1, _to_int), |
523 |
| -# ("car_out_temp", 1, _to_int), |
524 |
| -# ("standby_timeout", 2, _to_int), |
525 |
| -# ("lcd_sec", 2, _to_int), |
526 |
| -# ("lcd_brightness", 1, _to_int), |
527 |
| -# ("chg_power_dc", 4, _to_int), |
528 |
| -# ("chg_power_mppt", 4, _to_int), |
529 |
| -# ("chg_power_ac", 4, _to_int), |
530 |
| -# ("dsg_power_dc", 4, _to_int), |
531 |
| -# ("dsg_power_ac", 4, _to_int), |
532 |
| -# ("usb_used_time", 4, _to_int), |
533 |
| -# ("usbqc_used_time", 4, _to_int), |
534 |
| -# ("typec_used_time", 4, _to_int), |
535 |
| -# ("dc_out_used_time", 4, _to_int), |
536 |
| -# ("ac_out_used_time", 4, _to_int), |
537 |
| -# ("dc_in_used_time", 4, _to_int), |
538 |
| -# ("mppt_used_time", 4, _to_int), |
539 |
| -# (None, 5, None), |
540 |
| -# ("sys_chg_flag", 1, _to_int), |
541 |
| -# ("wifi_rssi", 1, _to_int), |
542 |
| -# ("wifi_watts", 1, _to_int), |
543 |
| -# ]) |
| 540 | +def parse_pd_river_mini(d: bytes): |
| 541 | + return _parse_dict(d, [ |
| 542 | + ("model", 1, _to_int), |
| 543 | + ("pd_error", 4, _to_int), |
| 544 | + ("pd_version", 4, _to_ver_reversed), |
| 545 | + ("wifi_version", 4, _to_ver_reversed), |
| 546 | + ("wifi_autorecovery", 1, _to_int), |
| 547 | + ("battery_level", 1, _to_int), |
| 548 | + ("out_power", 2, _to_int), |
| 549 | + ("in_power", 2, _to_int), |
| 550 | + ("remain_display", 4, _to_timedelta_min), |
| 551 | + ("beep", 1, _to_int), |
| 552 | + ("usb_out1_state", 1, _to_int), |
| 553 | + ("usb_out1_power", 1, _to_int), |
| 554 | + ("usb2_watts", 1, _to_int), |
| 555 | + ("usbqc1_watts", 1, _to_int), |
| 556 | + ("usbqc2_watts", 1, _to_int), |
| 557 | + ("typec1_watts", 1, _to_int), |
| 558 | + ("typec2_watts", 1, _to_int), |
| 559 | + ("typec1_temp", 1, _to_int), |
| 560 | + ("typec2_temp", 1, _to_int), |
| 561 | + ("car_out_state", 1, _to_int), |
| 562 | + ("car_out_power", 1, _to_int), |
| 563 | + ("car_out_temp", 1, _to_int), |
| 564 | + ("standby_timeout", 1, _to_int), |
| 565 | + ("unknown_1", 1, _to_hex_debug), |
| 566 | + ("lcd_timeout", 2, _to_int), |
| 567 | + ("lcd_brightness", 1, _to_int), |
| 568 | + ("car_in_energy", 4, _to_int), |
| 569 | + ("mppt_in_energy", 4, _to_int), |
| 570 | + ("ac_in_energy", 4, _to_int), |
| 571 | + ("dc_out_energy", 4, _to_int), |
| 572 | + ("ac_out_energy", 4, _to_int), |
| 573 | + ("usb_time", 4, _to_timedelta_sec), |
| 574 | + ("unknown_2", 8, _to_hex_debug), |
| 575 | + ("car_out_time", 4, _to_timedelta_sec), |
| 576 | + ("ac_out_time", 4, _to_timedelta_sec), |
| 577 | + ("car_in_time", 4, _to_timedelta_sec), |
| 578 | + ("mppt_time", 4, _to_timedelta_sec), |
| 579 | + ("unknown_3", 30, _to_hex_debug), |
| 580 | + ]) |
544 | 581 |
|
545 | 582 |
|
546 | 583 | def parse_serial(d: bytes) -> Serial:
|
|
0 commit comments