Incompatible Pointer Type Eclipse Function - c

I have a function which is performing some read operation from Sockets using udp,
the function is like this
int Read_packet(int CSPL_Socket, void *buf,int datalen)
{
int numb_bytes=0;
numb_bytes=read(CSPL_Socket, buf, datalen);
if(numb_bytes<0)
{
CSPL_SOK_ERROR(-6);
close(CSPL_Socket);
exit(1);
return -1;
}
else
{
//printf("Count %d\n",numb_bytes);
}
return 0;
}
When i call this from Eclipse ide, it shows a warning as shown below
But i dont see any performance issues here , everything is working good, how can i remove this warning ?
This is my definition for pkt
typedef struct UDP_Packet {
unsigned short Year; // year
unsigned char Month; // months
unsigned char Day; // day
unsigned char Hour; // hour
unsigned char Minute; // minute
unsigned char Seconds; // seconds
unsigned short Milliseconds; // milliseconds
unsigned char SeqNo; // packet sequence no
unsigned short CommandCode; // packet type
unsigned char DestSubSysID; // Destination sub system id (0 to 255)
unsigned char DestNodeID; // Destination node id
unsigned char SrcSubSysID; // Source sub system id
unsigned char SrcNodeID; // Source node id
unsigned short DataSize; // Data size in bytes
unsigned char AckSel; // select acknowledgment option
unsigned char AckID; // ID for ACK
unsigned char DataFlag; // Flag indicating single part(0) or multipart data (1)
unsigned char MessageID; // unique message ID
} UDP_Packet;
UDP_Packet pkt;

Related

How to pass Char array back

I'm writing a code to decode a specific, all function seem to be working fine with correct decoding result but I'm struggling to get the data into tydef struct
I'm define var like this
typedef struct{
unsigned char utctime[8];
unsigned char Lat[11];
unsigned char LatDirect;
unsigned char Status;
unsigned char Long[11];
unsigned char LongDirect;
//unsigned float speed;
unsigned char date[6];
}StrGPSDATA;
unsigned char datatestRealword1[100] = " *** TEST DATA HERE *** ";
Here is pseudo code.
unsigned char parseByDelimiter(char *inputData, const char delims, int index, unsigned int maxIndexSize){
unsigned char valOut[maxDataOut] = {0};
// Parse/Split value //
return valOut; // Debugging show correct result
}
void RMCDecode(unsigned char *dataIn, unsigned int sizeIn){
unsigned char dataExt[60] = {0};
// do something to get value to //
parseByDelimiter(dataExt, ',', 1, 60); // Send decoded value to parse
}
void main(void){
RMCDecode(datatestRealword1, 100);
}
A debugger report a correct value
But after when I tried
GPSDATARMC.utctime = parseByDelimiter(RMC_DATA, ',', 0, 10);
I gave an error incompatible data type, I don't know how to write value into my typedef. Anyone got an idea?
Thank you

Union / Struct (ARM) - Memory Space Assignation

Good moorning,
I am trying to create a struct of date of this style:
//Struct 1
union{
struct{
union{
struct{
bool interrupt_receive;
bool fifo_mode;
bool enable;
bool bits_14_mode;
bool int_source_readed;
bool void6;
bool void7;
bool void8;
};
unsigned char registro;
}REG_CTRL_FLG;
union{
struct{
unsigned int REG_CTRL_TIMEH;
unsigned int REG_CTRL_TIMEL;
};
unsigned short REG_CTRL_TIME;
};
unsigned int threshold; //Para pruebas pendiente de eliminar
//AXIS_STRUCT data_axis;
//AXIS_EXTEND_STRUCT data_full_axis;
}registros_acelerometro;
unsigned int registro[3];
}ACELEROMETRO;
//Struct 2
typedef union{
struct{
unsigned char dlc_0;
union{
struct{
unsigned char p15:1;
unsigned char p14:1;
unsigned char p13:1;
unsigned char p12:1;
unsigned char p11:1;
unsigned char p10:1;
unsigned char p9:1;
unsigned char p8:1;
unsigned char p7:1;
unsigned char p6:1;
unsigned char p5:1;
unsigned char p4:1;
unsigned char p3:1;
unsigned char p2:1;
unsigned char p1:1;
unsigned char p0:1;
};
unsigned short p;
}pulsadores;
union{
struct{
unsigned char lb0:1;
unsigned char lb1:1;
unsigned char ls0:1;
unsigned char ls1:1;
unsigned char iluminacion:1;
unsigned char completo:1;
unsigned char sobrecarga:1;
unsigned char void7:1;
}registro_cabina;
unsigned char estado_cabina;
};
unsigned char dlc_4;
}registros_can_data;
unsigned char can_data[5];
}TRESA_PULS;
The struct 1, i have been used with a STM32F7, ARM Compiler 6.11, and a Keil MDK 5.21, without any problem, but with the configuration that i use in the struct 2, it causes me some problems
The unions that contained int the structure, seem need a aditional memory space to work, which distorts the structure.
I've been thinking about it, but i dont find the error
Do you know if anything has changed?
Is there a pre-processing order that should be used?
Has it happened to any of you?
Do you see any trouble?
Thanks for your help and time.
Kinds Regards.

