Coder Social home page Coder Social logo

gpdaniels / spike-prime Goto Github PK

View Code? Open in Web Editor NEW
278.0 27.0 36.0 16.12 MB

Experiments with the LEGO Mindstorms (51515) and SPIKE Prime (45678)

License: MIT License

Python 82.67% CMake 3.74% TypeScript 7.81% Shell 0.57% Java 5.21%
spike-prime firmware lego mindstorms python 51515 45678 bluetooth

spike-prime's Introduction

Mindstorms / SPIKE Prime / SPIKE Essential

This repository is a collection of useful information about the Lego Mindstorms Robot Inventor (51515), Lego SPIKE Prime (45678) and Lego SPIKE Essential (45345). Mindstorms Robot Inventor Logo SPIKE Prime Logo

Hardware

Large Hub Hardware

This applies to both the SPIKE Prime and Mindstorms Robot Inventor large hubs.

          Part Description                               
CPU STM32F413 (Architecture: ARM Cortex M4, ROM: 1M, RAM: 320k, Clock: 100MHz).
Internal storage 32MB flash memory (IC: Winbond W25Q256JV).
Wireless connectivity Bluetooth supporting 1 BT and 4 BLE connections (IC: TI CC2564C).
Wired connectivity Micro USB cable.
Display 25 white LEDs in a 5x5 grid and 1 RGB LED (Driver IC: TI TLC5955).
Motor Drivers 6 motor outputs (Driver ICs: 3 x LB1836).
Battery Management Lithium ion battery management (IC: MPS 2639A).
Accerometer Three-axis accelerometer (IC: LSM6DS3TR).
Gyroscope Three-axis gyroscope (IC: LSM6DS3TR).
Ports 6 LPF2 ports = 4 normal speed (115kB), 2 high speed (?kB).

Small Hub Hardware

This applies to the SPIKE Essential small hub.

          Part Description                               
CPU ?
Internal storage ?
Wireless connectivity Bluetooth supporting 1 BT and 4 BLE connections (IC: ?).
Wired connectivity Micro USB cable.
Display 1 RGB LED (Driver IC: ?).
Motor Drivers 2 motor outputs (Driver ICs: 1 x ?).
Battery Management Lithium ion battery management (IC: ?).
Accerometer Three-axis accelerometer (IC: LSM6DS3TR).
Gyroscope Three-axis gyroscope (IC: LSM6DS3TR).
Ports 2 LPF2 ports = 2 normal speed (115kB).

Connecting to a hub

To connect to the hub you have two options, a micro USB cable or bluetooth. Both options create a serial connection between the hub and the computer. At the hub end of this serial connection is a micropython REPL (Read Evaluate Print Loop). You can use this REPL to run python commands just like you would in the python interpreter on your computer.

To connect on Linux you will normall use:

  • /dev/ttyACM0 for USB connections.
  • /dev/rfcomm0 for bluetooth connections.

Note: If you press and hold the left button then press the center button to power up the hub, it will startup bypassing the runtime on the hub.

I have found bluetooth on linux to be not that reliable and often have to follow this process:

bluetoothctl
> remove [ADDRESS]
> scan on
> connect [ADDRESS]
> pair [ADDRESS]
> trust [ADDRESS]

Then I can use rfcomm to create the bluetooth serial port /dev/rfcomm0:

sudo rfcomm connect hci0 [ADDRESS]

Directory Content

Controller

An attempt to create an application that can communicate with a hub to allow for remote control / sending of scripts / sensor logging without needing any of the LEGO apps.

Decompiler

This is a disassembler/decompiler that uses the mpy-tool from the micropython repository to disassemble mpy files from the hub filesystem.

Filesystem

Dumps of the micropython filesystem on the Lego hub using rshell.

# Install the rshell program if you do not already have it.
# pip3 install rshell

# Add udev rules for the hubs, and restart udev.
# cp ./filesystem/99-lego.rules /etc/udev/rules.d/99-lego.rules

rshell
> connect serial /dev/ttyACM0 115200
> rsync -a /pyboard ~/filesystem

