北斗短报文通信服务平台
This commit is contained in:
32
app/middleware/parseDataPackage/parseDataPackage.js
Normal file
32
app/middleware/parseDataPackage/parseDataPackage.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// 解析数据包
|
||||
module.exports = (middleware, data) => {
|
||||
const utils = middleware.utils;
|
||||
const shunt = middleware.shunt;
|
||||
let msg;
|
||||
if (data == 'e5bf83e8b7b3') {
|
||||
msg = 'e5bf83e8b7b37878787888888888';
|
||||
} else {
|
||||
let regex = /..?/g,
|
||||
arr = data.match(regex),
|
||||
baseArr = utils.getArr(arr, 0, 14),
|
||||
baseObj = {
|
||||
infoSource: { label: "信源", data: parseInt(baseArr[0] + baseArr[1], 16) },
|
||||
destination: { label: "信宿", data: parseInt(baseArr[2] + baseArr[3], 16) },
|
||||
packageNumber: { label: "包序号", data: parseInt(baseArr[4] + baseArr[5] + baseArr[6] + baseArr[7], 16) },
|
||||
dataItem: { label: "当前数据项", data: parseInt(baseArr[8], 16) },
|
||||
dataLength: { label: "当前数据段总长度", data: parseInt(baseArr[9] + baseArr[10], 16) },
|
||||
resendFlag: { label: "重发标志", data: parseInt(baseArr[11], 16) },
|
||||
resendItem: { label: "重发数据项", data: parseInt(baseArr[12], 16) },
|
||||
resendLength: { label: "重发数据段总长度", data: parseInt(baseArr[13] + baseArr[14], 16) },
|
||||
dataContent: { label: "数据段", }
|
||||
};
|
||||
if (baseObj.dataItem.data !== 0) {
|
||||
shunt.selectXFType(middleware, 'now', baseObj, arr);
|
||||
}
|
||||
if (baseObj.resendFlag.data !== 0) {
|
||||
shunt.selectXFType(middleware, 'resend', baseObj, arr);
|
||||
}
|
||||
msg = baseObj;
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
24
app/middleware/parseDataPackage/parseMsg.js
Normal file
24
app/middleware/parseDataPackage/parseMsg.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// 解析通信服务的通信数据
|
||||
module.exports = (type, msg) => {
|
||||
let regex, arr, result = '';
|
||||
if (type == '0000') {
|
||||
// 0000, 汉字编码,按14bit区位编码,前7位为区码,后7位为位码
|
||||
// 区号和位号分别加上160,再分别转换成十六进制数,就成为四位的十六进制GB2312国家标准编码
|
||||
regex = /.......?/g;
|
||||
arr = msg.match(regex);
|
||||
for (let t = 0; t < arr.length; t += 2) {
|
||||
result = result + (parseInt(arr[t], 2) + 160).toString(16) + (parseInt(arr[t + 1], 2) + 160).toString(16);
|
||||
}
|
||||
} else if (type == '0001') {
|
||||
// 0001,BCD码,按4bit编码,将每4bit二进制转换为一个十进制数,再拼接成字符串
|
||||
regex = /....?/g;
|
||||
arr = msg.match(regex);
|
||||
arr.forEach(element => {
|
||||
result = result + parseInt(element, 2);
|
||||
});
|
||||
} else {
|
||||
// 保留,二进制转为十进制
|
||||
result = parseInt(msg, 2);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
125
app/middleware/parseDataPackage/parseXFType004.js
Normal file
125
app/middleware/parseDataPackage/parseXFType004.js
Normal file
@@ -0,0 +1,125 @@
|
||||
// 解析通信服务信息
|
||||
module.exports = (middleware, dataArr, objCtx) => {
|
||||
const utils = middleware.utils;
|
||||
const parseDataPackage = middleware.parseDataPackage;
|
||||
let informationFieldString = utils.hexToBinary(utils.getString(dataArr, 0, dataArr.length - 1));
|
||||
objCtx.msgContent = {
|
||||
originalMsg: utils.getString(dataArr, 0, dataArr.length - 1),
|
||||
outboundTypeIdentification: { label: "出站类型标识", data: parseInt(informationFieldString.slice(0, 8), 2) },
|
||||
receiverType: { label: "收方类型", data: parseInt(informationFieldString.slice(8, 16), 2) },
|
||||
receiverAddress: { label: "收方地址", data: parseInt(informationFieldString.slice(parseInt(informationFieldString.slice(8, 16), 2) == 0 ? 40 : 16, 64), 2) },
|
||||
msgLength: { label: "信息长度", data: parseInt(informationFieldString.slice(64, 80), 2) },
|
||||
msgCategory: {
|
||||
label: "信息类别",
|
||||
retain: { label: "保留", data: informationFieldString.slice(80, 81) },
|
||||
outboundFrameCategory: { label: "出站帧类别", data: informationFieldString.slice(81, 83) },
|
||||
typeOfCommunication: { label: "通信类型", },
|
||||
},
|
||||
};
|
||||
informationFieldString = informationFieldString.slice(83, objCtx.msgContent.msgLength.data + 80);
|
||||
switch (informationFieldString.slice(0, 2)) {
|
||||
case '00':
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.shortMsg = { label: "短报文", data: informationFieldString.slice(0, 2) };
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.senderType = { label: "发方类型", data: informationFieldString.slice(2, 3) };
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.packetID = {
|
||||
label: "报文标识",
|
||||
instantMessages: { label: "是否为即时报文出站", data: informationFieldString.slice(3, 4) },
|
||||
acknowledgmentOfReceipt: { label: "是否需要收方用户自动回执", data: informationFieldString.slice(4, 5) },
|
||||
};
|
||||
break;
|
||||
case '01':
|
||||
if (informationFieldString.slice(2, 3) == '0') {
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.onDemandCommunications = { label: "点播通信", data: informationFieldString.slice(0, 3) };
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.senderType = { label: "发方类型", data: informationFieldString.slice(3, 4) };
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.realTimeIdentification = { label: "实时标识", data: informationFieldString.slice(4, 5) };
|
||||
} else {
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.retain = { label: "保留", data: informationFieldString.slice(0, 5) };
|
||||
}
|
||||
break;
|
||||
case '10':
|
||||
if (informationFieldString.slice(0, 5) == '10000') {
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.receiptQueryResults = { label: "回执查询结果", data: informationFieldString.slice(0, 5) };
|
||||
} else {
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.retain = { label: "保留", data: informationFieldString.slice(0, 5) };
|
||||
}
|
||||
break;
|
||||
case '11':
|
||||
if (informationFieldString.slice(0, 5) == '11000') {
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.multicastCommunication = { label: "组播通信", data: informationFieldString.slice(0, 5) };
|
||||
} else if (informationFieldString.slice(0, 5) == '11010') {
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.broadcastCommunications = { label: "通播通信", data: informationFieldString.slice(0, 5) };
|
||||
} else {
|
||||
objCtx.msgContent.msgCategory.typeOfCommunication.retain = { label: "保留", data: informationFieldString.slice(0, 5) };
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
if (informationFieldString.slice(0, 2) == '00' || informationFieldString.slice(0, 3) == '010' || informationFieldString.slice(0, 5) == '11000' || informationFieldString.slice(0, 5) == '11010') {
|
||||
let typeMsg = informationFieldString.slice(0, 5);
|
||||
objCtx.msgContent.outboundMsg = {
|
||||
label: "出站信息段",
|
||||
firstFrame: { label: "是否首帧", data: informationFieldString.slice(5, 6) },
|
||||
resumeFrame: { label: "有无续帧", data: informationFieldString.slice(6, 7) },
|
||||
senderAddress: { label: "发方地址", },
|
||||
};
|
||||
if (typeMsg.slice(0, 3) == '001' || typeMsg.slice(0, 4) == '0101') {
|
||||
objCtx.msgContent.outboundMsg.senderAddress.data = parseInt(informationFieldString.slice(7, 55), 2);
|
||||
informationFieldString = informationFieldString.slice(55, informationFieldString.length);
|
||||
} else {
|
||||
objCtx.msgContent.outboundMsg.senderAddress.data = parseInt(informationFieldString.slice(7, 31), 2);
|
||||
informationFieldString = informationFieldString.slice(31, informationFieldString.length);
|
||||
};
|
||||
objCtx.msgContent.outboundMsg.sendMsgTime = {
|
||||
label: "发信时间",
|
||||
weeklyInstructions: { label: "周指示", data: parseInt(informationFieldString.slice(0, 1), 2) },
|
||||
intraWeekSeconds: { label: "周内秒", data: parseInt(informationFieldString.slice(1, 21), 2) },
|
||||
};
|
||||
if (typeMsg.slice(0, 2) == '00' && objCtx.msgContent.receiverAddress.data == '通播地址') {
|
||||
objCtx.msgContent.outboundMsg.ancillaryInformation = {
|
||||
label: "辅助信息",
|
||||
msgNumber: { label: "信息编号", data: parseInt(informationFieldString.slice(21, 29), 2) },
|
||||
};
|
||||
informationFieldString = informationFieldString.slice(29, informationFieldString.length);
|
||||
} else if (typeMsg.slice(0, 2) == '00' && objCtx.msgContent.receiverAddress.data == '组播地址') {
|
||||
objCtx.msgContent.outboundMsg.ancillaryInformation = {
|
||||
label: "辅助信息",
|
||||
totalGroupMembers: { label: "编组组员总数", data: parseInt(informationFieldString.slice(21, 28), 2) },
|
||||
onlineGroupMembers: { label: "在线组员数", data: parseInt(informationFieldString.slice(28, 35), 2) },
|
||||
msgNumber: { label: "信息编号", data: parseInt(informationFieldString.slice(35, 43), 2) },
|
||||
};
|
||||
informationFieldString = informationFieldString.slice(43, informationFieldString.length);
|
||||
} else if (typeMsg.slice(0, 5) == '11000') {
|
||||
objCtx.msgContent.outboundMsg.multicastAncillaryInformation = {
|
||||
label: "组播辅助信息",
|
||||
totalGroupMembers: { label: "编组组员总数", data: parseInt(informationFieldString.slice(21, 28), 2) },
|
||||
onlineGroupMembers: { label: "在线组员数", data: parseInt(informationFieldString.slice(28, 35), 2) },
|
||||
};
|
||||
informationFieldString = informationFieldString.slice(35, informationFieldString.length);
|
||||
} else {
|
||||
informationFieldString = informationFieldString.slice(21, informationFieldString.length);
|
||||
}
|
||||
objCtx.msgContent.outboundMsg.encodingCategory = { label: "编码类别", data: informationFieldString.slice(0, 4) }
|
||||
objCtx.msgContent.outboundMsg.msgData = { label: "通信数据", data: parseDataPackage.parseMsg(objCtx.msgContent.outboundMsg.encodingCategory.data, informationFieldString.slice(4, informationFieldString.length)) }
|
||||
} else if (informationFieldString.slice(0, 5) == '10000') {
|
||||
objCtx.msgContent.receiptQueryResults = {
|
||||
label: "回执查询结果",
|
||||
communicationRecipientAddress: { label: "通信收方地址", data: parseInt(informationFieldString.slice(5, 29), 2), },
|
||||
receiptsNumber: { label: "回执数", data: parseInt(informationFieldString.slice(29, 32), 2), },
|
||||
}
|
||||
if (objCtx.msgContent.receiptQueryResults.receiptsNumber.data !== 0) {
|
||||
informationFieldString = informationFieldString.slice(32, informationFieldString.length);
|
||||
for (let k = 0; k < objCtx.msgContent.receiptQueryResults.receiptsNumber.data; k++) {
|
||||
let communicationTime = "communicationTime" + (k + 1);
|
||||
objCtx.msgContent.receiptQueryResults[communicationTime] = {
|
||||
label: "通信发信时间" + (k + 1),
|
||||
weeklyInstructions: { label: "周指示", data: parseInt(informationFieldString.slice(0, 1), 2) },
|
||||
intraWeekSeconds: { label: "周内秒", data: parseInt(informationFieldString.slice(1, 21), 2) },
|
||||
}
|
||||
informationFieldString = informationFieldString.slice(21, informationFieldString.length);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
objCtx.msgContent.retain = { label: "保留", data: informationFieldString.slice(5, informationFieldString.length), }
|
||||
};
|
||||
};
|
||||
52
app/middleware/parseDataPackage/parseXFType005.js
Normal file
52
app/middleware/parseDataPackage/parseXFType005.js
Normal file
@@ -0,0 +1,52 @@
|
||||
// 解析广播服务信息
|
||||
module.exports = (middleware, dataArr, objCtx) => {
|
||||
const utils = middleware.utils;
|
||||
let fixedFieldString = utils.hexToBinary(utils.getString(dataArr, 0, 15).slice(0, 16)),
|
||||
informationFieldString = utils.hexToBinary(utils.getString(dataArr, 17, objCtx.contentLength.data + 3));
|
||||
objCtx.msgContent = {
|
||||
fixedField: {
|
||||
label: "固定域",
|
||||
satelliteNumber: { label: "卫星号", data: parseInt(fixedFieldString.slice(0, 6), 2) },
|
||||
beamNumber: { label: "波束号", data: parseInt(fixedFieldString.slice(6, 10), 2) },
|
||||
hyperframeCount: { label: "超帧计数", data: parseInt(fixedFieldString.slice(10, 27), 2) },
|
||||
weeklyCount: { label: "周计数", data: parseInt(fixedFieldString.slice(27, 40), 2) },
|
||||
frequencyDynamicControl: { label: "频度动态控制", data: parseInt(fixedFieldString.slice(40, 44), 2) },
|
||||
outboundDelayForecast: { label: "出站时延预报", data: parseInt(fixedFieldString.slice(44, 48), 2) },
|
||||
integrityInformation: { label: "完好性信息", data: parseInt(fixedFieldString.slice(48, 50), 2) },
|
||||
reserved1: { label: "保留1", data: parseInt(fixedFieldString.slice(50, 55), 2) },
|
||||
reserved2: { label: "保留2", data: parseInt(fixedFieldString.slice(55, 64), 2) },
|
||||
repeat: { label: "重复" },
|
||||
},
|
||||
msgType: { label: "MsgType", data: parseInt(utils.hexToBinary(dataArr[16]), 2) },
|
||||
informationField: { label: "类别信息域", },
|
||||
}
|
||||
objCtx.msgContent.informationField.satellitesNumber = { label: "本帧电文包括卫星数", data: parseInt(informationFieldString.slice(0, 3), 2) };
|
||||
informationFieldString = informationFieldString.slice(3, informationFieldString.length);
|
||||
if (objCtx.msgContent.informationField.satellitesNumber.data !== 0) {
|
||||
for (let j = 0; j < objCtx.msgContent.informationField.satellitesNumber.data; j++) {
|
||||
let satellitesObj = "satellitesObj" + (j + 1);
|
||||
objCtx.msgContent.informationField[satellitesObj] = {
|
||||
label: "卫星" + (j + 1),
|
||||
PRNNumber: { label: "导航PRN号", data: parseInt(informationFieldString.slice(0, 6), 2) },
|
||||
beamsNumber: { label: "出站波束数量", data: parseInt(informationFieldString.slice(6, 10), 2) },
|
||||
reserved1: { label: "保留1", data: parseInt(informationFieldString.slice(10, 16), 2) },
|
||||
reserved2: { label: "保留2", data: parseInt(informationFieldString.slice(16, 22), 2) },
|
||||
}
|
||||
informationFieldString = informationFieldString.slice(22, informationFieldString.length);
|
||||
if (objCtx.msgContent.informationField[satellitesObj].beamsNumber.data !== 0) {
|
||||
for (let l = 0; l < objCtx.msgContent.informationField[satellitesObj].beamsNumber.data; l++) {
|
||||
let CenterObj = "CenterObj" + (l + 1);
|
||||
objCtx.msgContent.informationField[satellitesObj][CenterObj] = {
|
||||
label: "波束" + (l + 1) + "中心经纬度",
|
||||
longitude: { label: "经度", data: parseInt(informationFieldString.slice(0, 1), 2) == 0 ? parseInt(informationFieldString.slice(1, 9), 2) : '-' + parseInt(informationFieldString.slice(1, 9), 2) },
|
||||
latitude: { label: "纬度", data: parseInt(informationFieldString.slice(9, 10), 2) == 0 ? parseInt(informationFieldString.slice(10, 17), 2) : '-' + parseInt(informationFieldString.slice(10, 17), 2) },
|
||||
}
|
||||
informationFieldString = informationFieldString.slice(17, informationFieldString.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
objCtx.msgContent.informationField.reserved = { label: "保留", data: informationFieldString };
|
||||
} else {
|
||||
objCtx.msgContent.informationField.reserved = { label: "保留", data: informationFieldString };
|
||||
}
|
||||
};
|
||||
16
app/middleware/parseDataPackage/parseXFType099.js
Normal file
16
app/middleware/parseDataPackage/parseXFType099.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// 解析集团客户认证结果信息
|
||||
module.exports = (dataArr, objCtx) => {
|
||||
let authCoed = parseInt(dataArr.pop(), 16);
|
||||
if (authCoed == 1) {
|
||||
let token = '';
|
||||
dataArr.forEach(element => {
|
||||
token = token + String.fromCodePoint(parseInt(element, 16));
|
||||
});
|
||||
objCtx.token = token;
|
||||
objCtx.authStatus = '1';
|
||||
objCtx.resultMsg = '认证成功';
|
||||
} else if (authCoed == 0) {
|
||||
objCtx.authStatus = '0';
|
||||
objCtx.resultMsg = '认证失败';
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user