Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

93 rader
4.2 KiB

  1. #!/bin/bash
  2. ### Run as a normal user
  3. if [ $EUID -eq 0 ]; then
  4. echo "This script shouldn't be run as root."
  5. exit 1
  6. fi
  7. ## import common lib
  8. . "$HOME/.noaa.conf"
  9. . "$HOME/.tweepy.conf"
  10. . "$NOAA_HOME/common.sh"
  11. ## pass start timestamp and sun elevation
  12. PASS_START=$(expr "$5" + 90)
  13. SUN_ELEV=$(python3 "$NOAA_HOME"/sun.py "$PASS_START")
  14. if pgrep "rtl_fm" > /dev/null
  15. then
  16. log "There is an existing rtl_fm instance running, I quit" "ERROR"
  17. exit 1
  18. fi
  19. # $1 = Satellite Name
  20. # $2 = Frequency
  21. # $3 = FileName base
  22. # $4 = TLE File
  23. # $5 = EPOC start time
  24. # $6 = Time to capture
  25. # $7 = Satellite max elevation
  26. pre_samplerate=60k
  27. log "Starting rtl_fm record for $1 at $2 to $3 at epoch $5" "INFO"
  28. log "timeout ${6} /usr/local/bin/rtl_fm ${BIAS_TEE} -f ${2}M -s$pre_samplerate $GAIN -p $PPM_ERROR -E wav -E deemp -F 0 - | /usr/bin/sox -t raw -e signed -c 1 -b 16 -r $pre_samplerate - ${RAMFS_AUDIO}/audio/${3}.wav rate 11025" DEBUG
  29. timeout "${6}" /usr/local/bin/rtl_fm ${BIAS_TEE} -f "${2}"M -s$pre_samplerate $GAIN -p $PPM_ERROR -E wav -E deemp -F 0 - | /usr/bin/sox -t raw -e signed -c 1 -b 16 -r $pre_samplerate - "${RAMFS_AUDIO}/audio/${3}.wav" rate 11025
  30. if [ "${SUN_ELEV}" -gt "${SUN_MIN_ELEV}" ]; then
  31. ENHANCEMENTS="ZA MCIR MCIR-precip MSA MSA-precip HVC-precip HVCT-precip HVC HVCT"
  32. daylight="true"
  33. else
  34. ENHANCEMENTS="ZA MCIR MCIR-precip"
  35. daylight="false"
  36. fi
  37. log "Bulding pass map wxtoimg" "INFO"
  38. /usr/local/bin/wxmap -T "${1}" -H "${4}" -p 0 -l 0 -o "${PASS_START}" "${NOAA_HOME}/map/${3}-map.png"
  39. for i in $ENHANCEMENTS; do
  40. log "Decoding image" "INFO"
  41. /usr/local/bin/wxtoimg -o -m "${NOAA_HOME}/map/${3}-map.png" -e "$i" "${RAMFS_AUDIO}/audio/${3}.wav" "${NOAA_OUTPUT}/images/${3}-$i.jpg"
  42. /usr/bin/convert -quality 98 -format jpg "${NOAA_OUTPUT}/images/${3}-$i.jpg" -undercolor black -fill yellow -pointsize 18 -annotate +20+20 "${1} $i ${START_DATE} Elev: $7°" "${NOAA_OUTPUT}/images/${3}-$i.jpg"
  43. /usr/bin/convert -thumbnail 300 "${NOAA_OUTPUT}/images/${3}-$i.jpg" "${NOAA_OUTPUT}/images/thumb/${3}-$i.jpg"
  44. done
  45. log "Building noaa-apt maps" DEBUG
  46. curpath=$(pwd) # needed for faulty noaa-apt arm version
  47. cd /usr/bin
  48. noaa-apt "${RAMFS_AUDIO}/audio/${3}.wav" -R auto -m yes -o "${NOAA_OUTPUT}/images/${3}-noaa-apt.png"
  49. cd $curpath
  50. /usr/bin/convert -quality 98 -format jpg "${NOAA_OUTPUT}/images/${3}-noaa-apt.png" -undercolor black -fill yellow -pointsize 18 -annotate +20+20 "${1} $i ${START_DATE} Elev: $7°" "${NOAA_OUTPUT}/images/${3}-noaa-apt.jpg"
  51. /usr/bin/convert -thumbnail 300 "${NOAA_OUTPUT}/images/${3}-noaa-apt.jpg" "${NOAA_OUTPUT}/images/thumb/${3}-noaa-apt.jpg"
  52. rm "${NOAA_OUTPUT}/images/${3}-noaa-apt.png"
  53. rm "${NOAA_HOME}/map/${3}-map.png"
  54. if [ "${SUN_ELEV}" -gt "${SUN_MIN_ELEV}" ]; then
  55. sqlite3 $HOME/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 1,1);"
  56. else
  57. sqlite3 $HOME/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 0,1);"
  58. fi
  59. pass_id=$(sqlite3 $HOME/raspberry-noaa/panel.db "select id from decoded_passes order by id desc limit 1;")
  60. if [ -n "$CONSUMER_KEY" ]; then
  61. log "Posting to Twitter" "INFO"
  62. if [ "${SUN_ELEV}" -gt "${SUN_MIN_ELEV}" ]; then
  63. python3 "${NOAA_HOME}/post.py" "$1 ${START_DATE} Mas imagenes: https://weather.reyni.co/detail.php?id=$pass_id" "$7" "${NOAA_OUTPUT}/images/$3-MCIR-precip.jpg" "${NOAA_OUTPUT}/images/$3-MSA-precip.jpg" "${NOAA_OUTPUT}/images/$3-HVC-precip.jpg" "${NOAA_OUTPUT}/images/$3-HVCT-precip.jpg"
  64. else
  65. python3 "${NOAA_HOME}/post.py" "$1 ${START_DATE} Mas imagenes: https://weather.reyni.co/detail.php?id=$pass_id" "$7" "${NOAA_OUTPUT}/images/$3-MCIR-precip.jpg" "${NOAA_OUTPUT}/images/$3-MCIR.jpg"
  66. fi
  67. fi
  68. sqlite3 $HOME/raspberry-noaa/panel.db "update predict_passes set is_active = 0 where (predict_passes.pass_start) in (select predict_passes.pass_start from predict_passes inner join decoded_passes on predict_passes.pass_start = decoded_passes.pass_start where decoded_passes.id = $pass_id);"
  69. if [ "$DELETE_AUDIO" = true ]; then
  70. log "Deleting audio files" "INFO"
  71. rm "${RAMFS_AUDIO}/audio/${3}.wav"
  72. else
  73. log "Moving audio files out to the SD card" "INFO"
  74. mv "${RAMFS_AUDIO}/audio/${3}.wav" "${NOAA_OUTPUT}/audio/${3}_${pre_samplerate}_${7}.wav"
  75. fi