Skip to content

Instantly share code, notes, and snippets.

@seryh
Created January 22, 2016 10:08
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 seryh/0647788e26f7b54dfcef to your computer and use it in GitHub Desktop.
Save seryh/0647788e26f7b54dfcef to your computer and use it in GitHub Desktop.
(defn data-sum [^bytes data]
(let [count-data (count data)]
(loop [i 0 sum 0]
(let [val (hx/get-byte data i)
new-sum (+ sum val)]
(if (< i (dec count-data))
(recur (inc i) new-sum) new-sum)))))
(defn valid-CS? [^bytes data]
(let [count-data (count data)
origin-CS (aget data (- count-data 2))
unixtime (hx/subbytes data 5 9)
frames (get-frames data)
unixtime-sum (data-sum unixtime)
frames-sum (reduce + (map data-sum frames))
CS (hx/int->int8 (+ unixtime-sum frames-sum))]
(= origin-CS CS)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment