Пример #1
0
EIP_STATUS
notifyAssemblyConnectedDataReceived(S_CIP_Instance * pa_pstInstance,
    EIP_UINT8 * pa_pnData, EIP_UINT16 pa_nDataLength)
{
  S_CIP_Byte_Array *p;

  /* empty path (path size = 0) need to be checked and taken care of in future */
  /* copy received data to Attribute 3 */
  p = (S_CIP_Byte_Array *) pa_pstInstance->pstAttributes->pt2data;
  if (p->len != pa_nDataLength)
    {
      OPENER_TRACE_ERR("wrong amount of data arrived for assembly object\n");
      return EIP_ERROR; /*TODO question should we notify the application that wrong data has been recieved???*/
    }
  else
    {
      memcpy(p->Data, pa_pnData, pa_nDataLength);
      /* call the application that new data arrived */
    }

  return IApp_AfterAssemblyDataReceived(pa_pstInstance);
}
Пример #2
0
EIP_STATUS
setAssemblyAttributeSingle(S_CIP_Instance * pa_pstInstance,
                           S_CIP_MR_Request * pa_pstMRRequest,
                           S_CIP_MR_Response * pa_pstMRResponse)
{


  EIP_UINT8 * acReqData;
  S_CIP_attribute_struct * p;
  OPENER_TRACE_INFO(" setAttribute %d\n", pa_pstMRRequest->RequestPath.AttributNr);

  acReqData = pa_pstMRRequest->Data;

  pa_pstMRResponse->DataLength = 0;
  pa_pstMRResponse->ReplyService = (0x80 | pa_pstMRRequest->Service);
  pa_pstMRResponse->GeneralStatus = CIP_ERROR_ATTRIBUTE_NOT_SUPPORTED;
  pa_pstMRResponse->SizeofAdditionalStatus = 0;


  p = getAttribute(pa_pstInstance,
                   pa_pstMRRequest->RequestPath.AttributNr);

  if((p != 0) && (3 == pa_pstMRRequest->RequestPath.AttributNr))
    {
      if(p->pt2data != 0)
        {
          S_CIP_Byte_Array * pacData = (S_CIP_Byte_Array *) p->pt2data;

          //TODO: check for ATTRIBUTE_SET/GETABLE MASK
          if(true == isConnectedOutputAssembly(pa_pstInstance->nInstanceNr))
            {
              OPENER_TRACE_WARN("Assembly AssemblyAttributeSingle: received data for connected output assembly\n\r");
              pa_pstMRResponse->GeneralStatus = CIP_ERROR_ATTRIBUTE_NOT_SETTABLE;
            }
          else
            {
              if(pa_pstMRRequest->DataLength < pacData->len)
                {
                  OPENER_TRACE_INFO("Assembly setAssemblyAttributeSingle: not enough data received.\r\n");
                  pa_pstMRResponse->GeneralStatus = CIP_ERROR_NOT_ENOUGH_DATA;
                }
              else
                {
                  if(pa_pstMRRequest->DataLength > pacData->len)
                    {
                      OPENER_TRACE_INFO("Assembly setAssemblyAttributeSingle: too much data received.\r\n");
                      pa_pstMRResponse->GeneralStatus = CIP_ERROR_TOO_MUCH_DATA;
                    }
                  else
                    {
                      memcpy(pacData->Data, acReqData, pacData->len);

                      if(IApp_AfterAssemblyDataReceived(pa_pstInstance)
                         != EIP_OK)
                        {
                          /* punt early without updating the status... though I don't know
                           * how much this helps us here, as the attribute's data has already
                           * been overwritten.
                           *
                           * however this is the task of the application side which will
                           * take the data. In addition we have to inform the sender that the
                           * data was not ok.
                           */
                          pa_pstMRResponse->GeneralStatus
                            = CIP_ERROR_INVALID_ATTRIBUTE_VALUE;
                        }
                      else
                        {
                          pa_pstMRResponse->GeneralStatus = CIP_ERROR_SUCCESS;
                        }
                    }
                }
            }
        }
      else
        {
          /* the attribute was zero we are a heartbeat assembly */
          pa_pstMRResponse->GeneralStatus = CIP_ERROR_TOO_MUCH_DATA;
        }
    }

  return EIP_OK_SEND;
}