Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channel number for method "start_charge" seems wrong #1

Closed
Madmaxor opened this issue Oct 25, 2023 · 2 comments
Closed

Channel number for method "start_charge" seems wrong #1

Madmaxor opened this issue Oct 25, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Madmaxor
Copy link

In my device Skyrc MC3000 (fw. 1.15 hw >=2.2) channel numbers are: 0,1,3,7 instead of 0,1,2,3

To Reproduce
If I use (Python 3.11):
await mc3000.start_charge(2)
no effect, and:
await mc3000.start_charge(3)
starts slot 2 on the charger.
If you try different slot numbers you have:
raise ValueError("Invalid channel")

Workaround
My workaround is to change mc3000.py from:

async def start_charge(self, channel: int) -> None:
"""Start charging the battery in the specified channel."""
if channel not in range(0, MC3000_CHANNEL_COUNT):
raise ValueError("Invalid channel")

to:

async def start_charge(self, channel: int) -> None:
"""Start charging the battery in the specified channel."""
if channel not in range(0, MC3000_CHANNEL_COUNT+10):
raise ValueError("Invalid channel")

and then I have all the 4 channels working, with index 0,1,3,7.

@Madmaxor Madmaxor added the bug Something isn't working label Oct 25, 2023
@Madmaxor
Copy link
Author

Madmaxor commented Oct 31, 2023

A more "clean" solution could be to modify the file skyrc-ble-main/src/skyrc_ble/mc3000.py this way:


--- mc3000.py	2023-01-26 15:48:44.000000000 +0100
+++ ../mc3000_fixed.py	2023-10-26 17:27:02.000000000 +0200
@@ -38,6 +38,7 @@
 STRUCT_GET_VERSION_INFO = Struct(">xxxxxxxxxxxxBBB")
 STRUCT_GET_BASIC_DATA = Struct(">B?B?BH")
 
+CHN_NUM=[0,1,3,7]
 
 class Mc3000(SkyRcDevice[Mc3000State]):
 
@@ -77,13 +78,13 @@
         """Start charging the battery in the specified channel."""
         if channel not in range(0, MC3000_CHANNEL_COUNT):
             raise ValueError("Invalid channel")
-        await self._send_packet(CMD_START_CHARGE, [channel + 1])
+       await self._send_packet(CMD_START_CHARGE, [CHN_NUM[channel] + 1])
 
     async def stop_charge(self, channel: int) -> None:
         """Stop charging the battery in the specified channel."""
         if channel not in range(0, MC3000_CHANNEL_COUNT):
             raise ValueError("Invalid channel")
-        await self._send_packet(CMD_STOP_CHARGE, [channel + 1])
+       await self._send_packet(CMD_STOP_CHARGE, [CHN_NUM[channel] + 1])
 
     async def _send_packet(self, command: int, payload: list[int] = []) -> None:
         """Send a packet to the device."""

@kroimon kroimon closed this as completed in a69fd52 Nov 8, 2023
@kroimon
Copy link
Owner

kroimon commented Nov 8, 2023

You are right, the channel index for the start and stop commands is a bit field, so the indexes are 1, 2, 4, and 8.
This could be used to start multiple channels at once (e.g. 6 would start channels 2 and 3, or 15 would start all channels).

Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants