rt_powerlink_cn.c 3.84 KB
Newer Older
Claes Sjofors's avatar
Claes Sjofors committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/* 
 * Proview   Open Source Process Control.
 * Copyright (C) 2005-2012 SSAB EMEA AB.
 *
 * This file is part of Proview.
 *
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License as 
 * published by the Free Software Foundation, either version 2 of 
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
 * along with Proview. If not, see <http://www.gnu.org/licenses/>
 *
 * Linking Proview statically or dynamically with other modules is
 * making a combined work based on Proview. Thus, the terms and 
 * conditions of the GNU General Public License cover the whole 
 * combination.
 *
 * In addition, as a special exception, the copyright holders of
 * Proview give you permission to, from the build function in the
 * Proview Configurator, combine Proview with modules generated by the
 * Proview PLC Editor to a PLC program, regardless of the license
 * terms of these modules. You may copy and distribute the resulting
 * combined work under the terms of your choice, provided that every 
 * copy of the combined work is accompanied by a complete copy of 
 * the source code of Proview (the version used to produce the 
 * combined work), being distributed under the terms of the GNU 
 * General Public License plus this exception.
 **/

37
#if defined PWRE_CONF_EPL
Claes Sjofors's avatar
Claes Sjofors committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

#include "pwr.h"
#include "rt_io_msg.h"
#include "rt_pwr_msg.h"
#include "rt_gdh.h"
#include "rt_io_base.h"
#include "rt_errh.h"
#include "rt_aproc.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"

// Test for CN build
#include "Epl.h"
tEplKernel EplApiSetCdcFilename(char* pszCdcFilename_p) 
{
  return 0;
}

pwr_tStatus io_get_plhandler_object (  
  pwr_sClass_EplHandler	**o,
  pwr_tObjid		*roid
)
{
  pwr_tStatus		sts;
  pwr_tObjid		oid;

  // Get EplHandler object
  sts = gdh_GetClassList(pwr_cClass_EplHandler, &oid);
  if (EVEN(sts)) return sts;

  sts = gdh_ObjidToPointer( oid, (void *) o);
  if (EVEN(sts)) return sts;

  if (roid != NULL)
    *roid = oid;
  return IO__SUCCESS;
}


int main() 
{
  pwr_tStatus sts;
  io_tCtx io_ctx;
  float ctime = 1;
	
  pwr_sClass_EplHandler *plhp;
  pwr_tOid oid;
	
  struct timespec tim1, tim2;
	

  // Make connection to error handler
  errh_Init("pwr_powerlink", errh_eAnix_powerlink);
  errh_SetStatus( PWR__SRVSTARTUP);

  // Make connection to realtime database
  sts = gdh_Init("rt_powerlink");
  if (EVEN(sts)) {
    errh_Fatal("rt_powerlink aborted, gdh_Init failed\n%m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(sts);
  }

  // Get Powerlink handler object
  sts = io_get_plhandler_object(&plhp, &oid);
  if (EVEN(sts)) {
    errh_SetStatus( 0);
    errh_Info("rt_powerlink terminated, no EplHandler object found");
    exit(sts);
  }
	
  // Create context and call init functions of all agent,
  // rack and cardobjects
  sts = io_init(io_mProcess_Powerlink, pwr_cNObjid, &io_ctx, 1, ctime);
  if ( EVEN(sts)) {
    errh_SetStatus( PWR__SRVTERM);
    errh_Fatal("rt_powerlink aborted, io_init() failed\n%m", sts);
    exit(sts);
  }

  tim1.tv_sec = 0;
  tim1.tv_nsec = (plhp->CycleTime)*1000000000L;
	
  aproc_TimeStamp( plhp->CycleTime, 5.0);
  errh_SetStatus( PWR__SRUN);
  aproc_RegisterObject( oid);

  // Call IoAgentRead() IoAgentWrite() IoCardRead() IoCardWrite()
  // IoModuleRead() IoModuleWrite() forever
  for (;;) {
    
    sts = io_read(io_ctx);
    sts = io_write(io_ctx); 
    nanosleep(&tim1, &tim2);
132
    aproc_TimeStamp( plhp->CycleTime, 5.0);
Claes Sjofors's avatar
Claes Sjofors committed
133 134 135
  }
}

Claes's avatar
Claes committed
136 137 138 139 140 141 142 143 144
#else

#include <stdio.h>

int main() 
{
  printf("** Not built with Powerlink\n");
}
#endif
Claes Sjofors's avatar
Claes Sjofors committed
145