Claw machine Program API - xuebaodev/wawaji GitHub Wiki

Command structure

[Head= 0xFE][packet id(1-65535)][~0xfe = 0x01][~packet id][packet len][data][checksum]

  • assume data sector has only one data. then the min packet len is 9.
  • packet id is auto increase from 1- 65535,when to 65535 make it to 1, loop so on.
  • checksum = ([packet len] + [data])%100。
  • Except query state command, claw machine will always return the same data you send it.
  • [Command] is android or server send to claw machine.
  • [Notify] [Return] is claw machine auto generate send to server. When server recv it , don't reply back.

[Command]Start Game

Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x14),0x31 ,time_out,result,num3,num4,num5,num6,num7,num8,num9,num10,num11,[checksum]}

  • time_out:round time in second. When time end , You didn't send down claw, the claw will down automatically.
  • Result: 0 = don't let it grasp this time. 1 = let it grasp this time.
  • Num3 Grasp Power(1—48) in decimal.
  • Num4 Top Power(1—48) in decimal
  • Num5 Move Power(1—48)in decimal
  • Num6 MAX Power(1—48)in decimal
  • Num7 Top Height(0--10)in decimal
  • Num8 Line Length(10—35)in decimal
  • Num9 Front-back motor speed(1-5)in decimal
  • Num10 Left-right motor speed in decimal
  • Num11 Up-down motor speed(1-5)in decimal

Sample:fe 00 00 01 ff ff 14 31 3c 00 00 00 00 00 00 00 00 00 00 1D

NOTE:When Result = 1, the power and other param is auto by the claw machine, which means the param you set after is ignore.When Result = 0 , the param don't equals 0 is effective. But i highly suggest you leave it to 0.

[Command]Move operation

Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x0c),0x32, Num1, Num2, Num3, [checksum]} Num1:

  • 0 Move forward. Assume you are standing in front of the claw machine, the grasp is moving to you.
  • 1 Move backward.
  • 2 Move Left.
  • 3 Move Right.
  • 4 Down Grasp.
  • 5 Stop move(When you release moiving button you should send this)

Num2,num3: constant send num2=0x88 num3=0x19. this means when press move button ,how long will motor will move. The suggesttion value means it will moving until you release the button or it will move to end.

Sample:fe 00 00 01 ff ff 0c 32 00 88 19 17 Move froward.

Please see SimpleClient for more detail on how to use.Highly suggest! Or you will take plenty time to waste on that!

[Notify]Game End

Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x0c),0x33, Num1, Num2, Num3, [checksum]} Num1:

  • 1 Grasp a doll.
  • 0 No Grasp a doll. Num2,num3 is useless.

Sample:fe 00 00 01 ff ff 0c 33 01 00 00 3e The result is Grasp a doll.

[Notify]Heart beat

Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=21),0x35, mac0, mac1, mac2, mac3, mac4, mac5, mac6, mac7, mac8, mac9, mac10, mac11, [checksum]}

MAC:for serial moudle, this is its MAC. for Android ,is its eth0. heartbeat frequency is 10 seconds. MAC is in ascii string format. Get MAC in java: String strMAC = new String(total_data, 8, 12); Get MAC in C: pData[20] = 0; char* pStr = pData + 8; printf("mac recv is:%s\r\n", pStr); If MAC is:EA EB 12 23 33 44. then mac0 = 'E' mac1='A' mac2='E' mac3='B' and so on。

[Notify]Error Report

Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x0a),0x37, num1 [checksum]} Num1:

  • 101 Up down motor error.Or crown block is not wired or up sensor error.
  • 103 Left right motor error.
  • 104 Forward-backward motor error.or back sensor error.
  • 105 Up-Down motor error or down sensor error.
  • 106 Up sensor error.
  • 107 Left sensor error.
  • 108 Forward-backward motor error
  • 109 photoreceptor has block.
  • 111 Down line is too long.

Sample:fe 00 00 01 ff ff 0a 37 6d 4a photoreceptor has block

Option:Query machine state


Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x09),0x34, [checksum]} Sample:fe 00 00 01 ff ff 09 34 3d

[Return]result of query

fe 00 00 01 ff ff 0e 34 num1 num2 num3 num4 num5 [checksum]

  • Num1 Status: 0,1,2 is normal,other see ** [Notify]Error Report **
  • Num2 Up Grasp Power
  • Num3 Top Grasp Power
  • Num4 Move Grasp Power
  • Num5 MAX Power

Option:Query Game Result


Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x09),0x3E, [checksum]}

[Return]Query Result

0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x0B),0x3E,num1,num2, [checksum]

  • Num1 Machine State:0 free,1,2 is playing,other is error code
  • Num2 Game Result. 1 = Grasp 0 = not Grasp.

Usage:When you don't receive game result, you can send this to query.

Option:[Command]Shutdown heartbeat.

Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=9),0x36, [checksum]} Sample:fe 00 00 01 ff ff 09 36 3f if the claw machine recv this command, it will never heartbeat again.

Option:[Command]Reset Claw Machine

Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x09),0x38,[checksum]}

Important:[Command]Read Heartbeat.

Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x09),0x42, [checksum]}

When claw machine recv this command packet , it will return heartbeat message。 The condition fits:When network is drop,the module will reconnect to server.But the claw machine will not heartbeat immediately(Because it do not know. it heartbeat every 10 seconds.)The server can't handle its data when server do not know who is it.So when server receive any connection in 7770, it should send this command to get MAC of this connection to identify who it is.