Long version numbers are from running the help(hub) command on the board. Short versions numbers are from the version.py files where available.

SPIKE Prime

         Dump Description                               
v0.5.01.0000-42a938e Initial filesystem (Purchased on: 28/05/2020) (Box Version: 29).
v1.0.00.0027-64837e9 Additional filesystem in 1.0.0 on Windows (Extracted from app.asar).
v1.0.00.0030-b228d30 Filesystem from 1.0.0 on Windows (Extracted from app.asar).
v1.0.00.0033-268c151 Filesystem from 1.1.4 on Windows (Extracted from app.asar).
v1.0.03.0034-c3879ab Updated filesystem using 1.2.0 on Windows(Updated on: 02/07/2020).
v1.0.06.0034-b0c335b Updated filesystem using 1.2.1 on Windows (Updated on: 17/07/2020).
v1.1.01.0000-6b4a939 Updated filesystem using 1.3.0 on Windows (Updated on: 01/09/2020).
v1.1.01.0000-6b4a939 Updated filesystem using 1.3.1 on Windows (Updated on: 20/10/2020).
v1.1.01.0002-3e5a121 Updated filesystem using 1.3.2 on Windows (Updated on: 03/11/2020).
v1.1.01.0002-3e5a121 Updated filesystem using 1.3.3 on Windows (Updated on: 18/12/2020).
v1.1.01.0002-3e5a121 Updated filesystem using 1.3.4 on Windows (Updated on: 17/03/2021).
v1.2.01.0101-edc1be7 Updated filesystem using 2.0.0 on Windows (Updated on: 25/08/2021).
v1.2.01.0101-edc1be7 Updated filesystem using 2.0.1 on Windows (Updated on: 25/08/2021) [UNCHANGED].
v1.3.00.0000-e8c274a Updated filesystem using 2.0.3 / 2.0.4 on Windows (Updated on: 03/11/2021).
v1.3.00.0000-e8c274a Updated filesystem using 2.0.5 on Windows (Updated on: 09/05/2022) [UNCHANGED].
v1.3.00.0000-e8c274a Updated filesystem using 2.0.6 on Windows (Updated on: 09/05/2022) [UNCHANGED].
v1.3.00.0000-e8c274a Updated filesystem using 2.0.7 on Windows (Updated on: ??/??/????) [UNCHANGED].
v1.3.00.0000-e8c274a Updated filesystem using 2.0.8 on Windows (Updated on: ??/??/????) [UNCHANGED].
vX.X.XX.XXXX-XXXXXXX Updated filesystem using 3.3.1 on Windows (Updated on: 03/08/2023).

SPIKE Essential

         Dump Description                               
v1.0.00.0070-51a2ff4 Initial filesystem (Purchased on: 27/09/2021) (Box Version: 143).

Mindstorms Robot Inventor

         Dump Description                               
v0.5.01.0002-f75d82d Initial filesystem (Purchased on: 16/10/2020).
v1.0.06.0034-b0c335b Updated filesystem using 4.0.4-dev.99999 on Windows (Updated on: 20/10/2020).
v1.0.06.0034-b0c335b Updated filesystem using 10.0.3 on Android (Updated on: 29/11/2020).
v1.2.01.0103-d08b6fe Updated filesystem using 10.1.0 on Android (Updated on: 05/05/2021).
v1.3.00.0203-71f6a41 Updated filesystem using 10.2.0 on Android (Updated on: 19/08/2021).
v1.4.01.0000-594ce3d Updated filesystem using 10.3.0 on Android (Updated on: 13/12/2021).
v1.4.02.0000-f7a19ce Updated filesystem using 10.4.0 on Android (Updated on: 05/08/2022).

Firmware

Dumps of the firmware on the Lego hub using the micropython REPL.

The lines below will output a number of bytes of the firmware starting at the provided location, or false if past the end.

import firmware
firmware.flash_read(BYTE_NUMBER)

The first versions of the firmware on the device do not have the firmware library. To dump these you have to use the DFU tool after booting the device into DFU mode.

