Created
January 22, 2016 10:08
-
-
Save seryh/0647788e26f7b54dfcef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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