one (bit-range (string.byte padded (+ 1 in-index)) n 6)
two (bit-range (string.byte padded (+ 2 in-index)) 0 n)]
(set out (string.format "%s%.2X" out
(bor one
(lshift two (- 7 n) )
)))))
out))
(fn message->pdu [destination-number body]
;; expects destination-number to be international but no leading +
;; body is in gsm 7 bit alphabet
(let [fields
[
;; sms-submit, allow dups, no vaidity period, no rpely path, no udh,
;; no reply=path
"01"
;; ME can choose message reference number
"00"
(string.format "%.2X" (# destination-number))
;; destination-number is international (ITU E.164/E.163) without leading +
"91"
(phone-number->hex destination-number)
;; protocol identifier
"00"
;; data coding scheme (GSM 7 bit default alphabet)
"00"
(string.format "%.2X" (# body))
(septets->hex body)
]]
(table.concat fields)))
;; per worked example at https://www.developershome.com/sms/cmgsCommand4.asp
(assert (= (message->pdu "85291234567" "It is easy to send text messages.") "01000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E"))
(fn command [fd s]
(tx fd (.. s "\r\n"))
(expect fd "OK" "ERROR"))
@ -62,23 +143,23 @@
(tcsetattr fd 0 termios)
(tcdrain fd)
(doto fd
(command "AT")
(command "AT&F") ; revert to defaults
(command "ATE0") ; disable command echo
(command "AT+CMEE=1") ;print CME errors
(command "AT+CMGF=1") ;SMS text mode (vs. PDU mode)
(command "AT+CSCS=\"GSM\"") ; default character set
(command "AT+CSMP=17,12,0,0") ; message valid for 12*5 minutes