{"id":1189,"date":"2021-05-03T21:15:57","date_gmt":"2021-05-03T13:15:57","guid":{"rendered":"http:\/\/www.tinywsn.net\/wordpress\/?p=1189"},"modified":"2021-05-03T23:02:44","modified_gmt":"2021-05-03T15:02:44","slug":"pycrc","status":"publish","type":"post","link":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/2021\/05\/03\/pycrc\/","title":{"rendered":"\u4e00\u79cdCRC\u4ee3\u7801\u751f\u6210\u5de5\u5177"},"content":{"rendered":"\n<p>\u5728\u6570\u636e\u901a\u8baf\u9886\u57df\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6570\u636e\u7684\u6b63\u786e\uff0c\u5c31\u4e0d\u5f97\u4e0d\u91c7\u7528\u68c0\u9519\u7684\u624b\u6bb5\uff0cCRC\u662f\u6700\u5e38\u89c1\u7684\u4e00\u79cd\uff0c\u5b83\u7684\u6709\u957f\u5ea68\u4f4d\uff0c16\u4f4d\uff0c32\u4f4d\u7684\u5404\u79cd\u751f\u6210\u591a\u9879\u5f0f\uff0c\u8f93\u5165\u548c\u8f93\u51fa\u8fd8\u53ef\u80fd\u7ffb\u8f6c\uff0c\u53ef\u4ee5\u76f4\u63a5bit\u64cd\u4f5c\u6216\u8868\u9a71\u52a8\u8fdb\u884c\u7f16\u89e3\u7801\uff0c\u624b\u5de5\u7f16\u5199\u7f16\u89e3\u7801\u7a0b\u5e8f\u4e0d\u4f46\u7e41\u7410\uff0c\u800c\u4e14\u5bb9\u6613\u51fa\u9519\u3002<br>pycrc\u662f\u4e00\u79cd\u57fa\u4e8epython\u7684CRC\u5d4c\u5165C\u4ee3\u7801\u751f\u6210\u5668\uff0c\u5b83\u4e0b\u8f7d\u94fe\u63a5<br><a href=\"https:\/\/pycrc.org\/\">https:\/\/pycrc.org\/<\/a>, \u5b83\u53ef\u4ee5\u76f4\u63a5\u8f93\u51fa\u7b26\u5408C89, ANSI, C99\u7684C\u4ee3\u7801\uff0c\u5b83\u662f\u4e00\u4e2a\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u4e0b\u9762\u662f\u5b83\u7684\u4e00\u4e9b\u5e38\u89c1\u9009\u9879<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><thead><tr><th>\u9009\u9879<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>--width=<\/code><em><code>NUM<\/code><\/em><\/td><td>use <em><code>NUM<\/code><\/em> bits in the <em><code>Polynomial<\/code><\/em><\/td><\/tr><tr><td><code>--poly=<\/code><em><code>HEX<\/code><\/em><\/td><td>use <em><code>HEX<\/code><\/em> as <em><code>Polynomial<\/code><\/em><\/td><\/tr><tr><td>&#8211;<code>-reflect-in=<\/code><em><code>BOOL<\/code><\/em><\/td><td>reflect the octets in the input message<\/td><\/tr><tr><td>&#8212;<code>xor-in=<\/code><em><code>HEX<\/code><\/em><\/td><td>use <em><code>HEX<\/code><\/em> as initial value<\/td><\/tr><tr><td><code>--reflect-out=<\/code><em><code>BOOL<\/code><\/em><\/td><td>reflect the resulting checksum before applying the XorOut<\/td><\/tr><tr><td><code>--xor-out=<\/code><em><code>HEX<\/code><\/em><\/td><td>xor the final CRC value with <em><code>HEX<\/code><\/em><\/td><\/tr><tr><td><code>--algorithm=<\/code><em><code>ALGO<\/code><\/em><\/td><td>choose an algorithm from {<em><code>bit-by-bit<\/code><\/em>, <em><code>bbb<\/code><\/em>, <em><code>bit-by-bit-fast<\/code><\/em>, <em><code>bbf<\/code><\/em>, <em><code>table-driven<\/code><\/em>, <em><code>tbl<\/code><\/em>, <em><code>all<\/code><\/em>}<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3>\u751f\u6210\u63a5\u53e3<\/h3>\n\n\n\n<p>typedef uint16_t crc_t;<\/p>\n\n\n\n<p>typedef uint16_t crc_t;<\/p>\n\n\n\n<p>crc_t crc_init( void);<\/p>\n\n\n\n<p>crc_t crc_update( crc_t crc,<br>const unsigned char *data,<br>size_t data_len);<\/p>\n\n\n\n<p>crc_t crc_finalize( crc_t crc);<\/p>\n\n\n\n<h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n\n\n\n<p>#include &#8220;pycrc_generated_crc.h&#8221;<br>#include &lt;stdio.h><\/p>\n\n\n\n<p>int main(void)<br>{<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static const unsigned char str1&#91;] = \"1234\";\nstatic const unsigned char str2&#91;] = \"56789\";\ncrc_t crc;\n\ncrc = crc_init();\ncrc = crc_update(crc, str1, sizeof(str1) - 1);\ncrc = crc_update(crc, str2, sizeof(str2) - 1);\n\/* more calls to crc_update... *\/\ncrc = crc_finalize(crc);\n\nprintf(\"0x%lx\\n\", (long)crc);\nreturn 0;<\/code><\/pre>\n\n\n\n<p>}<\/p>\n\n\n\n<h2>\u5728\u7ebfCRC\u8ba1\u7b97\u5668<\/h2>\n\n\n\n<p><a href=\"https:\/\/crccalc.com\/\">https:\/\/crccalc.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6570\u636e\u901a\u8baf\u9886\u57df\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6570\u636e\u7684\u6b63\u786e\uff0c\u5c31\u4e0d\u5f97\u4e0d\u91c7\u7528\u68c0\u9519\u7684\u624b\u6bb5\uff0cCRC\u662f\u6700\u5e38\u89c1\u7684\u4e00\u79cd\uff0c\u5b83\u7684\u6709\u957f\u5ea68\u4f4d\uff0c16\u4f4d\uff0c32 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1189"}],"collection":[{"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=1189"}],"version-history":[{"count":10,"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1189\/revisions"}],"predecessor-version":[{"id":1204,"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1189\/revisions\/1204"}],"wp:attachment":[{"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=1189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=1189"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tinywsn.net\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=1189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}