Commit 7785c4c6 authored by Marcus Nordenberg's avatar Marcus Nordenberg

gsdml data: update how data is written according to chosen byte order

parent 8e744aa1
/*
* Copyright (C) 2010 SSAB Oxelsund AB.
* Copyright (C) 2010 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -123,6 +123,11 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
}
chanp->offset = input_counter;
chanp->mask = 1 << chan_di->Number;
// TODO Check with the PROFINET specification what to do with boolean values greater than 8 bit integers.
// The data coming from an et200sp 16 DI module represented as unsigned16 and the channel value of a
// AI modules channel represented as integer16 are sent with different byte order. Maybe booleans can be
// considered Little Endian...
// More TODO: Check host endianess aswell and take action accordingly
if (chan_di->Representation == pwr_eDataRepEnum_Bit16
&& op->ByteOrdering == pwr_eByteOrderingEnum_BigEndian)
chanp->mask = swap16(chanp->mask);
......@@ -132,8 +137,7 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
if (chan_di->Number == 0)
latent_input_count
= GetChanSize((pwr_eDataRepEnum)chan_di->Representation);
// printf("Di channel found in %s, Number %d, Offset %d\n",
// cardp->Name, chan_di->Number, chanp->offset);
//printf("Di channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_di->Number, chanp->offset);
break;
case pwr_cClass_ChanAi:
......@@ -187,8 +191,7 @@ static pwr_tStatus IoRackInit(io_tCtx ctx, io_sAgent* ap, io_sRack* rp)
if (chan_do->Number == 0)
latent_output_count
= GetChanSize((pwr_eDataRepEnum)chan_do->Representation);
// printf("Do channel found in %s, Number %d, Offset %d\n",
// cardp->Name, chan_do->Number, chanp->offset);
//printf("Do channel found in %s, Number %d, Offset %d\n", cardp->Name, chan_do->Number, chanp->offset);
break;
case pwr_cClass_ChanAo:
......
......@@ -44,6 +44,8 @@
#include "rt_pb_msg.h"
#include "rt_pn_gsdml_data.h"
#include "pwr_baseclasses.h"
typedef enum {
gsdmldata_eTag_,
gsdmldata_eTag_PnDevice,
......@@ -83,12 +85,15 @@ GsdmlDataRecord::GsdmlDataRecord(const GsdmlDataRecord& x)
}
}
int GsdmlDataRecord::print(std::ofstream& fp)
int GsdmlDataRecord::print(std::ofstream& fp, bool reverse_endianess)
{
char str[1024];
unsigned char* data = (reverse_endianess ? this->data_reversed_endianess : this->data);
co_xml_parser::data_to_ostring(data, data_length, str, sizeof(str));
fp << " <DataRecord Index=\"" << index << "\"\n"
<< " TransferSequence=\"" << transfer_sequence << "\"\n"
<< " DataLength=\"" << data_length << "\"\n"
......@@ -97,7 +102,7 @@ int GsdmlDataRecord::print(std::ofstream& fp)
return 1;
}
int GsdmlSubslotData::print(std::ofstream& fp)
int GsdmlSubslotData::print(std::ofstream& fp, bool reverse_endianess)
{
fp << " <Subslot SubslotNumber=\"" << subslot_number << "\"\n"
<< " SubmoduleEnumNumber=\"" << submodule_enum_number << "\"\n"
......@@ -107,14 +112,14 @@ int GsdmlSubslotData::print(std::ofstream& fp)
<< " IOOutputLength=\"" << io_output_length << "\" >\n";
for (unsigned int i = 0; i < data_record.size(); i++) {
data_record[i]->print(fp);
data_record[i]->print(fp, reverse_endianess);
}
fp << " </Subslot>\n";
return 1;
}
int GsdmlSlotData::print(std::ofstream& fp)
int GsdmlSlotData::print(std::ofstream& fp, bool reverse_endianess)
{
fp << " <Slot ModuleEnumNumber=\"" << module_enum_number << "\"\n"
<< " ModuleIdentNumber=\"" << module_ident_number << "\"\n"
......@@ -123,7 +128,7 @@ int GsdmlSlotData::print(std::ofstream& fp)
<< " SlotNumber=\"" << slot_number << "\" >\n";
for (unsigned int i = 0; i < subslot_data.size(); i++) {
subslot_data[i]->print(fp);
subslot_data[i]->print(fp, reverse_endianess);
}
fp << " </Slot>\n";
......@@ -147,6 +152,7 @@ int GsdmlDeviceData::print(const char* filename)
pwr_tFileName fname;
std::ofstream fp;
char* gsdmlfile_p;
bool reverse_endianess = false;
// Print name of gsdmlfile, not path
if ((gsdmlfile_p = strrchr(gsdmlfile, '/')))
......@@ -172,8 +178,30 @@ int GsdmlDeviceData::print(const char* filename)
<< " SubnetMask=\"" << subnet_mask << "\"\n"
<< " MAC_Address=\"" << mac_address << "\" />\n";
//Save in accordance to the chosen endianess
#if (pwr_dHost_byteOrder == pwr_dLittleEndian)
if (byte_order == pwr_eByteOrderingEnum_LittleEndian)
{
reverse_endianess = false;
}
else
{
// We use the data saved as the reversed endianess
reverse_endianess = true;
}
#elif (pwr_dHost_byteOrder == pwr_dBigEndian)
if (byte_order == pwr_eByteOrderingEnum_LittleEndian)
{
reverse_endianess = true;
}
else
{
reverse_endianess = false;
}
#endif
for (unsigned int i = 0; i < slot_data.size(); i++) {
slot_data[i]->print(fp);
slot_data[i]->print(fp, reverse_endianess);
}
for (unsigned int i = 0; i < iocr_data.size(); i++) {
iocr_data[i]->print(fp);
......
......@@ -46,12 +46,13 @@
class GsdmlDataRecord {
public:
GsdmlDataRecord()
: record_idx(0), data(0), data_length(0), index(0), transfer_sequence(0)
: record_idx(0), data(0), data_reversed_endianess(0), data_length(0), index(0), transfer_sequence(0)
{
}
unsigned int record_idx;
unsigned char* data;
unsigned char* data_reversed_endianess;
unsigned int data_length;
unsigned short index;
unsigned short transfer_sequence;
......@@ -63,7 +64,7 @@ public:
}
GsdmlDataRecord(const GsdmlDataRecord& x);
int print(std::ofstream& fp);
int print(std::ofstream& fp, bool reverse_endianess);
};
class GsdmlIOCRData {
......@@ -113,7 +114,7 @@ public:
data_record.push_back(new GsdmlDataRecord(*x.data_record[i]));
}
}
int print(std::ofstream& fp);
int print(std::ofstream& fp, bool reverse_endianess);
};
class GsdmlSlotData {
......@@ -153,7 +154,7 @@ public:
subslot_data.push_back(new GsdmlSubslotData(*x.subslot_data[i]));
}
}
int print(std::ofstream& fp);
int print(std::ofstream& fp, bool reverse_endianess);
};
class GsdmlChannelDiag {
......@@ -169,7 +170,7 @@ public:
class GsdmlDeviceData {
public:
GsdmlDeviceData()
: device_num(0), vendor_id(0), device_id(0), byte_order(0), instance(0)
: device_num(0), vendor_id(0), device_id(0), byte_order(0), read_data_is_native_ordered(1), instance(0)
{
device_name[0] = 0;
ip_address[0] = 0;
......@@ -189,6 +190,7 @@ public:
unsigned short device_id;
char version[20];
int byte_order;
int read_data_is_native_ordered;
unsigned short instance;
pwr_tFileName gsdmlfile;
std::vector<GsdmlSlotData*> slot_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment