示例#1
0
/*
 * Single click handler on up button
 */
static void up_single_click_handler(ClickRecognizerRef recognizer, void *context) {
  // Make the snooze and the cancel buttons the same way around as the default alarm app
  #ifdef PBL_COLOR
    snooze_alarm();
  #else
    cancel_alarm();
  #endif
  // Bring clock up to date if a button is pressed
  revive_clock_on_movement(CLOCK_UPDATE_THRESHOLD);
}
示例#2
0
static void send_packet(int fd_out, int fd2, unsigned char buffer[], int buffer_length, unsigned char response[], int *response_length) {
    int i, bytes_read, bytes_written;
    unsigned char len, seq;
    const int *was_timeout;

    seq = unchar(buffer[2]);

    for(i = 0; i < MAX_RETRIES; i++) {
        bytes_written = write(fd_out, buffer, buffer_length);

        if(bytes_written != buffer_length) {
            fprintf(stderr, "sender: error writing packet to pipe (?!?)\n");
            continue;
        }

        was_timeout = set_alarm(TIMEOUT);

        bytes_read = read(fd2, response, 0x64);

        cancel_alarm();

        if(*was_timeout) {
            fprintf(stderr, "sender: we timed out while waiting for the ACK to the packet %d\n", seq);
            continue;
        }

        len = unchar(response[1]);

        if(!crc_check(tabel, response, len)) {
            fprintf(stderr, "sender: failed CRC check for the ACK/NAK to the packet %d\n", seq);
            continue;
        }

        if ( ( response[3] == 'Y' && buffer[2] == response[2] ) ||
             ( response[3] == 'N' && buffer[2] + 1 == response[2] ) ) {
            *response_length = bytes_read;
            return;
        }
    }

    fprintf(stderr, "sender: exceeded maximum number of retries... exiting...\n");

    close(fd_out);
    close(fd2);
    exit(0);
}
示例#3
0
static void
run_child(void)
{
	struct sockaddr_in sin;
	int rc = 0;

	listen_socket = socket(PF_INET, SOCK_STREAM, 0);
	if (listen_socket < 0) {
		printf("# socket: %s\n", strerror(errno));
		rc = -1;
	}

	if (!rc) {
		bzero(&sin, sizeof(sin));
		sin.sin_len = sizeof(sin);
		sin.sin_family = AF_INET;
		sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
		sin.sin_port = htons(TEST_PORT);

		if (bind(listen_socket, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
			printf("# bind: %s\n", strerror(errno));
			rc = -1;
		}
	}

	if (!rc && listen(listen_socket, -1) < 0) {
		printf("# listen: %s\n", strerror(errno));
		rc = -1;
	}

	if (!rc) {
		accept_socket = accept(listen_socket, NULL, NULL);	
		setup_alarm(TEST_SECONDS);
		if (receive_test() != 0)
			rc = -1;
	}

	cancel_alarm();
	if (accept_socket > 0)
		close(accept_socket);
	if (listen_socket > 0)
		close(listen_socket);

	_exit(rc);
}
示例#4
0
void *play_alarms()
{
    int8_t hour = 23;
    int8_t min;
    int status;
    while (hour >= 0)
    {
        min = 59;
        while (min >= 0)
        {
            status = cancel_alarm(hour, min, 1);
            if (status) ++cancelled_alarms;
            else ++failed_cancel_alarms;
            min -= 1;
        }
        -- hour;
    }
    return NULL;
}
示例#5
0
/*
 * Single click handler on down button
 */
static void down_single_click_handler(ClickRecognizerRef recognizer, void *context) {
  revive_clock_on_movement(CLOCK_UPDATE_THRESHOLD);
  // Make the snooze and the cancel buttons the same way around as the default alarm app  
  cancel_alarm();
}