cc-haxe/src/kernel/peripherals/Modem.hx

102 lines
2.3 KiB
Haxe
Raw Normal View History

2021-12-20 00:55:30 +00:00
package kernel.peripherals;
import haxe.exceptions.NotImplementedException;
import haxe.Exception;
using lua.Table;
class Modem {
private final nativ:cc.periphs.Modem.Modem;
public final addr:String;
@:allow(kernel.peripherals)
2022-02-21 14:35:37 +00:00
private function new(nativePeripherals:cc.periphs.Modem.Modem, addr:String) {
2021-12-20 00:55:30 +00:00
this.nativ = nativePeripherals;
this.addr = addr;
}
2022-02-21 14:35:37 +00:00
public function open(chan:Int) {
2021-12-20 00:55:30 +00:00
nativ.open(chan);
}
2022-02-21 14:35:37 +00:00
public function isOpen(chan:Int):Bool {
2021-12-20 00:55:30 +00:00
return nativ.isOpen(chan);
}
2022-02-21 14:35:37 +00:00
public function close(chan:Int) {
2021-12-20 00:55:30 +00:00
nativ.close(chan);
}
public function closAll() {
nativ.closeAll();
}
2022-02-21 14:35:37 +00:00
public function transmit(chan:Int, replyChan:Int, payload:Any) {
nativ.transmit(chan, replyChan, payload);
2021-12-20 00:55:30 +00:00
}
2022-02-21 14:35:37 +00:00
public function isWireless():Bool {
2021-12-20 00:55:30 +00:00
return nativ.isWireless();
}
public function getNamesRemote():Array<String> {
2022-02-21 14:35:37 +00:00
if (isWireless()) {
2021-12-20 00:55:30 +00:00
throw new Exception("'getNamesRemote' only works with wired modems");
}
return nativ.getNamesRemote().toArray();
}
2022-02-21 14:35:37 +00:00
public function isPresentRemote(name:String):Bool {
if (isWireless()) {
2021-12-20 00:55:30 +00:00
throw new Exception("'isPresentRemote' only works with wired modems");
}
return nativ.isPresentRemote(name);
}
2022-02-21 14:35:37 +00:00
public function getTypeRemote(name:String):String {
if (isWireless()) {
2021-12-20 00:55:30 +00:00
throw new Exception("'getTypeRemote' only works with wired modems");
}
return nativ.getTypeRemote(name);
}
public function hasTypeRemote(name:String, type:String):Bool {
2022-02-21 14:35:37 +00:00
if (isWireless()) {
2021-12-20 00:55:30 +00:00
throw new Exception("'hasTypeRemote' only works with wired modems");
}
// Missing in upstream API
throw new haxe.exceptions.NotImplementedException();
// return nativ.hasRemoteType(name,type);
}
2022-02-21 14:35:37 +00:00
public function getMethodsRemote(name:String):Array<String> {
if (isWireless()) {
2021-12-20 00:55:30 +00:00
throw new Exception("'getMethodsRemote' only works with wired modems");
}
return nativ.getMethodsRemote(name).toArray();
}
2022-02-21 14:35:37 +00:00
public function callRemote(remoteName:String, method:String):Dynamic {
if (isWireless()) {
2021-12-20 00:55:30 +00:00
throw new Exception("'callRemote' only works with wired modems");
}
// TODO: implment or solve differently
throw new haxe.exceptions.NotImplementedException();
}
2022-02-21 14:35:37 +00:00
public function getNameLocal():String {
if (isWireless()) {
2021-12-20 00:55:30 +00:00
throw new Exception("'getNameLocal' only works with wired modems");
}
return nativ.getNameLocal();
}
}