Option:[Command]When Server detected there is an error occur,send this command to the the claw machine sound an alarm to let operation people notice and fix.

Buff[]={0XFE,pid/256,pid%256,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x09),0x43, [checksum]}

Condition fits:When server detected any error ,it can send this to notify and let people here to fix it.

===========================extra command for android and pc================================

Android board or Linux PC is completely compatible with serial port protocol. And the app extends the command below to make it more friendly use.

[Command]Save ip to claw machine。-this is a internal protocol between android and claw. The server can't send this.

Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x0d),0x39,num1,num2,num3,num4, [checksum]}

[Command]Save ID to claw machine. this is a deprecated.

Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x19),0x3a,num1,num2,num3,num4, num5,num6, num7, num8, num9, num10, num11, num12, num13, num14, num15, num16, [checksum]}

[Command]Save MAC to claw machine.-this is a internal protocol between android and claw. The server can't send this.

Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x15),0x3f,num1,num2,num3,num4,num5,num6, num7,num8,num9,num10,num11,num12,[checksum]}

Num1-num12 is MAC.

[Command]Restart Android.--this is send from server.

Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x09),0x88, [checksum]} Condition fits:When server detected some camera is not streaming, maybe you can send this command to restart android to make this camera back to normal. This is usually because plug or unplug the camera, or the camera wire bad contact by frequently move. When this happened , you must restart android to solve this problem. If it is happened by bad contact wire,these won't solve。 These problem fits adventive condition camera drop.

[Notify]When camera is drop and android is in normal running , android will send this data to server.It tells the server one or more camera is drop , and android need to be restart right now. Usually the android is restart automaticcally.

Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x0f),0x89, [frontCamstate], [backCamstate], [op], 00, 00, 00, [checksum]}

  • frontCamstate: 00=normal 01=running drop 02=does not didn't plug this in.
  • backCamstate: same above.
  • op: 0=restart。 1=report only,not restart。 Condition fits: In the real scene,sometimes the android synchronize time may take too much time and force begin to streaming.When streaming but time has changed ,the preview will stop. This is a system bug can't be resolve.Anyway, the app has dead, and can't be restore by restart app.The only way is to restart android system.There is another situation may cause this happen, that is when camera is normally streaming, but suddenly the wire is break, the preview will stop too. When this happened ,the streaming video can't be watch anymore, the android app will detected this situation and report this notification to server and then auto restart. In this notification, the android tell the server :Some camera's preview is not available.And the restart will happen in these condition:
  • 1.claw machine is idle,restart immediately.
  • 2.someone is playing. Refuse all start game command, wait for game end to restart.
  • 3.the xuebaoRtmpPush will send command to get claw machine state. if it didn't reply back in 3 seconds ,it will restart. When server receive this notify message, it must be set this machine as error, and refuse all start game command, if you done friendly ,send a message to all watcher in room. After receive this message, start game error, heartbeat timeout can't set this machine to error.The claw machine will auto reconnect server after restart.

**Notice, When server detected some claw machine always send this message ,you should notify the people at real place ,there must be wire break or not well contact in one of the camera. **

[Command]when android is in single stream mode, this 0x90 will switch the video stream to other camera.This function is nearly nobody will use.So, be carefully to use it. I highly suggest you never use it.

Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x09),0x90, [checksum]}

[Notify]when android is in single stream mode, return 0x91 to report which camera it is streaming.

Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x0A),0x91, index, [checksum]}

  • index :1=first camera 2=second camera

[Notfiy]When there is out of 20 second not receive any data from server, the android will send 0x92 to query network state.

Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x09),0x92, [checksum]} So when your server receive heartbeat, please reply back same data. Otherwise ,when fire 0x92, you MUST reply back 0x92! If not, the android will disconnect from you server, and try reconnect!!!This may cause many many serious problems.PLEASE DO NOT IGNORE IT!

[Command]When there is no people in room , the server can send 0x93 to stop streaming or make it streaming in low bitrate to save you bandwidth.When someone is enter room, the server can send 0x93 to make video streaming back to normal.

Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x0C),0x93, onOff,bitRate_l,bitRate_h [checksum]}

  • onOff 0=stop streaming 1=start streaming use this param bitRate_l,bitRate_h.
  • bitRate_l,bitRate_h bitrate= bitRate_l + bitRate_h * 256 0=same bitrate not0= this bitrate

the android will Reply back Buff[]={0XFE,pid/255,pid%255,~ Buff[0],~ Buff[1],~ Buff[2],(Length=0x0D),0x93, onOff,bitRate_l,bitRate_h,result [checksum]}

  • onOff 0=not streaming 1=streaming
  • bitRate_l,bitRate_h bitrate= bitRate_l + bitRate_h * 256 the current streaming bitrate
  • result the apply reult.
  • NOTICE:bitrate's unit is K。 Like F4 01 = 1*256 + 244 = 500 . That is 500K。

================================== android board sample(Like below) android board 1

Simple program introduction

  • 1.the remote adb port is 5555.
  • 2.serial port is /dev/ttyS1
  • order,USB Top slot is front camera. USB down slot is back camera
  • 4.Front camera is same like back camera except ID(Don't use mirror when programming)
  • 5.Silence install When you need silence install, just send a broadcast like below.The path param is your apk path. The android system will restart when complete install.
Intent intent=new Intent();

  • 6.When you need android to restart. Just send this below.
Intent intent=new Intent();

  • 7.The default display is in 1280*720 resolution. You can change it in setting - display.