void ShowStats(Serial *serial, unsigned int argc, char **argv){ serial->put_s("== Memory Info ==\r\n"); unsigned long heap = (unsigned long)_heap_address; unsigned long lastPointer = getLastPointer(); serial->put_s("Heap address :"); put_uint(serial, heap); put_crlf(serial); serial->put_s("Last pointer address :"); put_uint(serial, lastPointer); put_crlf(serial); serial->put_s("Heap size :"); put_uint(serial, (unsigned int)&_CONFIG_HEAP_SIZE); put_crlf(serial); serial->put_s("Estimated Usage :"); put_uint(serial, lastPointer - heap); put_crlf(serial); serial->put_s("== Lua Info ==\r\n"); lua_State *L = getLua(); lua_gc(L,LUA_GCCOLLECT,0); serial->put_s("Lua Top :"); put_int(serial, lua_gettop(L)); put_crlf(serial); serial->put_s("Lua GC Count :"); put_int(serial, lua_gc(L,LUA_GCCOUNT,0)); put_crlf(serial); serial->put_s("== Misc ==\r\n"); serial->put_s("sizeof LoggerConfig :"); put_int(serial, sizeof(LoggerConfig)); put_crlf(serial); serial->put_s("sizeof SampleRecord :"); put_int(serial, sizeof(SampleRecord)); put_crlf(serial); }
void pub3::msgpack::outbuf_t::encode_positive_int (u_int64_t i) { if (i <= 0x7f) { put_byte (i); } else if (i <= 0xff) { put_byte (0xcc); put_byte (i); } else if (i <= 0xffff) { put_byte (0xcd); u_int16_t s = i; put_int (s); } else if (i <= 0xffffffff) { put_byte (0xce); u_int32_t w = i; put_int (w); } else { if (_jsmode) { strbuf b; b << i; encode_str(b); } else { put_byte (0xcf); put_int (i); } } }
void pub3::msgpack::outbuf_t::encode_negative_int (int64_t i) { assert (i < 0); if (i >= -32) { put_byte (i); } else if (i >= -128){ put_byte (0xd0); put_byte (i); } else if (i >= -32768) { put_byte (0xd1); int16_t s = i; put_int (s); } else if (i >= -2147483648) { put_byte (0xd2); int32_t w = i; put_int (w); } else { put_byte (0xd3); if (_jsmode) { strbuf b; b << i; encode_str(b); } else { int64_t q = i; put_int (q); } } }
static void clean_buffer(void) { char line[LINE_BUFFER_SIZE]; unsigned int current, *last; if (use_to_unique_but_not_add) { if (fseek(use_to_unique_but_not_add, 0, SEEK_SET) < 0) pexit("fseek"); while (fgetl(line, sizeof(line), use_to_unique_but_not_add)) { if (cut_len) line[cut_len] = 0; last = &buffer.hash[line_hash(line)]; #if ARCH_LITTLE_ENDIAN && !ARCH_INT_GT_32 current = *last; #else current = get_int(last); #endif while (current != ENTRY_END_HASH) { if (current != ENTRY_DUPE && !strcmp(line, &buffer.data[current + 4])) { put_int(last, get_data(current)); put_data(current, ENTRY_DUPE); break; } last = (unsigned int *)&buffer.data[current]; current = get_int(last); } } } if (do_not_unique_against_self) return; if (fseek(output, 0, SEEK_SET) < 0) pexit("fseek"); while (fgetl(line, sizeof(line), output)) { if (cut_len) line[cut_len] = 0; last = &buffer.hash[line_hash(line)]; #if ARCH_LITTLE_ENDIAN && !ARCH_INT_GT_32 current = *last; #else current = get_int(last); #endif while (current != ENTRY_END_HASH && current != ENTRY_DUPE) { if (!strcmp(line, &buffer.data[current + 4])) { put_int(last, get_data(current)); put_data(current, ENTRY_DUPE); break; } last = (unsigned int *)&buffer.data[current]; current = get_int(last); } } if (ferror(output)) pexit("fgets"); /* Workaround a Solaris stdio bug */ if (fseek(output, 0, SEEK_END) < 0) pexit("fseek"); }
void prot_qun_get_info( struct qqclient* qq, uint number, uint pos ) { qqpacket* p = packetmgr_new_send( qq, QQ_CMD_QUN_CMD ); if( !p ) return; bytebuffer *buf = p->buf; put_byte( buf, 0x72 ); //command? put_int( buf, number ); // put_int( buf, pos ); // post_packet( qq, p, SESSION_KEY ); }
void prot_user_change_status( struct qqclient* qq ) { qqpacket* p = packetmgr_new_send( qq, QQ_CMD_CHANGE_STATUS ); if( !p ) return; bytebuffer *buf = p->buf; put_byte( buf, qq->mode ); put_int( buf, 0 ); put_int( buf, 1 ); //camera?? put_word( buf, 0 ); post_packet( qq, p, SESSION_KEY ); }
void prot_qun_get_membername( struct qqclient* qq, uint number ) { qqpacket* p = packetmgr_new_send( qq, QQ_CMD_QUN_CMD ); if( !p ) return; bytebuffer *buf = p->buf; put_byte( buf, 0x0F ); //command? put_int( buf, number ); // put_int( buf, 0x0 ); //?? which is position?? put_int( buf, 0x0 ); //?? post_packet( qq, p, SESSION_KEY ); }
void prot_login_send_info( struct qqclient* qq ) { static uchar unknown5[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00 }; static uchar unknown6[] = {0xE9,0xC4,0xD6,0x5C,0x4D,0x9D, 0xA0,0x17,0xE5,0x24,0x6B,0x55,0x57,0xD3,0xAB,0xF1 }; static uchar unknown7[] = {0xCB,0x8D,0xA4,0xE2,0x61,0xC2, 0xDD,0x27,0x39,0xEC,0x8A,0xCA,0xA6,0x98,0xF8,0x9B }; qqpacket* p = packetmgr_new_send( qq, QQ_CMD_LOGIN_SEND_INFO ); if( !p ) return; bytebuffer *buf = p->buf; //prepare sth. randkey( unknown6 ); randkey( unknown7 ); put_word( buf, 0x0001 ); put_data( buf, qq->data.version_spec, sizeof(qq->data.version_spec) ); put_int( buf, qq->data.login_info_unknown2 ); put_int( buf, qq->server_time ); put_int( buf, qq->client_ip ); put_int( buf, 00000000 ); put_word( buf, qq->data.login_info_large.len ); put_data( buf, qq->data.login_info_large.data, qq->data.login_info_large.len ); buf->pos += 35; put_data( buf, qq->data.exe_hash, sizeof(qq->data.exe_hash) ); put_byte( buf, rand2() ); //unknown important byte put_byte( buf, qq->mode ); put_data( buf, unknown5, sizeof(unknown5) ); put_data( buf, qq->data.server_data, sizeof(qq->data.server_data) ); put_data( buf, qq->data.locale, sizeof(qq->data.locale) ); buf->pos += 16; //16 zeros put_word( buf, qq->data.token_c.len ); put_data( buf, qq->data.token_c.data, qq->data.token_c.len ); put_int( buf, 0x00000007 ); put_int( buf, 0x00000000 ); put_int( buf, 0x08041801 ); put_byte( buf, 0x40 ); //length of the following put_byte( buf, 0x01 ); put_int( buf, rand2() ); // put_int( buf, 0x0741E9748 ); put_word( buf, sizeof(unknown6) ); put_data( buf, unknown6, sizeof(unknown6) ); put_data( buf, unknown5, sizeof(unknown5) ); put_data( buf, qq->data.server_data, sizeof(qq->data.server_data) ); put_byte( buf, 0x02 ); put_int( buf, rand2() ); // put_int( buf, 0x8BED382E ); put_word( buf, sizeof(unknown7) ); put_data( buf, unknown7, sizeof(unknown7) ); buf->pos += 249; //all zeros memcpy( p->key, qq->data.login_info_key1, sizeof(qq->data.login_info_key1) ); post_packet( qq, p, RANDOM_KEY ); }
void add_mail(char file_name[]) { FILE *fptr = fopen(file_name, "r"); int date=0,id=0; static char from[NAME_SIZE],to[NAME_SIZE]; if(fptr != NULL) { if(fgets(input_buffer, BUFFER_SIZE, fptr)) { //From: strcpy(from, &input_buffer[6]); } if(fgets(input_buffer, BUFFER_SIZE, fptr)) { //Date: date = get_time(&input_buffer[6]); } if(fgets(input_buffer, BUFFER_SIZE, fptr)) { //Message-ID: id = get_int(&input_buffer[12]); } if(fgets(input_buffer, BUFFER_SIZE, fptr)) { //Subject: index_keywords(id, &input_buffer[9]); } if(fgets(input_buffer, BUFFER_SIZE, fptr)) { //To: strcpy(to, &input_buffer[4]); } from[strlen(from)-1] = STREND; to[strlen(to)-1] = STREND; index_name(id, from, to); index_date(id, date); index_mail(id); if(fgets(input_buffer, BUFFER_SIZE, fptr)) { //Content: while(fgets(input_buffer, BUFFER_SIZE, fptr)) { index_keywords(id, input_buffer); } } p("Mail "); put_int(id); p(" added, you have "); put_int(mail_set.size()); p(" mails"); puts(""); fclose(fptr); } else { p("No file: "); p(file_name); p("!!!!\n"); return; } }
void prot_user_check_ip( struct qqclient* qq ) { qqpacket* p = packetmgr_new_send( qq, QQ_CMD_CHECK_IP ); if( !p ) return; bytebuffer *buf = p->buf; put_byte( buf, 2 ); put_byte( buf, 2 ); put_byte( buf, 0 ); put_int( buf, 0xD4020202 ); put_int( buf, qq->last_login_time ); put_byte( buf, 8 ); put_byte( buf, 3 ); post_packet( qq, p, SESSION_KEY ); }
void prot_qun_get_memberinfo( struct qqclient* qq, uint number, uint* numbers, int count ) { qqpacket* p = packetmgr_new_send( qq, QQ_CMD_QUN_CMD ); if( !p ) return; bytebuffer *buf = p->buf; put_byte( buf, 0x0C ); //command? put_int( buf, number ); // int i; if( count > 30 ) count = 30; //TXQQ一次获取30个。 for( i=0; i<count; i++ ){ put_int( buf, numbers[i] ); // } post_packet( qq, p, SESSION_KEY ); }
void remove_mail(int id) { if(remove_index(id)) { p("Mail "); put_int(id); p(" removed, you have "); put_int(mail_set.size()); p(" mails\n"); } else { p("Mail does not exist, you have "); put_int(mail_set.size()); p(" mails"); puts(""); } }
static void sendAnalogConfig(Serial *serial, size_t startIndex, size_t endIndex){ json_messageStart(serial); json_blockStart(serial, "getAnalogCfg"); for (size_t i = startIndex; i <= endIndex; i++){ ADCConfig *cfg = &(getWorkingLoggerConfig()->ADCConfigs[i]); json_blockStartInt(serial, i); json_channelConfig(serial, &(cfg->cfg), 1); json_int(serial, "scalMod", cfg->scalingMode, 1); json_int(serial, "prec", cfg->loggingPrecision, 1); json_float(serial, "linScal", cfg->linearScaling, ANALOG_SCALING_PRECISION, 1); json_blockStart(serial, "map"); json_arrayStart(serial, "raw"); for (size_t b = 0; b < ANALOG_SCALING_BINS; b++){ put_int(serial, cfg->scalingMap.rawValues[b]); if (b < ANALOG_SCALING_BINS - 1) serial->put_c(','); } json_arrayEnd(serial, 1); json_arrayStart(serial, "scal"); for (size_t b = 0; b < ANALOG_SCALING_BINS; b++){ put_float(serial, cfg->scalingMap.scaledValues[b], ANALOG_SCALING_PRECISION); if (b < ANALOG_SCALING_BINS - 1) serial->put_c(','); } json_arrayEnd(serial, 0); json_blockEnd(serial, 0); //map json_blockEnd(serial, i != endIndex); //index } json_blockEnd(serial, 0); json_blockEnd(serial, 0); }
void api_sendSampleRecord(Serial *serial, SampleRecord *sr, unsigned int tick, int sendMeta){ json_messageStart(serial); json_blockStart(serial, "s"); json_uint(serial,"t",tick,1); if (sendMeta) writeSampleMeta(serial, sr, getConnectivitySampleRateLimit(), 1); size_t channelCount = 0; unsigned int channelsBitmask = 0; json_arrayStart(serial, "d"); for (int i = 0; i < SAMPLE_RECORD_CHANNELS; i++){ ChannelSample *sample = &(sr->Samples[i]); ChannelConfig * channelConfig = sample->channelConfig; if (SAMPLE_DISABLED != channelConfig->sampleRate){ if (NIL_SAMPLE != sample->intValue){ channelsBitmask = channelsBitmask | (1 << channelCount); int precision = sample->precision; if (precision > 0){ put_float(serial, sample->floatValue, precision); } else{ put_int(serial, sample->intValue); } serial->put_c(','); } channelCount++; } } put_uint(serial, channelsBitmask); json_arrayEnd(serial, 0); json_blockEnd(serial, 0); json_blockEnd(serial, 0); }
void search_mails(char from[], char to[], char before[], char after[], char keywords[]) { Ordered_mails result; search_index_keywords(keywords, result); search_index_name(from, to, result); search_index_date(get_time(before), get_time(after), result); bool output=false; Ordered_mails::iterator mi; for(mi=result.begin(); mi!=result.end(); mi++) { if(!id_exist(*mi)) continue; if(output) { putchar(' '); } put_int(*mi); output = true; } if(!output) p("-1"); putchar('\n'); #ifdef DEBUG cerr << "Search Mail from '" << from << "' to '" << to << "' before '" << before << "' after '" << after << "' keywords '" << keywords << "'" << endl; #endif }
void exec_closedict() { TypeDicID id; DICTL *dictl; id = get_int(); if (!work_base) longjmp(error_ret, SJ3_NotConnected); for (dictl = dictlist ; dictl ; dictl = dictl -> next) if (dictl -> dict -> dicid == id) break; if (!dictl) longjmp(error_ret, SJ3_BadDictID); unlock_dict((DictFile *)(dictl -> dict), cur_cli -> fd); closedict((DictFile *)(dictl -> dict)); if (dictlist == dictl) { dictlist = dictl -> next; } else { DICTL *p; for (p = dictlist ; p -> next ; p = p -> next) { if (p -> next == dictl) { p -> next = dictl -> next; break; } } } free((char *)dictl); put_int(SJ3_NormalEnd); }
int len_int(int d) { char buffer[256]; return(put_int(buffer, d) - buffer); }
hasp_status_t CNOF(hasp_handle_t handle, int SW, int SR, int LHO1200, int SRX, int IEF, int *result) { hasp_status_t status; unsigned char iobuffer[256]; VM_IO_BUFFER_T iobuffer_cxt; hasp_size_t iolength = 0; hasp_u32_t vm_returncode = 0; /* initialize arrays and structs */ memset(iobuffer, 0, sizeof(iobuffer)); memset(&iobuffer_cxt, 0, sizeof(iobuffer_cxt)); /* assume that the operation fails */ *result = -1; /* prepare Aoc API input buffer */ iobuffer_cxt.cmdBuff = iobuffer; iobuffer_cxt.rspBuff = iobuffer; put_int(&iobuffer_cxt, SW); put_int(&iobuffer_cxt, SR); put_int(&iobuffer_cxt, LHO1200); put_int(&iobuffer_cxt, SRX); put_int(&iobuffer_cxt, IEF); /* iolength = iobuffer_cxt.cmdSize; */ iolength = sizeof(iobuffer); /* invoke the method of VM resource */ status = hasp_vm_invoke(handle, REDAppMethodId_CNOF, iobuffer, &iolength, &vm_returncode); if (status != HASP_STATUS_OK) { #ifdef DEBUG printf("hasp_vm_invoke(CNOF) failed with status: %d\n", status); if (status == HASP_VM_METHOD_EXCEPTION_OCCUR) printf("exception code is %d, exception info is: %s\n", vm_returncode, iobuffer); #endif return status; } *result = vm_returncode; return status; } /* CNOF */
void pub3::msgpack::outbuf_t::encode_len (size_t len, u_int8_t b, u_int8_t s, u_int8_t l) { if (len <= 0xf) { b |= len; put_byte (b); } else if (len <= 0xffff) { put_byte (s); u_int16_t i = len; put_int (i); } else { put_byte (l); u_int32_t i = len; put_int (i); } }
hasp_status_t CYSO(hasp_handle_t handle, int SH, int SST, int SYO, int HPW, int NGIP, int NOP, int SPEO, int YINOP, int YSINOP, int *result) { hasp_status_t status; unsigned char iobuffer[256]; VM_IO_BUFFER_T iobuffer_cxt; hasp_size_t iolength = 0; hasp_u32_t vm_returncode = 0; /* initialize arrays and structs */ memset(iobuffer, 0, sizeof(iobuffer)); memset(&iobuffer_cxt, 0, sizeof(iobuffer_cxt)); /* assume that the operation fails */ *result = -1; /* prepare Aoc API input buffer */ iobuffer_cxt.cmdBuff = iobuffer; iobuffer_cxt.rspBuff = iobuffer; put_int(&iobuffer_cxt, SH); put_int(&iobuffer_cxt, SST); put_int(&iobuffer_cxt, SYO); put_int(&iobuffer_cxt, HPW); put_int(&iobuffer_cxt, NGIP); put_int(&iobuffer_cxt, NOP); put_int(&iobuffer_cxt, SPEO); put_int(&iobuffer_cxt, YINOP); put_int(&iobuffer_cxt, YSINOP); /* iolength = iobuffer_cxt.cmdSize; */ iolength = sizeof(iobuffer); /* invoke the method of VM resource */ status = hasp_vm_invoke(handle, REDAppMethodId_CYSO, iobuffer, &iolength, &vm_returncode); if (status != HASP_STATUS_OK) { #ifdef DEBUG printf("hasp_vm_invoke(CYSO) failed with status: %d\n", status); if (status == HASP_VM_METHOD_EXCEPTION_OCCUR) printf("exception code is %d, exception info is: %s\n", vm_returncode, iobuffer); #endif return status; } *result = vm_returncode; return status; } /* CYSO */
void put_string(const std::string &value) { size_t size = value.size()*sizeof(char); put_int(size); memcpy(&m_byte_buffer[offset], &value[0], size); offset += size; assert(offset < max_size); }
int main(int argc, char *argv[]) { int result=0, i=40; result=fib(i); put_int(result); return 0; }
hasp_status_t updateConsumption(hasp_handle_t handle, uint8_t tagNo, int isActive, int consumption, uint8_t *random, int *result) { hasp_status_t status; unsigned char iobuffer[256]; VM_IO_BUFFER_T iobuffer_cxt; hasp_size_t iolength = 0; hasp_u32_t vm_returncode = 0; int returnValue = 0; /* false */ /* initialize arrays and structs */ memset(iobuffer, 0, sizeof(iobuffer)); memset(&iobuffer_cxt, 0, sizeof(iobuffer_cxt)); /* assume that the consumption update fails */ *result = 0 /* false */; /* prepare Aoc API input buffer */ iobuffer_cxt.cmdBuff = iobuffer; iobuffer_cxt.rspBuff = iobuffer; put_byte(&iobuffer_cxt, tagNo); put_bool(&iobuffer_cxt, isActive); put_int(&iobuffer_cxt, consumption); put_byte_array(&iobuffer_cxt, random, 8); /* iolength = iobuffer_cxt.cmdSize; */ iolength = sizeof(iobuffer); /* invoke the method of VM resource */ status = hasp_vm_invoke(handle, REDAppMethodId_updateConsumption, iobuffer, &iolength, &vm_returncode); if (status != HASP_STATUS_OK) { #ifdef DEBUG printf("hasp_vm_invoke(updateConsumption) failed with status: %d\n", status); if (status == HASP_VM_METHOD_EXCEPTION_OCCUR) printf("exception code is %d, exception info is: %s\n", vm_returncode, iobuffer); #endif return status; } returnValue = (vm_returncode != 0); if (returnValue) { /* fetch random output parameter */ get_byte_array(&iobuffer_cxt, random, 8); } *result = returnValue; return status; } /* updateConsumption */
void prot_group_download_labels( struct qqclient* qq, uint pos ) { qqpacket* p = packetmgr_new_send( qq, QQ_CMD_GROUP_LABEL ); if( !p ) return; bytebuffer *buf = p->buf; put_byte( buf, 0x1F ); //command? put_byte( buf, 0x01 ); put_int( buf, pos ); post_packet( qq, p, SESSION_KEY ); }
void prot_user_get_level( struct qqclient* qq ) { qqpacket* p = packetmgr_new_send( qq, QQ_CMD_GET_LEVEL ); if( !p ) return; bytebuffer *buf = p->buf; put_byte( buf, 0x88 ); put_int( buf, qq->number ); put_byte( buf, 0x00 ); post_packet( qq, p, SESSION_KEY ); }
void exec_closestdy() { if (!cur_cli -> stdy) longjmp(error_ret, SJ3_StdyFileNotOpened); closestdy(cur_cli -> stdy); cur_cli -> stdy = NULL; put_int(SJ3_NormalEnd); }
void prot_user_get_notice( struct qqclient* qq, uchar type ) { qqpacket* p = packetmgr_new_send( qq, QQ_CMD_GET_KEY ); if( !p ) return; bytebuffer *buf = p->buf; p->need_ack = 0; switch( type ){ case 0: put_int( buf, qq->number ); break; case 1: put_int( buf, qq->number ); put_word( buf, 0x0007 ); put_word( buf, 0x0008 ); break; default: DBG("unknown type."); } post_packet( qq, p, SESSION_KEY ); }
void put_vector_value(const std::vector<T> //typename std::enable_if<std::is_integral<T>::value, T>::type &value) { size_t size = value.size()*sizeof(T); put_int(size); if (size > 0) { memcpy(&m_byte_buffer[offset], &value[0], size); offset += size; } assert(offset < max_size); }
/* *初始化IDT */ void init_idt_desc(u8 vector,u8 desc_type, int_handler handler, u8 priviledge) { gate *p_gate = &(g_idt[vector]); u32 base = (u32)handler; p_gate->offset_low = base & 0xFFFF; put_int(33,3,4,SELECTOR_KERNEL_R); p_gate->selector = SELECTOR_KERNEL_R; p_gate->dcount = 0; p_gate->attr = desc_type | (priviledge << 5); p_gate->offset_high = (base >> 16) & 0xFFFF; }
void ShowStats(Serial *serial, unsigned int argc, char **argv) { // Memory Info putHeader(serial, "Memory Info"); putDataRowHeader(serial, "Total Memory"); put_uint(serial, (unsigned int) &_CONFIG_HEAP_SIZE); put_crlf(serial); putDataRowHeader(serial, "Free Memory"); put_uint(serial, portGetFreeHeapSize()); put_crlf(serial); // LUA Info putHeader(serial, "Lua Info"); //TODO: this was done for unit testing. fix when Lua runtime is part of unit testing framework lua_State *L = (lua_State *) getLua(); lua_gc(L, LUA_GCCOLLECT, 0); putDataRowHeader(serial, "Lua Top"); put_int(serial, lua_gettop(L)); put_crlf(serial); putDataRowHeader(serial, "Lua Memory Usage (KB)"); put_int(serial, lua_gc(L, LUA_GCCOUNT, 0)); put_crlf(serial); // Misc Info putHeader(serial, "Misc"); putDataRowHeader(serial, "Size of LoggerConfig"); put_int(serial, sizeof(LoggerConfig)); put_crlf(serial); putDataRowHeader(serial, "Size of ChannelSample"); put_int(serial, sizeof(ChannelSample)); put_crlf(serial); }