added distance to network message
This commit is contained in:
parent
409c4fb411
commit
f7c320c123
@ -34,7 +34,7 @@ class KernelEvents {
|
|||||||
channel:Int,
|
channel:Int,
|
||||||
replyChannel:Int,
|
replyChannel:Int,
|
||||||
message:Dynamic,
|
message:Dynamic,
|
||||||
distance:Int
|
distance:Null<Float>
|
||||||
}>;
|
}>;
|
||||||
public final onMonitorResize:Signal<String>;
|
public final onMonitorResize:Signal<String>;
|
||||||
public final onMonitorTouch:Signal<{addr:String, pos:Pos}>;
|
public final onMonitorTouch:Signal<{addr:String, pos:Pos}>;
|
||||||
@ -71,7 +71,7 @@ class KernelEvents {
|
|||||||
channel:Int,
|
channel:Int,
|
||||||
replyChannel:Int,
|
replyChannel:Int,
|
||||||
message:Dynamic,
|
message:Dynamic,
|
||||||
distance:Int
|
distance:Null<Float>
|
||||||
}> = Signal.trigger();
|
}> = Signal.trigger();
|
||||||
private final onMonitorResizeTrigger:SignalTrigger<String> = Signal.trigger();
|
private final onMonitorResizeTrigger:SignalTrigger<String> = Signal.trigger();
|
||||||
private final onMonitorTouchTrigger:SignalTrigger<{addr:String, pos:Pos}> = Signal.trigger();
|
private final onMonitorTouchTrigger:SignalTrigger<{addr:String, pos:Pos}> = Signal.trigger();
|
||||||
|
@ -13,5 +13,5 @@ interface INetworkInterface {
|
|||||||
public function send(chan: Int,replyChan: Int,payload: Any):Void;
|
public function send(chan: Int,replyChan: Int,payload: Any):Void;
|
||||||
public function name():String;
|
public function name():String;
|
||||||
public function getBaseRoutingCost():Int;
|
public function getBaseRoutingCost():Int;
|
||||||
public var onMessage (default, null): Signal<Package>;
|
public var onMessage (default, null): Signal<{pack:Package,?dist:Float}>;
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ using tink.CoreApi;
|
|||||||
class Loopback implements INetworkInterface {
|
class Loopback implements INetworkInterface {
|
||||||
public static final instance:Loopback = new Loopback();
|
public static final instance:Loopback = new Loopback();
|
||||||
|
|
||||||
public var onMessage(default, null):Signal<Package>;
|
public var onMessage(default, null):Signal<{pack:Package,dist:Null<Float>}>;
|
||||||
|
|
||||||
private final onMessageTrigger: SignalTrigger<Package> = Signal.trigger();
|
private final onMessageTrigger: SignalTrigger<{pack:Package,dist:Null<Float>}> = Signal.trigger();
|
||||||
private var openChans: Array<Int> = [];
|
private var openChans: Array<Int> = [];
|
||||||
|
|
||||||
private function new() {
|
private function new() {
|
||||||
@ -38,7 +38,7 @@ class Loopback implements INetworkInterface {
|
|||||||
|
|
||||||
public function send(chan:Int, replyChan:Int, payload:Any) {
|
public function send(chan:Int, replyChan:Int, payload:Any) {
|
||||||
if (this.openChans.contains(chan)){
|
if (this.openChans.contains(chan)){
|
||||||
this.onMessageTrigger.trigger(payload);
|
this.onMessageTrigger.trigger({pack:payload,dist:null});
|
||||||
}else{
|
}else{
|
||||||
Log.silly("Loopback got package on non open channel");
|
Log.silly("Loopback got package on non open channel");
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class Net {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function setupInterf(interf: INetworkInterface) {
|
private function setupInterf(interf: INetworkInterface) {
|
||||||
interf.onMessage.handle(pack -> handle(pack,interf));
|
interf.onMessage.handle(e -> handle(e.pack,interf,e.dist));
|
||||||
interf.listen(networkID);
|
interf.listen(networkID);
|
||||||
interf.listen(BRODCAST_PORT);
|
interf.listen(BRODCAST_PORT);
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ class Net {
|
|||||||
/**
|
/**
|
||||||
Called when a new package comes in.
|
Called when a new package comes in.
|
||||||
**/
|
**/
|
||||||
private function handle(pack:Package,interf: INetworkInterface) {
|
private function handle(pack:Package,interf: INetworkInterface, ?dist: Float) {
|
||||||
if (pack.toID == this.networkID || pack.toID == Net.BRODCAST_PORT){
|
if (pack.toID == this.networkID || pack.toID == Net.BRODCAST_PORT){
|
||||||
switch pack.type {
|
switch pack.type {
|
||||||
case Data(_) | DataNoResponse(_):
|
case Data(_) | DataNoResponse(_):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
|
import kernel.log.Log;
|
||||||
import kernel.net.Package;
|
import kernel.net.Package;
|
||||||
import kernel.net.INetworkInterface;
|
import kernel.net.INetworkInterface;
|
||||||
|
|
||||||
@ -7,9 +8,9 @@ using tink.CoreApi;
|
|||||||
|
|
||||||
class Modem implements INetworkInterface implements IPeripheral {
|
class Modem implements INetworkInterface implements IPeripheral {
|
||||||
public final addr:String;
|
public final addr:String;
|
||||||
public var onMessage(default, null):Signal<Package>;
|
public var onMessage(default, null):Signal<{pack:Package,dist:Null<Float>}>;
|
||||||
|
|
||||||
private final onMessageTrigger:SignalTrigger<Package> = Signal.trigger();
|
private final onMessageTrigger:SignalTrigger<{pack:Package,dist:Null<Float>}> = Signal.trigger();
|
||||||
private final native:cc.periphs.Modem.Modem;
|
private final native:cc.periphs.Modem.Modem;
|
||||||
|
|
||||||
@:allow(kernel.peripherals)
|
@:allow(kernel.peripherals)
|
||||||
@ -19,6 +20,7 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
|
|
||||||
KernelEvents.instance.onModemMessage.handle(params ->{
|
KernelEvents.instance.onModemMessage.handle(params ->{
|
||||||
|
try{
|
||||||
if (params.addr == this.addr){
|
if (params.addr == this.addr){
|
||||||
var pack:Package = {
|
var pack:Package = {
|
||||||
fromID: params.message.fromID,
|
fromID: params.message.fromID,
|
||||||
@ -29,7 +31,10 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
ttl: params.message.ttl,
|
ttl: params.message.ttl,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onMessageTrigger.trigger(pack);
|
this.onMessageTrigger.trigger({pack: pack, dist: params.distance});
|
||||||
|
}
|
||||||
|
}catch(e:Dynamic){
|
||||||
|
Log.error("Error while parsing modem message");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user