void InstructionPrinter::print_value(Value value) { if (value == NULL) { tty->print("NULL"); } else { print_temp(value); } }
//************************************************************** // main() //************************************************************** int main(){ #define Adresse 0x9E // evtl 9F für schreiben? #define Read 1 #define Write 0 unsigned char ucTemp1,ucTemp2; // Deklaration der Variablen display_init(); // Initialisiere Display int i; while(1) { signed int avg = 0; for(i = 0; i < 64; i++) { // Setzen der Startbedingung und warten bis slave antwortet mit ACK0 while(i2c_start(Adresse+Read)); ucTemp1 = i2c_rbyte(0); // Erstes Byte einlesen ucTemp2 = i2c_rbyte(1); // Zweites Byte einlesen i2c_stop(); // I2C wieder freigeben // Ausgabe der gelesenen Werte display_set_cursor(0, 0); print_temp(tempwert(ucTemp1, ucTemp2)); avg += tempwert(ucTemp1, ucTemp2); delay5ms(100); // Verzögerung 100 ms } display_set_cursor(0, 1); print_temp(avg >> 6); } while(1); // Endlosschleife }
static int wil_temp_debugfs_show(struct seq_file *s, void *data) { struct wil6210_priv *wil = s->private; u32 t_m, t_r; int rc = wmi_get_temperature(wil, &t_m, &t_r); if (rc) { seq_printf(s, "Failed\n"); return 0; } print_temp(s, "MAC temperature :", t_m); print_temp(s, "Radio temperature :", t_r); return 0; }
void print_readings(void) { for (uint8_t i=0; i<nSensors; i++ ) { logs_P("Sensor# "); logi((int) i+1); logs_P(" = "); print_temp(readings[i].subzero, readings[i].cel, readings[i].cel_frac_bits); logs_P("\r\n"); } }
/* * Intel specific log pages from * http://www.intel.com/content/dam/www/public/us/en/documents/product-specifications/ssd-dc-p3700-spec.pdf * * Though the version as of this date has a typo for the size of log page 0xca, * offset 147: it is only 1 byte, not 6. */ static void print_intel_temp_stats(void *buf, uint32_t size __unused) { struct intel_log_temp_stats *temp = buf; printf("Intel Temperature Log\n"); printf("=====================\n"); printf("Current: "); print_temp(temp->current); printf("Overtemp Last Flags %#jx\n", (uintmax_t)temp->overtemp_flag_last); printf("Overtemp Lifetime Flags %#jx\n", (uintmax_t)temp->overtemp_flag_life); printf("Max Temperature "); print_temp(temp->max_temp); printf("Min Temperature "); print_temp(temp->min_temp); printf("Max Operating Temperature "); print_temp(temp->max_oper_temp); printf("Min Operating Temperature "); print_temp(temp->min_oper_temp); printf("Estimated Temperature Offset: %ju C/K\n", (uintmax_t)temp->est_offset); }
//******************************************************************************************* // // Function : standby_display // Description : display board status such as AVR ip, server ip, countdown time, temparature // //******************************************************************************************* void standby_display ( void ) { BYTE generic_buf[64]; // update lcd display flag not set, exit from function if ( flag1.bits.update_display == 0 ) return; flag1.bits.update_display = 0; // lcd display is displaying other information, wait until busy flag clear if ( flag1.bits.lcd_busy ) return; // now displaying menu information, wait until exit from menu if ( menu_index ) return; // display status on lcd line 1 lcd_putc ( '\f' ); lcd_print ( (BYTE*)standby_list[ standby_cursor - 1 ] ); // display status devices on lcd line 2 lcd_putc ( '\n' ); if ( standby_cursor == 1 ) { print_devices (generic_buf,ind_device_cur); } // display avr ip if ( standby_cursor == 2 ) { print_ip ( generic_buf, (BYTE*)&avr_ip, 0 ); } // display server ip else if ( standby_cursor == 3 ) { print_ip ( generic_buf, (BYTE*)&server_ip, 0 ); } // display countdown timer else if ( standby_cursor == 4 ) { print_time ( generic_buf, count_time, 0 ); } // display current temparature else if ( standby_cursor == 5 ) { print_temp ( generic_buf ); } lcd_print ( generic_buf ); }
void InstructionPrinter::print_line(Instruction* instr) { // print instruction data on one line if (instr->is_pinned()) tty->put('.'); fill_to(bci_pos ); tty->print("%d", instr->bci()); fill_to(use_pos ); tty->print("%d", instr->use_count()); fill_to(temp_pos ); print_temp(instr); fill_to(instr_pos); print_instr(instr); tty->cr(); // add a line for StateSplit instructions w/ non-empty stacks // (make it robust so we can print incomplete instructions) StateSplit* split = instr->as_StateSplit(); if (split != NULL && split->state() != NULL && !split->state()->stack_is_empty()) { fill_to(instr_pos); print_stack(split->state()); tty->cr(); } }
void dump_waves(void) { int i,j; serial_puts("{\n"); for(i=0;i<8;i++) { const struct wave_s *wv = waves+i; char ebuf[] = "] },\n"; serial_puts(" \""); serial_puts(wv->name); serial_puts("\": {\n \"desc\": \""); serial_puts(wv->desc); serial_puts("\",\n \"pts\": ["); for(j=0;(j<48) && (wv->pt[j]);j++) { char buf[]="123, "; print_temp(buf,wv->pt[j]); buf[3] = ((j<47) && (wv->pt[j+1])) ? ',' : 0; serial_puts(buf); } ebuf[3] = i<7 ? ',' : ' '; serial_puts(ebuf); } serial_puts("}\n"); }
/** * \brief ADC interrupt handler. */ void ADC_Handler(void) { uint32_t ul_counter; int32_t l_vol; float f_temp; uint32_t ul_value = 0; uint32_t ul_temp_value = 0; if ((adc_get_status(ADC) & ADC_ISR_RXBUFF) == ADC_ISR_RXBUFF) { /* Multisample */ for (ul_counter = 0; ul_counter < BUFFER_SIZE; ul_counter++) { ul_value += gs_s_adc_values[ul_counter]; } /* Averaging */ ul_temp_value = ul_value / 10; ul_value = ul_value / 100; ul_temp_value -= (ul_value * 10); /* Round for last decimal */ if (ul_temp_value > 4) { ul_value++; } l_vol = ul_value * VOLT_REF / MAX_DIGITAL; #if SAM3S | SAM3XA /* Using multiplication (*0.37736) instead of division (/2.65). */ f_temp = (float)(l_vol - 800) * 0.37736 + 27.0; #else /* Using multiplication (*0.21186) instead of division (/4.72). */ f_temp = (float)(l_vol - 1440) * 0.21186 + 27.0; #endif print_temp(f_temp); /* Clear the buffer. */ memset(gs_s_adc_values, 0x0, sizeof(gs_s_adc_values)); /* Start new pdc transfer. */ adc_read_buffer(ADC, gs_s_adc_values, BUFFER_SIZE); } }
static int wil_bf_debugfs_show(struct seq_file *s, void *data) { int rc; int i; struct wil6210_priv *wil = s->private; struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev); struct wmi_notify_req_cmd cmd = { .interval_usec = 0, }; struct { struct wmi_cmd_hdr wmi; struct wmi_notify_req_done_event evt; } __packed reply; for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { u32 status; cmd.cid = i; rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, vif->mid, &cmd, sizeof(cmd), WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20); /* if reply is all-0, ignore this CID */ if (rc || is_all_zeros(&reply.evt, sizeof(reply.evt))) continue; status = le32_to_cpu(reply.evt.status); seq_printf(s, "CID %d {\n" " TSF = 0x%016llx\n" " TxMCS = %2d TxTpt = %4d\n" " SQI = %4d\n" " RSSI = %4d\n" " Status = 0x%08x %s\n" " Sectors(rx:tx) my %2d:%2d peer %2d:%2d\n" " Goodput(rx:tx) %4d:%4d\n" "}\n", i, le64_to_cpu(reply.evt.tsf), le16_to_cpu(reply.evt.bf_mcs), le32_to_cpu(reply.evt.tx_tpt), reply.evt.sqi, reply.evt.rssi, status, wil_bfstatus_str(status), le16_to_cpu(reply.evt.my_rx_sector), le16_to_cpu(reply.evt.my_tx_sector), le16_to_cpu(reply.evt.other_rx_sector), le16_to_cpu(reply.evt.other_tx_sector), le32_to_cpu(reply.evt.rx_goodput), le32_to_cpu(reply.evt.tx_goodput)); } return 0; } static int wil_bf_seq_open(struct inode *inode, struct file *file) { return single_open(file, wil_bf_debugfs_show, inode->i_private); } static const struct file_operations fops_bf = { .open = wil_bf_seq_open, .release = single_release, .read = seq_read, .llseek = seq_lseek, }; /*---------temp------------*/ static void print_temp(struct seq_file *s, const char *prefix, u32 t) { switch (t) { case 0: case ~(u32)0: seq_printf(s, "%s N/A\n", prefix); break; default: seq_printf(s, "%s %d.%03d\n", prefix, t / 1000, t % 1000); break; } } static int wil_temp_debugfs_show(struct seq_file *s, void *data) { struct wil6210_priv *wil = s->private; u32 t_m, t_r; int rc = wmi_get_temperature(wil, &t_m, &t_r); if (rc) { seq_puts(s, "Failed\n"); return 0; } print_temp(s, "T_mac =", t_m); print_temp(s, "T_radio =", t_r); return 0; } static int wil_temp_seq_open(struct inode *inode, struct file *file) { return single_open(file, wil_temp_debugfs_show, inode->i_private); } static const struct file_operations fops_temp = { .open = wil_temp_seq_open, .release = single_release, .read = seq_read, .llseek = seq_lseek, }; /*---------freq------------*/ static int wil_freq_debugfs_show(struct seq_file *s, void *data) { struct wil6210_priv *wil = s->private; struct wireless_dev *wdev = wil->main_ndev->ieee80211_ptr; u16 freq = wdev->chandef.chan ? wdev->chandef.chan->center_freq : 0; seq_printf(s, "Freq = %d\n", freq); return 0; } static int wil_freq_seq_open(struct inode *inode, struct file *file) { return single_open(file, wil_freq_debugfs_show, inode->i_private); } static const struct file_operations fops_freq = { .open = wil_freq_seq_open, .release = single_release, .read = seq_read, .llseek = seq_lseek, }; /*---------link------------*/ static int wil_link_debugfs_show(struct seq_file *s, void *data) { struct wil6210_priv *wil = s->private; struct station_info sinfo; int i, rc; for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { struct wil_sta_info *p = &wil->sta[i]; char *status = "unknown"; struct wil6210_vif *vif; u8 mid; switch (p->status) { case wil_sta_unused: status = "unused "; break; case wil_sta_conn_pending: status = "pending "; break; case wil_sta_connected: status = "connected"; break; } mid = (p->status != wil_sta_unused) ? p->mid : U8_MAX; seq_printf(s, "[%d][MID %d] %pM %s\n", i, mid, p->addr, status); if (p->status != wil_sta_connected) continue; vif = (mid < wil->max_vifs) ? wil->vifs[mid] : NULL; if (vif) { rc = wil_cid_fill_sinfo(vif, i, &sinfo); if (rc) return rc; seq_printf(s, " Tx_mcs = %d\n", sinfo.txrate.mcs); seq_printf(s, " Rx_mcs = %d\n", sinfo.rxrate.mcs); seq_printf(s, " SQ = %d\n", sinfo.signal); } else { seq_puts(s, " INVALID MID\n"); } } return 0; } static int wil_link_seq_open(struct inode *inode, struct file *file) { return single_open(file, wil_link_debugfs_show, inode->i_private); } static const struct file_operations fops_link = { .open = wil_link_seq_open, .release = single_release, .read = seq_read, .llseek = seq_lseek, }; /*---------info------------*/ static int wil_info_debugfs_show(struct seq_file *s, void *data) { struct wil6210_priv *wil = s->private; struct net_device *ndev = wil->main_ndev; int is_ac = power_supply_is_system_supplied(); int rx = atomic_xchg(&wil->isr_count_rx, 0); int tx = atomic_xchg(&wil->isr_count_tx, 0); static ulong rxf_old, txf_old; ulong rxf = ndev->stats.rx_packets; ulong txf = ndev->stats.tx_packets; unsigned int i; /* >0 : AC; 0 : battery; <0 : error */ seq_printf(s, "AC powered : %d\n", is_ac); seq_printf(s, "Rx irqs:packets : %8d : %8ld\n", rx, rxf - rxf_old); seq_printf(s, "Tx irqs:packets : %8d : %8ld\n", tx, txf - txf_old); rxf_old = rxf; txf_old = txf; #define CHECK_QSTATE(x) (state & BIT(__QUEUE_STATE_ ## x)) ? \ " " __stringify(x) : "" for (i = 0; i < ndev->num_tx_queues; i++) { struct netdev_queue *txq = netdev_get_tx_queue(ndev, i); unsigned long state = txq->state; seq_printf(s, "Tx queue[%i] state : 0x%lx%s%s%s\n", i, state, CHECK_QSTATE(DRV_XOFF), CHECK_QSTATE(STACK_XOFF), CHECK_QSTATE(FROZEN) ); } #undef CHECK_QSTATE return 0; } static int wil_info_seq_open(struct inode *inode, struct file *file) { return single_open(file, wil_info_debugfs_show, inode->i_private); } static const struct file_operations fops_info = { .open = wil_info_seq_open, .release = single_release, .read = seq_read, .llseek = seq_lseek, }; /*---------recovery------------*/ /* mode = [manual|auto] * state = [idle|pending|running] */ static ssize_t wil_read_file_recovery(struct file *file, char __user *user_buf, size_t count, loff_t *ppos) { struct wil6210_priv *wil = file->private_data; char buf[80]; int n; static const char * const sstate[] = {"idle", "pending", "running"}; n = snprintf(buf, sizeof(buf), "mode = %s\nstate = %s\n", no_fw_recovery ? "manual" : "auto", sstate[wil->recovery_state]); n = min_t(int, n, sizeof(buf)); return simple_read_from_buffer(user_buf, count, ppos, buf, n); } static ssize_t wil_write_file_recovery(struct file *file, const char __user *buf_, size_t count, loff_t *ppos) { struct wil6210_priv *wil = file->private_data; static const char run_command[] = "run"; char buf[sizeof(run_command) + 1]; /* to detect "runx" */ ssize_t rc; if (wil->recovery_state != fw_recovery_pending) { wil_err(wil, "No recovery pending\n"); return -EINVAL; } if (*ppos != 0) { wil_err(wil, "Offset [%d]\n", (int)*ppos); return -EINVAL; } if (count > sizeof(buf)) { wil_err(wil, "Input too long, len = %d\n", (int)count); return -EINVAL; } rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, buf_, count); if (rc < 0) return rc; buf[rc] = '\0'; if (0 == strcmp(buf, run_command)) wil_set_recovery_state(wil, fw_recovery_running); else wil_err(wil, "Bad recovery command \"%s\"\n", buf); return rc; } static const struct file_operations fops_recovery = { .read = wil_read_file_recovery, .write = wil_write_file_recovery, .open = simple_open, }; /*---------Station matrix------------*/ static void wil_print_rxtid(struct seq_file *s, struct wil_tid_ampdu_rx *r) { int i; u16 index = ((r->head_seq_num - r->ssn) & 0xfff) % r->buf_size; unsigned long long drop_dup = r->drop_dup, drop_old = r->drop_old; seq_printf(s, "([%2d] %3d TU) 0x%03x [", r->buf_size, r->timeout, r->head_seq_num); for (i = 0; i < r->buf_size; i++) { if (i == index) seq_printf(s, "%c", r->reorder_buf[i] ? 'O' : '|'); else seq_printf(s, "%c", r->reorder_buf[i] ? '*' : '_'); } seq_printf(s, "] total %llu drop %llu (dup %llu + old %llu) last 0x%03x\n", r->total, drop_dup + drop_old, drop_dup, drop_old, r->ssn_last_drop); }
static void print_log_health(void *buf, uint32_t size __unused) { struct nvme_health_information_page *health = buf; char cbuf[UINT128_DIG + 1]; int i; printf("SMART/Health Information Log\n"); printf("============================\n"); printf("Critical Warning State: 0x%02x\n", health->critical_warning.raw); printf(" Available spare: %d\n", health->critical_warning.bits.available_spare); printf(" Temperature: %d\n", health->critical_warning.bits.temperature); printf(" Device reliability: %d\n", health->critical_warning.bits.device_reliability); printf(" Read only: %d\n", health->critical_warning.bits.read_only); printf(" Volatile memory backup: %d\n", health->critical_warning.bits.volatile_memory_backup); printf("Temperature: "); print_temp(health->temperature); printf("Available spare: %u\n", health->available_spare); printf("Available spare threshold: %u\n", health->available_spare_threshold); printf("Percentage used: %u\n", health->percentage_used); printf("Data units (512,000 byte) read: %s\n", uint128_to_str(to128(health->data_units_read), cbuf, sizeof(cbuf))); printf("Data units written: %s\n", uint128_to_str(to128(health->data_units_written), cbuf, sizeof(cbuf))); printf("Host read commands: %s\n", uint128_to_str(to128(health->host_read_commands), cbuf, sizeof(cbuf))); printf("Host write commands: %s\n", uint128_to_str(to128(health->host_write_commands), cbuf, sizeof(cbuf))); printf("Controller busy time (minutes): %s\n", uint128_to_str(to128(health->controller_busy_time), cbuf, sizeof(cbuf))); printf("Power cycles: %s\n", uint128_to_str(to128(health->power_cycles), cbuf, sizeof(cbuf))); printf("Power on hours: %s\n", uint128_to_str(to128(health->power_on_hours), cbuf, sizeof(cbuf))); printf("Unsafe shutdowns: %s\n", uint128_to_str(to128(health->unsafe_shutdowns), cbuf, sizeof(cbuf))); printf("Media errors: %s\n", uint128_to_str(to128(health->media_errors), cbuf, sizeof(cbuf))); printf("No. error info log entries: %s\n", uint128_to_str(to128(health->num_error_info_log_entries), cbuf, sizeof(cbuf))); printf("Warning Temp Composite Time: %d\n", health->warning_temp_time); printf("Error Temp Composite Time: %d\n", health->error_temp_time); for (i = 0; i < 7; i++) { if (health->temp_sensor[i] == 0) continue; printf("Temperature Sensor %d: ", i + 1); print_temp(health->temp_sensor[i]); } }
int main(void) { uint32_t ui32ADC0Value[4]; ui32TempSet = 25; // Set System CLock SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Enaable UART SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // Enable GPIO SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable ADC Peripheral SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //Allow the ADC12 to run at its default rate of 1Msps. ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); //our code will average all four samples of temperature sensor data ta on sequencer 1 to calculate the temperature, so all four sequencer steps will measure the temperature sensor ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS); ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END); //enable ADC sequencer 1. ADCSequenceEnable(ADC0_BASE, 1); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); IntMasterEnable(); IntEnable(INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_3); // Set bit rate fr serial communication UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); while (1) { //indication that the ADC conversion process is complete ADCIntClear(ADC0_BASE, 1); //trigger the ADC conversion with software ADCProcessorTrigger(ADC0_BASE, 1); //wait for the conversion to complete while(!ADCIntStatus(ADC0_BASE, 1, false)) { } //read the ADC value from the ADC Sample Sequencer 1 FIFO ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value); ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4; ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10; ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5; print_temp(ui32TempValueC); SysCtlDelay(SysCtlClockGet() / 3); //delay ~1 sec if(ui32TempValueC < ui32TempSet) GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8); else GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2); } }
int main(void) { char str[] = "123 123\n"; uint32_t adc[2]; serial_init(19200); /* baud rate setting */ T0PR = (Fosc/1000)-1; /* 1ms granularity for both timers */ T1PR = (Fosc/1000)-1; T0TCR = 1; T1TCR = 0; T1TC = 0; // AD0.1, AD0.2 PINSEL1 = (1 << 24) | (1 << 26); IODIR0 = FAN_BIT | LAMP_BIT | BEEP_BIT; IOSET0 = FAN_BIT | LAMP_BIT | BEEP_BIT; delay_ms(100); BEEP_OFF; delay_ms(100); BEEP_ON; delay_ms(100); BEEP_OFF; do { uint8_t rb=0; for(; U0LSR & 0x01; rb=U0RBR) {} if ((rb >= '0') && (rb <= '3')) { T1TC = 0; if (rb & 1) { LAMP_ON; T1TCR = 1; } else { LAMP_OFF; } if (rb & 2) { FAN_ON; T1TCR = 1; } else { FAN_OFF; } } else if(rb == 'W') dump_waves(); // 3 seconds timeout if ((T1TCR) && (T1TC >= 3000)) { IOSET0 = LAMP_BIT | FAN_BIT; T1TCR = 0; T1TC = 0; } adc[0] = read_adc(1); adc[1] = read_adc(2); if((rb) && (rb!='W')) { print_temp(str, adc[0]); print_temp(str + 4, adc[1]); serial_puts(str); } } while ((adc[0] < MAXTEMP) && (adc[1] < MAXTEMP)); /* safeguard */ IODIR0 = LAMP_BIT | FAN_BIT | BEEP_BIT; // lamp off, beeper on, fan on IOSET0 = LAMP_BIT | BEEP_BIT; IOCLR0 = FAN_BIT; while (1) { } return 0; /* never reached */ }
int main(void) { CURL *curl_handle; CURLcode res; char *townName = (char *) secure_malloc(1); char readKeyBoard_char=' '; size_t townName_size=1; int choice=TOWN_NAME; char *name_validity_pointer=NULL; int query_strin_Size=strlen(initValue_queryValue)+1; char *query_string=(char *)secure_malloc(query_strin_Size); struct MemoryStruct chunk; secure_strcpy(query_string,initValue_queryValue); ////////////////////////////////begin big while LOOP while(1) { switch(choice) { case PRINT_TEMPERATURE: system("cls"); print_temp(chunk.memory); printf("\nPress anything to go back.."); _getch(); break; case PRINT_HUMIDITY: system("cls"); print_humidity(chunk.memory); printf("\nPress anything to back.."); _getch(); break; case TOWN_NAME: name_validity_pointer= NULL; while(name_validity_pointer==NULL){ chunk.memory =(char*) secure_malloc(1); /* will be grown as needed by the realloc above */ chunk.size = 0; /* no data at this point */ curl_global_init(CURL_GLOBAL_ALL); /* init the curl session */ curl_handle = curl_easy_init(); /* specify URL to get */ printf("\nplease enter townName:"); if(townName) { free(townName); townName=NULL; } townName_size=1; readKeyBoard_char=' '; townName=(char *) secure_malloc(1); while(1) { readKeyBoard_char=_getch(); if((int)readKeyBoard_char == ASCII_Code_ENTER) break; printf("%c",readKeyBoard_char); townName[townName_size-1]=readKeyBoard_char; townName[townName_size]='\0'; townName_size++; townName=(char *) realloc(townName,townName_size+1); } townName[townName_size]='\0'; secure_strcpy(query_string,initValue_queryValue); query_strin_Size = strlen(initValue_queryValue)+townName_size+strlen(lastPart_queryValue)+1; query_string=(char *) realloc(query_string,query_strin_Size); strcat_s(query_string,townName_size,townName); strcat_s(query_string,strlen(lastPart_queryValue),lastPart_queryValue); query_string[query_strin_Size]='\0'; curl_easy_setopt(curl_handle, CURLOPT_URL, query_string); /* send all data to this function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); /* we pass our 'chunk' struct to the callback function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); /* some servers don't like requests that are made without a user-agent field, so we provide one */ curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); /* get it! */ res = curl_easy_perform(curl_handle); /* check for errors */ if(res != CURLE_OK) { fprintf(stderr, "Connection to the server failed: %s\n", curl_easy_strerror(res)); } else { /* * Now, our chunk.memory points to a memory block that is chunk.size * bytes big and contains the remote file.*/ name_validity_pointer=strstr(chunk.memory,"Error: Not found city"); if(name_validity_pointer!=NULL) { printf("please enter a valid town name ,you have entered %s\n",townName); free_dynamicVar(chunk.memory); name_validity_pointer=NULL; } else{ name_validity_pointer = (char *) !NULL; } } } printf("\nThe town name %s is accepted",townName); Sleep(SECOND); break; case ABOUT_APPLICATION: system("cls"); printAbout(); printf("\nPress anything to back.."); _getch(); break; case EXIT: printf("Please enter any key to exit the Weather Application.."); _getch(); break; } if(choice == EXIT) break; system("cls"); printf("Welcome to Embedded Weather Station !\n"); printf("************The Menu ***************\n"); printf("1) Consult the temperature\n"); printf("2) Consult the humidity\n"); printf("3) change the town's name\n"); printf("4) About the application\n"); printf("5) exit the application\n"); printf("\nPlease enter a valid choice: (between 1 and 5):"); choice = DEFAULT; choice = (int)_getch() - ASCII_Code_0; while((choice < PRINT_TEMPERATURE) || (choice > EXIT)) { choice=(int)getchar()-ASCII_Code_0; } } ///////////////////////////////end big while /* cleanup curl stuff */ curl_easy_cleanup(curl_handle); free_dynamicVar(chunk.memory); free_dynamicVar(query_string); /* we're done with libcurl, so clean it up */ curl_global_cleanup(); return 0; }