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.
 
 
 
 
 
 

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