Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust robot command regex to allow whitespace at end #234

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading