PRIVATE void ept_insert( handle_t h, unsigned32 num_ents, ept_entry_t entries[], boolean32 replace, error_status_t *status) { epdb_handle_t epdb; ept_entry_t *entp; unsigned32 i; error_status_t tmp_st; epdb_handle_from_ohandle(h, &epdb, status); if (! STATUS_OK(status)) return; #ifndef REMOTE_ENDPOINT_ACCESS if ( is_unpriv_handle(h,&tmp_st) ) { assert(status != NULL); *status = ept_s_cant_perform_op; return; } #endif /* notdef REMOTE_ENDPOINT_ACCESS */ for (i = 0, entp = &entries[0]; i < num_ents; i++, entp++) { /* * Don't insert named pipe endpoints for the moment - there is * no client side code to support them. */ if (ept__is_ncacn_np(entp)) { /* skip */ continue; } epdb_insert(epdb, entp, replace, status); if (! STATUS_OK(status)) { if (dflag) show_st("ept_insert Unable to update endpoint database", status); ept_delete(h, i, entries, &tmp_st); return; } } }
PRIVATE void ept_mgmt_delete( handle_t h, boolean32 object_speced, uuid_p_t object, twr_p_t tower, error_status_t *status) { epdb_handle_t epdb; error_status_t tmp_st; epdb_handle_from_ohandle(h, &epdb, status); if (! STATUS_OK(status)) return; #ifndef REMOTE_ENDPOINT_ACCESS if ( is_unpriv_handle(h,&tmp_st) ) { assert(status != NULL); *status = ept_s_cant_perform_op; return; } #endif /* notdef REMOTE_ENDPOINT_ACCESS */ epdb_mgmt_delete(epdb, object_speced, object, tower, status); }
PRIVATE void ept_lookup( handle_t h, unsigned32 inquiry_type, uuid_p_t object, rpc_if_id_p_t interface, unsigned32 vers_option, ept_lookup_handle_t *entry_handle, unsigned32 max_ents, unsigned32 *num_ents, ept_entry_t entries[], error_status_t *status) { epdb_handle_t epdb; *num_ents = 0; epdb_handle_from_ohandle(h, &epdb, status); if (! STATUS_OK(status)) return; epdb_lookup(epdb, inquiry_type, object, interface, vers_option, entry_handle, max_ents, num_ents, entries, status); if (dflag) printf("ept_lookup entry_handle %p *entry_handle %p *num_ents %lu\n", entry_handle, *entry_handle, (unsigned long) *num_ents); }
PRIVATE void ept_inq_object( handle_t h, idl_uuid_t *object, error_status_t *status) { epdb_handle_t epdb; epdb_handle_from_ohandle(h, &epdb, status); if (! STATUS_OK(status)) return; epdb_inq_object(epdb, object, status); }
PRIVATE void ept_delete( handle_t h, unsigned32 num_ents, ept_entry_t entries[], error_status_t *status) { epdb_handle_t epdb; ept_entry_t *entp; unsigned32 i; error_status_t tmp_st; epdb_handle_from_ohandle(h, &epdb, status); if (! STATUS_OK(status)) return; #ifndef REMOTE_ENDPOINT_ACCESS if ( is_unpriv_handle(h,&tmp_st) ) { assert(status != NULL); *status = ept_s_cant_perform_op; return; } #endif /* notdef REMOTE_ENDPOINT_ACCESS */ for (i = 0, entp = &entries[0]; i < num_ents; i++, entp++) { epdb_delete(epdb, entp, status); if (! STATUS_OK(status)) { if (dflag) show_st("ept_delete Unable to update endpoint database", status); return; } } }
PRIVATE void ept_map( handle_t h, uuid_p_t object, twr_p_t map_tower, ept_lookup_handle_t *entry_handle, unsigned32 max_towers, unsigned32 *num_towers, twr_t *towers[], error_status_t *status) { epdb_handle_t epdb; *num_towers = 0; epdb_handle_from_ohandle(h, &epdb, status); if (! STATUS_OK(status)) return; epdb_map(epdb, object, map_tower, entry_handle, max_towers, num_towers, towers, status); #ifdef RPC_LLB if ((*status == ept_s_not_registered) || (*status == ept_s_invalid_context) || /* * If finished with ept dbase, search llb dbase */ ((*status == rpc_s_ok) && ((*num_towers < max_towers) || ((entry_handle != NULL) && (*entry_handle == NULL)) )) ) { h = lbdb_inq_handle(); lbdb_map(h, object, map_tower, entry_handle, max_towers, num_towers, towers, status); } #endif if (dflag) printf("ept_map entry_handle %p *entry_handle %p *num_towers %lu\n", entry_handle, *entry_handle, (unsigned long) *num_towers); }
INTERNAL int is_unpriv_handle( handle_t h, error_status_t *st ) { error_status_t status,status1; rpc_binding_vector_p_t bv; handle_t binding; unsigned_char_p_t stb,our_netaddr,client_netaddr; unsigned32 i; static unsigned_char_p_t *local_netaddr = NULL; static unsigned32 addr_count = 0; unsigned32 prot_seq = 0; rpc_transport_info_handle_t info; unsigned32 uid = (unsigned32) -1; unsigned32 gid = (unsigned32) -1; rpc_binding_inq_prot_seq(h, &prot_seq, &status); if (! STATUS_OK(&status)) { *st = status; return(1); } if (prot_seq == rpc_c_protseq_id_ncalrpc) { rpc_binding_inq_transport_info(h, &info, &status); if (! STATUS_OK(&status)) { *st = status; return(1); } rpc_lrpc_transport_info_inq_peer_eid(info, &uid, &gid); *st = rpc_s_ok; return (uid != 0); } /* Get client network address from binding handle (client_netaddr) */ rpc_binding_server_from_client(h,&binding,&status); if (! STATUS_OK(&status)) { *st = status; return(1); } rpc_binding_to_string_binding(binding,&stb,&status); if (! STATUS_OK(&status)) { rpc_binding_free(&binding,&status1); *st = status; return(1); } rpc_binding_free(&binding,&status1); rpc_string_binding_parse(stb,NULL,NULL,&client_netaddr,NULL,NULL,&status); if (! STATUS_OK(&status)) { rpc_string_free(&stb,&status1); *st = status; return(1); } rpc_string_free(&stb,&status1); /* * Lookup all of the addresses which this node answers to. * Cache these in static storage so we only do this work once. */ if (addr_count == 0) { rpc_server_inq_bindings(&bv,&status); if (! STATUS_OK(&status)) { rpc_string_free(&client_netaddr,&status1); *st = status; return(1); } addr_count = bv->count; local_netaddr = (unsigned_char_p_t *) malloc( (size_t) (addr_count * sizeof(unsigned_char_p_t))); if (local_netaddr == NULL) { rpc_string_free(&client_netaddr,&status1); rpc_binding_vector_free(&bv,&status1); *st = ept_s_no_memory; return(1); } for ( i=0; i < bv->count; i++ ) { rpc_binding_to_string_binding(bv->binding_h[i],&stb,&status); if (! STATUS_OK(&status)) { rpc_binding_vector_free(&bv,&status1); rpc_string_free(&client_netaddr,&status1); *st = status; return(1); } rpc_string_binding_parse(stb,NULL,NULL, &our_netaddr,NULL,NULL,&status); if (! STATUS_OK(&status)) { rpc_binding_vector_free(&bv,&status1); rpc_string_free(&stb,&status1); rpc_string_free(&client_netaddr,&status1); *st = status; return(1); } local_netaddr[i] = our_netaddr; rpc_string_free(&stb,&status1); } rpc_binding_vector_free(&bv,&status1); } /* * Compare the addresses with the client address */ *st = rpc_s_ok; for ( i=0; i < addr_count; i++ ) { if(strcmp((char*) client_netaddr, (char*) local_netaddr[i]) == 0) { rpc_string_free(&client_netaddr,&status1); return(0); } } rpc_string_free(&client_netaddr,&status1); return(1); }
int acqMdsPutTCData(TCMDS_INFO *tcmds, int mode) { int _null = 0; int status; int dtype_Double = DTYPE_DOUBLE; int dtype_Short = DTYPE_SHORT; int dtype_ULong = DTYPE_ULONG; int rawDataDesc; int rateDesc, startDesc, endDesc, voltageTDesc; int id_end_Desc; int i, j, k; int slot; FILE *fpRaw = NULL; int nTrueSampleCnt = 0; int nTrueSampleCnt_1; double fVpp10_16bit; double fStartTime; double fEndTime; double fRealTimeGap; int mdsSock; int shot = tcmds->shot; long totalCnt; FILE *fp; char szTemp[256]; int reConn = 0; char tempNode[200]; double *getData = NULL; nTrueSampleCnt = (tcmds->t1 - tcmds->t0) * 10; getData = (double *)malloc(sizeof(double)*nTrueSampleCnt); while(1) { if(mode == 1) { /* KSTAR MDS */ mdsSock = MdsConnect("172.17.100.202:8000"); } else if(mode == 0) { /* LOCAL MDS */ mdsSock = MdsConnect("172.17.121.244:8000"); } if(mdsSock == -1) { printf("--- MDS Connect Faile Reconnect [%d] ---\n", reConn); if(reConn >= 3) return -1; else reConn++; } else { break; } } reConn = 0; while(1) { if(mode == 1) /* KSTAR MDS */ status = MdsOpen("HEATING", &shot); else if(mode == 0) /* LOCAL MDS */ status = MdsOpen("nbi1", &shot); if ( !STATUS_OK(status) ) { epicsThreadSleep(0.1); fprintf(stderr,"Error opening tree for shot %d.\n",shot); printf("%s\n", MdsGetMsg(status)); if(reConn >= 3) return -1; else reConn++; } else { break; } } fStartTime = tcmds->t0; fEndTime = nTrueSampleCnt + fStartTime; fRealTimeGap = 1.0 / 10.0; nTrueSampleCnt_1 = nTrueSampleCnt - 1; rateDesc = descr(&dtype_Double, &fRealTimeGap, &_null); startDesc = descr(&dtype_Double, &fStartTime, &_null); endDesc = descr(&dtype_Double, &fEndTime, &_null); voltageTDesc = descr(&dtype_Double, &fVpp10_16bit, &_null); id_end_Desc = descr(&dtype_ULong, &nTrueSampleCnt_1, &_null); double read_data[nTrueSampleCnt*MAX_CARD_NUM]; double raw_data[TC_MAX_CH][nTrueSampleCnt]; for(slot=0; slot < MAX_CARD_NUM; slot++) { int ind = 0; int inc = 0; sprintf(szTemp, "/tmp/tc_%d_%d.dat", tcmds->card, slot); fp = fopen(szTemp, "r"); fread(&read_data[0], sizeof(double)*tcmds->t1*MAX_CARD_NUM*8, 1, fp); fclose(fp); for(i=0; i < tcmds->t1; i++) { for(j=0; j < TC_MAX_CH; j++) { for(k=0; k < 10; k++) { raw_data[j][k+ind] = read_data[k+inc]; } inc += 10; } ind += 10; } for(i=0; i < TC_MAX_CH; i++) { printf("TC MDS NODE : [%s]\n", tcmds->mdsinfo[slot][i].node); memcpy(getData, &raw_data[i], sizeof(double)*nTrueSampleCnt); rawDataDesc = descr(&dtype_Double, getData, &nTrueSampleCnt, &_null); if( tcmds->mdsinfo[slot][i].mdsput != 0) { sprintf(tempNode, "\\%s", tcmds->mdsinfo[slot][i].node); if(mode == 1) { /* KSTAR MDS */ status = MdsPut(tempNode, "BUILD_SIGNAL(BUILD_WITH_UNITS($,\"V\"),,MAKE_DIM(MAKE_WINDOW($,$,$),MAKE_SLOPE(MAKE_WITH_UNITS($,\"s\"))))", &rawDataDesc, &startDesc, &endDesc, &rateDesc, &rateDesc, &_null); } else if(mode == 0) { /* LOCAL MDS */ status = MdsPut(tempNode , "BUILD_SIGNAL(BUILD_WITH_UNITS($,\"V\"),,MAKE_DIM(MAKE_WINDOW(0,$,$),MAKE_SLOPE(MAKE_WITH_UNITS($,\"s\"))))", &rawDataDesc, &id_end_Desc, &startDesc, &rateDesc, &_null); } if(!((status) & 1)) { printf("MdsPut Error --> node [%s]\n", tcmds->mdsinfo[slot][i].node); } } } } if(mode == 1) /* KSTAR MDS */ status = MdsClose("HEATING", &shot); else if(mode == 0) /* LOCAL MDS */ status = MdsClose("nbi1", &shot); MdsDisconnect(mdsSock); free(getData); getData = NULL; printf("--- TC MDSPlus Data Put OK ---\n"); return 0; }
/***************************************************************************** 函 数 名: fan_power_scan_handler 功能描述: 风扇以及电源使用检测事件 输入参数: user_ctx ---- 存储电源和风扇状态的相关结构体 输出参数: 无 返 回 值: 无 ----------------------------------------------------------------------------- 最近一次修改记录: 修改作者: Fuzhiqing 修改目的: 新增函数 修改日期: 2009-08-19 *****************************************************************************/ void fan_power_scan_handler(void *user_ctx) { s32 ret; /*风扇使用检测*/ { int fanNum; entIndex_s ent_index; static s32 *status = NULL, cur_status; ret = sys_read_fan_num(&fanNum); if(ret != ERROR_SUCCESS) { return; } if(fanNum > 0) { int i; if (NULL == status) { status = (s32*)malloc(fanNum * sizeof(s32)); if (NULL == status) { return; /* 算了,不报错了 */ } for (i = 0; i < fanNum; i++) { status[i] = -1;/* 刚分配时置为无效值 */ } } for(i = 0; i < fanNum; i++) { ret = sys_read_fan_status(i, &cur_status); if(ERROR_SUCCESS != ret) { continue; } /* 判断与上次对照是否发生了插入或拔出风扇的操作,并发出相应系统日志 */ if (STATUS_ABSENT(status[i]) && STATUS_EXISTING(cur_status)) { syslogex_syslog_send("SYSM",LOG_NOTICE|LOG_USER, FAN_WAS_INPUT,i); } /* 风扇异常状态告警 */ if(cur_status == POWER_STATUS_ERROR) { syslogex_syslog_send("SYSM",LOG_WARNING|LOG_USER, FAN_WORKING_ERROR,i); ent_index.entclass = ENT_CLASS_FAN; ent_index.ent_num = i; mib_get_ent_index(&ent_index); trap_ipc_EntityAbnormal(ent_index.index,TRAP_ID_DPTECHDEVICEENTITYCROSSFAN_ABNORMAL); } if (STATUS_EXISTING(status[i]) && STATUS_ABSENT(cur_status)) { syslogex_syslog_send("SYSM",LOG_NOTICE|LOG_USER, FAN_WAS_DRAWN,i); } status[i] = cur_status; /* 更新风扇状态 */ } } } /*电源使用检测*/ { int powerNum; int i; static s32 *status = NULL, cur_status; entIndex_s ent_index; ret = sys_read_board_info(DRV_DEV_BOARD_POWER_NUM, &powerNum, sizeof(powerNum)); if(ret != ERROR_SUCCESS) { return; } if(powerNum > 0) { if (NULL == status) { status = (s32*)malloc(powerNum * sizeof(s32)); if (NULL == status) { return; /* 算了,不报错了 */ } for (i = 0; i < powerNum; i++) { status[i] = -1;/* 刚分配时置为无效值 */ } } for(i = 0; i < powerNum; i++) { ret = sys_read_power_status(i, &cur_status); if(ret != ERROR_SUCCESS) { continue; } /* 判断与上次对照是否发生了插入或拔出电源的操作,并发出相应系统日志 */ if (STATUS_ABSENT(status[i]) && STATUS_EXISTING(cur_status)) { syslogex_syslog_send("SYSM",LOG_NOTICE|LOG_USER, POWER_WAS_INPUT,i); } if(STATUS_ERROR(cur_status)) { five_minute += DETECT_MEM_USAGE_CYCLE; if(five_minute == DETECT_PART_USAGE_CYCLE) { syslogex_syslog_send("SYSM",LOG_WARNING|LOG_USER, POWER_WORKING, i); /* 每五分钟发送一次告警*/ five_minute = 0; } if(STATUS_OK(status[i])) { ent_index.entclass = ENT_CLASS_POWERSUPPLY; ent_index.ent_num = i; mib_get_ent_index(&ent_index); trap_ipc_EntityAbnormal(ent_index.index,TRAP_ID_DPTECHDEVICEENTITYCROSSPOWER_ABNORMAL); } } if (STATUS_EXISTING(status[i]) && STATUS_ABSENT(cur_status)) { syslogex_syslog_send("SYSM",LOG_NOTICE|LOG_USER, POWER_WAS_DRAWN,i); } if (STATUS_ERROR(status[i]) && STATUS_OK(cur_status)) { syslogex_syslog_send("SYSM",LOG_NOTICE|LOG_USER, POWER_WAS_RESUME,i); ent_index.entclass = ENT_CLASS_POWERSUPPLY; ent_index.ent_num = i; mib_get_ent_index(&ent_index); trap_ipc_EntityAbnormal(ent_index.index,TRAP_ID_DPTECHDEVICEENTITYCROSSPOWER_NORMAL); } status[i] = cur_status; /* 更新电源状态 */ } } } /*重新设置定时器*/ dloop_register_timeout(DETECT_MEM_USAGE_CYCLE, 0, fan_power_scan_handler, NULL); }