_NETWORKING INTELLIGENT DEVICES_ by Gil Gameiro Listing One typedef struct { nuint16 CheckSum; nuint16 Length; nuint16 ConnectionID; nuint16 SequenceNumber; nuint16 PacketVersionID; nuint16 Reserved; nuint16 Function; nuint16 SubFunction; nuint16 Flags; nuint16 Status; } NPHeader; /* NPHeader structure is part of every NP packet going on the wire. */ void doNPEspressoMaker(NPConnection *hConn, ECB *reqECB, ECB *replyECB); { /* Get a pointer to the request */ NPRequestBuffer *stdReq = reqECB->ECB_Fragment[1].FragmentAddress; /* Get a pointer to the reply packet */ NPReplyBuffer *stdReply = replyECB->ECB_Fragment[1].FragmentAddress; /* Extract the SubFunction number from the NP Header */ int replySize = 0; int SubFunction = NSwapHiLo16(stReq->Header.SubFunction); switch (SubFunction) { /* Remotely fake a local control pannel key press */ case EX_MAKER_FAKE_KEY: { /* the key ID to fake is in the first byte */ nuint8 key = stdReq->DataBuffer[0]; espressoAddKeyToQueue(key); break; } /* Remote client is requesting the current status */ case EX_MAKER_REQUEST_STATUS: { memcpy(stdReq->DataBuffer, espressoGetStatus(), replySize = SIZEOF_EspressoStatus); break; } /* Display a message on the Maker LCD Display */ case EX_MAKER_POST_MESSAGE: { /* Get NP Lenght field, convert HiLo to Native */ int msgSize = NSwapHiLo16(reqECB->Header.Length); msgSize -= (SIZEOF_NPHeader - 4); espressoPostLCD(stdReq->DataBuffer, msgSize); } /* don't forget to report an error otherwise */ default: stdReply->Header.Status = NSwapHiLo16(NPER_UNKNOWN_REQUEST); }; /* Always reply */ replyECB.ECB_FragmentCount = 2; replyECB->ECB_Fragment[1].FragmentLength = replySize + SIZEOF_NPHeader; } Listing Two typedef struct _eventDataBlock { struct _eventDataBlock *edbNext; void *edbConenction; int edbFunction; int edbSubFunction; int edbStatus; int edbRequestID; long edbDataSize; nuint8 edbDataBlock[420]; } EDB; /* The EDB Structure as defined in the NPCAPI.H file; the DLL API. */ int TMainWindow::sendNP(int subFunction, unsigned char *req, int reqSize, char *reply) { EDB edb; memset(&edb, 0, sizeof(edb)); edb.edbFunction = EX_ESPRESSO_CLASS; edb.edbSubFunction = subFunction; if (edb.edbDataSize = reqSize) memcpy(edb.edbDataBlock, req, reqSize); int error = ::NPSendExtendedNP(hConn, &edb); // If that request generated a reply, transfer it to the user if (!error && edb.edbDataSize && reply) // that guy's buffer better be big enough! memcpy(reply, edb.edbDataBlock, edb.edbDataSize); return error; } int TMainWinow::fakeKeyPress(int keyID) { unsigned char key = (unsigned)keyID; sendNP(EX_MAKER_FAKE_KEY, &key, 1, NULL); } Example 1: int msgSize = NSwapHiLo16(reqECB->Header.Length); msgSize -= (SIZEOF_NPHeader - 4);