Skip to content

Utilizar memoria flash para tabela de CRC #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions libraries/ModbusSerial/ModbusSerial.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
ModbusSerial.h - Header for ModbusSerial Library
Copyright (C) 2014 Andr� Sarmento Barbosa
Copyright (C) 2014 André Sarmento Barbosa
*/
#include <Arduino.h>
#include <Modbus.h>
@@ -9,11 +9,17 @@
#define MODBUSSERIAL_H

//#define USE_SOFTWARE_SERIAL
#define USE_FLASH_PROGMEM


#ifdef USE_SOFTWARE_SERIAL
#include <SoftwareSerial.h>
#endif

#ifdef USE_FLASH_PROGMEM
#include <avr/pgmspace.h>
#endif

class ModbusSerial : public Modbus {
private:
Stream* _port;
@@ -41,8 +47,14 @@ class ModbusSerial : public Modbus {
bool send(byte* frame);
};

/* Table of CRC values for high�order byte */
const byte _auchCRCHi[] = {
/* Table of CRC values for high–order byte */
#ifndef USE_FLASH_PROGMEM
const byte _auchCRCHi[] = {
#endif

#ifdef USE_FLASH_PROGMEM
const byte _auchCRCHi[] PROGMEM = {
#endif
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
@@ -62,8 +74,14 @@ const byte _auchCRCHi[] = {
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40};

/* Table of CRC values for low�order byte */
const byte _auchCRCLo[] = {
/* Table of CRC values for low–order byte */
#ifndef USE_FLASH_PROGMEM
const byte _auchCRCLo[] = {
#endif

#ifdef USE_FLASH_PROGMEM
const byte _auchCRCLo[] PROGMEM = {
#endif
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,
0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,
@@ -83,4 +101,3 @@ const byte _auchCRCLo[] = {
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,
0x40};

#endif //MODBUSSERIAL_H