void Chg_state (Uint8 cur_state)
{
Uint8 i;
Static Uint8 Last_state=invalid;
plc_state.wait_t = 0;
Plc_state.init=1;
for (i = 0; i < PLC_SLOT_SZ; i++)
{
if (plc_state_slot[i].cur_state = = cur_state)
{
Plc_state.pstate = (struct plc_state *) &plc_state_slot[i];
Break
}
}
if (i >= PLC_SLOT_SZ)
{
Plc_state.pstate = (struct plc_state *) &plc_state_slot[0];
}
if (last_state! = plc_state.pstate->cur_state)
{
plc_state.trycnt = 0;
}
Last_state = plc_state.pstate->cur_state;
Notify (Ev_state);
}
void local_frame_opt (struct shs_frame *pframe)
{
if (cmd_reginfor = = Pframe->infor[0])
{
Get_reg (pframe);
}
else if (Cmd_req_aid = = Pframe->infor[0])
{
Chg_state (S_aid);//carrier active access AID, indicating that the carrier chip may be reset.
}
else if (Cmd_unlink = = Pframe->infor[0])
{//Gateway disconnected, carrier chip escalated disconnect, start carrier registration Panid settings ....
Chg_state (S_pwdreg);
}
}
Uint8 Frame_handle (uint8 init, void *args)
{
Uint8 Len,ret;
struct Shs_frame *pframe = (struct shs_frame *) args;
if (pframe = = NULL) return (0);
if (Is_all_xx (Pframe->said, 0x00, Id_len))
{//local communication
Local_frame_opt (pframe);
return (1);
}
Else
{//Offsite communication
ret = remote_frame_opt (pframe);
if (Ret > 1) {
Len = Set_ret_frame (pframe, ret);
Uart_write ((uint8 *) pframe, Len);
}
}
return (0);
}
const struct Plc_state plc_state_slot[]=
{
Init plc
{RST_PLC, R_eid, RESET_PLC},
{R_eid, s_bps, Rd_plc_eid},
{R_eid, S_aid, Rd_plc_eid},
{s_bps, S_aid, wr_plc_bps},
{s_aid, S_pwdreg,wr_plc_aid},
{S_pwdreg, S_panid, Set_register},
{S_panid, _end, Wr_plc_panid},
#if Key_reg
Key Reg
{UNLINK1, S_reg, Set_unlink},
#endif
Password Registration
{pwd_err, UNLINK2, Set_register},
{UNLINK2, S_panid, Set_unlink},
Registration successful
{g_gwid, S_reg, Rd_gw_aid},
{S_reg, G_sid, set_register},//set the registration properties, wait for the carrier chip to escalate Panid
{g_sid, _end, Rd_gw_sid},
{_end, _end, Frame_handle},
};