📄 socrat_b.c
字号:
static void Msg_Soc_Hdlc_Reset (P_DDS_MSG pMsg)
{
WORD8 res;
const WORD8 *error_text = NULL;
/* Read parameters of received
message. */
G_V24 = MsgReadWord8 (pMsg,0);
res = MsgReadWord8 (pMsg,1);
/* Set error text dependent on
the received parameters. */
if (res > 0x03)
error_text = "RES";
/* Start processing if all
parameters are correct. */
if (error_text == NULL)
{
/* V24 control message:
When processing. */
V24_PRINT(("\n(SLOT %d) Soc_Hdlc_Bz_Reset:res=0x%02X", SLOT_NR, res));
Soc_Hdlc_Reset (res);
}
/* V24 control message:
When error. */
if (error_text != NULL)
{
V24_PRINT (("\n(SLOT %d) Soc_Hdlc_Bz_Reset: %s ", SLOT_NR, Error_Text_Start));
V24_PRINT (("%s ", error_text));
V24_PRINT (("%s", Error_Text_End));
}
/* Free received message
because no message is
returned to the user. */
DdsMsgFree (pMsg);
}
/*******************************************************************************
Description:
Receive message for writing HDLC EOC data via SOCRATES.
Arguments:
pMsg - pointer to received message
Return Value:
none
Remarks:
HDLC transmission done by function Soc_Eoc_Transmit.
*******************************************************************************/
static void Msg_Soc_Eoc_Transmit (P_DDS_MSG pMsg)
{
WORD16 nr, i;
WORD8 *data_array, mode, src_adr, dest_adr;
const WORD8 *error_text = NULL;
int ret;
/* Read parameters of received
message. */
G_V24 = MsgReadWord8 (pMsg,0);
mode = MsgReadWord8 (pMsg,1);
src_adr = MsgReadWord8 (pMsg,2);
dest_adr = MsgReadWord8 (pMsg,3);
nr = MsgReadWord8 (pMsg,5);
if (mode > 3) error_text = "MODE";
if (src_adr > 0x0f) error_text = "SRC_ADR";
if (dest_adr > 0x0f) error_text = "DEST_ADR";
if (nr == 0) error_text = "NR";
data_array = (WORD8 *) malloc (nr+2);
if (data_array == NULL)
{
printf ("\n(SLOT %d) SOCRAT_B.C: Memory overflow, ignore data", SLOT_NR);
DdsMsgFree (pMsg);
return;
}
/* Start processing if all
parameters are correct. */
if (error_text == NULL)
{
/* set MODE_E */
BFLD (SOCRATES_MODE_E, 0x03, mode);
/* build HDLC_E frame */
/* source address */
data_array [0] = MsgReadWord8 (pMsg,2) << 4;
/* destination address */
data_array [0] |= MsgReadWord8 (pMsg,3);
/* message ID */
data_array [1] = MsgReadWord8 (pMsg,4);
/* copy data to buffer*/
for (i = 0;i < nr; i++)
data_array[i+2] = MsgReadWord8 (pMsg, i+6);
/* V24 control message:
When processing. */
V24_PRINT(("\n(SLOT %d) Soc_Eoc_Transmit:data=", SLOT_NR));
for (i = 0;i < nr+2; i++)
V24_PRINT(("0x%02X,", data_array[i]));
ret = Soc_Eoc_Transmit (nr+2, data_array);
switch (ret)
{
case -1:
V24_PRINT(("\n(SLOT %d) HDLC EOC Transceiver not ready!", SLOT_NR));
free (data_array);
data_array = NULL;
break;
case -2:
V24_PRINT(("\n(SLOT %d) HDLC EOC Transceiver still busy!", SLOT_NR));
free (data_array);
data_array = NULL;
break;
}
}
/* V24 control message:
When error. */
if (error_text != NULL)
{
V24_PRINT (("\n(SLOT %d) Soc_Eoc_Transmit: %s ", SLOT_NR, Error_Text_Start));
V24_PRINT (("%s ", error_text));
V24_PRINT (("%s", Error_Text_End));
}
/* Free received message
because no message is
returned to the user. */
DdsMsgFree (pMsg);
}
/*******************************************************************************
Description:
Receive message for writing HDLC EOC data via SOCRATES.
Arguments:
pMsg - pointer to received message
Return Value:
none
Remarks:
HDLC transmission done by function Soc_Eoc_Transmit.
*******************************************************************************/
static void Msg_Soc_Eoc_Transmit_Block (P_DDS_MSG pMsg)
{
WORD8 block_nr, i;
WORD8 data [16];
const WORD8 *error_text = NULL;
WORD8 *data_array;
int ret;
/* Read parameters of received
message. */
G_V24 = MsgReadWord8 (pMsg,0);
block_nr = MsgReadWord8 (pMsg,1);
if ((block_nr > 0xFE) || (block_nr == 0))
error_text = "Block Number";
data_array = (WORD8 *) malloc (16*block_nr);
if (data_array == NULL)
{
printf ("\n(SLOT %d) SOCRAT_B.C: Memory overflow, ignore data", SLOT_NR);
DdsMsgFree (pMsg);
return;
}
/* Start processing if all
parameters are correct. */
if (error_text == NULL)
{
/* get the 16 defined bytes */
for (i=0; i<16; i++)
data [i] = MsgReadWord8 (pMsg, i+2);
/* build data to send:
block_nr times these 16 bytes */
for (i=0; i<block_nr; i++)
memcpy((void*) (data_array + (i*16)), (void*) data, 16);
/* try sending data */
ret = Soc_Eoc_Transmit (block_nr*16, data_array);
switch (ret)
{
case -1:
V24_PRINT(("\n(SLOT %d) HDLC EOC Transceiver not ready!", SLOT_NR));
free (data_array);
data_array = NULL;
break;
case -2:
V24_PRINT(("\n(SLOT %d) HDLC EOC Transceiver still busy!", SLOT_NR));
free (data_array);
data_array = NULL;
break;
}
}
/* V24 control message:
When error. */
if (error_text != NULL)
{
V24_PRINT (("\n(SLOT %d) Soc_Eoc_Transmit_Block: %s ", SLOT_NR, Error_Text_Start));
V24_PRINT (("%s ", error_text));
V24_PRINT (("%s", Error_Text_End));
}
/* Free received message
because no message is
returned to the user. */
DdsMsgFree (pMsg);
}
/*******************************************************************************
Description:
Receive message for resetting HDLC EOC part of SOCRATES.
Arguments:
pMsg - pointer to received message
Return Value:
none
Remarks:
HDLC reset done by function Soc_Eoc_Reset.
*******************************************************************************/
static void Msg_Soc_Eoc_Reset (P_DDS_MSG pMsg)
{
WORD8 res;
const WORD8 *error_text = NULL;
/* Read parameters of received
message. */
G_V24 = MsgReadWord8 (pMsg,0);
res = MsgReadWord8 (pMsg,1);
/* Set error text dependent on
the received parameters. */
if (res > 0x03)
error_text = "RES";
/* Start processing if all
parameters are correct. */
if (error_text == NULL)
{
/* V24 control message:
When processing. */
V24_PRINT(("\n(SLOT %d) Soc_Eoc_Reset:res=0x%02X", SLOT_NR, res));
Soc_Eoc_Reset (res);
}
/* V24 control message:
When error. */
if (error_text != NULL)
{
V24_PRINT (("\n(SLOT %d) Soc_Eoc_Reset: %s ", SLOT_NR, Error_Text_Start));
V24_PRINT (("%s ", error_text));
V24_PRINT (("%s", Error_Text_End));
}
/* Free received message
because no message is
returned to the user. */
DdsMsgFree (pMsg);
}
/*******************************************************************************
Description:
Set state of the G.hs statemachine.
Arguments:
pMsg - Pointer to received message.
Return:
none
Remarks:
none
******************************************************************************/
static void Msg_Soc_Ghs_Set_State (P_DDS_MSG pMsg)
{
WORD8 command;
const WORD8 *error_text = NULL;
/* Read parameters of received
message. */
G_V24 = MsgReadWord8 (pMsg, 0);
G_Ghsstate_Indication = MsgReadWord8 (pMsg, 1);
command = MsgReadWord8 (pMsg, 2);
/* Set error text dependent on
the received parameters. */
if (G_Ghsstate_Indication > 0x01)
error_text = "enable indication";
if (command > 0x80)
error_text = "command";
if (error_text == NULL)
{
if (command == DOWNLOAD_CL)
{
/* download capability list */
Soc_Cl_Download();
}
else
{
/* write command */
Out(SOCRATES_TCMD, command);
}
}
else
{ /* V24 control message:
When error. */
V24_PRINT (("\nSocrates_Ghs_Set_State: %s ", Error_Text_Start));
V24_PRINT (("%s ", error_text));
V24_PRINT (("%s", Error_Text_End));
}
DdsMsgFree (pMsg);
}
/*******************************************************************************
Description:
Automatically use the g.hs state machine for activation.
Arguments:
pMsg - Pointer to received message.
Return:
none
Remarks:
none
Author: CM
******************************************************************************/
static void Msg_Soc_Ghs_Activate (P_DDS_MSG pMsg)
{
WORD8 reset;
const WORD8 *error_text = NULL;
/* Read parameters of received
message. */
G_V24 = MsgReadWord8 (pMsg, 0);
G_Ghsstate_Indication = MsgReadWord8 (pMsg, 1);
reset = MsgReadWord8 (pMsg, 2);
/* Set error text dependent on
the received parameters. */
if (G_Ghsstate_Indication > 0x01)
error_text = "enable indication";
if (reset > 0x01)
error_text = "reset";
if (error_text == NULL)
{
if (reset == 0x01)
{
Out (SOCRATES_TCMD, RESTR);
}
else
{
/* download capability list */
Soc_Cl_Download();
/* start preactivation */
Out(SOCRATES_TCMD, PREACT);
}
}
else
{ /* V24 control message:
When error. */
V24_PRINT (("\nSocrates_Ghs_Activate: %s ", Error_Text_Start));
V24_PRINT (("%s ", error_text));
V24_PRINT (("%s", Error_Text_End));
}
DdsMsgFree (pMsg);
}
/*******************************************************************************
Description:
Read actual state of transceiver state machine
Arguments:
pMsg - Pointer to received message.
Return:
none
Remarks:
none
Author: CM
******************************************************************************/
static void Msg_Soc_Ghs_Indicate_State (P_DDS_MSG pMsg)
{
WORD8 state;
state = In (SOCRATES_TSTAT);
MsgWriteWord8 (pMsg, 0, state);
V24_PRINT (("\nTransceiver state machine reached: 0x%2X", state));
/* Send answer to user. */
MsgWriteWord8 (pMsg, 0, state);
pMsg->dst = 0;
pMsg->src = MOD_ID_SOCRATES_MODULE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -