📄 chatbroadcast.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 EXAMPLE PROGRAM *
* *** + + *** CC1010 CHAT *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* Author: JOL *
*****************************************************************************
* Revision history: *
* *
* $Log: chatBroadcast.c,v $
* Revision 1.1 2002/10/14 10:02:27 tos
* Initial version in CVS.
*
* *
****************************************************************************/
/*****************************************************************************
*****************************************************************************
************* BROADCAST FUNCTIONS (USED BY THE SERVER) *************
*****************************************************************************
****************************************************************************/
#include "chat.h"
//----------------------------------------------------------------------------
// void broadcastMessage(char xdata *pMessage, byte messageLen)
//
// Description:
// Send the message to all clients
// Lost are detected and removed from the client list. The new list is
// broadcasted and printed in the terminal window.
//
// Arguments:
// byte sourceAddress
// The original message source
//
// char xdata *pMessage
// Pointer to the message
//
// byte messageLen
// Length(*pMessage)
//----------------------------------------------------------------------------
void broadcastMessage(byte sourceAddress, char xdata *pMessage, byte messageLen) {
byte n;
byte delClientAddress[MAX_CLIENTS]; // Used to flag lost clients
bool updateClientList;
updateClientList = FALSE;
// Append the source address to the end of the message;
TXI.pDataBuffer = pMessage;
TXI.pDataBuffer[messageLen] = sourceAddress;
TXI.dataLen = messageLen + 1;
// Send the message to all other clients, except the message source
for (n = 1; n < MAX_CLIENTS; n++) {
delClientAddress[n] = INVALID_ADDRESS;
if (((TXI.destination = CI[n].address) != INVALID_ADDRESS) && (TXI.destination != sourceAddress)) {
TXI.flags = (CI[n].txFlags & SPP_SEQUENCE_BIT) | SPP_ACK_REQ | MSG_CHAT_DOWN;
sppSend(&TXI);
while (SPP_STATUS() != SPP_IDLE_MODE);
if (TXI.status != SPP_TX_FINISHED) {
delClientAddress[n] = CI[n].address;
updateClientList = TRUE;
}
CI[n].txFlags = TXI.flags;
}
}
// Update the client list if necessary
if (updateClientList) {
// Delete the info
for (n = 1; n < MAX_CLIENTS; n++) {
if (delClientAddress[n] != INVALID_ADDRESS) {
delClientInfo(delClientAddress[n]);
}
}
// ... and announce lost clients
broadcastClientList();
printClientList();
}
} // broadcastMessage
//----------------------------------------------------------------------------
// void broadcastUserList()
//
// Description:
// Broadcast the whole user list (address0 | name0 | address1 | ....)
//----------------------------------------------------------------------------
void broadcastClientList(void) {
byte n, bCnt;
restart:
// PREPARE THE TRANSMISSION BUFFER
TXI.pDataBuffer = pAdminTXBuffer;
bCnt = 0;
// CI list (address0 | name0 | address1 | name1 |...)
for (n = 0; n < MAX_CLIENTS; n++) {
if (CI[n].address != INVALID_ADDRESS) {
TXI.pDataBuffer[bCnt++] = CI[n].address;
memcpy(&TXI.pDataBuffer[bCnt], CI[n].name, NAME_LENGTH);
bCnt += NAME_LENGTH;
}
}
TXI.dataLen = bCnt;
// Send the list to all other clients (Skip n=0)
for (n = 1; n < MAX_CLIENTS; n++) {
if ((TXI.destination = CI[n].address) != INVALID_ADDRESS) {
TXI.flags = SPP_ACK_REQ & ~MSG_MASK;
TXI.flags |= MSG_NEW_CLIENT_LIST;
sppSend(&TXI);
while (SPP_STATUS() != SPP_IDLE_MODE);
if (TXI.status != SPP_TX_FINISHED) {
delClientInfo(TXI.destination);
goto restart;
}
}
}
} // broadcastDelUser
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -