| | |
| | | return(crc); |
| | | } |
| | | */ |
| | | const uint16_t crctalbeabs[] = { |
| | | 0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, |
| | | 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400 |
| | | }; |
| | | |
| | | uint16_t crc16tablefast(const uint8_t *ptr, uint16_t len) |
| | | { |
| | | uint16_t crc = 0xffff; |
| | | uint16_t i; |
| | | uint8_t ch; |
| | | |
| | | for (i = 0; i < len; i++) { |
| | | ch = *ptr++; |
| | | crc = crctalbeabs[(ch ^ crc) & 15] ^ (crc >> 4); |
| | | crc = crctalbeabs[((ch >> 4) ^ crc) & 15] ^ (crc >> 4); |
| | | } |
| | | |
| | | return crc; |
| | | } |
| | | |
| | | //********************************************************************** |
| | | //****************** Modbus slave ************************************ |
| | |
| | | case WriteCoil: //5 bit |
| | | //Store Datas; |
| | | //SetBitValue(&KMem.WR[Addr1],bitAddr,pPkg->nCount); |
| | | Addr1=(Addr&0xfff0)>>4; |
| | | bitAddr=Addr&0xf; |
| | | if (nCount == 0) // set to 0 |
| | | { |
| | | ResetBit(&KMem.WY[Addr1],bitAddr); |
| | | if (Addr < 2048) { ResetBit(&KMem.WY[Addr1],bitAddr);} |
| | | else {ResetBit(&KMem.WR[Addr1-128],bitAddr);} |
| | | }else if (nCount == 0xFF00) // set to 1 |
| | | { |
| | | SetAddrBit(&KMem.WY[Addr1],bitAddr); |
| | | }else |
| | | { |
| | | //error |
| | | if (Addr < 2048) { SetAddrBit(&KMem.WY[Addr1],bitAddr);} |
| | | else {SetAddrBit(&KMem.WR[Addr1-128],bitAddr);} |
| | | |
| | | } |
| | | memcpy(Pkgbuf,ptr,len); |
| | | needcrc=0; |