Commit 14b9b8ad authored by Claes Sjofors's avatar Claes Sjofors

Profinet, support for different API's

parent 8e2b1320
......@@ -109,7 +109,7 @@ PnViewerPNAC::PnViewerPNAC( pwr_tStatus *sts, const char *dev_name)
*sts = pnak_send_service_req_res(0, &local->service_req_res);
if (*sts == PNAK_OK) {
*sts = handle_service_con(local, 0);
*sts = wait_service_con(local, 0);
if (*sts != PNAK_OK) {
/* Loop through devices and calculate offset for io */
......@@ -123,7 +123,7 @@ PnViewerPNAC::PnViewerPNAC( pwr_tStatus *sts, const char *dev_name)
*sts = pnak_send_service_req_res(0, &local->service_req_res);
if (*sts == PNAK_OK) {
*sts = handle_service_con(local, 0);
*sts = wait_service_con(local, 0);
}
pMode.Mode = PNAK_MODE_ONLINE;
......@@ -167,7 +167,7 @@ void PnViewerPNAC::fetch_devices( vector<PnDevice>& dev_vect)
sts = pnak_send_service_req_res(0, &local->service_req_res);
if (sts == PNAK_OK) {
sts = handle_service_con(local, 0);
sts = wait_service_con(local, 0);
if (sts == PNAK_OK) {
if (local->dev_info.size() > 0) {
for (ii = 0; ii < local->dev_info.size(); ii++) {
......@@ -238,14 +238,14 @@ void PnViewerPNAC::set_device_properties( unsigned char *macaddress, unsigned ch
sts = pnak_send_service_req_res(0, &local->service_req_res);
if (sts == PNAK_OK) {
sts = handle_service_con(local, 0);
sts = wait_service_con(local, 0);
}
pack_set_ip_settings_req(&local->service_req_res, &dev_info);
sts = pnak_send_service_req_res(0, &local->service_req_res);
if (sts == PNAK_OK) {
sts = handle_service_con(local, 0);
sts = wait_service_con(local, 0);
}
}
......
......@@ -55,6 +55,18 @@ typedef struct _PN_Alarm_Data {
unsigned char *data;
} PN_Alarm_Data;
class PnApiData {
public:
PnApiData() : api(0) {}
unsigned int api;
vector<unsigned int> module_index;
~PnApiData() {}
int print( ofstream& fp);
};
class PnIOCRData {
public:
PnIOCRData() : type(0), number_modules(0), identifier(0), io_data_length(0), clean_io_data_length(0) {}
......
......@@ -394,7 +394,9 @@ void pack_download_req(T_PNAK_SERVICE_REQ_RES *ServiceReqRes, GsdmlDeviceData *d
unsigned short datarecord_ind = 0;
unsigned short data_record_length = 0;
unsigned short no_items;
unsigned short ii, jj, kk, length;
unsigned short ii, jj, kk, length, slot_api, found;
vector<PnApiData> apis;
static unsigned short phase = 1;
// static unsigned short old_red_ratio = 1;
......@@ -418,8 +420,7 @@ void pack_download_req(T_PNAK_SERVICE_REQ_RES *ServiceReqRes, GsdmlDeviceData *d
num_iocrs = dev_data->iocr_data.size();
if (num_iocrs > 0)
num_apis = 1;
/* Calculate num modules */
for (ii = 0; ii < dev_data->slot_data.size(); ii++) {
if ((dev_data->slot_data[ii]->module_enum_number != 0) ||
......@@ -430,6 +431,42 @@ void pack_download_req(T_PNAK_SERVICE_REQ_RES *ServiceReqRes, GsdmlDeviceData *d
// num_modules = dev_data->slot_data.size();
/* Calculate num apis */
if (num_iocrs > 0) {
for (ii = 0; ii < num_modules; ii++) {
slot_api = PROFINET_DEFAULT_API;
for (jj = 0; jj < dev_data->slot_data[ii]->subslot_data.size(); jj++) {
if (dev_data->slot_data[ii]->subslot_data[jj]->api > 0) {
slot_api = dev_data->slot_data[ii]->subslot_data[jj]->api;
break;
}
}
found = 0;
for (kk = 0; kk < apis.size(); kk++) {
if (apis[kk].api == slot_api) {
found = TRUE;
break;
}
}
if (!found) {
PnApiData api;
api.api = slot_api;
api.module_index.push_back(ii);
apis.push_back(api);
} else {
apis[kk].module_index.push_back(ii);
}
}
num_apis = apis.size();
}
/* Calculate num sub modules */
for (ii = 0; ii < num_modules; ii++) {
num_sm = dev_data->slot_data[ii]->subslot_data.size();
num_submodules += num_sm;
......@@ -647,21 +684,29 @@ void pack_download_req(T_PNAK_SERVICE_REQ_RES *ServiceReqRes, GsdmlDeviceData *d
/* Fill data for API */
/* pAPI->APIHighWordHighByte = _PN_U32_HIGH_HIGH_BYTE(15616);
pAPI->APIHighWordLowByte = _PN_U32_HIGH_LOW_BYTE(15616);
pAPI->APILowWordHighByte = _PN_U32_LOW_HIGH_BYTE(15616);
pAPI->APILowWordLowByte = _PN_U32_LOW_LOW_BYTE(15616);
pAPI->APIHighWordHighByte = _PN_U32_HIGH_HIGH_BYTE(PROFINET_DEFAULT_API);
pAPI->APIHighWordLowByte = _PN_U32_HIGH_LOW_BYTE(PROFINET_DEFAULT_API);
pAPI->APILowWordHighByte = _PN_U32_LOW_HIGH_BYTE(PROFINET_DEFAULT_API);
pAPI->APILowWordLowByte = _PN_U32_LOW_LOW_BYTE(PROFINET_DEFAULT_API);
pAPI->APILowWordLowByte = _PN_U32_LOW_LOW_BYTE(PROFINET_DEFAULT_API); */
pAPI->APIHighWordHighByte = _PN_U32_HIGH_HIGH_BYTE(apis[ii].api);
pAPI->APIHighWordLowByte = _PN_U32_HIGH_LOW_BYTE(apis[ii].api);
pAPI->APILowWordHighByte = _PN_U32_LOW_HIGH_BYTE(apis[ii].api);
pAPI->APILowWordLowByte = _PN_U32_LOW_LOW_BYTE(apis[ii].api);
pAPI->NumberOfModulesHighByte = _PN_U16_HIGH_BYTE(num_modules);
pAPI->NumberOfModulesLowByte = _PN_U16_LOW_BYTE(num_modules);
pAPI->NumberOfModulesHighByte = _PN_U16_HIGH_BYTE(apis[ii].module_index.size());
pAPI->NumberOfModulesLowByte = _PN_U16_LOW_BYTE(apis[ii].module_index.size());
/* Fill references to Modules */
pModuleReference = (T_PN_REFERENCE *) (pAPI + 1);
for (module_ind = 0; module_ind < num_modules; module_ind++) {
pModuleReference->ReferenceHighByte = _PN_U16_HIGH_BYTE(module_ind);
pModuleReference->ReferenceLowByte = _PN_U16_LOW_BYTE(module_ind);
for (module_ind = 0; module_ind < apis[ii].module_index.size(); module_ind++) {
pModuleReference->ReferenceHighByte = _PN_U16_HIGH_BYTE(apis[ii].module_index[module_ind]);
pModuleReference->ReferenceLowByte = _PN_U16_LOW_BYTE(apis[ii].module_index[module_ind]);
pModuleReference++;
}
......
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