|
|
|
@ -18,8 +18,6 @@ |
|
|
|
|
(assert false (.. "expected " ,(view expr) " = " e# |
|
|
|
|
", actual " a#))))) |
|
|
|
|
|
|
|
|
|
(test= (+ 5 4) 9) |
|
|
|
|
|
|
|
|
|
(fn escape-readably [s] |
|
|
|
|
(s:gsub "%c" (fn [x] (string.format "\\u{%.3x}" (string.byte x))))) |
|
|
|
|
|
|
|
|
@ -46,9 +44,6 @@ |
|
|
|
|
(test= (unicode->gsm "abc123") "abc123") |
|
|
|
|
(test= (unicode->gsm "abc{123}") "abc\x1b(123\x1b)") |
|
|
|
|
|
|
|
|
|
;(print (escape-readably(unicode-to-gsm "hello"))) |
|
|
|
|
;(print (escape-readably(unicode-to-gsm "{he@llo}€"))) |
|
|
|
|
|
|
|
|
|
(fn expect [fd pattern fail-pattern] |
|
|
|
|
(let [b (read fd 1024)] |
|
|
|
|
(if (> (# b) 0) |
|
|
|
@ -147,8 +142,18 @@ |
|
|
|
|
(tx fd (.. s "\r\n")) |
|
|
|
|
(expect fd "OK" "ERROR")) |
|
|
|
|
|
|
|
|
|
(fn send-sms [number body] |
|
|
|
|
(let [fd (fcntl.open "/dev/serial/by-id/usb-HUAWEI_HUAWEI_HiLink-if00-port0" posix.O_RDWR) |
|
|
|
|
(fn send-message [{: fd} number body] |
|
|
|
|
(let [pdu (message->pdu number (unicode->gsm body)) |
|
|
|
|
payload (.. "00" pdu)] |
|
|
|
|
(doto fd |
|
|
|
|
(tx (.. "AT+CMGS=" (string.format "%d" (/ (# pdu) 2)) "\r\n")) |
|
|
|
|
(expect ">" "ERROR") |
|
|
|
|
(tx payload) |
|
|
|
|
(tx "\026\r\n") |
|
|
|
|
(expect "OK")))) |
|
|
|
|
|
|
|
|
|
(fn new-sender [{: device : smsc : verbose}] |
|
|
|
|
(let [fd (fcntl.open device posix.O_RDWR) |
|
|
|
|
termios (tcgetattr fd)] |
|
|
|
|
(tset termios :cflag (bor termios.cflag CLOCAL CREAD)) |
|
|
|
|
(tset termios :lflag (band termios.lflag |
|
|
|
@ -157,24 +162,17 @@ |
|
|
|
|
(bnot ECHOE) |
|
|
|
|
(bnot ISIG))) |
|
|
|
|
(tset termios :oflag (band termios.oflag ( bnot OPOST))) |
|
|
|
|
(tcsetattr fd 0 termios) |
|
|
|
|
|
|
|
|
|
(tcdrain fd) |
|
|
|
|
|
|
|
|
|
(let [pdu (message->pdu number (unicode->gsm body)) |
|
|
|
|
payload (.. "00" pdu)] |
|
|
|
|
(doto fd |
|
|
|
|
(command "AT") |
|
|
|
|
(command "AT&F") ; revert to defaults |
|
|
|
|
(command "ATE0") ; disable command echo |
|
|
|
|
(command "AT+CMEE=1") ;print CME errors |
|
|
|
|
(command "AT+CSCA=\"+447958879879\",145\r\n") ;set SMSC |
|
|
|
|
(command "AT+CMGF=0") ;SMS PDU mode |
|
|
|
|
|
|
|
|
|
(tx (.. "AT+CMGS=" (string.format "%d" (/ (# pdu) 2)) "\r\n")) |
|
|
|
|
(expect ">" "ERROR") |
|
|
|
|
(tx payload) |
|
|
|
|
(tx "\026\r\n") |
|
|
|
|
(expect "OK"))))) |
|
|
|
|
|
|
|
|
|
{ :send send-sms } |
|
|
|
|
(doto fd |
|
|
|
|
(tcsetattr 0 termios) |
|
|
|
|
(tcdrain) |
|
|
|
|
|
|
|
|
|
(command "AT") |
|
|
|
|
(command "AT&F") ; revert to defaults |
|
|
|
|
(command "ATE0") ; disable command echo |
|
|
|
|
(command "AT+CMEE=1") ;print CME errors |
|
|
|
|
(command (.. "AT+CSCA=\"" smsc "\",145\r\n")) ;set SMSC |
|
|
|
|
(command "AT+CMGF=0")) ;SMS PDU mode |
|
|
|
|
|
|
|
|
|
{:send send-message :device device :smsc smsc :fd fd})) |
|
|
|
|
|
|
|
|
|
{ :new new-sender :verbose false } |
|
|
|
|