-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas O Fredericks
committed
Aug 15, 2017
1 parent
96abb12
commit 6a37497
Showing
13 changed files
with
44,875 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>AsciiMassage Websockets</title> | ||
<script src="libraries/p5.js" type="text/javascript"></script> | ||
|
||
<script src="libraries/p5.dom.js" type="text/javascript"></script> | ||
<script src="libraries/p5.sound.js" type="text/javascript"></script> | ||
|
||
<script src="libraries/AsciiMassagePacker.js" type="text/javascript"></script> | ||
<script src="libraries/AsciiMassageParser.js" type="text/javascript"></script> | ||
|
||
<script src="sketch.js" type="text/javascript"></script> | ||
|
||
<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
91 changes: 91 additions & 0 deletions
91
applications/Websocket Client(p5.js)/libraries/AsciiMassagePacker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
function AsciiMassagePacker() { | ||
|
||
this._messageSize; | ||
this._internalString = ""; | ||
this._ended = false; | ||
|
||
/// Returns size of buffer. | ||
this.size = function() { | ||
return this._internalString.length(); | ||
} | ||
|
||
// Returns a reference to the buffer. | ||
this.buffer = function() { | ||
if ( this.ended == false ) console.log("Warning: getting the buffer of an unended packet!"); | ||
return this._internalString; | ||
} | ||
|
||
/// Begins the sending of a message. | ||
this.beginPacket = function(address) { | ||
this._internalString = address; | ||
this._ended = false; | ||
} | ||
|
||
/// Adds a byte. | ||
this.addByte = function(value) { | ||
this._internalString = this._internalString +" " + value; | ||
} | ||
|
||
/// Adds an int. | ||
this.addInt = function(value) { | ||
this._internalString = this._internalString +" " + value; | ||
} | ||
|
||
/// Adds a long. | ||
this.addLong = function(value) { | ||
this._internalString = this._internalString +" " + value; | ||
} | ||
|
||
/// Adds a float. | ||
this.addFloat = function(value) { | ||
this._internalString = this._internalString +" " + value; | ||
} | ||
|
||
/// Ends the sending of a message. | ||
this.endPacket = function() { | ||
this._internalString += '\n'; | ||
this._ended = true; | ||
} | ||
|
||
/// Create a packet with no arguments. | ||
this.packEmpty = function(address) | ||
{ | ||
this.beginPacket(address); | ||
this.endPacket(); | ||
} | ||
|
||
/// Create a packet with a single byte value. | ||
this.packOneByte = function( address, value) | ||
{ | ||
this.beginPacket(address); | ||
this.addByte(value); | ||
this.endPacket(); | ||
} | ||
|
||
/// Create a packet with a single int value. | ||
this.packOneInt = function( address, value) | ||
{ | ||
this.beginPacket(address); | ||
this.addInt(value); | ||
this.endPacket(); | ||
} | ||
|
||
/// Create a packet with a single long value. | ||
this.packOneLong = function( address, value) | ||
{ | ||
this.beginPacket(address); | ||
this.addLong(value); | ||
this.endPacket(); | ||
} | ||
|
||
/// Create a packet with a single float value. | ||
this.packOneFloat = function( address, value) | ||
{ | ||
this.beginPacket(address); | ||
this.addFloat(value); | ||
this.endPacket(); | ||
} | ||
|
||
|
||
|
||
} |
101 changes: 101 additions & 0 deletions
101
applications/Websocket Client(p5.js)/libraries/AsciiMassageParser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
|
||
|
||
function AsciiMassageParser() { | ||
|
||
|
||
this._flush = function() { | ||
this._needToFlush = false; | ||
this._receivedDataIndex = 0; | ||
this._internalString = new Array(); | ||
this._currentWord = 0; | ||
this._ready = false; | ||
this._words = null; | ||
} | ||
|
||
this._flush(); | ||
|
||
this.parse = function ( data , callback = null ) { | ||
|
||
|
||
|
||
if ( this._needToFlush || this._receivedDataIndex > 1024 ) { | ||
this._flush(); | ||
} | ||
|
||
if ( data == '\n' ) { | ||
|
||
this._needToFlush = true; | ||
if ( this._receivedDataIndex > 0 ) { | ||
this._words = this._internalString.split(" "); | ||
this._ready = true; | ||
this._currentWord = 1; | ||
|
||
if ( callback != null ) callback(); | ||
return true; | ||
} | ||
|
||
} else { | ||
this._internalString += data; | ||
this._receivedDataIndex++; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
this._isReady = function() { | ||
|
||
if ( this._ready && this._currentWord < this._words.length ) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
this.fullMatch = function( address ) { | ||
if ( this._isReady() && this._words[0] == address ) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
this.nextByte = function() { | ||
|
||
if ( this._isReady() ) { | ||
var data = parseInt(this._words[this._currentWord]); | ||
this._currentWord++; | ||
return data; | ||
} | ||
return 0; | ||
} | ||
|
||
this.nextInt = function() { | ||
|
||
if ( this._isReady() ) { | ||
var data = parseInt(this._words[this._currentWord]); | ||
this._currentWord++; | ||
return data; | ||
} | ||
return 0; | ||
} | ||
|
||
this.nextFloat = function() { | ||
|
||
if ( this._isReady() ) { | ||
var data = parseFloat(this._words[this._currentWord]); | ||
this._currentWord++; | ||
return data; | ||
} | ||
return 0; | ||
} | ||
|
||
this.nextLong = function() { | ||
|
||
if ( this._isReady() ) { | ||
var data = parseInt(this._words[this._currentWord]); | ||
this._currentWord++; | ||
return data; | ||
} | ||
return 0; | ||
} | ||
|
||
} |
Oops, something went wrong.