/* * returns: * -1 no message * -2 sms buffer overflow */ int SerialGSM::receiveSMS(SMS& sms) { response = readline(buffer,BUFFERLEN,length_read); if(response<0) return -1; if (readline(buffer,BUFFERLEN,length_read)<7) return -1; //if CMT: is not in the line, it is not a message if (str_indexof(buffer, "CMT: ",0) ==-1 ) return -1; byte ph_start=str_indexof(buffer,"\"",0); byte ph_end = str_indexof(buffer,"\"",ph_start+1); // "PH_NO" | ph_start = 0 | ph_end = 6 // length should be 5 | it is (ph_end - ph_start) - 1 strcpy(sms.phone_no,0,buffer,ph_start+1,(ph_end-ph_start)-1); int sms_i=0; do { response = readline(buffer,BUFFERLEN,length_read); if(sms_i+length_read>MAXMSGLEN) { #ifdef DEBUG Serial.println(":: ERROR recieveSMS sms buffer overflow."); #endif return -2; } strcpy(sms.message,sms_i,buffer,0,length_read); sms_i+=length_read; } while(response>=0); return 0; }
void obj_hash_table_dump_func(FILE * fp, void * key,void * val) { if( val != NULL && str_indexof( (char *)key,"obj:") == 0 ) { fprintf(fp,"%s = (obj_t)\n",(char *)key, (char *)val); hash_table_iterate_file( ((obj_t*)val)->data,fp, obj_hash_table_dump_func); } else fprintf(fp,"%s = %s\n",(char *)key, (char *)val); }
int workerpool_get_nprocs() { FILE * f = fopen("/proc/cpuinfo", "r"); size_t n = 0; char * buf = NULL; int nproc = 0; while(getline(&buf, &n, f) != -1) { if(!str_starts_with(buf, "processor")) continue; int colon = str_indexof(buf, ":"); int v = atoi(&buf[colon+1]); if (v > nproc) nproc = v; } free(buf); return nproc; }