Skip to content

Instantly share code, notes, and snippets.

@kk7ds
Created January 31, 2017 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kk7ds/72afd27941233a263fbb3ce1d0b1576c to your computer and use it in GitHub Desktop.
Save kk7ds/72afd27941233a263fbb3ce1d0b1576c to your computer and use it in GitHub Desktop.
An emacs module for recording NTS traffic
;;
;; nts.el - Copyright 2009 Dan Smith KK7DS (dsmith at danplanet dot com)
;;
;; To use, place the following in ~/.emacs:
;;
;; (require 'nts)
;;
;; To instantiate a form, execute M-x nts-make-form RET
;;
;; The Validate, SENT, and RECV buttons will save the form in the Active
;; or Completed queues as appropriate.
;;
;; Version 10/8/2009
(setq nts-message-path (expand-file-name "~/NTS"))
(setq nts-active-queue "Active")
(setq nts-completed-queue "Completed")
(defun nts-count-message (message check)
"Count the number of words in message and make sure it's equal
to check. Return a status string"
(let ((copy (length (split-string message)))
(recv (string-to-number check)))
(if (= copy recv) "OK"
(if (< copy recv)
(concat "Missing " (number-to-string (- recv copy)) " word(s)")
(concat (number-to-string (- copy recv)) " extra words")))))
(defun nts-save ()
"Save the message, renaming to CALL_NUMBER.txt and placing in
the Active queue, if necessary"
(if (string= (buffer-name) "*NTS*")
(let ((fn (concat (widget-value nts-s-origin) "_"
(widget-value nts-number) ".txt")))
(rename-buffer fn)
(setq buffer-file-name (concat nts-message-path "/"
nts-active-queue "/" fn))))
(save-buffer))
(defun nts-completed ()
"Mark the message as completed by moving it into the Completed
queue"
(let ((old-fn buffer-file-name))
(setq buffer-file-name (concat nts-message-path "/"
nts-completed-queue "/"
(buffer-name)))
(save-buffer)
(delete-file old-fn)))
(defun nts-validate (widget &rest ignore)
"Validate the message by upcasing the header and verifying the
check. Also save the message in the active queue."
(dolist (widget (list nts-precedence nts-hx nts-s-origin))
(widget-value-set widget (upcase (widget-value widget))))
(let ((status (nts-count-message (widget-value nts-message)
(widget-value nts-check))))
(use-local-map widget-keymap)
(widget-setup)
(nts-save)
(message status)))
(defun nts-timestamp ()
"Return a timestamp for the received/sent fields"
(format-time-string "%m/%d/%Y %H%M"))
(defun nts-make-form ()
"Create an NTS form"
(interactive)
(switch-to-buffer "*NTS*")
(kill-all-local-variables)
(let ((inhibit-read-only t))
(erase-buffer))
(remove-overlays)
(make-local-variable 'nts-number)
(make-local-variable 'nts-precedence)
(make-local-variable 'nts-hx)
(make-local-variable 'nts-s-origin)
(make-local-variable 'nts-p-origin)
(make-local-variable 'nts-check)
(make-local-variable 'nts-date)
(make-local-variable 'nts-recip)
(make-local-variable 'nts-phone)
(make-local-variable 'nts-message)
(make-local-variable 'nts-signature)
(make-local-variable 'nts-recv)
(make-local-variable 'nts-sent)
(setq nts-number (widget-create 'editable-field
:size 1
:format "Num: %v "
""))
(setq nts-precedence (widget-create 'editable-field
:size 1
:format "Prec: %v "
""))
(setq nts-hx (widget-create 'editable-field
:size 1
:format "HX: %v "
""))
(setq nts-s-origin (widget-create 'editable-field
:size 1
:format "Station: %v "
""))
(setq nts-check (widget-create 'editable-field
:size 1
:format "Check: %v "
""))
(setq nts-p-origin (widget-create 'editable-field
:size 1
:format "Place: %v "
""))
(setq nts-date (widget-create 'editable-field
:size 1
:format "Date: %v "
""))
(insert "\n")
(setq nts-recip (widget-create 'text
:format "To:\n%v"
""))
(setq nts-phone (widget-create 'editable-field
:size 1
:format "Phone: %v "
""))
(insert "\n\n")
(setq nts-message (widget-create 'text
:format "Message:\n%v"
""))
(insert "\n")
(setq nts-signature (widget-create 'editable-field
:format "Signed: %v "
:size 1
""))
(widget-create 'push-button
:notify (lambda (widget &rest ignore)
(nts-validate widget))
"Validate")
(insert "\n\n")
(setq nts-recv (widget-create 'editable-field
:format "Recv'd: %v "
:size 1
""))
(widget-create 'push-button
:notify (lambda (widget &rest ignore)
(widget-value-set widget (nts-timestamp))
(nts-save))
"RECV")
(setq nts-sent (widget-create 'editable-field
:format " Sent: %v "
:size 1
""))
(widget-create 'push-button
:notify (lambda (widget &rest ignore)
(widget-value-set widget (nts-timestamp))
(nts-completed))
"SENT")
(insert "\n")
(use-local-map widget-keymap)
(widget-setup)
(goto-char 6)
(set-frame-width (selected-frame) 110)
(set-frame-height (selected-frame) 30)
)
(provide 'nts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment