📄 writer.cpp
字号:
// This test driver program encodes a data record and writes the encoded
// result to an output file..
#include <stdio.h>
#include <stdlib.h>
#include "NBAP-Constants.h"
#include "NBAP-Containers.h"
#include "NBAP-IEs.h"
#include "NBAP-PDU-ContentsTable.h"
#include "NBAP-PDU-DescriptionsTable.h"
#include "rtxsrc/rtxMemLeakCheck.h"
#include "rtxsrc/rtxDiag.h"
#define MAXMSGLEN 1024
OSBOOL verbose = FALSE, trace = TRUE;
DECLARE_MEMLEAK_DETECTOR;
int main (int argc, char** argv)
{
const OSOCTET* msgptr;
OSOCTET msgbuf[MAXMSGLEN];
OSBOOL verbose = FALSE, aligned = TRUE;
FILE* fp;
const char* filename = "message.dat";
int i, len, stat;
// Process command line arguments
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (!strcmp (argv[i], "-a")) aligned = TRUE;
else if (!strcmp (argv[i], "-u")) aligned = FALSE;
else if (!strcmp (argv[i], "-v")) verbose = TRUE;
else if (!strcmp (argv[i], "-o")) filename = argv[++i];
else if (!strcmp (argv[i], "-notrace")) trace = FALSE;
else {
printf ("usage: writer -a | -u [ -v ] [ -o <filename>\n");
printf (" -a use PER aligned encoding\n");
printf (" -u use PER unaligned encoding\n");
printf (" -v verbose mode: print trace info\n");
printf (" -o <filename> write encoded msg to <filename>\n");
printf (" -notrace do not display trace info\n");
return 0;
}
}
}
ASN1PEREncodeBuffer pebuf (msgbuf, sizeof(msgbuf), aligned);
// Populate and encode RL-InformationItemIE-RL-SetupRqstFDD
ASN1T_RL_InformationItem_RL_SetupRqstFDD rlInfoItem;
rlInfoItem.rL_ID = 25; // INTEGER (0..31)
rlInfoItem.c_ID = 1000; // INTEGER (0..65535)
rlInfoItem.firstRLS_indicator = FirstRLS_Indicator::first_RLS;
rlInfoItem.frameOffset = 99; // INTEGER (0..255)
rlInfoItem.chipOffset = 224; // INTEGER (0..38399)
rlInfoItem.propagationDelay = 22; // INTEGER (0..255)
rlInfoItem.m.diversityControlFieldPresent = 1;
rlInfoItem.diversityControlField = DiversityControlField::must_not;
ASN1C_FDD_DL_CodeInformation
codeInfoList (pebuf, rlInfoItem.dl_CodeInformation);
ASN1T_FDD_DL_CodeInformationItem codeInfoItem;
codeInfoItem.dl_ScramblingCode = 0;
codeInfoItem.fdd_DL_ChannelisationCodeNumber = 255;
codeInfoItem.transmissionGapPatternSequenceCodeInformation =
TransmissionGapPatternSequenceCodeInformation::nocode_change;
codeInfoList.Append (&codeInfoItem);
rlInfoItem.initialDL_transmissionPower = -22; // INTEGER (-350..150)
rlInfoItem.maximumDL_power = 100;
rlInfoItem.minimumDL_power = -100;
// Populate RL-InformationList-RL-SetupRqstFDD
ASN1T_RL_InformationList_RL_SetupRqstFDD_element rlInfoListElem;
rlInfoListElem.id = ASN1V_id_RL_InformationItem_RL_SetupRqstFDD;
rlInfoListElem.criticality = Criticality::notify;
rlInfoListElem.value.decoded = (void*)&rlInfoItem;
ASN1T_RL_InformationList_RL_SetupRqstFDD rlInfoList;
ASN1C_RL_InformationList_RL_SetupRqstFDD rlInfoListC (pebuf, rlInfoList);
rlInfoListC.Append (&rlInfoListElem);
// Populate RadioLinkSetupRequestFDD structure
ASN1T_RadioLinkSetupRequestFDD_protocolIEs_element protocolIE_1;
protocolIE_1.id = ASN1V_id_RL_InformationList_RL_SetupRqstFDD;
protocolIE_1.criticality = Criticality::notify;
protocolIE_1.value.decoded = (void*)&rlInfoList;
ASN1T_RadioLinkSetupRequestFDD rlSetupRequestFDD;
ASN1C_RadioLinkSetupRequestFDD_protocolIEs
rlSetupRequestFDDC (pebuf, rlSetupRequestFDD.protocolIEs);
rlSetupRequestFDDC.Append (&protocolIE_1);
// Populate NBAP-PDU structure
ASN1T_InitiatingMessage initMsg;
initMsg.procedureID.procedureCode = ASN1V_id_radioLinkSetup;
initMsg.procedureID.ddMode = ProcedureID_ddMode::fdd;
initMsg.criticality = Criticality::reject;
initMsg.messageDiscriminator = MessageDiscriminator::common;
initMsg.transactionID.t = T_TransactionID_shortTransActionId;
initMsg.transactionID.u.shortTransActionId = 1;
initMsg.value.decoded = (void*)&rlSetupRequestFDD;
ASN1T_NBAP_PDU pduData;
pduData.t = T_NBAP_PDU_initiatingMessage;
pduData.u.initiatingMessage = &initMsg;
// Encode the entire message
ASN1C_NBAP_PDU pdu (pebuf, pduData);
pebuf.SetTrace (trace);
if ((stat = pdu.Encode ()) == 0) {
if (trace) {
printf ("\n******\n");
printf ("NBAP PDU encoding was successful\n");
printf ("Hex dump of encoded record:\n");
pebuf.HexDump ();
printf ("Binary dump:\n");
pebuf.BinDump ("pdu");
}
}
else {
printf ("Encoding failed\n");
pebuf.PrintErrorInfo ();
return -1;
}
msgptr = pebuf.GetMsgPtr ();
len = pebuf.GetMsgLen ();
// Write the encoded message out to the output file
if (fp = fopen (filename, "wb")) {
fwrite (msgptr, 1, len, fp);
fclose (fp);
}
else {
printf ("Error opening %s for write access\n", filename);
return -1;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -