Code: Select all
(define (send-message type content)
;; send SOH
(unless (net-send (self 4) SOH) (throw-error (string "send soh failed: " (net-error))))
;; send length
(unless (net-send (self 4) (hex-str (+ 10 (length content)) 4)) (throw-error (string "send length failed: " (net-error))))
;; send type
(unless (net-send (self 4) type) (throw-error (string "send type failed: " (net-error))))
;; send content
(unless (net-send (self 4) content) (throw-error (string "send content failed: " (net-error))))
;; send checksum
(let (checksum-value (cal-checksum (total2 (append type content))))
(unless (net-send (self 4) (hex-str checksum-value 2)) (throw-error (string "send checksumfailed: " (net-error)))))
;; send ETX
(unless (net-send (self 4) ETX) (throw-error (string "send etx failed: " (net-error)))))