0

I have a script which does hexdump along with pipeline commands and finally I am redirecting it to a file. Now I am logging data from the serial port of my Raspberry Pi. I also call a python script(display time in milliseconds) from the shell script. I takes like 5 minutes for me to see the data on screen after I run the command.

            timeout 2s ./ExpHmax
            while :
            do
            sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | awk '$1=="ed" {
            getline byte1
            getline byte2
            number = strtonum("0x" substr(byte2,2,1))+2
            "./Time.py" |& getline timestamp;
            data = ":: "timestamp " ::ED." byte1"."byte2
            while(number-->0)
            {getline byte; data = data"."byte}
            print data"."
            }' |  tr '[a-z]' '[A-Z]'| grep -v '^.....................00' >      Thur.log
            done

Can anyone suggest me a way to do this script without doing the pipe. I guess that's causing the delay. Here is my Python script

   import time
   millis = int(round(time.time() * 1000))
   print millis
4
  • 1
    We can't judge if it's too slow without knowing exactly how much raw binary data is being copied from /dev/ttyUSB0, and we might need the respective speeds of the USB ports (i.e. the RaspPi and the system running the script).
    – agc
    May 2, 2016 at 0:57
  • have you benchmarked it without the pipes? My guess is that you're seeing buffers fill up on the pipes; look for the stdbuf command on the site for example usage.
    – Jeff Schaller
    May 2, 2016 at 2:10
  • No I haven't tried that! Can you suggest me how to do that ?
    – RajuBhai
    May 2, 2016 at 2:24
  • Why are we voting to close a shell scripting question?? May 2, 2016 at 7:27

1 Answer 1

0

You could start by not instantiating Python on every matching byte (!):

#!/usr/bin/awk -f
function de() {
  getline < "/proc/uptime"
  close("/proc/uptime")
  return $0
}
BEGIN {
  ec = de()
}
$0 == "ed" {
  getline byte1
  getline byte2
  number = strtonum("0x" substr(byte2, 2, 1)) + 2
  data = ":: " de() - ec " ::ED." byte1 "." byte2
  while (number--) {
    getline byte
    data = data "." byte
  }
  print data "."
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.