_Examining the SmartSockets Toolkit_ by Douglass L. Campbell Listing One #define USER_DEVICE_DATA 2000 T_IPC_MT userDeviceDataMsgType; struct userDeviceDataBuffer { T_INT2 fepId; T_INT2 chan; T_INT2 devAdr; T_INT2 numDataFields; struct { T_INT2 pointNum; T_INT4 pointVal; T_INT4 quality; T_INT4 dataTime; } data[]; }; //---------------------------------------------------------------- // CreateDeviceDataMsgType // Create a user defined message type //---------------------------------------------------------------- void CreateDeviceDataMsgType(void) { // Create message type. Grammar is used to allow message logging to an ASCII // file. Curly braces in grammar indicate fields that can be repeated. // Message type: USER_DEVICE_DATA // Purpose: Transport field device data // Grammar: // Fixed fields: // int2 - FEP id // int2 - Channel // int2 - Device address // Repeated fields: // int2 - Point number // int4 - Point value // int4 - Data quality flags // int4 - Value time tag userDeviceDataMsgType = TipcMtCreate("device_data", USER_DEVICE_DATA, "int2 int2 int2 {int2 int4 int4 int4}"); } //---------------------------------------------------------------- // CreateUserDeviceDataMsg // Create and return a UserDeviceData message. //---------------------------------------------------------------- T_IPC_MSG CreateUserDeviceDataMsg(void) { T_IPC_MSG msg; // Create a message to transport data msg = TipcMsgCreate(userDeviceDataMsgType); return msg; } //---------------------------------------------------------------- // LoadUserDeviceDataMsg // Load a UserDeviceData message from the supplied buffer //---------------------------------------------------------------- void LoadUserDeviceDataMsg(T_IPC_MSG msg, userDeviceDataBuffer* buf) { TipcMsgAppendInt2(msg, buf->fepId); TipcMsgAppendInt2(msg, buf->chan); TipcMsgAppendInt2(msg, buf->devAdr); for (int x=0; xnumDataFields; x++) { TipcMsgAppendInt2(msg, buf->data[x].pointNum); TipcMsgAppendInt4(msg, buf->data[x].pointVal); TipcMsgAppendInt4(msg, buf->data[x].quality); TipcMsgAppendInt4(msg, buf->data[x].dataTime); } } Listing Two //-------------------------------------------------------------------------- // AcquireAndSendData. Get data from a channel and send it to other processes //-------------------------------------------------------------------------- void AcquireAndSendData(void) { T_IPC_MSG userDeviceDataMsg; userDeviceDataBuffer buffer; // create the new message type CreateDeviceDataMsgType(); // create connection to the IPC manager TipcSrvCreate(T_IPC_SRV_CONN_FULL); // go get some data acquireData(buffer); // create a message to send data userDeviceDataMsg = CreateUserDeviceDataMsg(); // load data into message LoadUserDeviceDataMsg(userDeviceDataMsg, buffer); // set message destination // this message goes to the logical "device_data" destination TipcMsgSetDest(userDeviceDataMsg, "device_data"); // set GMD TipcMsgSetDeliveryMode(userDeviceDataMsg, T_IPC_DELIVERY_ALL); // send the message TipcSrvMsgSend(userDeviceDataMsg, TRUE); }