Example #1
0
}END_TEST

/* 
 Id/Title: tc-12 tests leds condition on 1 percentage
 Purpose: tests when battery percentage is 1, currentTimer minus previous Timer is greater than 500, then if 
 the ledState is LOW, the state should change to HIGH and the leds should be in LOW position.
 Expected results: All the ledpins be in LOW position
 Pass/Fail criteria: when check is run response is 100%: Checks: 15,
 Failures: 0, Errors: 0
 */

START_TEST(test_loop_ledState2) {
	//init_leds();
	
	display_percentage(1);
	
	int ledState = HIGH;
	
	if(ledState == LOW)
		ledState = HIGH;
	else {
		ledState = LOW;
	}

	
	fail_unless(digitalRead(ledPin1) == LOW);
	fail_unless(digitalRead(ledPin2) == ledState);
    fail_unless(digitalRead(ledPin3) == ledState);
    fail_unless(digitalRead(ledPin4) == ledState);
	
}END_TEST
Example #2
0
}END_TEST

/* 
 Id/Title: tc-10 tests leds condition on 1 percentage
 Purpose: tests when battery percentage is 1, currentTimer minus previous Timer is greater than 500, then currentTimer should
 be equal to previousTimer;
 Expected results: currentTimer equals to previousTimer
 Pass/Fail criteria: when check is run response is 100%: Checks: 15,
 Failures: 0, Errors: 0
 */

START_TEST(test_loop_timer) {
	init_leds();
	
	display_percentage(1);
	unsigned long currentTimer= 1200;
	unsigned long previousTimer= 600;
	
	if (currentTimer - previousTimer > 500 )
		
		previousTimer = currentTimer;
	 
	fail_unless(previousTimer == 1200);
	
	
}END_TEST
Example #3
0
/*!
 * @brief This function will be called by the Scheduler. It takes the battery number as input, and returns a binary message as output.
 * @param battery_number the battery number
 * @return a binary message that contains the battery level, from 0x0 to 0xE
 */
unsigned char get_battery_level(int battery_number) {
    /* get the percentage from the battery*/
    uint16_t percentage = get_percentage(battery_number);
        
    if (battery_number == FIRST_BATTERY) {
        /* send the percentage to the alarm */
        setup_alarm(percentage);
        /* send the percentage to the leds*/
        display_percentage(percentage);
    }
    /* the new bin msg protocol needs to be negotiated with Scheduler*/
//    uint8_t binMsg = make_msg(batteryNumber, percentage);
    unsigned char bin_msg = translate_level(percentage);
    
    return bin_msg;
}
Example #4
0
}END_TEST

/* 
 Id/Title: tc-07 tests leds condition on 21 percentage
 Purpose: tests when battery percentage is 21 then led 4 should be on and leds 1,2,3 should be off Prerequisites: leds be connected
 Expected results: All the ledpins be in HIGH position
 Pass/Fail criteria: when check is run response is 100%: Checks: 15,
 Failures: 0, Errors: 0
 */
START_TEST(test_loop_halfempty2) {
  init_leds();

  display_percentage(21);
	fail_unless(digitalRead(ledPin1) == LOW);
	fail_unless(digitalRead(ledPin2) == LOW);
    fail_unless(digitalRead(ledPin3) == LOW);
    fail_unless(digitalRead(ledPin4) == HIGH);

}END_TEST
Example #5
0
}END_TEST

/* 
 Id/Title: tc-02 tests leds condition on 100 percentage
 Purpose: tests when battery percentage is 100 then all the leds should be on
 Prerequisites: leds be connected
 Expected results: All the ledpins be in HIGH position
 Pass/Fail criteria: when check is run response is 100%: Checks: 15,
 Failures: 0, Errors: 0
 */

 START_TEST(test_loop_full) {
  init_leds();

  display_percentage(100);
	fail_unless(digitalRead(ledPin1) == HIGH);
	fail_unless(digitalRead(ledPin2) == HIGH);
    fail_unless(digitalRead(ledPin3) == HIGH);
    fail_unless(digitalRead(ledPin4) == HIGH);

}END_TEST
Example #6
0
int main (int argc, char **argv)
{
    const char *filename;
    tx_data_t data;
    nxt_link_t nxt;
    uint8_t buffer[USB_BUFSIZE];
    size_t read, sent;
    ssize_t total;
    FILE *ro_data;

    if (argc < 2) {
        fprintf(stderr, "Provide the ROM image as first parameter.\n");
        exit(1);
    }
    filename = argv[1];

    // FIXME this should be parametrized. Basically it's the address of
    // the first unlocked flash memory location.
    data.start_address = 0x108000;

    total = data.length = get_ro_size(filename);
    if (total == -1) {
        fprintf(stderr, "Invalid ROM image\n");
        exit(1);
    }
    
    if (nxt_init(&nxt)) {
        fprintf(stderr, "Initialization failed\n");
        exit(1);
    }

    ro_data = fopen(filename, "rb");
    if (ro_data == NULL) {
        fprintf(stderr, "Error in opening %s\n", filename);
        nxt_free(&nxt);
    }

    fprintf(stdout, "Sync sent: %d bytes\n"
                    "           start=%p\n"
                    "           length=%d\n",
            (int)nxt_send(&nxt, (void *)&data, sizeof(tx_data_t)),
            (void *)(uintmax_t)data.start_address,
            data.length);

    while ((read = fread((void *)buffer, 1, USB_BUFSIZE, ro_data)) > 0) {
        sent = nxt_send(&nxt, (void *)buffer, read);
        data.length -= sent;
        data.start_address += sent;
        display_percentage(total, &data);
        if (sent == -1) {
            fprintf(stderr, "Send failed: %s\r", nxt_libusb_strerr(&nxt));
            break;
        }
        usleep(DELAY_uSECS);
    }
    fprintf(stdout, "\nCompleted\n");

    if (ferror(ro_data)) {
        fprintf(stderr, "File error in %s\n", filename);
    }

    fclose(ro_data);
    nxt_free(&nxt);
    exit(0);
}