void nRF24L01_SimulationDataGenerator::CreateNRFTransaction()
{
	int c;

	if (mCsn != NULL)
		mCsn->Transition();

	mSpiSimulationChannels.AdvanceAll(mClockGenerator.AdvanceByHalfPeriod(SPACE_COMMAND));
	
	OutputWord(0xFF, 0x0E);		// NOP
	OutputWord(0xFF, 0x0E);		// this one causes an MCU error message

	NewCommand();

	OutputWord(0x50, 0x0E);		// ACTIVATE
	OutputWord(0x73, 0x00);		// the activate command

	NewCommand();

	OutputWord(0xE2, 0x0E);		// FLUSH_RX

	NewCommand();

	OutputWord(0x2A, 0x0E);		// W_REGISTER RX_ADDR_P0
	OutputWord(0xE7, 0x00);
	OutputWord(0xE8, 0x00);
	OutputWord(0xE9, 0x00);
	OutputWord(0xE0, 0x00);
	OutputWord(0xE1, 0x00);

	NewCommand();

	OutputWord(0x21, 0x0E);		// W_REGISTER EN_AA
	OutputWord(0x01, 0x00);		// EN_AA_P0

	NewCommand();

	OutputWord(0x20, 0x0E);		// W_REGISTER CONFIG
	OutputWord(0x0F, 0x00);		// EN_CRC | CRC0 | PWR_UP | PRIM_RX

	NewCommand();

	OutputWord(0xA8, 0x0E);		// W_ACK_PAYLOAD
	for (c = 0; c < 12; c++)
		OutputWord(14 - c, 0x00);	// ACK payload data

	NewCommand();
	
	OutputWord(0x60, 0x0E);		// R_RX_PL_WID
	OutputWord(0x00, 0x08);

	NewCommand();

	// read RX payload
	OutputWord(0x61, 0x40);		// R_RX_PAYLOAD

	for (c = 0; c < 8; c++)
		OutputWord(0x00, c);	// RX payload data

	NewCommand();

	// switch to TX mode
	OutputWord(0x20, 0x0E);		// W_REGISTER CONFIG
	OutputWord(0x0E, 0x00);		// EN_CRC | CRC0 | PWR_UP

	NewCommand();

	OutputWord(0xE1, 0x0E);		// FLUSH_TX

	NewCommand();

	OutputWord(0xA0, 0x0E);		// W_TX_PAYLOAD
	for (c = 0; c < 10; c++)
		OutputWord(10 - c, 0x00);	// TX payload data

	NewCommand();

	OutputWord(0xE3, 0x0E);		// REUSE_TX_PL

	NewCommand();

	OutputWord(0xB0, 0x0E);		// W_TX_PAYLOAD_NOACK
	for (c = 0; c < 6; c++)
		OutputWord(10 + c, 0x00);


	if (mCsn != NULL)
		mCsn->Transition();

	mSpiSimulationChannels.AdvanceAll(mClockGenerator.AdvanceByHalfPeriod(SPACE_CYCLE));
}
예제 #2
0
static int ReadCommands(CurPos &cp, const char *Name) {
    STARTFUNC("ReadCommands");
    LOG << "Name = " << (Name != NULL ? Name : "(null)") << ENDLINE;

    unsigned char obj;
    unsigned short len;
    long Cmd = NewCommand(Name);
    long cmdno;

    if (GetObj(cp, len) != CF_INT) ENDFUNCRC(-1);
    if (GetNum(cp, cmdno) == 0) ENDFUNCRC(-1);
    if (cmdno != (Cmd | CMD_EXT)) {
        fprintf(stderr, "Bad Command map %s -> %ld != %ld\n", Name, Cmd, cmdno);
        ENDFUNCRC(-1);
    }

    while ((obj = GetObj(cp, len)) != 0xFF) {
        switch (obj) {
        case CF_COMMAND:
            {
                //              char *s;
                long cnt;
                long ign;
                long cmd;

                //                if ((s = GetCharStr(cp, len)) == 0) return -1;
                if (GetNum(cp, cmd) == 0) ENDFUNCRC(-1);
                if (GetObj(cp, len) != CF_INT) ENDFUNCRC(-1);
                if (GetNum(cp, cnt) == 0) ENDFUNCRC(-1);
                if (GetObj(cp, len) != CF_INT) ENDFUNCRC(-1);
                if (GetNum(cp, ign) == 0) ENDFUNCRC(-1);

                //                if (cmd != CmdNum(s)) {
                //                    fprintf(stderr, "Bad Command Id: %s -> %d\n", s, cmd);
                //                    return -1;
                //                }

                if (AddCommand(Cmd, cmd, cnt, ign) == 0) {
                    if (Name == 0 || strcmp(Name, "xx") != 0) {
                        fprintf(stderr, "Bad Command Id: %ld\n", cmd);
                        ENDFUNCRC(-1);
                    }
                }
            }
            break;
        case CF_STRING:
            {
                const char *s = GetCharStr(cp, len);

                if (s == 0) ENDFUNCRC(-1);
                if (AddString(Cmd, s) == 0) ENDFUNCRC(-1);
            }
            break;
        case CF_INT:
            {
                long num;

                if (GetNum(cp, num) == 0) ENDFUNCRC(-1);
                if (AddNumber(Cmd, num) == 0) ENDFUNCRC(-1);
            }
            break;
        case CF_VARIABLE:
            {
                long num;

                if (GetNum(cp, num) == 0) ENDFUNCRC(-1);
                if (AddVariable(Cmd, num) == 0) ENDFUNCRC(-1);
            }
            break;
        case CF_CONCAT:
            if (AddConcat(Cmd) == 0) ENDFUNCRC(-1);
            break;
        case CF_END:
            ENDFUNCRC(Cmd);
        default:
            ENDFUNCRC(-1);
        }
    }
    ENDFUNCRC(-1);
}