mirror of
https://github.com/thiagoralves/OpenPLC_v3.git
synced 2026-09-28 15:47:31 +08:00
Fix indentation - convert tabs to spaces
This commit is contained in:
+393
-393
File diff suppressed because it is too large
Load Diff
+56
-56
@@ -52,75 +52,75 @@ struct enip_data_Unknown
|
||||
|
||||
struct enip_data_Unconnected
|
||||
{
|
||||
unsigned char *interface_handle;//[4]
|
||||
unsigned char *interface_handle;//[4]
|
||||
unsigned char *timeout;//[2]
|
||||
unsigned char *item_count;//[2]
|
||||
|
||||
unsigned char *item1_id;//[2]
|
||||
unsigned char *item1_length;//[2]
|
||||
|
||||
unsigned char *item2_id;//[2]
|
||||
unsigned char *item2_length;//[2]
|
||||
|
||||
unsigned char *service;//[1] 0x4b (Request)
|
||||
unsigned char *request_pathSize;//[1]
|
||||
unsigned char *request_path;//[4]
|
||||
unsigned char *requestor_idLength;//[1]
|
||||
unsigned char *vendor_id;//[2]
|
||||
unsigned char *serial_number;//[4]
|
||||
unsigned char *data;
|
||||
|
||||
unsigned char *item1_id;//[2]
|
||||
unsigned char *item1_length;//[2]
|
||||
|
||||
unsigned char *item2_id;//[2]
|
||||
unsigned char *item2_length;//[2]
|
||||
|
||||
unsigned char *service;//[1] 0x4b (Request)
|
||||
unsigned char *request_pathSize;//[1]
|
||||
unsigned char *request_path;//[4]
|
||||
unsigned char *requestor_idLength;//[1]
|
||||
unsigned char *vendor_id;//[2]
|
||||
unsigned char *serial_number;//[4]
|
||||
unsigned char *data;
|
||||
};
|
||||
|
||||
|
||||
struct enip_data_Connected
|
||||
{
|
||||
unsigned char *interface_handle;//[4]
|
||||
unsigned char *interface_handle;//[4]
|
||||
unsigned char *timeout;//[2]
|
||||
unsigned char *item_count;//[2]
|
||||
|
||||
unsigned char *item1_id;//[2]
|
||||
unsigned char *item1_length;//[2]
|
||||
|
||||
unsigned char *item2_id;//[2]
|
||||
unsigned char *item2_length;//[2]
|
||||
|
||||
unsigned char *service;//[1] 0x4b (Request)
|
||||
unsigned char *request_pathSize;//[1] -----------size in words
|
||||
unsigned char *request_path;//[4]
|
||||
unsigned char *actual_timeout;//[2]
|
||||
unsigned char *o2t_netConnectID;//[4]
|
||||
unsigned char *t2o_netConnectID;//[4]
|
||||
unsigned char *connect_serialNo;//[2]
|
||||
unsigned char *orig_vendorNo;//[2]
|
||||
unsigned char *orig_serialNo;//[4]
|
||||
unsigned char *timeout_multiplier;//[1]
|
||||
unsigned char *reserved;//[3]
|
||||
unsigned char *o2t_rpi;//[4]
|
||||
unsigned char *o2t_netConnectParam;//[2]
|
||||
unsigned char *t2o_rpi;//[4]
|
||||
unsigned char *t2o_netConnectParam;//[2]
|
||||
unsigned char *transport_trigger;//[1]
|
||||
unsigned char *connection_pathSize;//[1] ----- size in words
|
||||
unsigned char *connection_path;//[?]
|
||||
|
||||
unsigned char *item1_id;//[2]
|
||||
unsigned char *item1_length;//[2]
|
||||
|
||||
unsigned char *item2_id;//[2]
|
||||
unsigned char *item2_length;//[2]
|
||||
|
||||
unsigned char *service;//[1] 0x4b (Request)
|
||||
unsigned char *request_pathSize;//[1] -----------size in words
|
||||
unsigned char *request_path;//[4]
|
||||
unsigned char *actual_timeout;//[2]
|
||||
unsigned char *o2t_netConnectID;//[4]
|
||||
unsigned char *t2o_netConnectID;//[4]
|
||||
unsigned char *connect_serialNo;//[2]
|
||||
unsigned char *orig_vendorNo;//[2]
|
||||
unsigned char *orig_serialNo;//[4]
|
||||
unsigned char *timeout_multiplier;//[1]
|
||||
unsigned char *reserved;//[3]
|
||||
unsigned char *o2t_rpi;//[4]
|
||||
unsigned char *o2t_netConnectParam;//[2]
|
||||
unsigned char *t2o_rpi;//[4]
|
||||
unsigned char *t2o_netConnectParam;//[2]
|
||||
unsigned char *transport_trigger;//[1]
|
||||
unsigned char *connection_pathSize;//[1] ----- size in words
|
||||
unsigned char *connection_path;//[?]
|
||||
};
|
||||
|
||||
struct enip_data_Connected_0x70
|
||||
{
|
||||
unsigned char *interface_handle;//[4]
|
||||
unsigned char *interface_handle;//[4]
|
||||
unsigned char *timeout;//[2]
|
||||
unsigned char *item_count;//[2]
|
||||
|
||||
unsigned char *item1_id;//[2] --- 0x a1 00
|
||||
unsigned char *item1_length;//[2] --- 0x 04 00
|
||||
unsigned char *connection_id;//[4]
|
||||
|
||||
unsigned char *item2_id;//[2] --- 0x b1 00
|
||||
unsigned char *item2_length;//[2] length in bytes after this byte
|
||||
unsigned char *sequence_count;//[2]
|
||||
|
||||
unsigned char *service;//[1] --- 0x4b
|
||||
unsigned char *request_pathSize;//[1] --- 0x 20 67 24 01
|
||||
unsigned char *request_path;//[4]
|
||||
unsigned char *requestor_id;//[7]
|
||||
unsigned char *pcccData;//[?]
|
||||
|
||||
unsigned char *item1_id;//[2] --- 0x a1 00
|
||||
unsigned char *item1_length;//[2] --- 0x 04 00
|
||||
unsigned char *connection_id;//[4]
|
||||
|
||||
unsigned char *item2_id;//[2] --- 0x b1 00
|
||||
unsigned char *item2_length;//[2] length in bytes after this byte
|
||||
unsigned char *sequence_count;//[2]
|
||||
|
||||
unsigned char *service;//[1] --- 0x4b
|
||||
unsigned char *request_pathSize;//[1] --- 0x 20 67 24 01
|
||||
unsigned char *request_path;//[4]
|
||||
unsigned char *requestor_id;//[7]
|
||||
unsigned char *pcccData;//[?]
|
||||
};
|
||||
@@ -80,41 +80,41 @@ int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 18, 19 };
|
||||
//-----------------------------------------------------------------------------
|
||||
void initializeHardware()
|
||||
{
|
||||
gpioInitialise();
|
||||
//piHiPri(99);
|
||||
gpioInitialise();
|
||||
//piHiPri(99);
|
||||
|
||||
//set pins as input
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i]))
|
||||
{
|
||||
gpioSetMode(inBufferPinMask[i], PI_INPUT);
|
||||
gpioSetPullUpDown(inBufferPinMask[i], PI_PUD_UP); //pull up enabled
|
||||
}
|
||||
}
|
||||
//set pins as input
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i]))
|
||||
{
|
||||
gpioSetMode(inBufferPinMask[i], PI_INPUT);
|
||||
gpioSetPullUpDown(inBufferPinMask[i], PI_PUD_UP); //pull up enabled
|
||||
}
|
||||
}
|
||||
|
||||
//set pins as output
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i]))
|
||||
gpioSetMode(outBufferPinMask[i], PI_OUTPUT);
|
||||
}
|
||||
//set pins as output
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i]))
|
||||
gpioSetMode(outBufferPinMask[i], PI_OUTPUT);
|
||||
}
|
||||
|
||||
//set PWM pins as output
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), analogOutBufferPinMask[i])){
|
||||
gpioSetMode(analogOutBufferPinMask[i], PI_ALT5);
|
||||
gpioSetPWMrange(analogOutBufferPinMask[i], 1024);
|
||||
}
|
||||
}
|
||||
//set PWM pins as output
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), analogOutBufferPinMask[i])){
|
||||
gpioSetMode(analogOutBufferPinMask[i], PI_ALT5);
|
||||
gpioSetPWMrange(analogOutBufferPinMask[i], 1024);
|
||||
}
|
||||
}
|
||||
|
||||
// Modbus
|
||||
rpi_modbus_rts_pin = MODBUS_RTS;
|
||||
// Modbus
|
||||
rpi_modbus_rts_pin = MODBUS_RTS;
|
||||
|
||||
// I²C?
|
||||
// I²C?
|
||||
|
||||
// 1-Wire?
|
||||
// 1-Wire?
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -123,7 +123,7 @@ void initializeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void finalizeHardware()
|
||||
{
|
||||
gpioTerminate();
|
||||
gpioTerminate();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -133,16 +133,16 @@ void finalizeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersIn()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
//INPUT
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i]))
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = !gpioRead(inBufferPinMask[i]);
|
||||
}
|
||||
//INPUT
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i]))
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = !gpioRead(inBufferPinMask[i]);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -152,21 +152,21 @@ void updateBuffersIn()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersOut()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
//OUTPUT
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i]))
|
||||
if (bool_output[i/8][i%8] != NULL) gpioWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
}
|
||||
//OUTPUT
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i]))
|
||||
if (bool_output[i/8][i%8] != NULL) gpioWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
}
|
||||
|
||||
//ANALOG OUT (PWM)
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
if (int_output[i] != NULL) gpioPWM(analogOutBufferPinMask[i], (*int_output[i] / 64));
|
||||
}
|
||||
//ANALOG OUT (PWM)
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
if (int_output[i] != NULL) gpioPWM(analogOutBufferPinMask[i], (*int_output[i] / 64));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
@@ -56,19 +56,19 @@ void finalizeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersIn()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
/*********READING AND WRITING TO I/O**************
|
||||
/*********READING AND WRITING TO I/O**************
|
||||
|
||||
*bool_input[0][0] = read_digital_input(0);
|
||||
write_digital_output(0, *bool_output[0][0]);
|
||||
*bool_input[0][0] = read_digital_input(0);
|
||||
write_digital_output(0, *bool_output[0][0]);
|
||||
|
||||
*int_input[0] = read_analog_input(0);
|
||||
write_analog_output(0, *int_output[0]);
|
||||
*int_input[0] = read_analog_input(0);
|
||||
write_analog_output(0, *int_output[0]);
|
||||
|
||||
**************************************************/
|
||||
**************************************************/
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -78,18 +78,18 @@ void updateBuffersIn()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersOut()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
/*********READING AND WRITING TO I/O**************
|
||||
/*********READING AND WRITING TO I/O**************
|
||||
|
||||
*bool_input[0][0] = read_digital_input(0);
|
||||
write_digital_output(0, *bool_output[0][0]);
|
||||
*bool_input[0][0] = read_digital_input(0);
|
||||
write_digital_output(0, *bool_output[0][0]);
|
||||
|
||||
*int_input[0] = read_analog_input(0);
|
||||
write_analog_output(0, *int_output[0]);
|
||||
*int_input[0] = read_analog_input(0);
|
||||
write_analog_output(0, *int_output[0]);
|
||||
|
||||
**************************************************/
|
||||
**************************************************/
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -303,7 +303,7 @@ void finalizeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersIn()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
/* read digital inputs */
|
||||
int i = 0;
|
||||
@@ -330,7 +330,7 @@ void updateBuffersIn()
|
||||
i++;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -340,7 +340,7 @@ void updateBuffersIn()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersOut()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
/* write digital outputs */
|
||||
int i = 0;
|
||||
@@ -377,6 +377,6 @@ void updateBuffersOut()
|
||||
i++;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
|
||||
}
|
||||
|
||||
@@ -67,33 +67,33 @@ int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 3, 4 };
|
||||
//-----------------------------------------------------------------------------
|
||||
void initializeHardware()
|
||||
{
|
||||
// Init
|
||||
wiringPiSetup();
|
||||
// Init
|
||||
wiringPiSetup();
|
||||
|
||||
//set pins as input
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
|
||||
{
|
||||
pinMode(inBufferPinMask[i], INPUT);
|
||||
}
|
||||
}
|
||||
//set pins as input
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
|
||||
{
|
||||
pinMode(inBufferPinMask[i], INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
//set pins as output
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), i))
|
||||
pinMode(outBufferPinMask[i], OUTPUT);
|
||||
}
|
||||
// pwmSetRange(1024);
|
||||
// pwmSetClock(1);
|
||||
// //set PWM pins as output
|
||||
// for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
// {
|
||||
// if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), analogOutBufferPinMask[i])) {
|
||||
// pinMode(analogOutBufferPinMask[i], PWM_OUTPUT);
|
||||
// }
|
||||
// }
|
||||
//set pins as output
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), i))
|
||||
pinMode(outBufferPinMask[i], OUTPUT);
|
||||
}
|
||||
// pwmSetRange(1024);
|
||||
// pwmSetClock(1);
|
||||
// //set PWM pins as output
|
||||
// for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
// {
|
||||
// if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), analogOutBufferPinMask[i])) {
|
||||
// pinMode(analogOutBufferPinMask[i], PWM_OUTPUT);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -112,16 +112,16 @@ void finalizeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersIn()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
//INPUT
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]);
|
||||
}
|
||||
//INPUT
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -131,21 +131,21 @@ void updateBuffersIn()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersOut()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
//OUTPUT
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), i))
|
||||
if (bool_output[i/8][i%8] != NULL) digitalWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
}
|
||||
//ANALOG OUT (PWM)
|
||||
// for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
// {
|
||||
// if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
//OUTPUT
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), i))
|
||||
if (bool_output[i/8][i%8] != NULL) digitalWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
}
|
||||
//ANALOG OUT (PWM)
|
||||
// for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
// {
|
||||
// if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
// if (int_output[i] != NULL) pwmWrite(analogOutBufferPinMask[i], (*int_output[i] / 64));
|
||||
// }
|
||||
// }
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -187,33 +187,33 @@ int Spi_AutoModeDAC(struct pixtOutDAC *OutputDataDAC) {
|
||||
|
||||
int Spi_Set_Aout(int channel, uint16_t value)
|
||||
{
|
||||
unsigned char spi_output[2];
|
||||
int spi_device = 1;
|
||||
int len = 2;
|
||||
uint16_t tmp;
|
||||
unsigned char spi_output[2];
|
||||
int spi_device = 1;
|
||||
int len = 2;
|
||||
uint16_t tmp;
|
||||
|
||||
spi_output[0] = 0b00010000;
|
||||
spi_output[0] = 0b00010000;
|
||||
|
||||
if(channel)
|
||||
{
|
||||
spi_output[0] = spi_output[0] | 0b10000000;
|
||||
}
|
||||
if(value > 1023)
|
||||
{
|
||||
value=1023;
|
||||
}
|
||||
if(channel)
|
||||
{
|
||||
spi_output[0] = spi_output[0] | 0b10000000;
|
||||
}
|
||||
if(value > 1023)
|
||||
{
|
||||
value=1023;
|
||||
}
|
||||
|
||||
tmp = value & 0b1111000000;
|
||||
tmp = tmp >> 6;
|
||||
spi_output[0]=spi_output[0] | tmp;
|
||||
tmp = value & 0b1111000000;
|
||||
tmp = tmp >> 6;
|
||||
spi_output[0]=spi_output[0] | tmp;
|
||||
|
||||
tmp = value & 0b0000111111;
|
||||
tmp = tmp << 2;
|
||||
spi_output[1]=tmp;
|
||||
tmp = value & 0b0000111111;
|
||||
tmp = tmp << 2;
|
||||
spi_output[1]=tmp;
|
||||
|
||||
wiringPiSPIDataRW(spi_device, spi_output, len);
|
||||
wiringPiSPIDataRW(spi_device, spi_output, len);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Spi_AutoModeV2S(struct pixtOutV2S *OutputData, struct pixtInV2S *InputData)
|
||||
@@ -557,9 +557,9 @@ void finalizeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersIn()
|
||||
{
|
||||
//lock mutexes
|
||||
pthread_mutex_lock(&bufferLock);
|
||||
pthread_mutex_lock(&localBufferLock);
|
||||
//lock mutexes
|
||||
pthread_mutex_lock(&bufferLock);
|
||||
pthread_mutex_lock(&localBufferLock);
|
||||
|
||||
//DIGITAL INPUT
|
||||
for (int i = 0; i < MAX_DIG_IN; i++)
|
||||
@@ -641,9 +641,9 @@ void updateBuffersIn()
|
||||
|
||||
}
|
||||
|
||||
//unlock mutexes
|
||||
pthread_mutex_unlock(&localBufferLock);
|
||||
pthread_mutex_unlock(&bufferLock);
|
||||
//unlock mutexes
|
||||
pthread_mutex_unlock(&localBufferLock);
|
||||
pthread_mutex_unlock(&bufferLock);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -653,9 +653,9 @@ void updateBuffersIn()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersOut()
|
||||
{
|
||||
//lock mutexes
|
||||
pthread_mutex_lock(&bufferLock);
|
||||
pthread_mutex_lock(&localBufferLock);
|
||||
//lock mutexes
|
||||
pthread_mutex_lock(&bufferLock);
|
||||
pthread_mutex_lock(&localBufferLock);
|
||||
|
||||
//DIGITAL OUTPUT
|
||||
for (int i = 0; i < MAX_DIG_OUT; i++)
|
||||
@@ -726,7 +726,7 @@ void updateBuffersOut()
|
||||
// PWM1BL - PWM1BH
|
||||
if (byte_output[7] != NULL) OutputData.byPWM1B = *byte_output[7];
|
||||
|
||||
//unlock mutexes
|
||||
pthread_mutex_unlock(&localBufferLock);
|
||||
pthread_mutex_unlock(&bufferLock);
|
||||
//unlock mutexes
|
||||
pthread_mutex_unlock(&localBufferLock);
|
||||
pthread_mutex_unlock(&bufferLock);
|
||||
}
|
||||
|
||||
@@ -67,37 +67,37 @@ int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 18 };
|
||||
//-----------------------------------------------------------------------------
|
||||
void initializeHardware()
|
||||
{
|
||||
gpioInitialise();
|
||||
//piHiPri(99);
|
||||
gpioInitialise();
|
||||
//piHiPri(99);
|
||||
|
||||
//set pins as input
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i]))
|
||||
{
|
||||
gpioSetMode(inBufferPinMask[i], PI_INPUT);
|
||||
if (i != 0 && i != 1) //pull down can't be enabled on the first two pins
|
||||
{
|
||||
gpioSetPullUpDown(inBufferPinMask[i], PI_PUD_DOWN); //pull down enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
//set pins as input
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i]))
|
||||
{
|
||||
gpioSetMode(inBufferPinMask[i], PI_INPUT);
|
||||
if (i != 0 && i != 1) //pull down can't be enabled on the first two pins
|
||||
{
|
||||
gpioSetPullUpDown(inBufferPinMask[i], PI_PUD_DOWN); //pull down enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//set pins as output
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i]))
|
||||
gpioSetMode(outBufferPinMask[i], PI_OUTPUT);
|
||||
}
|
||||
//set pins as output
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i]))
|
||||
gpioSetMode(outBufferPinMask[i], PI_OUTPUT);
|
||||
}
|
||||
|
||||
//set PWM pins as output
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), analogOutBufferPinMask[i])) {
|
||||
gpioSetMode(analogOutBufferPinMask[i], PI_ALT5);
|
||||
gpioSetPWMrange(analogOutBufferPinMask[i], 1024);
|
||||
}
|
||||
}
|
||||
//set PWM pins as output
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), analogOutBufferPinMask[i])) {
|
||||
gpioSetMode(analogOutBufferPinMask[i], PI_ALT5);
|
||||
gpioSetPWMrange(analogOutBufferPinMask[i], 1024);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -106,7 +106,7 @@ void initializeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void finalizeHardware()
|
||||
{
|
||||
gpioTerminate();
|
||||
gpioTerminate();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -116,16 +116,16 @@ void finalizeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersIn()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
//INPUT
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i]))
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = gpioRead(inBufferPinMask[i]);
|
||||
}
|
||||
//INPUT
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i]))
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = gpioRead(inBufferPinMask[i]);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -135,21 +135,21 @@ void updateBuffersIn()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersOut()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
//OUTPUT
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i]))
|
||||
if (bool_output[i/8][i%8] != NULL) gpioWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
}
|
||||
//OUTPUT
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i]))
|
||||
if (bool_output[i/8][i%8] != NULL) gpioWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
}
|
||||
|
||||
//ANALOG OUT (PWM)
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
if (int_output[i] != NULL) gpioPWM(analogOutBufferPinMask[i], (*int_output[i] / 64));
|
||||
}
|
||||
//ANALOG OUT (PWM)
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
if (int_output[i] != NULL) gpioPWM(analogOutBufferPinMask[i], (*int_output[i] / 64));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
@@ -68,35 +68,35 @@ int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 1 };
|
||||
//-----------------------------------------------------------------------------
|
||||
void initializeHardware()
|
||||
{
|
||||
wiringPiSetup();
|
||||
//piHiPri(99);
|
||||
wiringPiSetup();
|
||||
//piHiPri(99);
|
||||
|
||||
//set pins as input
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
|
||||
{
|
||||
pinMode(inBufferPinMask[i], INPUT);
|
||||
if (i != 0 && i != 1) //pull down can't be enabled on the first two pins
|
||||
{
|
||||
pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
//set pins as input
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
|
||||
{
|
||||
pinMode(inBufferPinMask[i], INPUT);
|
||||
if (i != 0 && i != 1) //pull down can't be enabled on the first two pins
|
||||
{
|
||||
pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//set pins as output
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), i))
|
||||
pinMode(outBufferPinMask[i], OUTPUT);
|
||||
}
|
||||
//set pins as output
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), i))
|
||||
pinMode(outBufferPinMask[i], OUTPUT);
|
||||
}
|
||||
|
||||
//set PWM pins as output
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
pinMode(analogOutBufferPinMask[i], PWM_OUTPUT);
|
||||
}
|
||||
//set PWM pins as output
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
pinMode(analogOutBufferPinMask[i], PWM_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -114,16 +114,16 @@ void finalizeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersIn()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
//INPUT
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]);
|
||||
}
|
||||
//INPUT
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -133,21 +133,21 @@ void updateBuffersIn()
|
||||
//-----------------------------------------------------------------------------
|
||||
void updateBuffersOut()
|
||||
{
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
//OUTPUT
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), i))
|
||||
if (bool_output[i/8][i%8] != NULL) digitalWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
}
|
||||
//OUTPUT
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), i))
|
||||
if (bool_output[i/8][i%8] != NULL) digitalWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
}
|
||||
|
||||
//ANALOG OUT (PWM)
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
if (int_output[i] != NULL) pwmWrite(analogOutBufferPinMask[i], (*int_output[i] / 64));
|
||||
}
|
||||
//ANALOG OUT (PWM)
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i))
|
||||
if (int_output[i] != NULL) pwmWrite(analogOutBufferPinMask[i], (*int_output[i] / 64));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
}
|
||||
|
||||
+1046
-1046
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+60
-60
@@ -74,10 +74,10 @@ void sleep_until(struct timespec *ts, long long delay)
|
||||
//-----------------------------------------------------------------------------
|
||||
void sleepms(int milliseconds)
|
||||
{
|
||||
struct timespec ts;
|
||||
ts.tv_sec = milliseconds / 1000;
|
||||
ts.tv_nsec = (milliseconds % 1000) * 1000000;
|
||||
nanosleep(&ts, NULL);
|
||||
struct timespec ts;
|
||||
ts.tv_sec = milliseconds / 1000;
|
||||
ts.tv_nsec = (milliseconds % 1000) * 1000000;
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,25 +304,25 @@ int main(int argc,char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Define the start, end, cycle time and latency time variables
|
||||
struct timespec cycle_start, cycle_end, cycle_time;
|
||||
struct timespec timer_start, timer_end, sleep_latency;
|
||||
// Define the start, end, cycle time and latency time variables
|
||||
struct timespec cycle_start, cycle_end, cycle_time;
|
||||
struct timespec timer_start, timer_end, sleep_latency;
|
||||
|
||||
//gets the starting point for the clock
|
||||
printf("Getting current time\n");
|
||||
clock_gettime(CLOCK_MONOTONIC, &timer_start);
|
||||
//gets the starting point for the clock
|
||||
printf("Getting current time\n");
|
||||
clock_gettime(CLOCK_MONOTONIC, &timer_start);
|
||||
|
||||
//======================================================
|
||||
// MAIN LOOP
|
||||
//======================================================
|
||||
while(run_openplc)
|
||||
{
|
||||
// Get the start time for the running cycle
|
||||
clock_gettime(CLOCK_MONOTONIC, &cycle_start);
|
||||
//======================================================
|
||||
// MAIN LOOP
|
||||
//======================================================
|
||||
while(run_openplc)
|
||||
{
|
||||
// Get the start time for the running cycle
|
||||
clock_gettime(CLOCK_MONOTONIC, &cycle_start);
|
||||
|
||||
//make sure the buffer pointers are correct and
|
||||
//attached to the user variables
|
||||
glueVars();
|
||||
//make sure the buffer pointers are correct and
|
||||
//attached to the user variables
|
||||
glueVars();
|
||||
|
||||
#ifdef _ethercat_src
|
||||
boolvar_call_back bool_input_callback = bool_input_call_back;
|
||||
@@ -337,9 +337,9 @@ int main(int argc,char **argv)
|
||||
int64var_call_back lint_output_callback = lint_output_call_back;
|
||||
#endif
|
||||
|
||||
updateBuffersIn(); //read input image
|
||||
updateBuffersIn(); //read input image
|
||||
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
|
||||
|
||||
#ifdef _ethercat_src
|
||||
@@ -358,55 +358,55 @@ int main(int argc,char **argv)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
updateCustomIn();
|
||||
updateCustomIn();
|
||||
updateBuffersIn_MB(); //update input image table with data from slave devices
|
||||
handleSpecialFunctions();
|
||||
config_run__(__tick++); // execute plc program logic
|
||||
updateCustomOut();
|
||||
config_run__(__tick++); // execute plc program logic
|
||||
updateCustomOut();
|
||||
updateBuffersOut_MB(); //update slave devices with data from the output image table
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
|
||||
updateBuffersOut(); //write output image
|
||||
updateBuffersOut(); //write output image
|
||||
|
||||
updateTime();
|
||||
updateTime();
|
||||
|
||||
// Get the end time for the running cycle
|
||||
clock_gettime(CLOCK_MONOTONIC, &cycle_end);
|
||||
// Compute the time usage in one cycle and do max/min/total comparison/recording
|
||||
timespec_diff(&cycle_end, &cycle_start, &cycle_time);
|
||||
if (cycle_time.tv_nsec > cycle_max)
|
||||
cycle_max = cycle_time.tv_nsec;
|
||||
if (cycle_time.tv_nsec < cycle_min)
|
||||
cycle_min = cycle_time.tv_nsec;
|
||||
cycle_total = cycle_total + cycle_time.tv_nsec;
|
||||
// Get the end time for the running cycle
|
||||
clock_gettime(CLOCK_MONOTONIC, &cycle_end);
|
||||
// Compute the time usage in one cycle and do max/min/total comparison/recording
|
||||
timespec_diff(&cycle_end, &cycle_start, &cycle_time);
|
||||
if (cycle_time.tv_nsec > cycle_max)
|
||||
cycle_max = cycle_time.tv_nsec;
|
||||
if (cycle_time.tv_nsec < cycle_min)
|
||||
cycle_min = cycle_time.tv_nsec;
|
||||
cycle_total = cycle_total + cycle_time.tv_nsec;
|
||||
|
||||
sleep_until(&timer_start, common_ticktime__);
|
||||
sleep_until(&timer_start, common_ticktime__);
|
||||
|
||||
// Get the sleep end point which is also the start time/point of the next cycle
|
||||
clock_gettime(CLOCK_MONOTONIC, &timer_end);
|
||||
// Compute the time latency of the next cycle(caused by sleep) and do max/min/total comparison/recording
|
||||
timespec_diff(&timer_end, &timer_start, &sleep_latency);
|
||||
if (sleep_latency.tv_nsec > latency_max)
|
||||
latency_max = sleep_latency.tv_nsec;
|
||||
if (sleep_latency.tv_nsec < latency_min)
|
||||
latency_min = sleep_latency.tv_nsec;
|
||||
latency_total = latency_total + sleep_latency.tv_nsec;
|
||||
// Get the sleep end point which is also the start time/point of the next cycle
|
||||
clock_gettime(CLOCK_MONOTONIC, &timer_end);
|
||||
// Compute the time latency of the next cycle(caused by sleep) and do max/min/total comparison/recording
|
||||
timespec_diff(&timer_end, &timer_start, &sleep_latency);
|
||||
if (sleep_latency.tv_nsec > latency_max)
|
||||
latency_max = sleep_latency.tv_nsec;
|
||||
if (sleep_latency.tv_nsec < latency_min)
|
||||
latency_min = sleep_latency.tv_nsec;
|
||||
latency_total = latency_total + sleep_latency.tv_nsec;
|
||||
|
||||
// Store the cycle_time/sleep_latency in microsecond, so it can be displayed in the webpage
|
||||
RecordCycletimeLatency((long)cycle_time.tv_nsec / 1000, (long)sleep_latency.tv_nsec / 1000);
|
||||
}
|
||||
// Store the cycle_time/sleep_latency in microsecond, so it can be displayed in the webpage
|
||||
RecordCycletimeLatency((long)cycle_time.tv_nsec / 1000, (long)sleep_latency.tv_nsec / 1000);
|
||||
}
|
||||
|
||||
// Compute/print the max/min/avg cycle time and latency
|
||||
cycle_avg = (long)cycle_total / __tick;
|
||||
latency_avg = (long)latency_total / __tick;
|
||||
printf("###Summary: The maximum/minimum/average cycle time in microsecond is %ld/%ld/%ld\n",
|
||||
cycle_max / 1000, cycle_min / 1000, cycle_avg / 1000);
|
||||
printf("###Summary: The maximum/minimum/average latency in microsecond is %ld/%ld/%ld\n",
|
||||
latency_max / 1000, latency_min / 1000, latency_avg / 1000);
|
||||
// Compute/print the max/min/avg cycle time and latency
|
||||
cycle_avg = (long)cycle_total / __tick;
|
||||
latency_avg = (long)latency_total / __tick;
|
||||
printf("###Summary: The maximum/minimum/average cycle time in microsecond is %ld/%ld/%ld\n",
|
||||
cycle_max / 1000, cycle_min / 1000, cycle_avg / 1000);
|
||||
printf("###Summary: The maximum/minimum/average latency in microsecond is %ld/%ld/%ld\n",
|
||||
latency_max / 1000, latency_min / 1000, latency_avg / 1000);
|
||||
|
||||
//======================================================
|
||||
// SHUTTING DOWN OPENPLC RUNTIME
|
||||
//======================================================
|
||||
// SHUTTING DOWN OPENPLC RUNTIME
|
||||
//======================================================
|
||||
pthread_join(interactive_thread, NULL);
|
||||
#ifdef _ethercat_src
|
||||
ethercat_terminate_src();
|
||||
@@ -415,7 +415,7 @@ int main(int argc,char **argv)
|
||||
disableOutputs();
|
||||
updateCustomOut();
|
||||
updateBuffersOut();
|
||||
finalizeHardware();
|
||||
finalizeHardware();
|
||||
printf("Shutting down OpenPLC Runtime...\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
+589
-589
File diff suppressed because it is too large
Load Diff
+375
-375
File diff suppressed because it is too large
Load Diff
@@ -44,23 +44,23 @@ void startPstorage()
|
||||
sleepms(100);
|
||||
|
||||
char log_msg[1000];
|
||||
|
||||
struct persistentBufferCell
|
||||
{
|
||||
IEC_INT int_cell;
|
||||
IEC_DINT dint_cell;
|
||||
IEC_LINT lint_cell;
|
||||
};
|
||||
|
||||
struct persistentBufferCell
|
||||
{
|
||||
IEC_INT int_cell;
|
||||
IEC_DINT dint_cell;
|
||||
IEC_LINT lint_cell;
|
||||
};
|
||||
|
||||
persistentBufferCell persistentBuffer[BUFFER_SIZE];
|
||||
persistentBufferCell persistentBuffer[BUFFER_SIZE];
|
||||
|
||||
//Read initial buffers into persistent struct
|
||||
pthread_mutex_lock(&bufferLock); //lock mutex
|
||||
for (int i = 0; i < BUFFER_SIZE; i++)
|
||||
{
|
||||
if (int_memory[i] != NULL) persistentBuffer[i].int_cell = *int_memory[i];
|
||||
if (dint_memory[i] != NULL) persistentBuffer[i].dint_cell = *dint_memory[i];
|
||||
if (lint_memory[i] != NULL) persistentBuffer[i].lint_cell = *lint_memory[i];
|
||||
if (dint_memory[i] != NULL) persistentBuffer[i].dint_cell = *dint_memory[i];
|
||||
if (lint_memory[i] != NULL) persistentBuffer[i].lint_cell = *lint_memory[i];
|
||||
}
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
|
||||
@@ -165,14 +165,14 @@ int readPersistentStorage()
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct persistentBufferCell
|
||||
{
|
||||
IEC_INT int_cell;
|
||||
IEC_DINT dint_cell;
|
||||
IEC_LINT lint_cell;
|
||||
};
|
||||
struct persistentBufferCell
|
||||
{
|
||||
IEC_INT int_cell;
|
||||
IEC_DINT dint_cell;
|
||||
IEC_LINT lint_cell;
|
||||
};
|
||||
|
||||
persistentBufferCell persistentBuffer[BUFFER_SIZE];
|
||||
persistentBufferCell persistentBuffer[BUFFER_SIZE];
|
||||
|
||||
if (fread(persistentBuffer, sizeof(persistentBufferCell), BUFFER_SIZE, fd) < BUFFER_SIZE)
|
||||
{
|
||||
@@ -190,8 +190,8 @@ int readPersistentStorage()
|
||||
for (int i = 0; i < BUFFER_SIZE; i++)
|
||||
{
|
||||
if (int_memory[i] != NULL) *int_memory[i] = persistentBuffer[i].int_cell;
|
||||
if (dint_memory[i] != NULL) *dint_memory[i] = persistentBuffer[i].dint_cell;
|
||||
if (lint_memory[i] != NULL) *lint_memory[i] = persistentBuffer[i].lint_cell;
|
||||
if (dint_memory[i] != NULL) *dint_memory[i] = persistentBuffer[i].dint_cell;
|
||||
if (lint_memory[i] != NULL) *lint_memory[i] = persistentBuffer[i].lint_cell;
|
||||
}
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
|
||||
|
||||
Reference in New Issue
Block a user