⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sensor_init.cpp

📁 使用TRUETIME仿真软件编写的关于分布式实时控制系统的仿真程序
💻 CPP
字号:
// Distributed control system: sensor node//// Samples the plant periodically and sends the samples to the // controller node.#define S_FUNCTION_NAME sensor_init#include "ttkernel.cpp"// code functiondouble sensor_code(int seg, void *data) {  static double *y;  switch (seg) {  case 1:    y = new double;    *y = ttAnalogIn(1);    return 0.0005;  case 2:    ttSendMsg(3, y, 80); // Send measurement (80 bits) to node 3 (controller)    return 0.0004;  case 3:    return FINISHED;  }  return FINISHED; // to supress compilation warnings}double msgRcvhandler(int seg, void *data){  printf("ERROR: sensor received a message!\n");  return FINISHED;}void init(){  // Initialize TrueTime kernel  ttInitKernel(1, 0, prioFP); // nbrOfInputs, nbrOfOutputs, fixed priority  // Sensor task  double offset = 0.0;  double period = 0.010;  double prio = 1.0;  ttCreatePeriodicTask("sensor_task", offset, period, prio, sensor_code);  // Initialize network  ttCreateInterruptHandler("msgRcv", prio, msgRcvhandler);  ttInitNetwork(4, "msgRcv"); // node #4 in the network}void cleanup() {}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -