void On_simulation_begin() //************************ // VMLAB informs you that the simulation is starting. Initialize pin values // here Open files; allocate memory, etc. // Although the log filename doesn't change with each simulation, it's better to // open it here and close it in On_simulation_end(). This allows the user to // delete or move the log file without having to close or rebuild the project. { char strBuffer[MAXBUF]; // Initialize per instance simulation variables. VAR(Clock_delay) = 0; VAR(Log_time) = 0; VAR(Log_data) = 0; // Create or overwrite log file in current directory snprintf(strBuffer, MAXBUF, "%s.log", GET_INSTANCE()); VAR(File) = fopen(strBuffer, "w"); // We can still run if the file won't open; we just can't log anything if(!VAR(File)) { snprintf(strBuffer, MAXBUF, "Could not create \"%s.log\" file: %s", GET_INSTANCE(), strerror(errno)); BREAK(strBuffer); } }
UINT JoyPad_Frame(ENUM_JOYPAD _Key,BYTE _Num) { switch(_Key) { default: return -1; break; case JOYKEY_BUTTON: return (GET_INSTANCE(NatsumeGrass::System::InputClass))->Joy_Button_Frame(_Num); break; case JOYKEY_POV: return (GET_INSTANCE(NatsumeGrass::System::InputClass))->Joy_Pov_Frame(_Num); break; } }
void init() { TopologySystemInformationOptions & o = getOptions<TopologySystemInformationOptions>(); topology = GET_INSTANCE(Topology, o.topology); assert(topology); TopologyObject ontologyTopologyObject = topology->registerObjectByPath( {{"ModuleName", "SystemInformationIDManager", "Module"}} ); pluginTopoObjectID = ontologyTopologyObject.id(); TopologyTypeId systemInfoID = topology->registerType("SystemInformation").id(); hostID = topology->registerType("Host").id(); deviceID = topology->registerType("Device").id(); fsID = topology->registerType("Filesystem").id(); interfaceID = topology->registerType("Interface").id(); activityID = topology->registerType("Activity").id(); attrNameID = topology->registerAttribute( systemInfoID, "Name", VariableDatatype::Type::STRING ).id(); attrInterfaceNameID = topology->registerAttribute( systemInfoID, "Interface", VariableDatatype::Type::STRING ).id(); attrImplementationNameID = topology->registerAttribute( systemInfoID, "Implementation", VariableDatatype::Type::STRING ).id(); attrNodeID = topology->registerAttribute( systemInfoID, "Node", VariableDatatype::Type::UINT32 ).id(); attrUNIDID = topology->registerAttribute( systemInfoID, "UNID", VariableDatatype::Type::UINT32 ).id(); attrDeviceNameID = topology->registerAttribute( systemInfoID, "LocalName", VariableDatatype::Type::STRING ).id(); attrFSNameID = topology->registerAttribute( systemInfoID, "GlobalName", VariableDatatype::Type::STRING ).id(); }
void ReasonerStandardImplementation::start(){ ReasonerStandardImplementationOptions & options = getOptions<ReasonerStandardImplementationOptions>(); StatisticsCollector * statColl = GET_INSTANCE(StatisticsCollector, options.statisticsCollector); if ( statColl != nullptr ){ // request everything we'll need. nodeStatistics = StatisticsCollection::makeCollection(statColl, {{ {"utilization/cpu", "@localhost"}, {"utilization/memory", "@localhost"}, // Alternative: {"utilization/memory/vm", "@localhost"}, {"utilization/io", "@localhost"}, {"utilization/network/send", "@localhost"}, {"utilization/network/receive", "@localhost"}, {"time/cpu/UnhaltedConsumed", "@localhost"}, // CONSUMED_CPU_SECONDS // #ifdef ENABLE_LIKWID_POWER {"energy/Socket/rapl", "@localhost"}, // you may replace this with utilization/cpu to make it runnable :-) // #else //{"utilization/cpu", "@localhost"}, // stupid replacement for the energy metric... // #endif ENABLE_LIKWID_POWER {"utilization/memory", "@localhost"}, // CONSUMED_MEMORY_BYTES // If likwid is used to observe the memory throughput the correct counter could be used: //{"quantity/memory/volume", "@localhost"}, // CONSUMED_MEMORY_BYTES {"quantity/network/volume", "@localhost"}, // CONSUMED_NETWORK_BYTES {"quantity/io/volume", "@localhost"}, // CONSUMED_IO_BYTES }}, true); } comm = new ReasonerCommunication(*this); comm->init( options.communicationOptions ); periodicThread = thread( & ReasonerStandardImplementation::PeriodicRun, this ); Reasoner::start(); }
void On_simulation_begin() //************************ // VMLAB informs you that the simulation is starting. Initialize pin values // here Open files; allocate memory, etc. // The first instance to enter this function is responsible for opening the // single log file and initializing any global data. Although the log filename // doesn't change with each simulation, it's better to open it here and close it // in On_simulation_end(). This allows the user to delete or move the log file // without having to close or rebuild the project. { char strBuffer[MAXBUF]; // Force the initial value of data input to be logged at time step 0 VAR(Log_data) = -1; // Keep track of how many instances have already been created VAR(Instance_number) = Instance_count; Instance_count++; // Because the VCD file format uses a single ASCII character to identify each // signal, it limits the number of vcdlog instances that can be used in a // project if(VAR(Instance_number) + MIN_ID > MAX_ID) { snprintf(strBuffer, MAXBUF, "Too many instances (max %d)", MAX_ID - MIN_ID + 1); BREAK(strBuffer); Close_file(); } // The first instance to have its On_simulation_begin() called is responsible // for opening the log file and initializing global variables. if(Instance_count == 1) { Total_time = 0; // Setting Log_time to -1 forces the first instance entering // On_time_step(), to finish writing the VCD header section. Log_time = -1; // Create or overwrite log file in current directory File = fopen(FILE_NAME, "w"); // We can still run if the file won't open; we just can't log anything. if(!File) { snprintf(strBuffer, MAXBUF, "Could not create \"%s\" file: %s", FILE_NAME, strerror(errno)); BREAK(strBuffer); } // Write out the global VCD file header Log_printf("$version VMLAB vcdlog component $end\n"); Log_printf("$timescale 1 %s $end\n", TIME_UNITS); Log_printf("$scope module vmlab $end\n"); } // Write out per instance part of the VCD header that contains the variable // name and the ASCII identifier. Log_printf("$var wire 1 %c %s $end\n", VAR(Instance_number) + MIN_ID, GET_INSTANCE()); }
void load_gravity_well (BYTE selector) { COUNT i; RES_TYPE rt; RES_INSTANCE ri; RES_PACKAGE rp; MEM_HANDLE hLastIndex; hLastIndex = SetResourceIndex (hResIndex); if (selector == NUMBER_OF_PLANET_TYPES) { planet[0] = CaptureDrawable ( LoadGraphic (SAMATRA_BIG_MASK_PMAP_ANIM) ); planet[1] = planet[2] = 0; } else { if (selector & PLANET_SHIELDED) { rt = GET_TYPE (SHIELDED_BIG_MASK_PMAP_ANIM); ri = GET_INSTANCE (SHIELDED_BIG_MASK_PMAP_ANIM); rp = GET_PACKAGE (SHIELDED_BIG_MASK_PMAP_ANIM); } else { rt = GET_TYPE (PLANET00_BIG_MASK_PMAP_ANIM); ri = GET_INSTANCE (PLANET00_BIG_MASK_PMAP_ANIM) + (selector * NUM_VIEWS); rp = GET_PACKAGE (PLANET00_BIG_MASK_PMAP_ANIM) + selector; } for (i = 0; i < NUM_VIEWS; ++i, ++ri) { planet[i] = CaptureDrawable ( LoadGraphic (MAKE_RESOURCE (rp, rt, ri)) ); } } SetResourceIndex (hLastIndex); }
//色付き箱の表示 HRESULT CreateBox(CustomSquare _Obj,DWORD _Color ) { NatsumeGrass::System::Polygon_2D *PolInstance; PolInstance = GET_INSTANCE(NatsumeGrass::System::Polygon_2D); PolInstance->CreateSquare(_Obj.x,_Obj.y,_Obj.Height,_Obj.Width,_Color); return S_OK; }
void On_simulation_begin() //************************ // VMLAB informs you that the simulation is starting. Initialize pin values // here Open files; allocate memory, etc. // Although the wav filename doesn't change with each simulation, it's better to // open it here and close it in On_simulation_end(). This allows the user to // delete or move the log file without having to close or rebuild the project. { char strBuffer[MAXBUF]; // Open existing wav file in current directory. The libsndfile API requires // the SF_INFO.format field set to 0 before opening a file for read access. VAR(File_info).format = 0; snprintf(strBuffer, MAXBUF, "%s.wav", GET_INSTANCE()); VAR(File) = sf_open(strBuffer, SFM_READ, &VAR(File_info)); // We can still run if the file won't open; output stays at POWER()/2. if(!VAR(File)) { snprintf(strBuffer, MAXBUF, "Could not open \"%s.wav\" file: %s", GET_INSTANCE(), sf_strerror(VAR(File))); BREAK(strBuffer); return; } // If the WAV file contains more than one channel, print an error mssage // that the additional channels will be ignored. if(VAR(File_info).channels != 1) { snprintf(strBuffer, MAXBUF, "File \"%s.wav\" has multiple channels; " "only first (left) channel used", GET_INSTANCE()); PRINT(strBuffer); } // Allocate buffer large enough to hold a single sample across all the // channels. The libsndfile library requires that all the channels are read // at once, and it provides no way to ignore unwanted channels. VAR(Sample_buffer) = (double *) malloc(sizeof(double) * VAR(File_info).channels); if(!VAR(Sample_buffer)) { BREAK("Error allocating memory buffer"); Close_file(); return; } }
HRESULT EndRender() { //画面に描画を行います。 if(FAILED( ( GET_INSTANCE(NatsumeGrass::System::NatsumeManager) )->EndRender() )) { Error("NatsumeGrass::Draw EndRender Error"); return E_FAIL; } return S_OK; }
HRESULT BeginRender() { //画面クリアと if( FAILED( ( GET_INSTANCE(NatsumeGrass::System::NatsumeManager) )->ClearRender() ) ) { Error("NatsumeGrass::Draw Clear Error"); return E_FAIL; } //BeginRenderを呼び出します。 if(FAILED( ( GET_INSTANCE(NatsumeGrass::System::NatsumeManager) )->BeginRender() ) ) { Error("NatsumeGrass::Draw BeginRender Error"); return E_FAIL; } return S_OK; }
LONG JoyPad_Stick(ENUM_JOYPAD _Stick) { switch(_Stick) { default: return -1; break; case JOYSTICK_LEFT_X: return (GET_INSTANCE(NatsumeGrass::System::InputClass))->Joy_StickLeftX(); break; case JOYSTICK_LEFT_Y: return (GET_INSTANCE(NatsumeGrass::System::InputClass))->Joy_StickLeftY(); break; case JOYSTICK_RIGHT_X: return (GET_INSTANCE(NatsumeGrass::System::InputClass))->Joy_StickRightX(); break; case JOYSTICK_RIGHT_Y: return (GET_INSTANCE(NatsumeGrass::System::InputClass))->Joy_StickRightY(); break; } }
HRESULT Initialize(HINSTANCE _hInstance) { CREATE_SINGLETON_INSTANCE(System::NatsumeManager); if(FAILED( (GET_INSTANCE(System::NatsumeManager))->Initialize(_hInstance) )) { return E_FAIL; } return S_OK; }
void ReasonerCommunication::init(ReasonerCommunicationOptions & options){ CommunicationModule * comm = GET_INSTANCE(CommunicationModule, options.comm); assert(comm != nullptr); this->reasonerID = options.reasonerID; // spawn the server upon which we receive the remote status of different nodes. if ( options.serviceAddress != "" ){ server = comm->startServerService(options.serviceAddress, this); } if ( options.upstreamReasoner != "" ){ upstreamReasoner = comm->startClientService( options.upstreamReasoner, this, this ); } }
void main (void){ timer= newObj(Timer,(ulong)500); /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ Teclas_Init(); Display_Init(); // Inicializacion del display Grabacion_Init(); newAllocObj(&mainThread,ThreadAdjuntable); cap=GET_INSTANCE(); #ifdef _ENTRADA_SIMULADA CapturadorSimulado_setMicroSegundos(cap,100000000); CapturadorSimulado_setPulsos(cap,2); #endif { void * adjuntador= ThreadAdjuntable_getAdjuntador(&mainThread); newAllocObj(&sensorRpm,SensorRpm,adjuntador,1000,cap,&config,"SEn rPM"); deleteObj(&adjuntador); } for(;;){ WDog1_Clear(); if(Timer_isfinish(timer)){ Timer_Restart(timer); _GetterPrint(&sensorRpm,1); // Pasar_Numero(Capturador_getMicroSegundos(cap)/1000,0,0); // Pasar_Numero(Capturador_getPulsos(cap),1,0); // CapturadorSimulado_setPulsos(cap,CapturadorSimulado_getPulsos(cap)+1); } //Eventos MethodContainer_Execute(&mainThread); } }
void Close_file(void) //******************** // Close the wav file, and check for any I/O errors that can occur when // closing the file. { char strBuffer[MAXBUF]; // Do nothing if the wav file is already closed if(!VAR(File)) { return; } // Close the wav file so it can be moved or deleted if(sf_close(VAR(File))) { snprintf(strBuffer, MAXBUF, "Error closing \"%s.wav\" file: %s", GET_INSTANCE(), sf_strerror(VAR(File))); BREAK(strBuffer); } VAR(File) = NULL; }
void On_remind_me(double pTime, int pData) //*************************************** // VMLAB notifies about a previouly sent REMIND_ME() function. // Read the next voltage sample from the WAV file, set the analog voltage on the // output pin, and schedule another output update based on the sampling rate of // the input wav file. { char strBuffer[MAXBUF]; // Do nothing if the wav file is closed due to an error if(!VAR(File)) { return; } // Read the next voltage sample from the wav file. If an error occurs or // EOF is reached, then the wav file is closed, the output voltage remains // set to the previous value and no more output updates are scheduled. if(sf_readf_double(VAR(File), VAR(Sample_buffer), 1) != 1) { // Break with an error message if an actual I/O or decode error occurred if(sf_error(VAR(File))) { snprintf(strBuffer, MAXBUF, "Error reading \"%s.wav\" file: %s", GET_INSTANCE(), sf_strerror(VAR(File))); BREAK(strBuffer); } // Close the file on either an error or a normal end-of-file Close_file(); return; } // The voltage in VMLAB ranges from 0 to POWER(), while the sample that // libsndfile returns ranges from -1 to +1. Only the sample from the // first (left) channel is used here. Samples from additional channels // are simply discarded. SET_VOLTAGE(DATA, (*VAR(Sample_buffer) + 1) * 0.5 * POWER()); // Schedule the next On_remind_me() based on the sampling rate REMIND_ME(1.0 / VAR(File_info).samplerate); }
void Write_log(double pTime) //******************** // If the elapsed time "pTime" of the current time step is different from the // previous time step at "VAR(Log_time)" then write a log entry for the previous // time step. Because On_digital_in_edge() may be called multiple times for the // same time step, we want to delay writing any log entry until we know the time // step has been fully simulated. { char strBuffer[MAXBUF]; double logCycle; // Do nothing if log file could not be opened or if the next time step has // not been reached yet. if(!VAR(File) || pTime == VAR(Log_time)) { return; } // The elapsed time (in seconds) is converted to a cycle count based on the // MCU's clock rate (specified as a parameter). The "- VAR(offset)" subtracts // out the initial power on delay from the cycle count. Also, to avoid any // floating point round off errors, the fprintf() is used to round up the // result to the closest integer instead of using an integer cast. logCycle = (VAR(Log_time) - VAR(Clock_delay)) / VAR(Clock_period); fprintf(VAR(File), "%09.0lf:%02X\n", logCycle, VAR(Log_data)); // If any errors occur with writing the file, then break with an error // message and close the file to prevent any further logging. if(ferror(VAR(File))) { snprintf(strBuffer, MAXBUF, "Could not write \"%s.log\" file: %s", GET_INSTANCE(), strerror(errno)); BREAK(strBuffer); Close_file(); } // Record current time so next log entry isn't written until next time step VAR(Log_time) = pTime; }
void main (void){ char tecla; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ newAlloced(&plataforma,&PlataformaEmbedded); Teclas_Init(); Display_Init(); // Inicializacion del display com_initialization(&arrayNodosComunicacion); add1msListener(_new(&Method,on1ms,0)); add40msListener(_new(&Method,on40ms,0)); newAlloced(&mainThread,&ThreadAdjuntable); cap=GET_INSTANCE(); #ifdef _ENTRADA_SIMULADA CapturadorSimulado_setMicroSegundos(cap,100000000); CapturadorSimulado_setPulsos(cap,2); #endif { void * adjuntador= ThreadAdjuntable_getAdjuntador(&mainThread); newAlloced(&sensorRpm,&SensorRpm,adjuntador,1000,cap,&config,"SEn rPM"); _delete(adjuntador); } newAlloced(&pwm,&PWMTimer,&pwm_config,0); newAlloced(&pid,ControlPID,&pid_config,&sensorRpm,&pwm); newAlloced(&msj[0],MessageOut); #ifndef HD90 PID_AddOnTSalChange(&pid,OnTSalChange,NULL); #endif /* DN_Init(&CBox_Pri); Sets_Init(); PWM_Hmi_Add(&pwm,0); SenRpmHmi_Add(&sensorRpm,0); PidHmi_AddBoxes(&pid,0); // PidHmi_AddBoxes(&pid,2); // PidHmi_AddBoxes(&pid,3); Sets_AddBoxes(); */ DN_staticInit(&OpList,&AccessList); setConectada(&pwm,TRUE); LedsSalida_init(&ledsSalida); for(;;){ WDog1_Clear(); tecla=get_key(); //Eventos MethodContainer_execute(&mainThread); mainLoop(&plataforma); DN_Proc(tecla); } }
//テクスチャの読み込み INT LoadTexture(LPCSTR _GraphicLocation) { return (GET_INSTANCE(NatsumeGrass::System::TextureClass))->LoadTexture(_GraphicLocation); }
bool Texture::_loadTexture(const char *path, bool resist) { if (!FileSystem::getInstance().isFileExists(path)) { DBGLog("Texture file '%s' does not exist.\n", path); return false; } if (mLoaded) { unload(); _freeTextureData(true); } bool loaded = false; mResist = resist; mPath = path; ImageParserBase *imgParser = NULL; File *imgFile = new File(path); imgFile->load(); HG_BREAK_BEG; imgParser = GET_INSTANCE(ImageParserManager).getParserForPath(path); if (imgParser == NULL) break; if (imgParser->parse((char *)imgFile->getData(), imgFile->getSize()) == 0) { DBGLog("unable to parse texture '%s'\n", path); break; } if (mTextureData != NULL) delete [] mTextureData; mTextureData = new uchar[imgParser->getSize()]; memcpy(mTextureData, imgParser->getImageData(), imgParser->getSize()); mTextureDataSize = imgParser->getSize(); mWidth = imgParser->getWidth(); mHeight = imgParser->getHeight(); mMipmapLevel = 0; switch (imgParser->getPixelLayout()) { case TexturePixelLayout_RGBA8888: mBPP = 4; mFormat = GL_RGBA; mType = GL_UNSIGNED_BYTE; break; case TexturePixelLayout_RGB888: mBPP = 3; mFormat = GL_RGB; mType = GL_UNSIGNED_BYTE; break; case TexturePixelLayout_RGB565: mBPP = 2; mFormat = GL_RGB; mType = GL_UNSIGNED_SHORT_5_6_5; break; case TexturePixelLayout_RGBA4444: mBPP = 2; mFormat = GL_RGBA; mType = GL_UNSIGNED_SHORT_4_4_4_4; break; case TexturePixelLayout_RGBA5551: mBPP = 2; mFormat = GL_RGBA; mType = GL_UNSIGNED_SHORT_5_5_5_1; break; case TexturePixelLayout_Gray: mBPP = 0; // TODO mFormat = GL_LUMINANCE; mType = GL_UNSIGNED_BYTE; break; case TexturePixelLayout_GrayAlpha: mBPP = 0; // TODO mFormat = GL_LUMINANCE_ALPHA; mType = GL_UNSIGNED_BYTE; break; default: break; } loaded = true; HG_BREAK_END; DBGLog("Texture '%s' loaded (w:%d h:%d bpp:%d size:%d)\n", path, mWidth, mHeight, mBPP, (int)mTextureDataSize); if (imgParser != NULL) delete imgParser; if (imgFile != NULL) delete imgFile; return loaded; }
void Play(UINT _Key) { (GET_INSTANCE(NatsumeGrass::System::NatsumeSound))->SoundPlay(_Key); }
void Stop(UINT _Key) { (GET_INSTANCE(NatsumeGrass::System::NatsumeSound))->SoundStop(_Key); }
UINT LoadSound(TCHAR *_FileName) { return ( (GET_INSTANCE(NatsumeGrass::System::NatsumeSound))->SoundDataLoad(_FileName) ); }
//テクスチャの表示 HRESULT DrawTexture(INT _TextureKey,CustomSquare _Square,BOOL _AlphaUse,BYTE _AlphaColor) {//(引数2つver) return (GET_INSTANCE(NatsumeGrass::System::TextureClass) )->DrawTexture(_TextureKey,_Square,_AlphaUse,_AlphaColor); }
HRESULT DrawTexture(INT _TextureKey,float _x,float _y,float _Height,float _Width,BOOL _AlphaUse,BYTE _AlphaColor) {//(引数複数ver) CustomSquare _Square = CustomSquare(_x,_y,_Height,_Width); return (GET_INSTANCE(NatsumeGrass::System::TextureClass) )->DrawTexture(_TextureKey,_Square,_AlphaUse,_AlphaColor); }
UINT KeyCheckFrame(BYTE _DIK_) { return ( (GET_INSTANCE(NatsumeGrass::System::InputClass) )->KeyCheckFrame(_DIK_) ); }
//入力インターフェースのアップデート HRESULT UpdateAcquire() { return (GET_INSTANCE(NatsumeGrass::System::InputClass) )->Acquire(); }