// testEVE.cpp : Defines the entry point for the console application. // #include "stdio.h" #include "string.h" #define EVE_PRICE_LG 10 #define EVE_PRICE_COEF 3 class GLPrice { public: double price; int nbDec; }; void EncodePrice(char* _pEveField, GLPrice _glprice) { printf("==> entry price [%f]\n",_glprice.price); if( _pEveField == NULL ) { // xLog.Log(WARNG,"EveFieldEncoder::EncodePrice: NULL POINTER!"); //throw REJGL0016; printf("==> bad buffer entry\n"); } char v_format[20] = {""}; char v_price[EVE_PRICE_LG+30] = {""}; char* v_pt = NULL; int v_i = 0; printf("==> entry price after local data init [%f]\n",_glprice.price); if( EVE_PRICE_COEF > 9 ) { //xLog.Log(WARNG,"EveFieldEncoder::EncodePrice: COEF!" ); // throw REJGL008; printf("wrong coef\n"); } // define the format string sprintf( v_format, "%%d%%0%d.0%df",EVE_PRICE_LG ,EVE_PRICE_COEF ); printf("==> used format [%s]\n",v_format); // format the quantity string sprintf( v_price, v_format,EVE_PRICE_COEF, _glprice.price ); printf("==> coded price before dot removing [%s]\n",v_price); // get the dot in the string v_pt =strchr( v_price, '.' ); printf("==> strch resut %p %x\n",v_pt,v_pt); if( v_pt == NULL ) { //xLog.Log(WARNG,"EveFieldEncoder::EncodePrice: no dot in the string!" ); // throw REJGL008; } //xLog.Log(WARNG,"EveFieldEncoder::EncodePrice: v_format=%s\r\nv_price=%s\r\nv_pt=%s", v_format,v_price,v_pt ); // delete the dot in the string and keep number after the dot for( v_i = 0; v_i < EVE_PRICE_COEF;v_i++ ) { *v_pt = *(v_pt+1); printf("==> in loop *v_pt[%c] *(v_pt+1)[%c] v_i[%u]\n",*v_pt,*(v_pt+1),v_i); v_pt++; } // put the '\0' *v_pt = 0; v_i = strlen( v_price ); printf("==> result strlen [%u]\n",v_i); if( v_i != EVE_PRICE_LG ) { memset( _pEveField, '*', EVE_PRICE_LG ); //xLog.Log(WARNG,"EveFieldEncoder::EncodePrice: price format error: %s", v_price ); //throw REJGL008; } memcpy( _pEveField, v_price, EVE_PRICE_LG ); _pEveField[EVE_PRICE_LG]='\0'; } void PrintHex(double _toPrint); int main(int argc, char* argv[]) { /* simple test */ printf("########################################\n"); printf("############# simples test #############\n"); printf("########################################\n"); printf("just print 34.84: %f\n",34.84); printf("print 34.84 as hexa (shoulbe [40 41 6b ff85]) is"); PrintHex(34.84); printf("result of 32.61+2.23 (should be 34.840000) is:%f\n",32.61+2.23); printf("result of 17.42*2 (should be 34.840000) is:%f\n",17.42*2); printf("\n\n"); /* Encoding as EVE */ char v_msg[40+1]; GLPrice v_price; printf("########################################\n"); printf("############ Encoding test #############\n"); printf("########################################\n"); v_price.price = 34.84; EncodePrice(v_msg,v_price); printf("34.84 encoded as EVE price[%s]\n",v_msg); v_price.price = 4.84; EncodePrice(v_msg,v_price); printf("4.84 encoded as EVE price[%s]\n",v_msg); v_price.price = 22.94; EncodePrice(v_msg,v_price); printf("22.94 encoded as EVE price[%s]\n",v_msg); v_price.price = 48.45; EncodePrice(v_msg,v_price); printf("48.45 encoded as EVE price[%s]\n",v_msg); v_price.price = 48.47; EncodePrice(v_msg,v_price); printf("48.47 encoded as EVE price[%s]\n",v_msg); v_price.price = 27.14; EncodePrice(v_msg,v_price); printf("27.14 encoded as EVE price[%s]\n",v_msg); v_price.price = 4.85; EncodePrice(v_msg,v_price); printf("4.85 encoded as EVE price[%s]\n",v_msg); v_price.price = 48.44; EncodePrice(v_msg,v_price); printf("48.44 encoded as EVE price[%s]\n",v_msg); v_price.price = 64.84; EncodePrice(v_msg,v_price); printf("64.84 encoded as EVE price[%s]\n",v_msg); v_price.price = 92.94; EncodePrice(v_msg,v_price); printf("92.94 encoded as EVE price[%s]\n",v_msg); v_price.price = 29.44; EncodePrice(v_msg,v_price); printf("29.44 encoded as EVE price[%s]\n",v_msg); printf("\n\n"); return 0; } void PrintHex(double _toPrint) { char v_tmp[4]; memcpy(v_tmp,&_toPrint,4); unsigned short v_int1 = v_tmp[0],v_int2 = v_tmp[1],v_int3 = v_tmp[2],v_int4 = v_tmp[3]; printf(" %x %x %x %x\n",v_int1,v_int2,v_int3,v_int4); }