void Comm::process() { if (m_addr) { // slave process_wire(); } else { // master process_serial(); } }
void main ( void ) #endif { init_sumo(); sumo_move(STOP); //wait_5s(); for(;;) { process_serial(); do_autonomous(); } }
void sensors_thread() { TBuff<uint8_t> buff; orcp2::packet pkt; buff.resize(2048); pkt.message.resize(256); if(!buff.data || !pkt.message.data) { ROS_ERROR("[!] Error: cant allocate memory!\n"); return ; } if(!sensors_serial.connected()) { ROS_WARN("Port not opened!\n"); return; } while (!global_stop) { process_serial(sensors_serial, buff, pkt); } }
/* * Computes all serial numbers of a device. This is done through brute force as * there's no heuristic than can help. * * The serial number is assumed to be in the following format: * CP$(YY)$(WW)--$(P1)$(P2)$(P3) ex: CP0923H3FHE2 * Where: * $(YY) is the year [04, 09] * $(WW) is the week number [01, 52] * $(P*) a single character in the range ['A' .. 'Z', '0' .. '9'] * * This function can be called from different threads in order to parallelize * the computations and get the results faster. When called from multiple * threads, the batches are distributed among all workers based on the modulo * of the serial's year (year % batch_max == batch_i). This means than a user * should not start more threads than there are years to be computed. Otherwise * exceeding threads will not be able to cooperate on the computation. * */ static void compute_serials (ThreadCtx *ctx) { unsigned char year, week, p1, p2, p3; /* Serial number that gets digested through SHA1; all serials numbers start with "CP" */ char serial [SERIAL_LENGTH + 1]; memset(serial, 0, sizeof(serial)); serial[0] = 'C'; serial[1] = 'P'; /* Build each part of the serial string and compute the key for each unique serial number */ for (year = ctx->year_start; year < ctx->year_end; ++year) { if (year % ctx->batch_max != (ctx->batch_i)) { continue; } SERIAL_DIGIT(serial, 2, year); for (week = 1; week <= 52; ++week) { SERIAL_DIGIT(serial, 4, week); /* The serial contains 3 letters that are in the range ['A' .. 'Z', '0' .. '9'] */ for (p1 = 0; p1 < 36; ++p1) { SERIAL_PART(serial, 6, p1); for (p2 = 0; p2 < 36; ++p2) { SERIAL_PART(serial, 8, p2); for (p3 = 0; p3 < 36; ++p3) { SERIAL_PART(serial, 10, p3); process_serial(ctx, serial, sizeof(serial)); } } } } } }
/** * \brief Control request event handler * * This implementation handles the control requests for the GuiderPort device */ void EVENT_USB_Device_ControlRequest() { if (is_control()) { if (is_incoming()) { switch (USB_ControlRequest.bRequest) { case FOCUSER_RESET: process_reset(); break; case FOCUSER_SET: process_set(); break; case FOCUSER_LOCK: process_lock(); break; case FOCUSER_STOP: process_stop(); break; case FOCUSER_SERIAL: process_serial(); break; } } if (is_outgoing()) { switch (USB_ControlRequest.bRequest) { case FOCUSER_GET: process_get(); break; case FOCUSER_RCVR: process_rcvr(); break; case FOCUSER_SAVED: process_saved(); break; } } } }
int main() { cli(); wdt_disable(); // To make sure nothing weird happens init_tlc5940(); init_spi(); init_ps(); init_blank_timer(); init_effect_timer(); init_playlist(); initUSART(); sei(); hcsr04_start_continuous_meas(); adc_start(); serial_boot_report(); // Select correct startup mode pick_startup_mode(); while(1) { /* Serial processing is implementation specific and defined in * serial_common.c */ process_serial(); switch (mode) { case MODE_SLEEP: // Fall through to MODE_IDLE case MODE_IDLE: // No operation sleep_if_no_traffic(); break; case MODE_PLAYLIST: ticks = centisecs(); if (ticks > effect_length) { next_effect(); init_current_effect(); } // no need to break! // fall to MODE_EFFECT on purpose case MODE_EFFECT: // If a buffer is not yet flipped, wait interrupts if (flags.may_flip) { sleep_if_no_traffic(); break; } // Update clock ticks = centisecs(); /* Go back to serial handler if drawing time * is reached. By doing this we avoid serial * port slowdown when FPS is low */ if (ticks < next_draw_at ) { sleep_if_no_traffic(); break; } /* Restart effect if maximum ticks is * reached. This may result a glitch but is * better than the effect to stop. */ if (ticks == ~0) { init_current_effect(); ticks = 0; } // Update sensor values sensors.distance1 = hcsr04_get_distance_in_cm(); sensors.distance2 = hcsr04_get_distance_in_cm(); //TODO: use separate sensor sensors.ambient_light = adc_get(0) >> 2; sensors.sound_pressure_level = adc_get(1) >> 2; // Do the actual drawing draw_t draw = (draw_t)pgm_get(effect->draw,word); if (draw != NULL) { draw(); allow_flipping(true); } // Update time when next drawing is allowed next_draw_at = ticks + pgm_get(effect->minimum_ticks,byte); break; } } return 0; }