Skip to content

Commit

Permalink
Adjust robot command regex to allow whitespace at end (#234)
Browse files Browse the repository at this point in the history
Co-authored-by: Devin Jean <[email protected]>
  • Loading branch information
gsteinLTU and dragazo authored Dec 11, 2024
1 parent 0bab8a4 commit c9026f2
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/procedures/roboscape/robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,50 +482,50 @@ Robot.prototype.onMessage = function (message) {
Robot.prototype.onCommand = function (command) {
const cases = [
{
regex: /^is alive$/,
regex: /^is alive\s*$/,
handler: () => {
this.sendToClient("alive", {});
return this.isAlive();
},
},
{
regex: /^beep (-?\d+)[, ](-?\d+)$/,
regex: /^beep (-?\d+)[, ](-?\d+)\s*$/,
handler: () => {
this.beep(+RegExp.$1, +RegExp.$2);
},
},
{
regex: /^set speed (-?\d+)[, ](-?\d+)$/,
regex: /^set speed (-?\d+)[, ](-?\d+)\s*$/,
handler: () => {
this.setSpeed(+RegExp.$1, +RegExp.$2);
},
},
{
regex: /^drive (-?\d+)[, ](-?\d+)$/,
regex: /^drive (-?\d+)[, ](-?\d+)\s*$/,
handler: () => {
this.drive(+RegExp.$1, +RegExp.$2);
},
},
{
regex: /^turn wheels (-?\d+)[, ](-?\d+)$/,
regex: /^turn wheels (-?\d+)[, ](-?\d+)\s*$/,
handler: () => {
this.drive(+RegExp.$1, +RegExp.$2);
},
},
{
regex: /^get range$/,
regex: /^get range\s*$/,
handler: () => {
return this.getRange();
},
},
{
regex: /^get ticks$/,
regex: /^get ticks\s*$/,
handler: () => {
return this.getTicks();
},
},
{
regex: /^set encryption ([^ ]+)(| -?\d+([ ,]-?\d+)*)$/, // name of the cipher
regex: /^set encryption ([^ ]+)(| -?\d+([ ,]-?\d+)*)\s*$/, // name of the cipher
handler: () => {
let cipherName = RegExp.$1.toLowerCase();
var key = RegExp.$2.split(/[, ]/);
Expand All @@ -537,7 +537,7 @@ Robot.prototype.onCommand = function (command) {
},
},
{ // deprecated
regex: /^set key(| -?\d+([ ,]-?\d+)*)$/,
regex: /^set key(| -?\d+([ ,]-?\d+)*)\s*$/,
handler: () => {
var encryption = RegExp.$1.split(/[, ]/);
if (encryption[0] === "") {
Expand All @@ -547,25 +547,25 @@ Robot.prototype.onCommand = function (command) {
},
},
{
regex: /^set total rate (-?\d+)$/,
regex: /^set total rate (-?\d+)\s*$/,
handler: () => {
this.setTotalRate(+RegExp.$1);
},
},
{
regex: /^set client rate (-?\d+)[, ](-?\d+)$/,
regex: /^set client rate (-?\d+)[, ](-?\d+)\s*$/,
handler: () => {
this.setClientRate(+RegExp.$1, +RegExp.$2);
},
},
{
regex: /^set led (-?\d+)[, ](-?\d+)$/,
regex: /^set led (-?\d+)[, ](-?\d+)\s*$/,
handler: () => {
this.setLed(+RegExp.$1, +RegExp.$2);
},
},
{
regex: /^show number (\d+)(?:[, ](\d+))?$/,
regex: /^show number (\d+)(?:[, ](\d+))?\s*$/,
handler: () => {
this.setNumericDisplay(
+RegExp.$1,
Expand All @@ -574,19 +574,19 @@ Robot.prototype.onCommand = function (command) {
},
},
{
regex: /^infra light (-?\d+)[, ](-?\d+)$/,
regex: /^infra light (-?\d+)[, ](-?\d+)\s*$/,
handler: () => {
this.infraLight(+RegExp.$1, +RegExp.$2);
},
},
{
regex: /^reset seq$/,
regex: /^reset seq\s*$/,
handler: () => {
this.resetSeqNum();
},
},
{
regex: /^reset rates$/,
regex: /^reset rates\s*$/,
handler: () => {
this.resetRates();
},
Expand Down

0 comments on commit c9026f2

Please sign in to comment.