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

M115 does not work on serial/USB #31

Closed
beikeland opened this issue Jul 21, 2019 · 11 comments
Closed

M115 does not work on serial/USB #31

beikeland opened this issue Jul 21, 2019 · 11 comments

Comments

@beikeland
Copy link

Wanted to grab the FW version from M115 off the serial, but when sending M115 the response is Emulation of unknown is not yet supported. M115 works as expected in Web UI.

@beikeland
Copy link
Author

beikeland commented Jul 22, 2019

FYI, I just wanted to make it easier and more consistent to report what version is being tested against, and to rule out human error in the process. Came up with a workaround based off the currently loaded firmware binary

if of interest:

pi@duet3:~ $ ./versions.sh
duetcontrolserver=1.0.2.1
duetruntime=1.0.2.1
duetsd=1.0.1
duetsoftwareframework=1.0.2.1
duettools=1.0.2.1
duetwebcontrol=2.0.0-2
duetwebserver=1.0.1.1
duet3firmware=3.0b6-ch@2019-07-21b1
pi@duet3:~ $ cat versions.sh
#!/bin/bash
PORT=/dev/ttyACM0
URL=http://localhost/machine/code
FW=Duet3Firmware.bin
FWPATH=/opt/dsf/
if [ -c $PORT ]; then
  stty -F $PORT 57600 raw -echo    #configure serial port
  exec 3<$PORT                     #redirect serial output to fd 3
    cat <&3 > /tmp/ttyDump.dat &   #redirect serial output to file
    PID=$!                         #save pid to kill cat
      echo "M115" > $PORT          #send command string to serial port
      sleep 0.5s                   #wait for response
    kill -PIPE $PID                      #kill cat process
  exec 3<&-                        #free fd 3
  FWVER=`/bin/grep FIRMWARE_VERSION: /tmp/ttyDump.dat | /usr/bin/cut -d' ' -f8`
  FWDATE=`/bin/grep FIRMWARE_VERSION: /tmp/ttyDump.dat | /usr/bin/cut -d' ' -f15`
  FWMETHOD=serial
  rm /tmp/ttyDump.dat
fi
[ -z $FWVER ] && FWMETHOD=http
[ -z $FWVER ] && FWDATE=`/usr/bin/wget -qO- --post-data='M115' --header='Content-Type:text/plain' "$URL" | /usr/bin/cut -d' ' -f15`
[ -z $FWVER ] && FWVER=`/usr/bin/wget -qO- --post-data='M115' --header='Content-Type:text/plain' "$URL" | /usr/bin/cut -d' ' -f8`
[ -z $FWVER ] && FWMETHOD=binary
[ -z $FWVER ] && FWDATE=`/usr/bin/strings $FWPATH$FW | /bin/grep FIRMWARE_DATE -B1 | /usr/bin/head -n1`
[ -z $FWVER ] && FWVER=`/usr/bin/strings $FWPATH$FW | /bin/grep version= | /usr/bin/cut -d= -f2`
SWVER=`apt list 2>/dev/null | /bin/grep duet | awk -F'[/ ]' '{print $1"="$3}'`
echo $SWVER | /usr/bin/tr ' ' '\n'
echo "duet3_firmware=$FWVER@$FWDATE"
echo "(firmware version from $FWMETHOD)"



@wilriker
Copy link
Contributor

@beikeland Nice idea. But I think when fetching the FIRMWARE_DATE you wanted to use grep -B1 FIRMWARE_DATE (mind the capital B). This will also relief you from using awk and everything that follows. :-)

@beikeland
Copy link
Author

beikeland commented Jul 22, 2019

True story!

Thanks, edited the post above to reflect your input. But parsing M115 would be less error prone, although my pi downloads and flashes any updates at boot, so if the file is at that location it is the one running on the duet. Think maybe it should try serial, http and fall back to the binary file if serial or http doesn't work.

Runs this on boot, but it takes forever as it depletes the /dev/urandom entropy or something
https://gist.github.com/beikeland/70aa86308fd84adf3a58e6f057b51249

@wilriker
Copy link
Contributor

Also here is a version that runs on Arch Linux

#!/usr/bin/env bash

pacman -Qs duet | grep "local/" | sed 's#local/##g' | tr ' ' =

FW=/opt/dsf/sd/sys/Duet3Firmware.bin
FWVERSION=$(strings "${FW}" | grep "version=" | cut -d= -f2)
FWDATE=$(strings "${FW}" | grep -B1 "FIRMWARE_DATE" | head -1)
echo "duet3firmware=${FWVERSION}@${FWDATE}"

I also removed awk in my version completely (I just don't like it) and I am pointing to the firmware file that was uploaded through DWC most recently.

@wilriker
Copy link
Contributor

wilriker commented Jul 22, 2019

If you are running a regular RPi you should look into setting up rngd to use the hardware RNG that is on-board.

/usr/bin/rngd -f -o /dev/random -r /dev/hwrng

EDIT: just being a wise-guy here: /dev/urandom cannot be depleted. If it runs out of real random data it will just use a very weak but fast RNG to fill it up. But everything that relies on security will avoid /dev/urandom and use /dev/random instead which is guaranteed to have always good random data - but it can be depleted. haveged helps on machine not having a hardware RNG and for those with one (like RPi) rngd can be used.

@beikeland
Copy link
Author

The good thing about wise-guys is that it makes us non-wise guys less non-wise ;)

Seriously, thanks for sharing!

Did away with an awk as well, when all you have in your toolbox is a hammer, the scews feel the pain..

@beikeland
Copy link
Author

Since this is already waay off topic; simply installing rng-tools seems to have sorted the entropy deficiency on the pi, and its swiftly updated on boot flashing and notifying me as needed. Yay!

Beats me why the rng-tools package isn't installed by default, but thats a topic for another place, thanks again!

@beikeland
Copy link
Author

Still slightly unrelated to the actual issue, but think the serial and http part is sorted, should increase the odds of reporting the actual running firmware version

@wilriker
Copy link
Contributor

Took me a while to get at actually testing the initial issue and I cannot reproduce it:

$ miniterm.py --echo /dev/ttyACM0 115200
--- Miniterm on /dev/ttyACM0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
M115
FIRMWARE_NAME: RepRapFirmware for Duet 3 v0.5 FIRMWARE_VERSION: 3.0b6-ch ELECTRONICS: Duet 3 prototype v0.5 FIRMWARE_DATE: 2019-07-21b1

@chrishamm
Copy link
Contributor

I think this has been fixed in a recent RRFv3 version. There was an error concerning emulation.

@beikeland
Copy link
Author

Confirmed; works as of duet3_firmware=3.0b7-ch@2019-08-07b2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants