mirror of https://github.com/lumapu/ahoy.git
				
				
			
							committed by
							
								 GitHub
								GitHub
							
						
					
				
				 11 changed files with 226 additions and 123 deletions
			
			
		| @ -0,0 +1,43 @@ | |||
| #include "crc.h" | |||
| 
 | |||
| uint8_t crc8(uint8_t buf[], uint8_t len) { | |||
|     uint8_t crc = CRC8_INIT; | |||
|     for(uint8_t i = 0; i < len; i++) { | |||
|         crc ^= buf[i]; | |||
|         for(uint8_t b = 0; b < 8; b ++) { | |||
|             crc = (crc << 1) ^ ((crc & 0x80) ? CRC8_POLY : 0x00); | |||
|         } | |||
|     } | |||
|     return crc; | |||
| } | |||
| 
 | |||
| uint16_t crc16(uint8_t buf[], uint8_t len) { | |||
|     uint16_t crc = 0xffff; | |||
|     uint8_t shift = 0; | |||
| 
 | |||
|     for(uint8_t i = 0; i < len; i ++) { | |||
|         crc = crc ^ buf[i]; | |||
|         for(uint8_t bit = 0; bit < 8; bit ++) { | |||
|             shift = (crc & 0x0001); | |||
|             crc = crc >> 1; | |||
|             if(shift != 0) | |||
|                 crc = crc ^ 0xA001; | |||
|         } | |||
|     } | |||
|     return crc; | |||
| } | |||
| 
 | |||
| uint16_t crc16nrf24(uint8_t buf[], uint16_t lenBits, uint16_t startBit, uint16_t crcIn) { | |||
|     uint16_t crc = crcIn; | |||
|     uint8_t idx, val = buf[(startBit >> 3)]; | |||
| 
 | |||
|     for(uint16_t bit = startBit; bit < lenBits; bit ++) { | |||
|         idx = bit & 0x07; | |||
|         if(0 == idx) | |||
|             val = buf[(bit >> 3)]; | |||
|         crc ^= 0x8000 & (val << (8 + idx)); | |||
|         crc = (crc & 0x8000) ? ((crc << 1) ^ CRC16_NRF24_POLYNOM) : (crc << 1); | |||
|     } | |||
| 
 | |||
|     return crc; | |||
| } | |||
| @ -0,0 +1,16 @@ | |||
| #ifndef __CRC_H__ | |||
| #define __CRC_H__ | |||
| 
 | |||
| #include <cstdint> | |||
| 
 | |||
| #define CRC8_INIT               0x00 | |||
| #define CRC8_POLY               0x01 | |||
| 
 | |||
| #define CRC16_MODBUS_POLYNOM    0xA001 | |||
| #define CRC16_NRF24_POLYNOM     0x1021 | |||
| 
 | |||
| uint8_t crc8(uint8_t buf[], uint8_t len); | |||
| uint16_t crc16(uint8_t buf[], uint8_t len); | |||
| uint16_t crc16nrf24(uint8_t buf[], uint16_t lenBits, uint16_t startBit = 0, uint16_t crcIn = 0xffff); | |||
| 
 | |||
| #endif /*__CRC_H__*/ | |||
| @ -1 +1 @@ | |||
| String index_html = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">            window.setInterval(\"getAjax('/uptime', 'uptime')\", 1000);            window.setInterval(\"getAjax('/time', 'time')\", 1000);            function getAjax(url, resid) {                var http = null;                http = new XMLHttpRequest();                if(http != null) {                   http.open(\"GET\", url, true);                   http.onreadystatechange = print;                   http.send(null);                }                function print() {                    if(http.readyState == 4) {                        document.getElementById(resid).innerHTML = http.responseText;                    }                }            }        </script></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><p><a href=\"/update\">Update</a><br/><br/><a href=\"/setup\">Setup</a><br/><a href=\"/reboot\">Reboot</a></p><p><span class=\"des\">Uptime: </span><span id=\"uptime\"></span></p><p><span class=\"des\">Time: </span><span id=\"time\"></span></p></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"right\">AHOY :: {VERSION}</p></div></body></html>"; | |||
| String index_html = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">            window.setInterval(\"getAjax('/uptime', 'uptime')\", 1000);            window.setInterval(\"getAjax('/time', 'time')\", 1000);            window.setInterval(\"getAjax('/cmdstat', 'cmds')\", 2000);            function getAjax(url, resid) {                var http = null;                http = new XMLHttpRequest();                if(http != null) {                   http.open(\"GET\", url, true);                   http.onreadystatechange = print;                   http.send(null);                }                function print() {                    if(http.readyState == 4) {                        document.getElementById(resid).innerHTML = http.responseText;                    }                }            }        </script></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><p><a href=\"/update\">Update</a><br/><br/><a href=\"/setup\">Setup</a><br/><a href=\"/reboot\">Reboot</a></p><p><span class=\"des\">Uptime: </span><span id=\"uptime\"></span></p><p><span class=\"des\">Time: </span><span id=\"time\"></span></p><p><span class=\"des\">Statistics: </span><pre id=\"cmds\"></pre></p></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"right\">AHOY :: {VERSION}</p></div></body></html>"; | |||
|  | |||
					Loading…
					
					
				
		Reference in new issue