嵌入式Java代码生成与分布式控制模型解析
1. 嵌入式Java代码生成基础
在嵌入式Java开发中,Ptolemy II是一个强大的工具,它可以基于模型生成代码。下面我们先来看一个低级别输入参与者(actor)的实现示例:
public class JopSerialRead extends Source {
public JopSerialRead(...) {}
private boolean firstFire = true;
private IntToken val = new IntToken(0);
// Read the input port on the first
// invocation of fire(). Send the value
// on each fire().
public void fire() {
super.fire();
if (firstFire) {
int v = readSerialPort();
val = new IntToken(v);
firstFire = false;
}
output.send(0, val);
}
// Enable read for the next fire().
public boolean postfire() {
firstFire = true;
return super.postfire();