To boot the device into DFU mode:

  1. Turn the hub off and disconnect the USB wire from your computer.
  2. Hold down the bluetooth button and plug in the USB wire to your computer.
  3. Keep holding the bluetooth button until it starts flashing in a cycle (pink-green-blue-off).
  4. The hub is now in DFU mode.
  5. The dfu-util program can be used to extract the firmware, see the script below.
# Install the dfu-util program if you do not already have it.
# sudo apt-get install dfu-util

# List the connected devices, this should show the hub is connected.
sudo dfu-util --list

# Read the firmware.
sudo dfu-util --alt 0 --dfuse-address 0x08000000:1048576 --upload ~/firmware.bin

# Take ownership of the file created by the dfu-util program.
sudo chown $(whoami) ~/firmware.bin

# Remove the first 0x8000 bytes, as these are before the firmware starts.
fallocate -c -o 0 -l 32768 ~/firmware.bin

# Remove the trailing bytes that have the value 0xFF, as these are unnecessary.
sed -i '$ s/\xFF*$//' ~/firmware.bin

# Rename the firmware to the md5 hash of itself.
mv ~/firmware.bin ~/$(md5sum ~/firmware.bin | awk '{ print $1 }').bin

Long version numbers are from running the help(hub) command on the board. Short versions numbers are from the version.py files where available.

SPIKE Prime

         Dump Description                               
v0.5.01.0000-42a938e MISSING Initial firmware (Purchased on: 28/05/2020) (Box Version: 29).
v1.0.00.0027-64837e9 MISSING Additional firmware in 1.0.0 on Windows (Extracted from app.asar).
v1.0.00.0030-b228d30 Firmware from 1.0.0 on Windows (Extracted from app.asar).
v1.0.00.0033-268c151 Firmware from 1.1.4 on Windows (Extracted from app.asar).
v1.0.03.0034-c3879ab Updated firmware using 1.2.0 on Windows (Updated on: 02/07/2020).
v1.0.06.0034-b0c335b Updated firmware using 1.2.1 on Windows (Updated on: 17/07/2020).
v1.1.01.0000-6b4a939 Updated firmware using 1.3.0 on Windows (Updated on: 01/09/2020).
v1.1.01.0000-6b4a939 Updated firmware using 1.3.1 on windows (Updated on: 20/10/2020) [UNCHANGED].
v1.1.01.0002-3e5a121 Updated firmware using 1.3.2 on Windows (Updated on: 03/11/2020).
v1.1.01.0002-3e5a121 Updated firmware using 1.3.3 on windows (Updated on: 18/12/2020) [UNCHANGED].
v1.1.01.0002-3e5a121 Updated firmware using 1.3.4 on Windows (Updated on: 17/03/2021) [UNCHANGED].
v1.2.01.0101-edc1be7 Updated firmware using 2.0.0 on Windows (Updated on: 25/08/2021).
v1.2.01.0101-edc1be7 Updated firmware using 2.0.1 on Windows (Updated on: 25/08/2021) [UNCHANGED].
v1.3.00.0000-e8c274a Updated firmware using 2.0.3 / 2.0.4 on Windows (Updated on: 03/11/2021).
v1.3.00.0000-e8c274a Updated firmware using 2.0.5 on Windows (Updated on: 09/05/2022) [UNCHANGED].
v1.3.00.0000-e8c274a Updated firmware using 2.0.6 on Windows (Updated on: 09/05/2022) [UNCHANGED].
v1.3.00.0000-e8c274a Updated firmware using 2.0.7 on Windows (Updated on: ??/??/????) [UNCHANGED].
v1.3.00.0000-e8c274a Updated firmware using 2.0.8 on Windows (Updated on: ??/??/????) [UNCHANGED].
vX.X.XX.XXXX-XXXXXXX Updated firmware using 3.3.1 on Windows (Updated on: 03/08/2023).

SPIKE Essential

         Dump Description                               
v1.0.00.0070-51a2ff4 MISSING Initial firmware (Purchased on: 27/09/2021) (Box Version: 143).

Mindstorms Robot Inventor

         Dump Description                               
v0.5.01.0002-f75d82d Initial firmware (Purchased on: 16/10/2020).
v1.0.06.0034-b0c335b Updated firmware using 4.0.4-dev.99999 on Windows (Updated on: 20/10/2020).
v1.0.06.0034-b0c335b Updated firmware using 10.0.3 on Android (Updated on: 29/11/2020) [UNCHANGED].
v1.2.01.0103-d08b6fe Updated firmware using 10.1.0 on Android (Updated on: 05/05/2021).
v1.3.00.0203-71f6a41 Updated firmware using 10.2.0 on Android (Updated on: 19/08/2021).
v1.4.01.0000-594ce3d Updated firmware using 10.3.0 on Android (Updated on: 13/12/2021).
v1.4.02.0000-f7a19ce Updated firmware using 10.4.0 on Android (Updated on: 05/08/2022).

Simulator

A recreation of the spike prime hardware using python to allow testing and debugging python scripts on a PC.

The aim is to create a script to dump the functions of the real hardware and then mock them to allow local development.

Currently there is two main scripts one to simulate running micropython scripts on a hub and one to push micropython scripts to a real connected hub. The simulator uses a mocked implementation of the micropython modules available on the phyical hub that redirect actions to the simulator gui.

          File Description                                
simulator.py A python3 gui based simulator for the Lego hub.
run.py A python3 script to run a micropython script on a connected Lego hub.
upload.py A python3 script to upload a micropython script to a connected Lego hub.

Specifications

Specification pdfs for internal parts of the Lego components.

          File Description                                
stm32f413 The microprocessor inside the hub.

SPIKE Prime and Mindstorms Robot Inventor

          File Description                                
large-hub The main SPIKE Prime hub.
large-hub-rechargeable-battery Rechargeable lithium ion battery pack for the hub, capacity 2100 mAH.
medium-angular-motor Medium motor with integrated absolute orientation sensor, accuracy +- 3 degrees.
large-angular-motor Large motor with integrated absolute orientation sensor, accuracy +- 3 degrees.
force-sensor Measures touch, tap, and force up to 10N (About 1Kg) at an accuracy of 0.65N.
distance-sensor Measures depth to 2m (fast to 30cm) with 1mm resolution. Has 4 white LED outputs.
color-sensor Measures 8 colours, reflectivity, and ambient light. Has 3 white LED outputs.

SPIKE Essential

          File Description                                
small-hub The smaller SPIKE Essential hub.
small-hub-rechargeable-battery Rechargeable lithium ion battery pack for the hub, capacity 620 mAH.
small-angular-motor Small motor with integrated absolute orientation sensor, accuracy +- 3 degrees.
color-light-matrix 3x3 RGB Light matrix with individual segment control.
color-sensor Measures 8 colours, reflectivity, and ambient light. Has 3 white LED outputs.

License

Where documents, code, graphics, binary or any other files have been created by me they are licensed under the MIT license. Other files that have been pulled from the firmware or filesystem of LEGO products remain licensed by LEGO.

The MIT License

Copyright (c) 2020 Geoffrey Daniels. http://gpdaniels.com/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .

spike-prime's People

Contributors

cscovino avatar gpdaniels avatar markbush avatar pitust avatar python273 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spike-prime's Issues

STM32 chip

Do you have the complete product code of the STM32F413 chip used for the Spike Hub?
STM32F413?? ?
Have you also a picture of the main board?

Missing initial firmware for new SPIKE Prime Hub (v0.5.01.0000-42a938e)

If you have a brand new SPIKE Prime hub running the below script will allow you to copy the firmware from the device.
This requires a linux machine (I used ubuntu 18.04)

# Install the dfu-util program if you do no already have it.
# sudo apt-get install dfu-util

# List the connected devices, this should show the hub is connected.
sudo dfu-util --list

# Read the firmware.
sudo dfu-util --alt 0 --dfuse-address 0x08000000:1048576 --upload ~/firmware.bin

# Take ownership of the file created by the dfu-util program.
sudo chown $(whoami) ~/firmware.bin

# Remove the first 0x8000 bytes, as these are before the firmware starts.
fallocate -c -o 0 -l 32768 ~/firmware.bin

# Remove the trailing bytes that have the value 0xFF, as these are unnecessary.
sed -i '$ s/\xFF*$//' ~/firmware.bin

# Rename the firmware to the md5 hash of itself.
mv ~/firmware.bin ~/$(md5sum ~/firmware.bin | awk '{ print $1 }').bin

I foolishly updated my hub before ripping the firmware.

Add upload script?

Hey I just found this repo, and it seems like you've been doing really amazing work.

I've been working on writing an upload script that works on Linux.
I documented the effort in an issue on this other repo I found that was documenting the hub internals:
azzieg/mindstorms-inventor#2

I've just successfully uploaded my first program:
https://gist.github.com/pepijndevos/9d55dd4b53f630186545fa6361fc229a

Feel free to integrate this code in any way you like.

Are you aware of where the AFOL Mindstorms community hangs out? Would be great to share info as we learn more.

Factory reset via hardware?

I made the mistake of updating the firmware using the new SPIKE 3 software ... now I can't run my Python scripts, AND I can't reprogram back to the previous firmware! Yikes! Is there any way to revert to a previous firmware using a hardware reset?

Decompiler output expectations?

When I execute the decompile the decompiled .py files contain less than expected code. Many of the files when I decompile them result in .py files containing output similar to the following event_loop.py where the file has imports, a declaration, then return none.

import utimeq
import collections
EventLoop = __build_class__(0, "EventLoop")
return None

Other files have lines like the following

$push(3)
BROKEN_OP`eq`
BROKEN_OP`btrue 147`
$push(hasattr(hub, "display"))

I was expecting to see more information like class, methods, variables, conditional statements, loops, etc.

Is the decompiler working as expected with the output I am getting?

Dump the `hub` module

I theorycrafted a way to dump the contents of the built-in hub module to hopefully be able to implement a full-featured open-source firmware for the LEGO SPIKE Hub.
Here is how it works (on paper):

# The hub module
import hub
# For memory access
import machine
module_ptr = id(hub)
# module->globals.map.table[0]
name_ptr = machine.mem32[machine.mem32[machine.mem32[module_ptr + 4] + 12] + 0 * 8]
data_ptr = machine.mem32[machine.mem32[machine.mem32[module_ptr + 4] + 12] + 0 * 8 + 4]
def read_str(ptr):
    len = machine.mem32[ptr + 8]
    addr = machine.mem32[ptr + 12]
    return bytes_at(addr, len).decode()
print(read_str(name_ptr))

Can you still write uncompiled programs?

Is it still possible to write uncompiled .py files like in the 1.0 firmware?
I'd like to write a program in micro-python and I want it to be launchable from the default menu. (Adding a program-picture etc.)

[Question] Flash firmware to Spike Prime

Is there a way that I can flash firmware on the LEGO Spike Prime over serial communication? The idea is to update the firmware without the LEGO desktop app.
And the next question would be how I can get the updated firmware.

Connecting to Hub Failed! Opening COM8: File not found

Hello, First of all, thank you so much for this great plugin. I am trying to connect lego minestrone inventor with this plugin via VS code. Unfortunately, I am getting this Connecting to Hub Failed! Opening COM8: File not found.

Can you please look into this issue?

image

Add special hub boot routines to docs.

  I found the following in my notes (it has been a while), but it would be good if someone wants to confirm:
  • Hold left during boot: Do not mount file system, so skip executing boot.py and main.py.
  • Hold right during boot: Mount file system, run boot.py but skip main.py.
  • Hold left + right: Mount, but then reset the file system, creating a new boot.py and main.py.

I don't know if left+right will work if the file system is already corrupted. If it's the same as the Pyboard reset then it should probably work.

And if not, you should still be able to hold only left, and then use the REPL to reset the filesystem instead.

Originally posted by @laurensvalk in #41 (reply in thread)

Add official api docs

Python lego mindstorms has some official docs. Could they be added here? (just pull them out of the apk)

Please add latest Spike Prime firmware

The new firmware is supposed to have some significant changes at MicroPython level.

I only have the Robot Inventor hub, but the Spike app 3.0 won't update it. I've heard the Spike firmware does run on Robot Inventor.

ls /pyboard with rshell fails

Hi everyone,
I have a problem with rshell. Though I do know that you most certainly won't be able to solve it, I am hoping you might have an idea who I could contact to solve this, as you seem far more experienced hacking around with mindstorms.

I just got the new mindstorms and started poking around with it. I have no experience with micropython and read about rshell here for the first time.
Unfortunately I have a pretty fundamental problem. Whenever I try to list the /pyboard directory using rshell, an error is thrown, as the result cannot be parsed. It seems like the result from the helper functions print is incomplete and the beginning is missing.
I already noticed this behavior a couple of days before when I was just using screen to connect to the mindstorms and started printing the content of files out of curiosity whats going on on the mindstorms: In my helper functions I had to read the files line by line and use separate print commands for each line to get the complete file content. Otherwise I had the same behavior that I was just seeing the end of the files. It seems like the mindstorms print command has some hiccups, too small buffer, I don't know..
Do you have any idea who to contact to somehow solve this?

In case you are interested, this is how the debug output of rshell looks like

/Users/mschulte> ls /pyboard/
Executing "ls /pyboard/"
----- About to send 634 bytes of code to the pyboard -----
def stat(filename):
    """Returns os.stat for a given file, adjusting the timestamps as appropriate."""
    import os
    try:
        # on the host, lstat won't try to follow symlinks
        rstat = os.lstat(filename)
    except:
        rstat = os.stat(filename)
    return rstat[:7] + tuple(tim + 946681200 for tim in rstat[7:])


def get_stat(filename):
    """Returns the stat array for a given file. Returns all 0's if the file
       doesn't exist.
    """
    try:
        return stat(filename)
    except OSError:
        return (0,) * 10
output = get_stat('/')
if output is None:
    print("None")
else:
    print(output)

-----
-----Response-----
b'(16384, 0, 0, 0, 0, 0, 0, 946681200, 946681200, 946681200)\r\n'
-----
----- About to send 1207 bytes of code to the pyboard -----
def is_visible(filename):
    """Determines if the file should be considered to be a non-hidden file."""
    return filename[0] != '.' and filename[-1] != '~'


def stat(filename):
    """Returns os.stat for a given file, adjusting the timestamps as appropriate."""
    import os
    try:
        # on the host, lstat won't try to follow symlinks
        rstat = os.lstat(filename)
    except:
        rstat = os.stat(filename)
    return rstat[:7] + tuple(tim + 946681200 for tim in rstat[7:])


def listdir_stat(dirname, show_hidden=True):
    """Returns a list of tuples for each file contained in the named
       directory, or None if the directory does not exist. Each tuple
       contains the filename, followed by the tuple returned by
       calling os.stat on the filename.
    """
    import os
    try:
        files = os.listdir(dirname)
    except OSError:
        return None
    if dirname == '/':
        return list((file, stat('/' + file)) for file in files if is_visible(file) or show_hidden)
    return list((file, stat(dirname + '/' + file)) for file in files if is_visible(file) or show_hidden)
output = listdir_stat('/')
if output is None:
    print("None")
else:
    print(output)

