-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runtime: Обработка данных в памяти сведена к единому интерфейсу.
- Loading branch information
Showing
9 changed files
with
69 additions
and
94 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,59 @@ | ||
#ifndef DATAINTERFACE_H | ||
#define DATAINTERFACE_H | ||
|
||
#include <cstring> | ||
|
||
template<int data_size> | ||
class DataInterface | ||
{ | ||
public: | ||
virtual bool read_bit(int offset, int bit_idx) = 0; | ||
bool read_bit(int offset, int bit_idx) | ||
{ return (m_data[offset] & (1 << bit_idx)); } | ||
void write_bit(int offset, int bit_idx, bool val) | ||
{ | ||
if (val) | ||
m_data[offset] |= (1 << bit_idx); | ||
else | ||
m_data[offset] &= ~(1 << bit_idx); | ||
} | ||
|
||
uint8_t read_ubyte(int offset) | ||
{ return m_data[offset]; } | ||
void write_ubyte(int offset, uint8_t val) | ||
{ m_data[offset] = val; } | ||
|
||
int8_t read_byte(int offset) | ||
{ return m_data[offset]; } | ||
void write_byte(int offset, int8_t val) | ||
{ m_data[offset] = val; } | ||
|
||
uint16_t read_word(int offset) | ||
{ return *((uint16_t*)&m_data[offset]); } | ||
void write_word(int offset, uint16_t val) | ||
{ *((uint16_t*)&m_data[offset]) = val; } | ||
|
||
int16_t read_int(int offset) | ||
{ return *((int16_t*)&m_data[offset]); } | ||
void write_int(int offset, int16_t val) | ||
{ *((int16_t*)&m_data[offset]) = val; } | ||
|
||
virtual uint8_t read_ubyte(int offset) = 0; | ||
virtual int8_t read_byte(int offset) = 0; | ||
uint32_t read_dword(int offset) | ||
{ return *((uint32_t*)&m_data[offset]); } | ||
void write_dword(int offset, uint32_t val) | ||
{ *((uint32_t*)&m_data[offset]) = val; } | ||
|
||
virtual uint16_t read_word(int offset) = 0; | ||
virtual int16_t read_int(int offset) = 0; | ||
float read_real(int offset) | ||
{ return *((float*)&m_data[offset]); } | ||
void write_real(int offset, float val) | ||
{ *((float*)&m_data[offset]) = val; } | ||
|
||
virtual uint32_t read_dword(int offset) = 0; | ||
|
||
virtual float read_real(int offset) = 0; | ||
void update_inputs(uint8_t* PIP) | ||
{ std::memcpy(this->m_data, PIP, IO_AREA_SIZE); } | ||
void update_outputs(uint8_t* POP) | ||
{ std::memcpy(POP, this->m_data, IO_AREA_SIZE); } | ||
protected: | ||
char m_data[data_size]; | ||
}; | ||
|
||
#endif // DATAINTERFACE_H |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "plcdata.h" | ||
|
||
DataInterface<IO_AREA_SIZE> plc_inputs; | ||
DataInterface<IO_AREA_SIZE> plc_outputs; | ||
DataInterface<MEM_AREA_SIZE> plc_memory; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef PLCDATA_H | ||
#define PLCDATA_H | ||
|
||
#include "settings.h" | ||
#include "datainterface.h" | ||
|
||
extern DataInterface<IO_AREA_SIZE> plc_inputs; | ||
extern DataInterface<IO_AREA_SIZE> plc_outputs; | ||
extern DataInterface<MEM_AREA_SIZE> plc_memory; | ||
|
||
#endif // PLCDATA_H |
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
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