What is the best way to set the bit field values using loops?

This is simple code; I am using this code snippet in my project and its working fine.
My question if it is the best way or otherwise What is the best way to set the bit fields using loops in C?
#define NUM_OF_MAX_SENSOR 10
typedef float SENSOR_VAL ;
typedef struct
{
unsigned char bit0:1;
unsigned char bit1:1;
unsigned char bit2:1;
unsigned char bit3:1;
unsigned char bit4:1;
unsigned char bit5:1;
unsigned char bit6:1;
unsigned char bit7:1;
}BYTE_FIELD;
typedef struct
{
BYTE_FIELD funP1;
BYTE_FIELD funP2;
}LOG_DATA;
LOG_DATA xlog;
typedef struct
{
unsigned char ok:1;
unsigned char open:1;
unsigned char shrt:1;
unsigned char unused:5;
}SENSOR_FLAGS;
typedef struct
{
SENSOR_FLAGS flag;
SENSOR_VAL val;
}SENSOR_DATA;
typedef union
{
SENSOR_DATA sensor[NUM_OF_MAX_SENSOR];
unsigned char buff[sizeof(SENSOR_DATA) * NUM_OF_MAX_SENSOR];
}SENSOR;
SENSOR sensor;
These are the structures I used and these are the max details I can provide.
void UpdateLogData()
{
int i = 0;
unsigned char *funPAddr =(unsigned char *) &xlog.funP1;
for(i=0;i<8;i++)
*(funPAddr) |= sensor.sensor[i].flag.ok << i;
printf("0x%x",*(funPAddr));
}
//main
int main()
{
sensor.sensor[0].flag.ok = 1;
sensor.sensor[4].flag.ok = 1;
sensor.sensor[5].flag.ok = 1;
sensor.sensor[6].flag.ok = 1;
sensor.sensor[7].flag.ok = 1;
UpdateLogData();
}

error while make runs. Conflicting types and previous declaration

I found an implementation of AES for a project I'm doing.
However when i integrate it I'm getting the following errors during the build.
In file included from ff.h:26:0,
from disp.h:4,
from main.c:14:
aes.h:14:3: error: conflicting types for 'AesCtx'
aes.h:14:3: note: previous declaration of 'AesCtx' was here
aes.h:28:5: error: conflicting types for 'AesCtxIni'
aes.h:28:5: note: previous declaration of 'AesCtxIni' was here
aes.h:29:5: error: conflicting types for 'AesEncrypt'
aes.h:29:5: note: previous declaration of 'AesEncrypt' was here
aes.h:30:5: error: conflicting types for 'AesDecrypt'
aes.h:30:5: note: previous declaration of 'AesDecrypt' was here
The header file itself is:
// AES context structure
typedef struct {
unsigned int Ek[60];
unsigned int Dk[60];
unsigned int Iv[4];
unsigned char Nr;
unsigned char Mode;
} AesCtx;
// key length in bytes
#define KEY128 16
#define KEY192 24
#define KEY256 32
// block size in bytes
#define BLOCKSZ 16
// mode
#define EBC 0
#define CBC 1
// AES API function prototype
int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode);
int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen);
int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen);
and then the respective C file uses.
int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode)
{
// Cut out code for brevity
}
int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen)
{
// Cut out code for brevity
}
int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen)
{
// Cut out code for brevity
}
I know these errors usually occur because either the function hasn't been pre-declared or because it's slightly different to it's declaration, but I can't see a difference.
Any ideas?
What compiler are you using? My best guess that it's trying to say aes.h is being #included twice. Try adding header guards at the beginning and end of the aes.h:
#ifndef AES_H_
#define AES_H_
typedef struct {
...
int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen);
#endif /* !AES_H_ */

typecast to a not typedefined struct

Basicly I am getting data from another thread in the RTOS. This data is a pin on the board. All the IO ports are in structures / unions in an iodefine.h file. See this for example on how Micrium made it:
struct st_portd {
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} DDR;
unsigned char wk0[31];
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} DR;
unsigned char wk1[31];
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} PORT;
unsigned char wk2[31];
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} ICR;
unsigned char wk3[95];
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} PCR;
};
Very clever way if you ask me.
So I save this pin as 2 chars in a struct, called Port and Pin.
struct StepperMotor {
CPU_INT32U ID;
CPU_CHAR *EnablePort;
CPU_CHAR EnablePin;
CPU_CHAR *DirectionPort;
CPU_CHAR DirectionPin;
CPU_CHAR *PulsePort;
CPU_CHAR PulsePin;
};
I would like to use the pin in this way:
(struct st_portd)(steppermotor->PulsePort)->DR.BYTE ^= (1 << steppermotor->PulsePin);
steppermotor is the struct.
Only with this way I get an error saying
request for member 'DR' in something not a structure or union
How am I able to use the steppermotor->PulsePort->DR.BYTE without making a new variable for it?
I hope anyone can help me!
Since you are casting a pointer, you should be casting it to a pointer to a structure, rather than a structure itself, like this:
((struct st_portd*)steppermotor->PulsePort)->DR.BYTE ^= (1 << steppermotor->PulsePin);
Also note that your parentheses are in a wrong place.

Resources