?? sensor_init.cpp
字號(hào):
// 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(4, y, 10); // Send measurement (10 bytes) to node 4 (controller) return 0.0004; case 3: return FINISHED; }}double msgRcvhandler(int seg, void *data){ printf("ERROR: sensor received a message!\n"); return FINISHED;}void init(){ // Initialize TrueTime kernel ttInitKernel(1, 0, FP); // 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(3, "msgRcv"); // node #3 in the network}void cleanup() {}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -