AFSIM - #001 使用node接收warlock的数据

在这里插入图片描述

使用node接收warlock的数据

1 目标

本文的目的是使用node接收warlock的数据。

2 代码

const isim_proto = require('./afsim_proto')
const grpc = require('@grpc/grpc-js')


// 配置常量
const CONFIG = {
   
   
  serverAddress: '127.0.0.1:5005',
  maxRetries: 3,
  retryDelay: 2000,
  connectionTimeout: 5000, // 5秒连接超时
  reconnectBackoff: {
   
   
    initial: 1000,
    max: 5000
  }
}

// 重试状态
const state = {
   
   
  currentRetry: 0,
  isShuttingDown: false
}

// 格式化位置信息
function formatPosition(pos) {
   
   
  if (!pos) return '  位置信息: 无可用数据'
  
  // 防御性检查,确保所有字段存在
  const safeNumber = (num, precision = 6) => 
    typeof num === 'number' ? num.toFixed(precision) : '无数据'

  return `
  位置详情:
    坐标: (${
     
     safeNumber(pos.lat)}, ${
     
     safeNumber(pos.lon)}) 高度: ${
     
     safeNumber(pos.alt, 1)}米
    北东天坐标: [X: ${
     
     safeNumber(pos.neu_x, 2)}, Y: ${
     
     safeNumber(pos.neu_y, 2)}, Z: ${
     
     safeNumber(pos.neu_z, 2)}]
    姿态: 航向 ${
     
     safeNumber(pos.heading, 1)}°, 俯仰 ${
     
     safeNumber(pos.pitch, 1)}°, 横滚 ${
     
     safeNumber(pos.roll, 1)}°
    速度: ${
     
     safeNumber(pos.speed, 1)} 米/秒 (北东天速度: [${
     
     safeNumber(pos.neu_vx, 1)}, ${
     
     safeNumber(pos.neu_vy, 1)}, ${
     
     safeNumber(pos.neu_vz, 1)}])
    角度: 攻角 ${
     
     safeNumber(pos.attack_angle, 2)}°, 侧滑角 ${
     
     safeNumber(pos.sideslip_angle, 2)}°
  `
}

// 格式化传感器信息
function formatSensorInfo(sensors) {
   
   
  if (!sensors || !sensors.length) return '  传感器: 无'
  
  return sensors.map(sensor => `
    传感器 ${
     
     sensor.id || '未知'}:
      名称: ${
     
     sensor.name || '未知'}
      类型: ${
     
     sensor.type || '未知'}
      状态: ${
     
     sensor.on_off ? '开启' : '关闭'}
      探测范围: ${
     
     sensor.detect_range?.toFixed(2) || '未知'}米
      方位角: ${
     
     sensor.detect_azimuth_angle?.toFixed(2) || '未知'}°
      俯仰角: ${
     
     sensor.detect_elevation_angle?.toFixed(2) || '未知'}°
      追踪状态: ${
     
     sensor.follow_off ? '开启' : '关闭'}
  `).join('\n')
}

// 格式化武器信息
function formatWeaponInfo(weapons) {
   
   
  if (!weapons || !weapons.length) return '  武器: 无'
  
  return weapons.map(weapon => `
    武器 ${
     
     weapon.id || '未知'}:
      名称: ${
     
     weapon.name || '未知'}
      类型: ${
     
     weapon.type || '未知'}
      剩余数量: ${
     
     weapon.quantity_remaining?.toFixed(0) || '未知'}
  `).join('\n')
}

// 格式化通信信息
function formatCommInfo(comms) {
   
   
  if (!comms || !comms.length) return '  通信设备: 无'
 
  
  return comms.map(comm => `
    通信设备 ${
     
     comm.id || '未知'}:
      名称: ${
     
     comm.name || '未知'}
      类型: <
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

满天飞飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值