pic.programmer
Advanced Member level 3
- Joined
- Aug 19, 2015
- Messages
- 773
- Helped
- 141
- Reputation
- 284
- Reaction score
- 140
- Trophy points
- 43
- Activity points
- 7,531
I am making a Biometric Attendance System and I am have problem declaring a struct.
Here is the struct.
It is giving errors.
Errors given are
- - - Updated - - -
I came to know that functions cannot be used inside struct.
Here is my new code. I am getting error creating a enum like myFpsCommands.
Here is the struct.
It is giving errors.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 #define bool char #define true 1 #define flase 0 struct Commands_Packet { struct Commands { enum Commands_Enum { NotSet = 0x00, // Default value for enum. Scanner will return error if sent this. Open = 0x01, // Open Initialization Close = 0x02, // Close Termination UsbInternalCheck = 0x03, // UsbInternalCheck Check if the connected USB device is valid ChangeEBaudRate = 0x04, // ChangeBaudrate Change UART baud rate SetIAPMode = 0x05, // SetIAPMode Enter IAP Mode In this mode, FW Upgrade is available CmosLed = 0x12, // CmosLed Control CMOS LED GetEnrollCount = 0x20, // Get enrolled fingerprint count CheckEnrolled = 0x21, // Check whether the specified ID is already enrolled EnrollStart = 0x22, // Start an enrollment Enroll1 = 0x23, // Make 1st template for an enrollment Enroll2 = 0x24, // Make 2nd template for an enrollment Enroll3 = 0x25, // Make 3rd template for an enrollment, merge three templates into one template, save merged template to the database IsPressFinger = 0x26, // Check if a finger is placed on the sensor DeleteID = 0x40, // Delete the fingerprint with the specified ID DeleteAll = 0x41, // Delete all fingerprints from the database Verify1_1 = 0x50, // Verification of the capture fingerprint image with the specified ID Identify1_N = 0x51, // Identification of the capture fingerprint image with the database VerifyTemplate1_1 = 0x52, // Verification of a fingerprint template with the specified ID IdentifyTemplate1_N = 0x53, // Identification of a fingerprint template with the database CaptureFinger = 0x60, // Capture a fingerprint image(256x256) from the sensor MakeTemplate = 0x61, // Make template for transmission GetImage = 0x62, // Download the captured fingerprint image(256x256) GetRawImage = 0x63, // Capture & Download raw fingerprint image(320x240) GetTemplate = 0x70, // Download the template of the specified ID SetTemplate = 0x71, // Upload the template of the specified ID GetDatabaseStart = 0x72, // Start database download, obsolete GetDatabaseEnd = 0x73, // End database download, obsolete UpgradeFirmware = 0x80, // Not supported UpgradeISOCDImage = 0x81, // Not supported Ack = 0x30, // Acknowledge. Nack = 0x31 // Non-acknowledge }; }; Commands.Commands_Enum fpsCommand; unsigned char Parameter[4]; // Parameter 4 bytes, changes meaning depending on command static const byte COMMAND_START_CODE_1 = 0x55; // Static byte to mark the beginning of a command packet - never changes static const byte COMMAND_START_CODE_2 = 0xAA; // Static byte to mark the beginning of a command packet - never changes static const byte COMMAND_DEVICE_ID_1 = 0x01; // Device ID Byte 1 (lesser byte) - theoretically never changes static const byte COMMAND_DEVICE_ID_2 = 0x00; // Device ID Byte 2 (greater byte) - theoretically never changes unsigned char command[2]; // Command 2 bytes unsigned char* GetPacketBytes(); // returns the bytes to be transmitted void ParameterFromInt(int i); unsigned int _CalculateChecksum(); // Checksum is calculated using byte addition unsigned char GetHighByte(unsigned int w); unsigned char GetLowByte(unsigned int w); unsigned char* Command_Packet_GetPacketBytes() { unsigned char packetbytes[12]; unsigned int cmd, checksum; // update command before calculating checksum (important!) cmd = Command; command[0] = GetLowByte(cmd); command[1] = GetHighByte(cmd); checksum = _CalculateChecksum(); packetbytes[0] = COMMAND_START_CODE_1; packetbytes[1] = COMMAND_START_CODE_2; packetbytes[2] = COMMAND_DEVICE_ID_1; packetbytes[3] = COMMAND_DEVICE_ID_2; packetbytes[4] = Parameter[0]; packetbytes[5] = Parameter[1]; packetbytes[6] = Parameter[2]; packetbytes[7] = Parameter[3]; packetbytes[8] = command[0]; packetbytes[9] = command[1]; packetbytes[10] = GetLowByte(checksum); packetbytes[11] = GetHighByte(checksum); return packetbytes; } // Converts the int to bytes and puts them into the paramter array void Command_Packet_ParameterFromInt(int i) { Parameter[0] = (i & 0x000000ff); Parameter[1] = (i & 0x0000ff00) >> 8; Parameter[2] = (i & 0x00ff0000) >> 16; Parameter[3] = (i & 0xff000000) >> 24; } // Returns the high byte from a word unsigned char Command_Packet_GetHighByte(unsigned int w) { return (unsigned char)(w>>8)&0x00FF; } // Returns the low byte from a word unsigned char Command_Packet_GetLowByte(unsigned int w) { return (unsigned char)w&0x00FF; } unsigned int Command_Packet__CalculateChecksum() { unsigned int w = 0; w += COMMAND_START_CODE_1; w += COMMAND_START_CODE_2; w += COMMAND_DEVICE_ID_1; w += COMMAND_DEVICE_ID_2; w += Parameter[0]; w += Parameter[1]; w += Parameter[2]; w += Parameter[3]; w += command[0]; w += command[1]; return w; } };
Errors given are
Code:
0 122 Compilation Started FPS Text.c
41 396 Invalid declarator expected'(' or identifier FPS Text.c
42 396 Invalid declarator expected'(' or identifier FPS Text.c
46 300 Syntax Error: ';' expected, but '.' found FPS Text.c
46 398 Declarator error FPS Text.c
46 371 Specifier needed FPS Text.c
46 402 ; expected, but 'fpsCommand' found FPS Text.c
49 402 ; expected, but 'COMMAND_START_CODE_1' found FPS Text.c
49 402 ; expected, but '=' found FPS Text.c
49 371 Specifier needed FPS Text.c
49 396 Invalid declarator expected'(' or identifier FPS Text.c
50 402 ; expected, but 'COMMAND_START_CODE_2' found FPS Text.c
50 312 Internal error '' FPS Text.c
0 102 Finished (with errors): 16 Jan 2016, 16:20:09 FPS Text.mcp32
- - - Updated - - -
I came to know that functions cannot be used inside struct.
Here is my new code. I am getting error creating a enum like myFpsCommands.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 struct Cmds_Packet { struct Commands { enum Commands_Enum { NotSet = 0x00, // Default value for enum. Scanner will return error if sent this. Open = 0x01, // Open Initialization Close = 0x02, // Close Termination UsbInternalCheck = 0x03, // UsbInternalCheck Check if the connected USB device is valid ChangeEBaudRate = 0x04, // ChangeBaudrate Change UART baud rate SetIAPMode = 0x05, // SetIAPMode Enter IAP Mode In this mode, FW Upgrade is available CmosLed = 0x12, // CmosLed Control CMOS LED GetEnrollCount = 0x20, // Get enrolled fingerprint count CheckEnrolled = 0x21, // Check whether the specified ID is already enrolled EnrollStart = 0x22, // Start an enrollment Enroll1 = 0x23, // Make 1st template for an enrollment Enroll2 = 0x24, // Make 2nd template for an enrollment Enroll3 = 0x25, // Make 3rd template for an enrollment, merge three templates into one template, save merged template to the database IsPressFinger = 0x26, // Check if a finger is placed on the sensor DeleteID = 0x40, // Delete the fingerprint with the specified ID DeleteAll = 0x41, // Delete all fingerprints from the database Verify1_1 = 0x50, // Verification of the capture fingerprint image with the specified ID Identify1_N = 0x51, // Identification of the capture fingerprint image with the database VerifyTemplate1_1 = 0x52, // Verification of a fingerprint template with the specified ID IdentifyTemplate1_N = 0x53, // Identification of a fingerprint template with the database CaptureFinger = 0x60, // Capture a fingerprint image(256x256) from the sensor MakeTemplate = 0x61, // Make template for transmission GetImage = 0x62, // Download the captured fingerprint image(256x256) GetRawImage = 0x63, // Capture & Download raw fingerprint image(320x240) GetTemplate = 0x70, // Download the template of the specified ID SetTemplate = 0x71, // Upload the template of the specified ID GetDatabaseStart = 0x72, // Start database download, obsolete GetDatabaseEnd = 0x73, // End database download, obsolete UpgradeFirmware = 0x80, // Not supported UpgradeISOCDImage = 0x81, // Not supported Ack = 0x30, // Acknowledge. Nack = 0x31 // Non-acknowledge }myCommands_Enum; }myCommands; myCommands.Commands_Enum myFpsCommands unsigned char Parameter[4]; // Parameter 4 bytes, changes meaning depending on command unsigned char COMMAND_START_CODE_1; // Static byte to mark the beginning of a command packet - never changes unsigned char COMMAND_START_CODE_2; // Static byte to mark the beginning of a command packet - never changes unsigned char COMMAND_DEVICE_ID_1; // Device ID Byte 1 (lesser byte) - theoretically never changes unsigned char COMMAND_DEVICE_ID_2; // Device ID Byte 2 (greater byte) - theoretically never changes unsigned char command[2]; // Command 2 bytes }Commands_Packet;