Skip to content

TCP IP OPCODE

chradams edited this page Apr 12, 2020 · 1 revision

Contents

  1. Introduction
  2. Motor OPCODES
    2.1. Motor Configuration
    2.1.1. Microstepping
    2.1.2. Servo Bound Upper
    2.1.3. Servo Bound Lower
    2.2. Motor Control
    2.2.1. Move
    2.2.2. Goto
    2.2.3. Stop
  3. Device OPCODES
    3.1. WiFi
    3.1.1. Connect
    3.1.2. Disconnect
    3.2. OTA
    3.2.1. OTA Password Change
  4. TCP IP Structure
    4.1. JSON over TCP
    4.1.1. Motor OPCODE
    4.1.2. WiFi OPCODE
    4.2. UDP
    4.2.1. Motor OPCODE
    4.2.2. WiFi OPCODE

1 Introduction

Control commands may be issued to a controller via JSON over TCP or binary over UDP. In this document we will review the available OPCODE commands and command structure over each transport layer.

2 Motor OPCODES

2.1 Motor Configuration

2.1.1 Microstepping

Compatibility:

  • Servo: ❌
  • Stepper: ✔️

Description: Sets stepper driver micro step mode
code: 'U'
data:
1. motor id: ID of the motor to control
2. queue: Set to 1: add command to queue 0: clear queue and run command
3. step num: N/A
4. step rate: if greater than 0, microstepping enabled. Otherwise, disabled

2.1.2 Servo Bound Upper

Compatibility:

  • Servo: ✔️
  • Stepper: ❌

Description: Set maximum servo angle
code: 'H'
data:
1. motor id: ID of the motor to control
2. queue: Can not be queued
3. step num: N/A
4. step rate: Maximum servo location in degrees; limit is 200 degrees

2.1.3 Servo Bound Lower

Compatibility:

  • Servo: ✔️
  • Stepper: ❌

Description: Set minimum servo angle
code: 'L'
data:
1. motor id: ID of the motor to control
2. queue: Can not be queued
3. step num: N/A
4. step rate: Minimum servo location in degrees; limit is 0 degrees

2.2 Motor Control

2.2.1 Move

Compatibility:

  • Servo: ✔️
  • Stepper: ✔️

Description: Traverses a number of units from the current location
code: 'M'
data:
1. motor id: ID of the motor to control
2. queue: Set to 1: add command to queue 0: clear queue and run command
3. step num: For Steppers, the number of steps to move; for servos, the number of degrees to move
4. step rate: For Steppers, the number of steps to move per second; for servos, the number of degrees to move per second

2.2.2 Goto

Compatibility:

  • Servo: ✔️
  • Stepper: ✔️

Description: Move to a specific location
code: 'G'
data:
1. motor id: ID of the motor to control
2. queue: Set to 1: add command to queue 0: clear queue and run command
3. step num: For steppers, the number of steps from the home location to travel to; for servos, the specific angular degree to travel to
4. step rate: For Steppers, the number of steps to move per second; for servos, the number of degrees to move per second

2.2.3 Stop

Compatibility:

  • Servo: ✔️
  • Stepper: ✔️

Description: Pauses movement for specific amount of time
code: 'S'
data:
1. motor id: ID of the motor to control
2. queue: Set to 1: add command to queue 0: clear queue and run command
3. step num: For steppers, the number of cycles to wait; for servos, the number of cycles to wait
4. step rate: For steppers, the period of wait cycles in milliseconds; for servos, the number of wait cycles per second

3 Device OPCODES

3.1 WiFi

3.1.1 Connect

Compatibility:

  • Servo: ✔️
  • Stepper: ✔️

Description: Connect to WiFi SSID
code: 'C'
data:
1. SSID: SSID of target network
2. Password: Password of target network

3.1.2 Disconnect

Compatibility:

  • Servo: ✔️
  • Stepper: ✔️

Description: Disconnect from WiFi
code: 'D'
data:
1. SSID: N/A
2. Password: N/A

3.2 OTA

3.2.1 OTA Password Change

Compatibility:

  • Servo: ✔️
  • Stepper: ✔️

Description: Changes the OTA password
code: 'O'
data:
1. SSID: Old OTA password
2. Password: New OTA password

4 TCP IP Structure

4.1 JSON over TCP

JSON packets should be sent with a HTTP POST.

4.1.1 Motor OPCODE

Motor OPCODE Structure:

{
  "commands": [
    {
      "code": "?",
      "data": [
        "motor_id",
        "queue",
        "step_num",
        "step_rate"
      ]
    }
  ]
}

Motor OPCODE Example:

  • Move, motor zero, no queue, 400 steps at 100 rate.
{
  "commands": [
    {
      "code": "M",
      "data": [
        0,
        0,
        400,
        100
      ]
    }
  ]
}

4.1.2 WiFi OPCODE

Wifi OPCODE Structure:

{
  "commands": [
    {
      "code": "?",
      "data": [
        "SSID",
        "Password"
      ]
    }
  ]
}

Wifi OPCODE Example:

  • Connect to "HomeWiFi" with password "1234"
{
  "commands": [
    {
      "code": "C",
      "data": [
        "HomeWiFi",
        "1234"
      ]
    }
  ]
}

4.2 UDP

4.2.1 Motor OPCODE

Motor OPCODE C Structure:

struct stepper_command_packet 
{
  unsigned short port;
  char opcode;
  uint8_t queue;
  int32_t stepNum;
  uint16_t stepRate;
  uint8_t motorID;
};

Motor OPCODE example:

  • Move, motor zero, no queue, 400 steps at 100 rate. Hexadecimal UDP data:
00004D0000000190006400

4.2.2 WiFi OPCODE

WiFi OPCODE C Structure:

struct wifi_command_packet {
  char opcode;
  char ssid[32];
  char password[63];
};

WiFi OPCODE example:

  • Connect to "HomeWiFi" with password "1234"
    Hexadecimal UDP data:
43486F6D6557694669000000000000000000000000000000000000000000000000313233340000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000