You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

98 lines
4.0 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. SYSTEM_MEMORY=$(free -m | awk '/^Mem:/{print $2}')
  12. if [ "$SYSTEM_MEMORY" -lt 2000 ]; then
  13. log "The system doesn't have enough space to store a Meteor pass on RAM" "INFO"
  14. RAMFS_AUDIO="${METEOR_OUTPUT}"
  15. fi
  16. if [ "$FLIP_METEOR_IMG" == "true" ]; then
  17. log "I'll flip this image pass because FLIP_METEOR_IMG is set to true" "INFO"
  18. FLIP="-rotate 180"
  19. else
  20. FLIP=""
  21. fi
  22. ## pass start timestamp and sun elevation
  23. PASS_START=$(expr "$5" + 90)
  24. SUN_ELEV=$(python3 "$NOAA_HOME"/sun.py "$PASS_START")
  25. if pgrep "rtl_fm" > /dev/null
  26. then
  27. log "There is an already running rtl_fm instance but I dont care for now, I prefer this pass" "INFO"
  28. pkill -9 -f rtl_fm
  29. fi
  30. # $1 = Satellite Name
  31. # $2 = Frequency
  32. # $3 = FileName base
  33. # $4 = TLE File
  34. # $5 = EPOC start time
  35. # $6 = Time to capture
  36. # $7 = Satellite max elevation
  37. log "Starting rtl_fm record" "INFO"
  38. timeout "${6}" /usr/local/bin/rtl_fm ${BIAS_TEE} -p $PPM_ERROR -M raw -f "${2}"M -s 144k $GAIN | sox -t raw -r 144k -c 2 -b 16 -e s - -t wav "${RAMFS_AUDIO}/audio/${3}.wav" #rate 96k
  39. log "Demodulation in progress (QPSK)" "INFO"
  40. [ $1 = "METEOR-M2 2"] && demod_extra="-m opsk"
  41. meteor_demod $demod_extra -B -o "${METEOR_OUTPUT}/${3}.qpsk" "${RAMFS_AUDIO}/audio/${3}.wav"
  42. if [ "$DELETE_AUDIO" = true ]; then
  43. log "Deleting audio files" "INFO"
  44. rm "${RAMFS_AUDIO}/audio/${3}.wav"
  45. else
  46. log "Moving audio files out to the SD card" "INFO"
  47. mv "${RAMFS_AUDIO}/audio/${3}.wav" "${NOAA_OUTPUT}/audio/${3}.wav"
  48. rm "${METEOR_OUTPUT}/audio/${3}.wav"
  49. rm "${RAMFS_AUDIO}/audio/${3}.wav"
  50. fi
  51. log "Decoding in progress (QPSK to BMP)" "INFO"
  52. [ $1 = "METEOR-M2 2"] && medet_extra="-diff"
  53. medet_arm $medet_extra "${METEOR_OUTPUT}/${3}.qpsk" "${METEOR_OUTPUT}/${3}" -cd
  54. rm "${METEOR_OUTPUT}/${3}.qpsk"
  55. if [ -f "${METEOR_OUTPUT}/${3}.dec" ]; then
  56. if [ "${SUN_ELEV}" -lt "${SUN_MIN_ELEV}" ]; then
  57. log "I got a successful ${3}.dec file. Decoding APID 68" "INFO"
  58. medet_arm "${METEOR_OUTPUT}/${3}.dec" "${NOAA_OUTPUT}/images/${3}-122" -r 68 -g 68 -b 68 -d
  59. /usr/bin/convert $FLIP -negate "${NOAA_OUTPUT}/images/${3}-122.bmp" "${NOAA_OUTPUT}/images/${3}-122.bmp"
  60. else
  61. log "I got a successful ${3}.dec file. Creating false color image" "INFO"
  62. medet_arm "${METEOR_OUTPUT}/${3}.dec" "${NOAA_OUTPUT}/images/${3}-122" -r 65 -g 65 -b 64 -d
  63. fi
  64. log "Rectifying image to adjust aspect ratio" "INFO"
  65. python3 "${NOAA_HOME}/rectify.py" "${NOAA_OUTPUT}/images/${3}-122.bmp"
  66. convert "${NOAA_OUTPUT}/images/${3}-122-rectified.jpg" -channel rgb -normalize -undercolor black -fill yellow -pointsize 60 -annotate +20+60 "${1} ${START_DATE} Elev: $7°" "${NOAA_OUTPUT}/images/${3}-122-rectified.jpg"
  67. /usr/bin/convert -thumbnail 300 "${NOAA_OUTPUT}/images/${3}-122-rectified.jpg" "${NOAA_OUTPUT}/images/thumb/${3}-122-rectified.jpg"
  68. rm "${NOAA_OUTPUT}/images/${3}-122.bmp"
  69. rm "${METEOR_OUTPUT}/${3}.bmp"
  70. rm "${METEOR_OUTPUT}/${3}.dec"
  71. sqlite3 $HOME/raspberry-noaa/panel.db "insert into decoded_passes (pass_start, file_path, daylight_pass, sat_type) values ($5,\"$3\", 1,0);"
  72. pass_id=$(sqlite3 $HOME/raspberry-noaa/panel.db "select id from decoded_passes order by id desc limit 1;")
  73. if [ -n "$CONSUMER_KEY" ]; then
  74. log "Posting to Twitter" "INFO"
  75. python3 "${NOAA_HOME}/post.py" "$1 ${START_DATE} Resolución completa: https://weather.reyni.co/detail.php?id=$pass_id" "$7" "${NOAA_OUTPUT}/images/${3}-122-rectified.jpg"
  76. fi
  77. else
  78. log "Decoding failed, either a bad pass/low SNR or a software problem" "ERROR"
  79. fi
  80. 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);"