HackRF Shell: FFT Averaging and Display Progress

I’m not quite sure I have all the bugs worked out yet, but I implemented simple averaging, as well and the frequency display. The latter required implementing fft-shift to move center frequency to the center. The above plot shows FM stations at 101.1, 102.5, 103.9, and 104.7 Mhz, matching local stations I know about.

These simple things took quite a while, mainly because of the busyness of other life responsibilities; but also because the process of implementation led to fixing some bugs, which led to cleaning up some code, which led to learning new things about Guile scheme and C.

In Guile scheme, I learned how to implement a procedure to auto-close unreachable ports:

(define ports-guardian #f)

(define (close-guarded-ports)
  (let f ()
    (let ((p (ports-guardian)))
      (when p (begin (close-port p) (f))))))

(define (initialize-ports-guardian)
  (when (not ports-guardian)
    (set! ports-guardian (make-guardian))
    (add-hook! after-gc-hook (lambda () (close-guarded-ports)))))

(initialize-ports-guardian)

(define (register-autoclose p) (ports-guardian p) p)

register-autoclose can simply be wrapped around the port, e.g.:

(define (hackrf-cb-rx-to-file filename)
  (hackrf-cb-rx-to-stream
   (register-autoclose (open-output-file filename))))

This uses Guile scheme “guardian” functionality, which is an object that can return registered objects if the have become unreachable everywhere else.

git clone git://git.librehacker.com/pub/git/hackrf-rkt.git

Advertisement

Curse of War Tips

Curse of War, an Ncurses-based strategy game. I am the green population.

http://a-nikolaev.github.io/curseofwar/

Here are a few tips, some of which you might not learn unless you inspect the source code:

  • Population on a hex can only grow to a maximum of 499, at which point growth slows to zero. So, a full hex might look good but actually has stopped producing.
  • Subject to the caveat above, your hex population growth is a percentage of population already on the hex.
  • Migration from deep territory to the front is a slow process.
  • Because of the above three factors, you generally want to place new villages and towns at locations that are neither too close nor too far from the front of war. If they are too close, the bonus growth effect will be operating on hexes that have only a few troops that are passing through on their way to the front. But too far away, and the bonus will be applied to hexes that are saturated and cannot produce more population anyway.
  • Battle outcomes are basically just a function of which player has more troops on the hex. So, you generally don’t want to push forward your war front that part of the front is mostly full of saturated (499 troop) or nearly-saturated tiles. Pushing forward effectively generally means putting flags directly in front of your current line of flags and then removing the old ones. Then wait until those new hexes become saturated.
  • If you realized you have pushed your front forward too quickly and are getting overcome, you can usually save the line by just pulling the front back a little.
  • You may want to play with the -i 0 option to ensure basically fair starting balance between players.
  • It usually makes more sense, mathematically, to build a new village, than to upgrade to a town or castle. This is due to cost vs. growth percentage increase. Towns or castles don’t give any kind of actual defensive bonus, just the growth increase.
  • If you have a good grasp of the battle, migration, and population growth mechanics, you basically know what you need to know to win most games against the AI. However, a tricky part in some games is knowing how to manipulate the other players against each other, so that they are attacking each other more instead of you. If you have a strong, non-moving set of fronts, generally you AI will attack the other players who have weaker fronts. However, this can back-fire if you allow one opponent to become stronger than you, after slurping up weaker enemies. It is a careful balancing act that requires you to intelligently focus your resource development and front movement.
  • At first it is tempting to focus exclusively on capturing mines, but your overall front movement and population growth is generally the more important thing to focus on. Of course, a front-movement strategy that will eventually get you three more mines, certainly has some points going for it.