How split up a double value into 8 sets of uint8
-
Hi all, i am working on a simulink model (graphical block programming) and in a block i am supposed to write a user defined function (S-Function) which takes a double value and outputs 8 uint8 values. It has some simulink related commands but basically C Code. Since i have an error message, i would like to share it with you all to find a way out. #define S_FUNCTION_NAME double2integer #define S_FUNCTION_LEVEL 2 #include "simstruc.h" typedef union { uint8_T uvalue[8]; real_T d; //real_T is double } UnionNum; static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDataType(S, 0, SS_DOUBLE); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S,1)) return; ssSetOutputPortWidth(S, 0, 8); ssSetOutputPortDataType(S, 0, SS_UINT8); ssSetNumSampleTimes(S, 1); ssSetOptions(S,0); } static void mdlOutputs(SimStruct *S, int_T tid) { int_T i; int_T width = ssGetOutputPortWidth(S,0); InputPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0); uint8_T *y = (uint8_T *)ssGetOutputPortSignal(S,0); UnionNum num; num.d = *uPtrs[0] ; for(i=0; i
-
Hi all, i am working on a simulink model (graphical block programming) and in a block i am supposed to write a user defined function (S-Function) which takes a double value and outputs 8 uint8 values. It has some simulink related commands but basically C Code. Since i have an error message, i would like to share it with you all to find a way out. #define S_FUNCTION_NAME double2integer #define S_FUNCTION_LEVEL 2 #include "simstruc.h" typedef union { uint8_T uvalue[8]; real_T d; //real_T is double } UnionNum; static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDataType(S, 0, SS_DOUBLE); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S,1)) return; ssSetOutputPortWidth(S, 0, 8); ssSetOutputPortDataType(S, 0, SS_UINT8); ssSetNumSampleTimes(S, 1); ssSetOptions(S,0); } static void mdlOutputs(SimStruct *S, int_T tid) { int_T i; int_T width = ssGetOutputPortWidth(S,0); InputPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0); uint8_T *y = (uint8_T *)ssGetOutputPortSignal(S,0); UnionNum num; num.d = *uPtrs[0] ; for(i=0; i
cahit23 wrote:
Error : Have illegal types 'double' and 'void'
Do you not think it pertinent to include the line number of the code this error refers to? We're not mind readers.:rolleyes:
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
-
Hi all, i am working on a simulink model (graphical block programming) and in a block i am supposed to write a user defined function (S-Function) which takes a double value and outputs 8 uint8 values. It has some simulink related commands but basically C Code. Since i have an error message, i would like to share it with you all to find a way out. #define S_FUNCTION_NAME double2integer #define S_FUNCTION_LEVEL 2 #include "simstruc.h" typedef union { uint8_T uvalue[8]; real_T d; //real_T is double } UnionNum; static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; /* Parameter mismatch will be reported by Simulink */ } if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDataType(S, 0, SS_DOUBLE); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S,1)) return; ssSetOutputPortWidth(S, 0, 8); ssSetOutputPortDataType(S, 0, SS_UINT8); ssSetNumSampleTimes(S, 1); ssSetOptions(S,0); } static void mdlOutputs(SimStruct *S, int_T tid) { int_T i; int_T width = ssGetOutputPortWidth(S,0); InputPtrsType uPtrs = ssGetInputPortSignalPtrs(S,0); uint8_T *y = (uint8_T *)ssGetOutputPortSignal(S,0); UnionNum num; num.d = *uPtrs[0] ; for(i=0; i
cahit23 wrote:
How split up a double value into 8 sets of uint8
use this :
union DoubleToBytes {
double _d;
uint8 _ui[8];
};
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
cahit23 wrote:
Error : Have illegal types 'double' and 'void'
Do you not think it pertinent to include the line number of the code this error refers to? We're not mind readers.:rolleyes:
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
DavidCrow wrote:
Do you not think it pertinent to include the line number of the code this error refers to? We're not mind readers.
Oh sorry, pointed lines are : real_T d; and ** real_T is the representation of double in this format, even if i write there 'double' appears again as error ** num.d = *uPtrs[0]; Thank you for your consideration! Cahit