void setup(void) { // // Print preamble // Serial.begin(57600); // make sure serial terminal is closed before booting the Core while(!Serial.available()); // wait for user to open serial terminal and press enter SERIAL("\n\rSparkCore-RF24/Examples/GettingStartedRF24\n\r"); SERIAL("ROLE: RECEIVING\n\r"); SERIAL("*** PRESS 'T' to begin transmitting to the other node\n\r"); // // Setup and configure rf radio // radio.begin(); // optionally, uncomment to increase the delay between retries & # of retries. // delay is in 250us increments (4ms max), retries is 15 max. //radio.setRetries(15,15); // optionally, uncomment to reduce the payload size. // seems to improve reliability. //radio.setPayloadSize(8); // // Open pipes to other nodes for communication // // This simple sketch opens two pipes for these two nodes to communicate // back and forth. // Open 'our' pipe for writing // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) if ( role == role_ping_out ) { radio.openWritingPipe(pipes[0]); radio.openReadingPipe(1,pipes[1]); } else { radio.openWritingPipe(pipes[1]); radio.openReadingPipe(1,pipes[0]); } // // Start listening // radio.startListening(); // // Dump the configuration of the rf unit for debugging // radio.printDetails(); }
// // Start implementation // PR_BEGIN_EXTERN_C BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity) { xSerial = new mbSerial; // start port if (xSerial) { SERIAL(xSerial)->settings( ucPORT, ulBaudRate, ucDataBits, eParity); return SERIAL(xSerial)->start(); } return false; }
// This checks the Serial stream for characters, and assembles them into a buffer. // When the terminator character (default '\r') is seen, it starts parsing the // buffer for a prefix command, and calls handlers setup by addCommand() member bool SerialCommand::readSerial() { // If we're using the Hardware port, check it. Otherwise check the user-created SoftwareSerial Port #ifdef SERIALCOMMAND_HARDWAREONLY while (Serial.available() > 0) #else while ((usingSoftwareSerial==0 && Serial.available() > 0) || (usingSoftwareSerial==1 && SoftSerial->available() > 0) ) #endif { if (!usingSoftwareSerial) { // Hardware serial port inChar=Serial.read(); // Read single available character, there may be more waiting } else { #ifndef SERIALCOMMAND_HARDWAREONLY // SoftwareSerial port inChar = SoftSerial->read(); // Read single available character, there may be more waiting #endif } SERIAL("%c", inChar); // Echo back to serial stream if (inChar == '\r' || inChar == '\n') { // Check for the terminator meaning end of command string IF_SERIAL_DEBUG(SERIAL_LN("Received: %s", buffer)); return scanStateMachine(); } else if (isprint(inChar)) { // Only printable characters into the buffer buffer[bufPos++] = inChar; // Put character into buffer if (bufPos > SERIALCOMMANDBUFFER-1) bufPos=0; // wrap buffer around if full } } return true; }
void loop(void) { // // Ping out role. Repeatedly send the current time // if (role == role_ping_out) { // Switch to a Receiver before each transmission, // or this will only transmit once. radio.startListening(); // Re-open the pipes for Tx'ing radio.openWritingPipe(pipes[0]); radio.openReadingPipe(1,pipes[1]); // First, stop listening so we can talk. radio.stopListening(); // Take the time, and send it. This will block until complete unsigned long time = millis(); SERIAL("Now sending %lu...",time); bool ok = radio.write( &time, sizeof(unsigned long) ); if (ok) SERIAL("ok...\n\r"); else SERIAL(" failed.\n\r"); // Try again 1s later delay(100); } // // Pong back role. Receive each packet, dump it out, and send it back // if ( role == role_pong_back ) { // if there is data ready if ( radio.available() ) { // Dump the payloads until we've gotten everything unsigned long got_time; bool done = false; while (!done) { // Fetch the payload, and see if this was the last one. done = radio.read( &got_time, sizeof(unsigned long) ); // Spew it //printf("Got payload %lu...\n\r",got_time); Serial.print("Got payload "); Serial.println(got_time); // Delay just a little bit to let the other unit // make the transition to receiver delay(20); } // Switch to a transmitter after each received payload // or this will only receive once radio.stopListening(); // Re-open the pipes for Rx'ing radio.openWritingPipe(pipes[1]); radio.openReadingPipe(1,pipes[0]); // Now, resume listening so we catch the next packets. radio.startListening(); } } // // Change roles // if ( Serial.available() ) { char c = toupper(Serial.read()); if ( c == 'T' && role == role_pong_back ) { SERIAL("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r"); // Become the primary transmitter (ping out) role = role_ping_out; radio.openWritingPipe(pipes[0]); radio.openReadingPipe(1,pipes[1]); radio.stopListening(); } else if ( c == 'R' && role == role_ping_out ) { SERIAL("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r"); // Become the primary receiver (pong back) role = role_pong_back; radio.openWritingPipe(pipes[1]); radio.openReadingPipe(1,pipes[0]); radio.startListening(); } else if ( c == 'P' ) { SERIAL("*** PRINTING DETAILS\n\r"); radio.printDetails(); } } }
static struct flist *asymm_and_merge(RefList *in, const SymOpList *sym, UnitCell *cell, double rmin, double rmax, SymOpList *amb) { Reflection *refl; RefListIterator *iter; RefList *asym; struct flist *f; int n; asym = reflist_new(); if ( asym == NULL ) return NULL; for ( refl = first_refl(in, &iter); refl != NULL; refl = next_refl(refl, iter) ) { signed int h, k, l; signed int ha, ka, la; Reflection *cr; double res; get_indices(refl, &h, &k, &l); if ( cell == NULL ) { ERROR("Can't calculate resolution cutoff - no cell\n"); } else { res = 2.0*resolution(cell, h, k, l); if ( res < rmin ) continue; if ( res > rmax ) continue; } get_asymm(sym, h, k, l, &ha, &ka, &la); if ( amb != NULL ) { signed int hr, kr, lr; signed int hra, kra, lra; get_equiv(amb, NULL, 0, ha, ka, la, &hr, &kr, &lr); get_asymm(sym, hr, kr, lr, &hra, &kra, &lra); /* Skip twin-proof reflections */ if ( (ha==hra) && (ka==kra) && (la==lra) ) { //STATUS("%i %i %i is twin proof\n", h, k, l); continue; } } cr = find_refl(asym, ha, ka, la); if ( cr == NULL ) { cr = add_refl(asym, ha, ka, la); assert(cr != NULL); copy_data(cr, refl); } else { const double i = get_intensity(cr); const int r = get_redundancy(cr); set_intensity(cr, (r*i + get_intensity(refl))/(r+1)); set_redundancy(cr, r+1); } } f = malloc(sizeof(struct flist)); if ( f == NULL ) { ERROR("Failed to allocate flist\n"); return NULL; } n = num_reflections(asym); f->s = malloc(n*sizeof(unsigned int)); f->s_reidx = malloc(n*sizeof(unsigned int)); f->i = malloc(n*sizeof(float)); f->i_reidx = malloc(n*sizeof(float)); if ( (f->s == NULL) || (f->i == NULL) || (f->s_reidx == NULL) || (f->i_reidx == NULL) ) { ERROR("Failed to allocate flist\n"); return NULL; } f->n = 0; for ( refl = first_refl(asym, &iter); refl != NULL; refl = next_refl(refl, iter) ) { signed int h, k, l; get_indices(refl, &h, &k, &l); f->s[f->n] = SERIAL(h, k, l); f->i[f->n] = get_intensity(refl); f->n++; } assert(f->n == n); if ( amb != NULL ) { RefList *reidx = reflist_new(); if ( reidx == NULL ) return NULL; for ( refl = first_refl(asym, &iter); refl != NULL; refl = next_refl(refl, iter) ) { signed int h, k, l; signed int hr, kr, lr; signed int hra, kra, lra; Reflection *cr; get_indices(refl, &h, &k, &l); get_equiv(amb, NULL, 0, h, k, l, &hr, &kr, &lr); get_asymm(sym, hr, kr, lr, &hra, &kra, &lra); cr = add_refl(reidx, hra, kra, lra); copy_data(cr, refl); } n = 0; for ( refl = first_refl(reidx, &iter); refl != NULL; refl = next_refl(refl, iter) ) { signed int h, k, l; get_indices(refl, &h, &k, &l); f->s_reidx[n] = SERIAL(h, k, l); f->i_reidx[n++] = get_intensity(refl); } reflist_free(reidx); } reflist_free(asym); return f; }
BOOL xMBPortSerialGetByte(CHAR * pucByte) { return SERIAL(xSerial)->getByte( pucByte ); }
BOOL xMBPortSerialPutByte(CHAR ucByte) { return SERIAL(xSerial)->putByte( ucByte ); }