connecting and disconnecting cable are working

This commit is contained in:
Jessica Pixel
2017-10-04 17:38:10 -07:00
parent 89c2eac9cd
commit 03e31be2ea
4 changed files with 279 additions and 195 deletions
-138
View File
@@ -1,138 +0,0 @@
//this will eventually get worked into something larger
integer masterLightBus;
integer slaveLightBus;
key ownerKey;
integer getChannel(key UUID) {
masterLightBus = -1 - (integer)("0x" + llGetSubString(UUID, -7, -1))+106;
return masterLightBus;
}
init() {
ownerKey = llGetOwner();
getChannel(ownerKey);
//llOwnerSay("Channel: " + (string)channelLightBus);
llListen(masterLightBus+1, "", NULL_KEY, "");
}
integer scanRange = 1000;
scan() {
llSensor("", NULL_KEY, AGENT, scanRange, PI);
}
list avatarList = [];
list keyList = [];
selectMenu(list avatars) {
string text = "[" + (string)llGetListLength(avatars) + "] avatars detected.";
text += "\nScan range: " + (string)scanRange + "m";
llDialog(ownerKey, text, avatars, masterLightBus+1);
}
string unitName = "";
key getUUID(string name) {
unitName = name;
integer x = llListFindList(avatarList, [name]);
return llList2String(keyList, x);
}
permission(key UUID) {
llOwnerSay("Asking " + unitName + " for permission.");
slaveLightBus = -1 - (integer)("0x" + llGetSubString((string)UUID, -7, -1))+106;
llListen(slaveLightBus, "", NULL_KEY, "");
llSay(slaveLightBus, "auth scanner " + (string)ownerKey);
}
getPort(string UUID) {
if (UUID = "") { llSay(slaveLightBus, "port-connect data-1"); }
else { llSay(slaveLightBus, "port-connect " + UUID); }
}
connect(string UUID) {
llOwnerSay("Port UUID: " + UUID);
particles(UUID);
}
disconnect() {
llSay(slaveLightBus, "remove scanner");
particles((string)ownerKey);
}
list options = ["CONNECT","DISCONNECT"];
optionsMenu() {
llDialog(ownerKey, "Options Menu", options, masterLightBus+1);
}
particles(string UUID) {
llParticleSystem([
PSYS_PART_FLAGS, 0
| PSYS_PART_FOLLOW_VELOCITY_MASK
| PSYS_PART_INTERP_COLOR_MASK
| PSYS_PART_TARGET_POS_MASK
| PSYS_PART_RIBBON_MASK,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_DROP,
PSYS_PART_START_COLOR, <1,1,1>,
PSYS_PART_END_COLOR, <1,1,1>,
PSYS_PART_START_ALPHA, 1.0,
PSYS_PART_END_ALPHA, 1.0,
PSYS_PART_START_SCALE, <0.04, 0.04, 0>,
PSYS_SRC_TEXTURE, TEXTURE_BLANK,
PSYS_SRC_TARGET_KEY, (key)UUID,
PSYS_SRC_MAX_AGE, 0.0,
PSYS_PART_MAX_AGE, 10.0,
PSYS_SRC_BURST_RATE, 0.0,
PSYS_SRC_BURST_PART_COUNT, 10
]);
}
default
{
state_entry()
{
init();
scan();
}
listen(integer c, string n, key k, string m) {
if (c == masterLightBus+1) {
if (m == "DISCONNECT") { disconnect(); }
else {
key UUID = getUUID(m);
llOwnerSay("UUID: " + (string)UUID);
permission(UUID);
}
}
//04d7d605-a379-408a-ad81-1933a54af844
if (c == slaveLightBus) {
llOwnerSay(m);
if (m == "accept " + (string)ownerKey) { llOwnerSay("Connection approved."); getPort(""); }
if (llGetSubString(m, 0, 8) == "port-real") {
string portUUID = llGetSubString(m, 10, -1);
llOwnerSay(portUUID);
connect(portUUID);
}
else if (llGetSubString(m, 0, 3) == "port") {
string UUID = llGetSubString(m, -36, -1);
llOwnerSay(UUID);
getPort(UUID);
}
}
}
sensor(integer d)
{
integer x = 0;
while (x < d) {
avatarList += llDetectedName(x);
keyList += llDetectedKey(x);
x++;
}
selectMenu(avatarList);
}
no_sensor()
{
list x = [];
selectMenu(x);
}
}
+7 -2
View File
@@ -134,6 +134,10 @@ integer channelLightBus;
integer running = TRUE;
vector color;
statusMessage() {
llWhisper(PUBLIC_CHANNEL, "NS Personal Wireless Charger\nAuto charge below 20%");
}
default
{
state_entry() {
@@ -150,11 +154,12 @@ default
{
string toggleMessage = "command " + (string)ownerKey + " toggle";
if (m == "probe") { llSay(channelLightBus, "add charger"); }
else if (m == "remove charger") { llOwnerSay("Removing charger."); }
else if (m == "add-confirm") { llSay(channelLightBus, "add-command toggle"); }
else if (m == "charge start" || m == "off" ) { turnOff("Charge disabled."); }
else if (m == "poke " + (string)llGetOwner()) { llDialog(llGetOwner(), "Charger Menu", ["CABLE"], channelLightBus); }
else if (m == "peek " + (string)llGetOwner()) { statusMessage() ;}
else if (llGetSubString(m,0,9) == "power 0.99") { turnOff("Charge complete!"); }
else if (llGetSubString(m,0,8) == "power 0.2") { turnOn("Low power. Charge enabled..."); }
else if (llGetSubString(m,0,8) == "power 0.1") { turnOn("Low power. Charge enabled..."); }
else if (m == toggleMessage) {
if (running) { turnOff("Charge disabled.");}
else { turnOn("Charge enabled..."); }
+262
View File
@@ -0,0 +1,262 @@
key ownerKey;
integer ownerLightBus;
integer listenOLB;
list unitList;
list keyList;
string unitName = "none";
vector unitColor;
key unitKey;
integer unitLightBus;
integer listenULB;
integer getChannel(key UUID) {
return -1-(integer)("0x" + llGetSubString(UUID, -7, -1))+106;
}
init() {
updateText("INIT");
llParticleSystem([]);
hoverText("");
ownerKey = llGetOwner();
ownerLightBus = getChannel(ownerKey);
listenOLB = llListen(ownerLightBus+1, "", NULL_KEY, "");
llListenControl(listenOLB, FALSE);
updateText("Ready!");
}
updateText(string message) {
llMessageLinked(LINK_ALL_OTHERS, 122, message, (string)color);
}
displayVitals() {
string display = unitName + "\n----------\nPower: " + power;
updateText(display);
}
scan(float range) {
llSensor("", NULL_KEY, AGENT, range, PI);
}
key getUUID(string name) {
unitName = name;
integer x = llListFindList(unitList, [name]);
return llList2String(keyList, x);
}
permission(key UUID) {
llOwnerSay("Asking " + unitName + " for permission.");
unitLightBus = -1-(integer)("0x" + llGetSubString((string)UUID, -7, -1))+106;
llListen(unitLightBus, "", NULL_KEY, "");
llSay(unitLightBus, "auth scanner " + (string)ownerKey);
}
getPort(key UUID) {
if (UUID == NULL_KEY) {
llOwnerSay("sending [port-connect data-1]");
llSay(unitLightBus, "port-connect data-1"); }
else {
llOwnerSay("sending [port-connect " + (string)UUID + "]");
llSay(unitLightBus, "port-connect " + (string)UUID); }
}
connect(key UUID) {
updateText("Unit: " + unitName);
particles(UUID);
}
disconnect() {
llParticleSystem([]);
llListenControl(listenULB, FALSE);
llOwnerSay("Disconnecting scanner.");
llSay(unitLightBus, "remove scanner");
updateText("Disconnected");
}
particles(key UUID) {
llParticleSystem([
PSYS_PART_FLAGS, 0
| PSYS_PART_FOLLOW_VELOCITY_MASK
| PSYS_PART_INTERP_COLOR_MASK
| PSYS_PART_TARGET_POS_MASK
| PSYS_PART_RIBBON_MASK,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_DROP,
PSYS_PART_START_COLOR, <1,1,1>,
PSYS_PART_END_COLOR, <1,1,1>,
PSYS_PART_START_ALPHA, 1.0,
PSYS_PART_END_ALPHA, 1.0,
PSYS_PART_START_SCALE, <0.04, 0.04, 0>,
PSYS_SRC_TEXTURE, TEXTURE_BLANK,
PSYS_SRC_TARGET_KEY, UUID,
PSYS_SRC_MAX_AGE, 0.0,
PSYS_PART_MAX_AGE, 10.0,
PSYS_SRC_BURST_RATE, 0.0,
PSYS_SRC_BURST_PART_COUNT, 1
]);
}
beep() { updateText("beep"); llOwnerSay("beep"); }
vector color = <1,1,1>;
hoverText(string input) {
llSetText(input, color, 0.5);
}
mainMenu(key UUID) {
llListenControl(listenOLB, TRUE);
llSetTimerEvent(60);
string x = "Spam: off";
if (busSpam) { x = "Spam: on"; }
llDialog(UUID, "Select an option.\nCurrent unit: " + unitName + "\n" + x, ["SCAN","SPAM","DISPLAY","DISCONNECT","RESET"], ownerLightBus+1);
}
selectMenu(key UUID) {
llListenControl(listenOLB, TRUE);
llSetTimerEvent(60);
string text = "[" + (string)llGetListLength(unitList) + "] units detected.";
updateText(text);
llDialog(UUID, text, unitList, ownerLightBus+1);
}
disableListen() {
llListenControl(listenOLB, FALSE);
llSetTimerEvent(0);
}
integer busSpam = FALSE;
toggleSpam() {
if (!busSpam) { busSpam = TRUE; }
else { busSpam = FALSE; }
}
processCommand(string input) {
string command = llGetSubString(input, 0, llSubStringIndex(input, " ")-1);
string params = llGetSubString(input, llSubStringIndex(input, " ")+1, -1);
//hoverText("Heard command: " + command);
//hoverText("Heard params: " + params);
if (command == "color") { messageColor(params); }
if (command == "power") { messagePower(params); }
//if (command == "persona") { messagePersona(params); }
//if (command == "persona-eject") { messagePersona(""); }
//if (command == "poke") { messagePoke(params); }
//if (command == "peek") { messagePeek(params); }
//if (command == "bolts") { messageBolts(params); }
//if (command == "charge") { messageCharge(params); }
//if (command == "weather") { messageWeather(params); }
}
messageColor(string input) {
list rgb = llParseString2List(input, [" "], []);
unitColor = <llList2Float(rgb, 0), llList2Float(rgb, 1), llList2Float(rgb, 2)>;
}
messagePersona(string input) {
if (input == "") {
hoverText("Changing persona...");
} else {
hoverText("New persona: " + input);
}
}
string power;
messagePower(string input) {
float powerFloat = (float)input * 100;
integer powerInt = (integer)powerFloat;
power = (string)powerInt;
//hoverText("Current power: " + (string)powerInt + "%");
}
messagePoke(string input) {
hoverText("Poke: " + input);
}
messagePeek(string input) {
hoverText("Peek: " + input);
}
messageBolts(string input) {
if (input == "off") {
hoverText("Unit unlocked");
} else {
hoverText("Unit locked");
}
}
messageCharge(string input) {
if (input == "start") {
hoverText("Charge: started");
} else {
hoverText("Charge: ended");
}
}
messageWeather(string input) {
string weather = llGetSubString(input, 0, llSubStringIndex(input, " ")-1);
integer temp = (integer)llGetSubString(input, llSubStringIndex(input, " ")+1, -1);
hoverText("Weather: " + weather + "\nTemp: " + (string)temp + "C");
}
default
{
state_entry() { init(); }
listen(integer c, string n, key k, string m) {
if (c == ownerLightBus+1) {
disableListen();
if (m == "SCAN") { updateText("Scanning for units..."); scan(20); }
else if (m == "DISCONNECT") { updateText("Disconnecting..."); disconnect(); mainMenu(ownerKey); }
else if (m == "RESET") { llResetScript(); }
else if (m == "OK") { mainMenu(ownerKey); }
else if (m == "SPAM") { toggleSpam(); mainMenu(ownerKey); }
else if (m == "DISPLAY") { displayVitals(); mainMenu(ownerKey); }
else {
key UUID = getUUID(m);
permission(UUID);
}
}
if (c == unitLightBus) {
if (busSpam) { updateText(m); }
if (m == "accept " + (string)ownerKey) { llOwnerSay("Connection approved."); llSay(unitLightBus, "add scanner"); getPort(NULL_KEY); }
else if (m == "add-confirm") { llOwnerSay("Device added."); }
else if (m == "add-fail") { llOwnerSay("Connection failed."); }
else if (m == "remove-confirm") { llOwnerSay("Disconnect successful."); }
else if (m == "remove-fail") { llOwnerSay("Unable to remove."); }
else if (llGetSubString(m, 0, 8) == "port-real") {
key portUUID = (key)llGetSubString(m, 17, -1);
connect(portUUID);
}
else if (llGetSubString(m, 0, 3) == "port") {
key UUID = (key)llGetSubString(m, -36, -1);
llOwnerSay("Port forward to: " + (string)UUID);
getPort(UUID);
}
}
}
sensor(integer d)
{
unitList = [];
keyList = [];
integer x = 0;
while (x < d) {
unitList += llDetectedName(x);
keyList += llDetectedKey(x);
x++;
}
selectMenu(ownerKey);
}
no_sensor()
{
selectMenu(ownerKey);
}
touch_end(integer d) {
mainMenu(ownerKey);
}
timer() {
disableListen();
}
}
+10 -55
View File
@@ -1,7 +1,3 @@
//A lightbus sniffer for NS units
//Jessyka Richard - Jessica Pixel
//9/2017
integer channelLightBus;
integer listenLightBus;
vector color;
@@ -27,19 +23,22 @@ messagePersona(string input) {
messagePower(string input) {
float powerFloat = (float)input * 100;
integer powerInt = (integer)powerFloat;
hoverText("Current power: " + (string)powerInt + "%");
//hoverText("Current power: " + (string)powerInt + "%");
}
messagePoke(string input) {
hoverText("Poke: " + input);
llDialog((key)input, "Charger Menu", ["CABLE ", "CABLEOFF "], channelLightBus);
}
messagePeek(string input) {
hoverText("Peek: " + input);
}
messageBolts(string input) {
if (input == "off") {
hoverText("Bolts: unlocked");
hoverText("Unit unlocked");
} else {
hoverText("Bolts: locked");
hoverText("Unit locked");
}
}
@@ -51,48 +50,6 @@ messageCharge(string input) {
}
}
getPort(string port) {
llSay(channelLightBus, "port-connect " + port);
}
string cablePort;
string cableId;
connectCable(string input) {
cablePort = llGetSubString(input, 0, llSubStringIndex(input, " ")-1);
//llOwnerSay("Port: " + cablePort);
cableId = llGetSubString(input, llSubStringIndex(input, " ")+1, -1);
//llOwnerSay("key: " + cableId);
particles(cableId);
}
particles(string uuid) {
llParticleSystem([
PSYS_PART_FLAGS, 0
| PSYS_PART_FOLLOW_VELOCITY_MASK
| PSYS_PART_INTERP_COLOR_MASK
| PSYS_PART_TARGET_POS_MASK
| PSYS_PART_RIBBON_MASK,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_DROP,
PSYS_PART_START_COLOR, color,
PSYS_PART_END_COLOR, color,
PSYS_PART_START_ALPHA, 1.0,
PSYS_PART_END_ALPHA, 1.0,
PSYS_PART_START_SCALE, <0.04, 0.04, 0>,
PSYS_SRC_TEXTURE, TEXTURE_BLANK,
PSYS_SRC_TARGET_KEY, (key)uuid,
PSYS_SRC_MAX_AGE, 0.0,
PSYS_PART_MAX_AGE, 10.0,
PSYS_SRC_BURST_RATE, 0.0,
PSYS_SRC_BURST_PART_COUNT, 10
]);
}
disconnectCable(string input) {
llParticleSystem([]);
llSay(channelLightBus, "port-disconnect " + cablePort);
}
messageWeather(string input) {
string weather = llGetSubString(input, 0, llSubStringIndex(input, " ")-1);
integer temp = (integer)llGetSubString(input, llSubStringIndex(input, " ")+1, -1);
@@ -102,18 +59,16 @@ messageWeather(string input) {
processCommand(string input) {
string command = llGetSubString(input, 0, llSubStringIndex(input, " ")-1);
string params = llGetSubString(input, llSubStringIndex(input, " ")+1, -1);
//hoverText("Heard: " + command);
//hoverText("Heard: " + params);
//hoverText("Heard command: " + command);
//hoverText("Heard params: " + params);
if (command == "color") { messageColor(params); }
if (command == "power") { messagePower(params); }
if (command == "persona") { messagePersona(params); }
if (command == "persona-eject") { messagePersona(""); }
if (command == "poke") { messagePoke(params); }
if (command == "peek") { messagePeek(params); }
if (command == "bolts") { messageBolts(params); }
if (command == "charge") { messageCharge(params); }
if (command == "CABLE") { getPort("data-1"); }
if (command == "port-real") { connectCable(params); }
if (command == "CABLEOFF") { disconnectCable(params); }
if (command == "weather") { messageWeather(params); }
}