-----
-----Response-----
b"00, 946681200)), ('sounds', (16384, 0, 0, 0, 0, 0, 0, 946681200, 946681200, 946681200)), ('spike', (16384, 0, 0, 0, 0, 0, 0, 946681200, 946681200, 946681200)), ('ui', (16384, 0, 0, 0, 0, 0, 0, 946681200, 946681200, 946681200)), ('hub_runtime.mpy', (32768, 0, 0, 0, 0, 0, 2015, 946681200, 946681200, 946681200)), ('version.py', (32768, 0, 0, 0, 0, 0, 54, 946681200, 946681200, 946681200)), ('.runtime_hash', (32768, 0, 0, 0, 0, 0, 953, 946681200, 946681200, 946681200)), ('extra_files', (16384, 0, 0, 0, 0, 0, 0, 946681200, 946681200, 946681200)), ('.extra_files_hash', (32768, 0, 0, 0, 0, 0, 539, 946681200, 946681200, 946681200))]\r\n"
-----
Traceback (most recent call last):
  File "/usr/local/bin/rshell", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/rshell/command_line.py", line 4, in main
    rshell.main.main()
  File "/usr/local/lib/python3.9/site-packages/rshell/main.py", line 2966, in main
    real_main()
  File "/usr/local/lib/python3.9/site-packages/rshell/main.py", line 2949, in real_main
    shell.cmdloop(cmd_line)
  File "/usr/local/lib/python3.9/site-packages/rshell/main.py", line 1755, in cmdloop
    cmd.Cmd.cmdloop(self)
  File "/usr/local/Cellar/[email protected]/3.9.1_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/cmd.py", line 138, in cmdloop
    stop = self.onecmd(line)
  File "/usr/local/lib/python3.9/site-packages/rshell/main.py", line 1785, in onecmd
    self.onecmd_exec("".join(group))
  File "/usr/local/lib/python3.9/site-packages/rshell/main.py", line 1796, in onecmd_exec
    return cmd.Cmd.onecmd(self, line)
  File "/usr/local/Cellar/[email protected]/3.9.1_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/cmd.py", line 217, in onecmd
    return func(arg)
  File "/usr/local/lib/python3.9/site-packages/rshell/main.py", line 2423, in do_ls
    ldir_stat = auto(listdir_stat, filename)
  File "/usr/local/lib/python3.9/site-packages/rshell/main.py", line 588, in auto
    return dev.remote_eval(func, dev_filename, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/rshell/main.py", line 1515, in remote_eval
    return eval(self.remote(func, *args, **kwargs))
  File "<string>", line 1
    00, 946681200)), ('sounds', (16384, 0, 0, 0, 0, 0, 0, 946681200, 946681200, 946681200)), ('spike', (16384, 0, 0, 0, 0, 0, 0, 946681200, 946681200, 946681200)), ('ui', (16384, 0, 0, 0, 0, 0, 0, 946681200, 946681200, 946681200)), ('hub_runtime.mpy', (32768, 0, 0, 0, 0, 0, 2015, 946681200, 946681200, 946681200)), ('version.py', (32768, 0, 0, 0, 0, 0, 54, 946681200, 946681200, 946681200)), ('.runtime_hash', (32768, 0, 0, 0, 0, 0, 953, 946681200, 946681200, 946681200)), ('extra_files', (16384, 0, 0, 0, 0, 0, 0, 946681200, 946681200, 946681200)), ('.extra_files_hash', (32768, 0, 0, 0, 0, 0, 539, 946681200, 946681200, 946681200))]
                 ^
SyntaxError: unmatched ')'

Decompiled .mpy files

Hi!

I've been working on understanding Spike Prime Hub internals as well.
Were you able to decompile the .mpy files or reverse engineer the ujson protocol?

Create images of each sensor and motor module

Known sensors

  • Large angular motor
  • Medium angular motor
  • Colour sensor
  • Depth sensor
  • Force sensor

Will need tiles for the motors, colour sensor, and depth sensor as they are outputs.

The decompiler does not handle all operations

Current issues:

  • Some operations are not handled correctly by the disassembler.
  • Not all required information (for decompilation) is output by the disassembler.
  • The decompiler doesn't handle all operations.

Problems with decompiler: container.sh

Hi, I'm having a problem with the container.sh script that I didn't have before and a friend of mine is encountering the same problem. In the past the script used to work correctly but now it looks like is having some problems while initializing the builda.

image

Generate a hub API from a dump.

Using the dump-api.py script from the simulator it's possible to get what I hope is all the functions available on the hub (along with lots of other information)

What is needed:

  • See if it possible to determine all the built in modules, help("modules") prints to stdout, but on the hub this cannot be redirected because the micropython version is too old.
  • Extract recursively hub modules/classes/functions/variables.
  • Search the hub filesystem for any further modules/classes/functions.
  • Determine the arguments to all these modules/classes/functions (I think the mpy tool might be able to help with some).
  • Extract the values of all variables discovered.
  • Generate stub (or filled if possible) modules/classes/functions/variables for all functions on the hub.
  • Link remaining functions to the simulator virtual hub API.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.