Exemplo n.º 1
0
/**
 * @brief
 * @note
 * @param
 * @retval
 */
void UIPDebug::uip_debug_printbytes(const uint8_t* data, uint8_t len) {
    for(uint8_t i = 0; i < len; i++) {
        pc.printf("%d", data[i]);
        if(i < len - 1)
            pc.printf(",");
    }
}
Exemplo n.º 2
0
int main() {
    Serial *pc = new Serial(USBTX, USBRX);

    MBED_HOSTTEST_TIMEOUT(20);
    MBED_HOSTTEST_SELECT(serial_nc_tx_auto);
    MBED_HOSTTEST_DESCRIPTION(Serial NC TX);
    MBED_HOSTTEST_START("MBED_38");

    // Wait until we receive start signal from host test
    char c = pc->getc();
    delete pc;

    // If signal is correct, start the test
    if (c == 'S') {
      Serial *pc = new Serial(USBTX, NC);
      pc->printf("TX OK - Expected\r\n");
      wait(0.5);  // wait for characters to finish transmitting

      delete pc;

      pc = new Serial(NC, USBRX);
      pc->printf("TX OK - Unexpected\r\n");
      wait(0.5);  // wait for characters to finish transmitting
      delete pc;
    }

    while (1) {
    }
}
Exemplo n.º 3
0
/**
 * @brief
 * @note
 * @param
 * @retval
 */
void UIPDebug::uip_debug_printconns(void) {
    for(uint8_t i = 0; i < UIP_CONNS; i++) {
        if(uip_debug_printcon(&con[i], &uip_conns[i])) {
            pc.printf("connection[");
            pc.printf("%d", i);
            pc.printf("] changed.\n");
        }
    }
}
Exemplo n.º 4
0
static void btn_onpress(void)
{
    /* attempt copy from box_challenge context
     * we know the context is properly aligned so we try to obtain a carbon copy
     * of its memory location */
    pc.printf("attempting to read the secret...");
    memcpy(&g_challenge, g_box_context, sizeof(g_challenge));
    pc.printf(" done\n\r");
}
char set_i2c_pointer(char addr, char reg)
{
    if (i2c.write(addr) == 0)
    {
        if (DEBUG)
            pc.printf("Could not write device address (set_i2c_pointer)\r\n");
        return 0;
    }
    if (i2c.write(reg) == 0)
    {
        if (DEBUG)
            pc.printf("Could not write reg address (set_i2c_pointer)\r\n");
        return 0;
    }
    return 1;
}
Exemplo n.º 6
0
void LED_board::print_board(){
   for(int i = 0; i < NUM_ROW; i++){
        for(int j = 0; j < NUM_COL; j++){
            pc.printf("row_buffer[%d][%d] = %x\r\n", i, j, row_buffer[i][j]);
        }
    }
}
Exemplo n.º 7
0
/* This function tries to send the latest logging data over Iridium */
void iridiumLoop(const void *context) {
    char data_buffer[200];
    sprintf(data_buffer,"IRIDIUM: %s %.6f %.6f %.6f %lu %.6f %.6f %.6f %.6f %lu %hu %hu",
        date,latitude,longitude,altitude,precision,internal_temp,external_temp,pressure,power,
        encoded_chars,good_sentences,failed_checksums);
    int err = isbd.sendSBDText(data_buffer);
    if (err == ISBD_BUSY) {
        diagSerial.printf("IRIDIUM IS BUSY\r\n");
        return;
    }
    if (err != 0) {
        diagSerial.printf("sendReceiveSBDText failed: error ");
        diagSerial.printf("%d\n", err);
    }

}
Exemplo n.º 8
0
// Sets a global with failure or success, assumes 1 thread all the time
int send_wnc_cmd(const char * s, string ** r, int ms_timeout)
{
  static const char * rsp_lst[] = { "OK", "ERROR", NULL };
  int len;
  
  pc.printf("Send: %s\r\n",s);
  int res = mdm_sendAtCmdRsp(s, rsp_lst, ms_timeout, &wncStr, &len);
  *r = &wncStr;   // Return a pointer to the static string
      
  if (res >= 0)
  {
      pc.puts("[");
      pc.puts(wncStr.data());
      pc.puts("]\n\r");
      if (res > 0)
      {
          if (WNC_MDM_ERR != WNC_NO_RESPONSE)
            WNC_MDM_ERR = WNC_CMD_ERR;
          return -1;
      }
      else
          return 0;
  }
  else
  {
      WNC_MDM_ERR = WNC_NO_RESPONSE;
      pc.puts("No response from WNC!\n\r");
      return -2;
  }
}
Exemplo n.º 9
0
/*
initialize the limits for LWM2M mode and set the state by reporting the first sample
set LWM2M_observing true or false depending on desired behavior
if LWM2M_observing is false, the sample won't be transmitted
*/
void LWM2M_notification_init()
{
    pc.printf("init\r\n");
    limits[0] = LWM2M_lt;
    limits[1] = LWM2M_gt;
    report_sample(get_sample());
    return;
}
Exemplo n.º 10
0
/** SENSOR functions -----------------------------------------------------------------------------*/
void node::createSensor(PinName sensorPin, PinName voltageCtrl, int num)  //Create new ligths in the node.
{
    if (num <= 5) {
        mySensors[num - 1] = new sensor(sensorPin, voltageCtrl);
    } else {
        pc.printf("Sensor number %d is invalid", num);
    }
}
Exemplo n.º 11
0
void node::sensorVccOff(int sensorNum)
{
    if (sensorNum <= 5) {
        return mySensors[sensorNum - 1]->sensorOff();
    } else {
        pc.printf("Sensor number %d is invalid", sensorNum);        
    }
}
Exemplo n.º 12
0
int node::sensorVccState(int sensorNum)
{
    if (sensorNum <= 5) {
        return mySensors[sensorNum - 1]->sensorState();
    } else {
        pc.printf("Sensor number %d is invalid", sensorNum);
        return 10000;
    }
}
Exemplo n.º 13
0
void SDHandler::_dirTest() {
#if DEBUG_LOGGING
  std::string path = "/sd/";
  _filenames = _read_directory(path);
  for(vector<std::string>::iterator it = _filenames.begin(); it < _filenames.end(); it++) {
    BT.printf("%s\n", (*it).c_str());
  }
#endif
}
Exemplo n.º 14
0
int read(char addr, char reg, char *buf, int n)
{
    i2c.start();
    if (set_i2c_pointer(addr, reg) == 0)
    {
        if (DEBUG)
            pc.printf("Could not set i2c pointer (read)\r\n");
        return 0;
    }
    if (i2c.read(addr|1, buf, n, true) != 0)
    {
        if (DEBUG)
            pc.printf("Could not execute read sequence (read)\r\n");
        return 0;
    }
    i2c.stop();
    return n;
}
Exemplo n.º 15
0
// disable accelerometer to save power
int accelerometer_standby()
{
    char power_ctl;
    int ret = read(accel_w, ACCEL_POWER_CTL, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error putting accelerometer in standby (accelerometer_standby)\r\n");
        return 0;
    }
    power_ctl &= 0xF7 ;
    ret = write(accel_w, ACCEL_POWER_CTL, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error putting accelerometer in standby (accelerometer_standby)\r\n");
        return 0;
    }
    return 1;
}
Exemplo n.º 16
0
int gyro_turnoff()
{
    char power_ctl;
    int ret = read(gyro_w, GYRO_CTRL_REG1, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error turning off gyro (gyro_turnoff)\r\n");
        return 0;
    }
    power_ctl &= 0xF7 ;
    ret = write(gyro_w, GYRO_CTRL_REG1, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error turning off gyro (gyro_turnoff)\r\n");
        return 0;
    }
    return 1;
}
Exemplo n.º 17
0
// enable accelerometer for measurements
int accelerometer_measure()
{
    char power_ctl;
    int ret = read(accel_w, ACCEL_POWER_CTL, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error putting accelerometer in measure mode (accelerometer_measure)\r\n");
        return 0;
    }
    power_ctl |= 0x8 ;
    ret = write(accel_w, ACCEL_POWER_CTL, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error putting accelerometer in measure mode (accelerometer_measure)\r\n");
        return 0;
    }
    return 1;
}
Exemplo n.º 18
0
int config_gyro()
{
    // turn on the gyro via i2c
    int ret = gyro_turnon();
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error starting up gyro\r\n");
        return 0;
    }
    return 4;
}
Exemplo n.º 19
0
int config_accelerometer(void)
{
    // take accelerometer out of standby mode
    int ret = accelerometer_measure();
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error starting up accelerometer\r\n");
        return 0;
    }
    return 8;
}
Exemplo n.º 20
0
	/*
	 * See header file
	 */
	void store_impact(void)
	{
		uint16_t i;
		pcSerial.printf("\nImpact complete:\nStarttime: %d\n", impact->starttime);
		pcSerial.printf("Samples: %d\nPeaks: %d\nMaximum: %d\n***********\n", impact->sample_count, impact->peak_count, impact->max_amplitude);
		
		// samples
		for(i = 0; i < impact->sample_count; i++){
			pcSerial.printf("%10u, %5hd; ", impact->starttime + i, impact->samples[i]);
		}
		pcSerial.printf("\n\n");
		
		// peaks
		for(i = 0; i < impact->peak_count + 3; i++){
			pcSerial.printf("%3hu: %10u %5hd\n", i, impact->peaks[i].timestamp, impact->peaks[i].value);
		}
		pcSerial.printf("\n");
		ImpStd_t std;
		std.numberOfPkgs = 1;
		std.maxPeaks = impact->max_amplitude;
		//printf("amplitude %x\n",impact->max_amplitude);
		std.timestamp = impact->starttime;
		//printf("starttime %x\n",impact->starttime);
		std.nrOfPeaks = impact->peak_count;
		//printf("peak_count %x\n",impact->peak_count);
		std.duration = impact->sample_count;
		//printf("sample_count %x\n",impact->sample_count);
		enqueueMessage(7,std,0x01,canId,IMPACT_STD_SINGLE);
	}
