private void publishMethod() { if (accx < 5000) { accx += 2; } else { accx = 0; } if (accy < 5000) { accy += 1; } else { accy = 0; } if (accz < 5000) { accz += 5; } else { accz = 0; } FlatBufferBuilder fbb = new FlatBufferBuilder(1); StringOffset fbb_name = fbb.CreateString("sample"); Sample.StartSample(fbb); Sample.AddTopicName(fbb, fbb_name); Sample.AddAcc(fbb, Vec3.CreateVec3(fbb, accx, accy, accz)); Sample.AddGyro(fbb, Vec3.CreateVec3(fbb, 3, 2, 1)); Sample.AddMag(fbb, Vec3.CreateVec3(fbb, 4, 5, 6)); Sample.AddGps(fbb, GPS.CreateGPS(fbb, 84.123456, 84.123456, 213, 30, 20, 10)); Sample.AddEuler(fbb, Vec3.CreateVec3(fbb, 10, 15, 30)); Sample.AddQuat(fbb, Vec4.CreateVec4(fbb, 1, 0.5f, 0.3f, 0.2f)); var offset = Sample.EndSample(fbb); Sample.FinishSampleBuffer(fbb, offset); byte[] bMsg = fbb.SizedByteArray(); Debug.Log(bMsg.Length); pub.publish(bMsg); }
public byte[] pack() { StringOffset fbb_name = fbb.CreateString("sample"); Sample.StartSample(fbb); Sample.AddTopicName(fbb, fbb_name); Sample.AddAcc(fbb, Vec3.CreateVec3(fbb, acc.x, acc.y, acc.z)); Sample.AddGyro(fbb, Vec3.CreateVec3(fbb, gyro.x, gyro.y, gyro.z)); Sample.AddMag(fbb, Vec3.CreateVec3(fbb, mag.x, mag.y, mag.z)); Sample.AddGps(fbb, GPS.CreateGPS(fbb, lat, lon, alt, gsN, gsE, gsD)); Sample.AddEuler(fbb, Vec3.CreateVec3(fbb, euler.x, euler.y, euler.z)); Sample.AddQuat(fbb, Vec4.CreateVec4(fbb, quat.w, quat.x, quat.y, quat.z)); var offset = Sample.EndSample(fbb); Sample.FinishSampleBuffer(fbb, offset); byte[] bMsg = fbb.SizedByteArray(); return(bMsg); }