Exemplo n.º 21
0
int write(char addr, char reg, char *buf, int n)
{
    i2c.start();
    if (set_i2c_pointer(addr, reg) == 0)
    {
        if (DEBUG)
            pc.printf("Could not set i2c pointer (write)\r\n");
        return 0;
    }
    for (int i=0; i<n; i++)
    {
        if (i2c.write(buf[i]) == 0)
        {
            i2c.stop();
            if (DEBUG)
                pc.printf("Only sent %i/%i bytes (write)\r\n", i, n);
            return i;
        }
    }
    i2c.stop();
    return n;

}
Exemplo n.º 22
0
int main() {
    Serial *pc = new Serial(USBTX, USBRX);

    MBED_HOSTTEST_TIMEOUT(20);
    MBED_HOSTTEST_SELECT(serial_nc_rx_auto);
    MBED_HOSTTEST_DESCRIPTION(Serial NC RX);
    MBED_HOSTTEST_START("MBED_37");

    char c = pc->getc();


    // This should be true, sync the start of test
    if (c == 'S') {
        pc->printf("RX OK - Start NC test\r\n");

        // disconnect TX and  get char
        delete pc;
        pc = new Serial(NC, USBRX);
        c = pc->getc();
        if (c == 'E') {
            // ok disconnect Rx and answer to host
            delete pc;
            pc = new Serial(USBTX, NC);
            pc->printf("RX OK - Expected\r\n");

            c = pc->getc();
            // This should be false/not get here
            if (c == 'U') {
                pc->printf("RX OK - Unexpected\r\n");
            }
        }
        delete pc;
    }

    while (1) {
    }
}
Exemplo n.º 23
0
/*
Thread to sample the input and use the update callback on_update when sensor values change.
on_update will run the limits test and set the notification event trigger accordingly.
Also checks for the event trigger and sends a notification packet in this thread.
This allows the notification trigger to be set in a hardware timer ISR without blocking
the ISR with a network operation.
*/
static void LWM2M_notification_thread(void const *args)
{
    while (true){
        wait(.1);
        current_sample = LWM2M_Sensor.read() * (float) 100;
        
        // if this csample is different from last sample, then call the resource on_update
        if((current_sample != last_sample) && LWM2M_observing){
            //pc.printf("LWM2M resource update: %3.1f => %3.1f\r\n", last_sample, current_sample);
            last_sample = current_sample;
            on_update(current_sample); // callback to process notification attributes
        }
        
        // if triggered and in observing mode, build and send the notification packet
        if (notification_trigger && LWM2M_observing){
            
            if (pmax_exceeded){ pc.printf("pmax exceeded\r\n"); pmax_exceeded = false; }
            if (pmin_trigger){pc.printf("pmin trigger\r\n"); pmin_trigger = false; }
            
            sprintf(LWM2M_value_string, "%3.1f", notify_sample); 
            pc.printf("Sending: %s\r\n", LWM2M_value_string);        
            LWM2M_obs_number++;
            if(sn_nsdl_send_observation_notification
                (LWM2M_obs_token_ptr, LWM2M_obs_token_len, 
                (uint8_t*)LWM2M_value_string, strlen(LWM2M_value_string), 
                &LWM2M_obs_number, sizeof(LWM2M_obs_number), 
                COAP_MSG_TYPE_NON_CONFIRMABLE, 0) == 0){
                    
                pc.printf("LWM2M notification failed\r\n");
            }
            else{
                pc.printf("LWM2M notification\r\n");
                notification_trigger = false;
            }
        }
    }
}
Exemplo n.º 24
0
// Randomly initialize a blob's position, velocity, color, radius, etc.
// Set the valid flag to true and the delete_now flag to false.
// delete_now is basically the derivative of valid. It goes true for one
// fram when the blob is deleted, and then it is reset to false in the next frame
// when that blob is deleted.
void BLOB_init(BLOB* b)
{
    //std::srand(time(NULL)); // use current time as seed
    b->posx = (std::rand() % WORLD_WIDTH) - WORLD_WIDTH/2;
    b->posy = (std::rand() % WORLD_HEIGHT) - WORLD_HEIGHT/2;
    b->vx = std::rand() % 10 + 1;
    b->vy = std::rand()% 10 + 1;
    b->rad = std::rand() % 10 + 1;
    b->valid = true;
    b->delete_now = false;
    b->filled = false;
    pc.printf("X pos: %f\n", b-> posx);         // Let us know you made it this far
    pc.printf("Y pos: %f\n", b-> posy);         // Let us know you made it this far


}
Exemplo n.º 25
0
int read_gyro(struct sensor* s)
{
    int ret = read(gyro_w, GYRO_X, s->raw_data, 6);
    if (ret == 0)
    {
        pc.printf("Error, could not read (read_gyro)\r\n");
        return 0;
    }
    int16_t gxlsb = (int16_t) s->raw_data[0];
    int16_t gxmsb = (int16_t) s->raw_data[1];
    int16_t gylsb = (int16_t) s->raw_data[2];
    int16_t gymsb = (int16_t) s->raw_data[3];
    int16_t gzlsb = (int16_t) s->raw_data[4];
    int16_t gzmsb = (int16_t) s->raw_data[5];

    s->gx = ((gxmsb << 8) + gxlsb);
    s->gy = ((gymsb << 8) + gylsb);
    s->gz = ((gzmsb << 8) + gzlsb);
    return 1;
}
Exemplo n.º 26
0
int read_accelerometer(struct sensor* s)
{
    int ret = read(accel_w, ACCEL_X, s->raw_data, 6);
    if (ret == 0)
    {
        pc.printf("Error, could not read (read_accelerometer)\r\n");
        return 0;
    }
    int16_t axlsb = (int16_t) s->raw_data[0];
    int16_t axmsb = (int16_t) s->raw_data[1];
    int16_t aylsb = (int16_t) s->raw_data[2];
    int16_t aymsb = (int16_t) s->raw_data[3];
    int16_t azlsb = (int16_t) s->raw_data[4];
    int16_t azmsb = (int16_t) s->raw_data[5];

    s->ax = ((axmsb << 8) + axlsb);
    s->ay = ((aymsb << 8) + aylsb);
    s->az = ((azmsb << 8) + azlsb);
    return 1;
}
Exemplo n.º 27
0
	/*
	 * See header file
	 */
	void new_impact(Input_t imp_input)
	{
		#ifdef DEBUG_IMPACT
		uint16_t i;
		pcSerial.printf("\t\tnew impact\n");
		#endif
		impact->starttime = imp_input.timestamp;
		impact->baseline = baseline;
		impact->sample_count = 0;
		impact->peak_count = 0;
		impact->max_amplitude = 0;
		// OPTION: don't reset arrays to zero.
		#ifdef DEBUG_IMPACT
		for ( i = 0; i < MAX_IMPACT_LENGTH; i++){
			impact->samples[i] = 0;
			impact->peaks[i].timestamp = 0;
			impact->peaks[i].value = 0;
		}
		#endif
	}
Exemplo n.º 28
0
void resolve_mdm(void)
{
    do
    {
      WNC_MDM_ERR = WNC_OK;
      at_dnsresolve_wnc(MY_SERVER_URL, &MyServerIpAddress);
      if (WNC_MDM_ERR == WNC_NO_RESPONSE)
      {
        reinitialize_mdm();
        software_init_mdm();
      }
      else if (WNC_MDM_ERR == WNC_CMD_ERR)
      {
        pc.puts("Bad URL!!!!!!\r\n");
        MyServerIpAddress = "192.168.0.1";
        WNC_MDM_ERR = WNC_OK;
      }
    } while (WNC_MDM_ERR != WNC_OK);
    
    pc.printf("My Server IP: %s\r\n", MyServerIpAddress.data());
}
Exemplo n.º 29
0
/*
examine one query option to see if the tag matches one of the observe attributes
if so, set the corresponding attribute pmin, pmax, lt, gt, step and flag pending update
*/
void set_notification_attribute(char* option)
{
    char* attribute = strtok(option, "="); // first token
    char* value = strtok(NULL, "="); // next token
    
    pc.printf("Setting: %s = %s\r\n", attribute, value);

    if (strcmp(attribute, "pmin") == 0){
        sscanf(value, "%f", &LWM2M_pmin);
        attribute_update = true;
        return;
    }
    else if(strcmp(attribute, "pmax") == 0){
        sscanf(value, "%f", &LWM2M_pmax);
        attribute_update = true;
        return;
    }
    else if(strcmp(attribute, "gt") == 0){
        sscanf(value, "%f", &LWM2M_gt);
        attribute_update = true;
        return;
    }
    else if(strcmp(attribute, "lt") == 0){
        sscanf(value, "%f", &LWM2M_lt);
        attribute_update = true;
        return;
    }    
    else if(strcmp(attribute, "st") == 0){
        sscanf(value, "%f", &LWM2M_step);
        attribute_update = true;
        return;
    }
    else if(strcmp(attribute, "cancel") == 0){
        LWM2M_stop_notification();
        attribute_update = true;
        return;
    }
}
Exemplo n.º 30
0
// For debug purposes, you can use this to print a blob's properties to your computer's serial monitor.
void BLOB_print(BLOB b)
{
    pc.printf("(%f, %f) <%f, %f> Color: 0x%x\n", b.posx, b.posy, b.vx, b.vy, b.color);
}