Struct Byte Alignment Issue XCode 4.3 - objective-c

I'm trying to use struct to map header of a BitMap file. It seems that compiler is doing 4byte (32bit) alignment but I need 2Byte. I tried to change that via complier directive as below
#pragma pack(2)
and
__attribute__ ((aligned(xx)));
those two doesn't seem to have any effect. Is there another way to do this?
I'm using XCode 4.3 on Mac OS X Lion. I Tested both Apple LLVM and Apple GCC compliers.
Here is the Struct type definition
typedef struct {
int16_t bfType;
int32_t bfSize;
int16_t bfReserved1;
int16_t bfReserved2;
int32_t bfOffBits;
int32_t biSize;
int32_t biWidth;
int32_t biHeight;
int16_t biPlanes;
int16_t biBitCount;
int32_t biComression;
int32_t biSizeImage;
int32_t biXPelsPerMeter;
int32_t biYPelsPerMeter;
int32_t biClrUsed;
int32_t biClrImportant;
} THeader;

Huh? works on my machine? Bear in mind that the pack pragma is possibly being overridden somewhere else?
#include <inttypes.h>
#include <stddef.h>
#pragma pack(push,2)
typedef struct {
int16_t bfType;
int32_t bfSize;
int16_t bfReserved1;
int16_t bfReserved2;
int32_t bfOffBits;
int32_t biSize;
int32_t biWidth;
int32_t biHeight;
int16_t biPlanes;
int16_t biBitCount;
int32_t biComression;
int32_t biSizeImage;
int32_t biXPelsPerMeter;
int32_t biYPelsPerMeter;
int32_t biClrUsed;
int32_t biClrImportant;
} THeader;
#pragma pack(pop)
#include <stdio.h>
int main(void)
{
printf("%lu\n", offsetof(THeader, bfType));
printf("%lu\n", offsetof(THeader, bfSize));
printf("%lu\n", offsetof(THeader, bfReserved1));
printf("%lu\n", offsetof(THeader, bfReserved2));
return 0;
}
$ clang -o pack pack.c
$ ./pack
0
2
6
8

Related

UDP socket server/client on different machine won't communicate

these code are from https://www.geeksforgeeks.org/udp-server-client-implementation-c/. it runs well when run server and client on same machine.
but if run on two different machine in same network( they can ping each other). then server won't receive Hello from client.
I noticed that both server and client set address INADDR_ANY. this means any machine in the local network, Am I right?
and I tried on client side specify server's ip address. server still won't get message from client.
please give me some clue.
thank you.
server.c
// Server side implementation of UDP client-server model
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define PORT 8080
#define MAXLINE 1024
// Driver code
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from server";
struct sockaddr_in servaddr, cliaddr;
// Creating socket file descriptor
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
perror("socket creation failed");
exit(EXIT_FAILURE);
}
memset(&servaddr, 0, sizeof(servaddr));
memset(&cliaddr, 0, sizeof(cliaddr));
// Filling server information
servaddr.sin_family = AF_INET; // IPv4
servaddr.sin_addr.s_addr = INADDR_ANY;
servaddr.sin_port = htons(PORT);
// Bind the socket with the server address
if ( bind(sockfd, (const struct sockaddr *)&servaddr,
sizeof(servaddr)) < 0 )
{
perror("bind failed");
exit(EXIT_FAILURE);
}
int len, n;
n = recvfrom(sockfd, (char *)buffer, MAXLINE,
MSG_WAITALL, ( struct sockaddr *) &cliaddr,
&len);
buffer[n] = '\0';
printf("Client : %s\n", buffer);
sendto(sockfd, (const char *)hello, strlen(hello),
MSG_CONFIRM, (const struct sockaddr *) &cliaddr,
len);
printf("Hello message sent.\n");
return 0;
}
client.c
// Client side implementation of UDP client-server model
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define PORT 8080
#define MAXLINE 1024
// Driver code
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from client";
struct sockaddr_in servaddr;
// Creating socket file descriptor
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
perror("socket creation failed");
exit(EXIT_FAILURE);
}
memset(&servaddr, 0, sizeof(servaddr));
// Filling server information
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
servaddr.sin_addr.s_addr = INADDR_ANY;
int n, len;
sendto(sockfd, (const char *)hello, strlen(hello),
MSG_CONFIRM, (const struct sockaddr *) &servaddr,
sizeof(servaddr));
printf("Hello message sent.\n");
n = recvfrom(sockfd, (char *)buffer, MAXLINE,
MSG_WAITALL, (struct sockaddr *) &servaddr,
&len);
buffer[n] = '\0';
printf("Server : %s\n", buffer);
close(sockfd);
return 0;
}
in client.c
make following change. ( 192.168.1.1 ) is server's IP address. then they talk.
//servaddr.sin_addr.s_addr = INADDR_ANY;
servaddr.sin_addr.s_addr = inet_addr("192.168.1.1");

How to distinguish MacBook and Mac desktops programmatically?

I'm working on a Mac app that should distinguish MacBook and Mac desktops (iMac/Mac Pro).
I think I can get it done with model number. Then how I can get the model number? And which letter indicates it's a notebook or desktop? Or is there any other easier or better way?
You can use this little program. NSLog the output to test it.
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
+ (NSString *)machineModel
{
size_t length = 0;
sysctlbyname("hw.model", NULL, &length, NULL, 0);
if (length) {
char *m = malloc(length * sizeof(char));
sysctlbyname("hw.model", m, &length, NULL, 0);
NSString *model = [NSString stringWithUTF8String:m];
free(m);
return model;
}
return #"Unknown model";
}
It will provide the same output as entering sysctl hw.model on the terminal.
You haven't specified a language, but from Terminal sysctl hw.model will return with an identifier for the current Mac. For example, on my computer it returns MacBookPro5,5.

How to declare packed struct (without padding) for LLVM?

It's possible to tell GCC it should not use padding for the struct. This is done using __attribute__((packed)).
typedef struct {
uint8_t startSymbol;
uint8_t packetType;
uint32_t deviceId;
uint16_t packetCRC;
} PacketData __attribute__((packed));
However, newest Xcode uses LLVM and does not recognize the attribute. How to define packed struct for LLVM?
The full description of the problem might be found here
UPDATE I'm using Xcode 4.5.1 for iOS which uses Apple LLVM 4.1 compiler. I'm getting "'packed' attribute ignored" warning in Xcode in the code example above.
Did you actually try it? I just tested it on my machine, and __attribute__((packed)) compiled fine using clang.
Edit: I got the same warning ("Warning: packed attribute unused") for
typedef struct {
int a;
char c;
} mystruct __attribute__((packed));
and in this case sizeof(mystruct) was 8.
However,
typedef struct __attribute__((packed)) {
int a;
char c;
} mystruct;
worked just fine, and sizeof(mystruct) was 5.
Conclusion: it seems that the attribute needs to preceed the struct label in order to get this working.
You can use preprocessor directive to specify byte alignment for the struct so no padding will be done by the compiler:
#pragma pack(1)
typedef struct {
char t1;
long long t2;
char t3;
} struct_size_test;
#pragma options align=reset
See the answer to this question on stackoverflow.
clang 3.5 on Linux -
typedef struct __attribute__((packed)) thing1 { int blah; } THING_ONE;
worked.

Repetier V0.70b firmware uploading to Printrboard

I am new to the RepRap community, 3D printing in general, and the new Printrbot PLUS. I am trying to update the firmware to Repetier's package as I would like to use their software and want as much compatibility as possible.
I've heard the Sprinter firmware works well on the Printrboard but considering the Repetier recently updated their package for the Printrboard as well, I'd like to give it a go.
I go to hit upload in Arduino 1.01 after changing the first configuration setting to 9 (for Printrboard) and then get these errors:
In file included from Commands.cpp:23:
/Reptier.h: In function 'void extruder_unstep()':
Reptier.h:189: error: 'DIO34_WPORT' was not declared in this scope
Reptier.h:189: error: 'DIO34_PIN' was not declared in this scope
Reptier.h:189: error: 'DIO34_WPORT' was not declared in this scope
Reptier.h:189: error: 'DIO34_PIN' was not declared in this scope
/Reptier.h: In function 'void extruder_set_direction(byte)':
Reptier.h:212: error: 'DIO35_WPORT' was not declared in this scope
Reptier.h:212: error: 'DIO35_PIN' was not declared in this scope
Reptier.h:212: error: 'DIO35_WPORT' was not declared in this scope
Reptier.h:212: error: 'DIO35_PIN' was not declared in this scope
Reptier.h:214: error: 'DIO35_WPORT' was not declared in this scope
Reptier.h:214: error: 'DIO35_PIN' was not declared in this scope
Reptier.h:214: error: 'DIO35_WPORT' was not declared in this scope
Reptier.h:214: error: 'DIO35_PIN' was not declared in this scope
This is all on the "Repetier.h" tab of the file stack which reads as follows.
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
*/
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#define COMPAT_PRE1
#endif
#include "gcode.h"
#include "fastio.h"
#ifdef SDSUPPORT
#include "Sd2Card.h"
#include "SdFat.h"
extern void initsd();
#endif
#define REPETIER_VERSION "0.71"
#define uint uint16_t
#define uint8 uint8_t
#define int8 int8_t
#define uint32 uint32_t
#define int32 int32_t
/*#if MOTHERBOARD==6 || MOTHERBOARD==62 || MOTHERBOARD==7
#if MOTHERBOARD!=7
#define SIMULATE_PWM
#endif
#define EXTRUDER_TIMER_VECTOR TIMER2_COMPA_vect
#define EXTRUDER_OCR OCR2A
#define EXTRUDER_TCCR TCCR2A
#define EXTRUDER_TIMSK TIMSK2
#define EXTRUDER_OCIE OCIE2A
#define PWM_TIMER_VECTOR TIMER2_COMPB_vect
#define PWM_OCR OCR2B
#define PWM_TCCR TCCR2B
#define PWM_TIMSK TIMSK2
#define PWM_OCIE OCIE2B
#else*/
#define EXTRUDER_TIMER_VECTOR TIMER0_COMPA_vect
#define EXTRUDER_OCR OCR0A
#define EXTRUDER_TCCR TCCR0A
#define EXTRUDER_TIMSK TIMSK0
#define EXTRUDER_OCIE OCIE0A
#define PWM_TIMER_VECTOR TIMER0_COMPB_vect
#define PWM_OCR OCR0B
#define PWM_TCCR TCCR0A
#define PWM_TIMSK TIMSK0
#define PWM_OCIE OCIE0B
//#endif
/** \brief Data to drive one extruder.
This structure contains all definitions for an extruder and all
current state variables, like current temperature, feeder position etc.
*/
typedef struct { // Size: 12*1 Byte+12*4 Byte+4*2Byte = 68 Byte
byte id;
long xOffset;
long yOffset;
float stepsPerMM; ///< Steps per mm.
byte sensorType; ///< Type of temperature sensor.
byte sensorPin; ///< Pin to read extruder temperature.
byte enablePin; ///< Pin to enable extruder stepper motor.
// byte directionPin; ///< Pin number to assign the direction.
// byte stepPin; ///< Pin number for a step.
byte enableOn;
// byte invertDir; ///< 1 if the direction of the extruder should be inverted.
float maxFeedrate;
float maxAcceleration; ///< Maximum acceleration in mm/s^2.
float maxStartFeedrate; ///< Maximum start feedrate in mm/s.
long extrudePosition; ///< Current extruder position in steps.
int currentTemperature; ///< Currenttemperature value read from sensor.
int targetTemperature; ///< Target temperature value in units of sensor.
int currentTemperatureC; ///< Current temperature in °C.
int targetTemperatureC; ///< Target temperature in °C.
long lastTemperatureUpdate; ///< Time in millis of the last temperature update.
char heatManager; ///< How is temperature controled. 0 = on/off, 1 = PID-Control
int watchPeriod; ///< Time in seconds, a M109 command will wait to stabalize temperature
#ifdef USE_ADVANCE
#ifdef ENABLE_QUADRATIC_ADVANCE
float advanceK; ///< Koefficient for advance algorithm. 0 = off
#endif
float advanceL;
#endif
// byte output; ///< Output value 0 = off, 255=MAX
#ifdef TEMP_PID
long tempIState; ///< Temp. var. for PID computation.
byte pidDriveMax; ///< Used for windup in PID calculation.
byte pidDriveMin; ///< Used for windup in PID calculation.
long pidPGain; ///< Pgain (proportional gain) for PID temperature control [0,01 Units].
long pidIGain; ///< Igain (integral) for PID temperature control [0,01 Units].
long pidDGain; ///< Dgain (damping) for PID temperature control [0,01 Units].
byte pidMax; ///< Maximum PWM value, the heater should be set.
long tempIStateLimitMax;
long tempIStateLimitMin;
byte tempPointer;
int tempArray[8];
#endif
} Extruder;
extern const uint8 osAnalogInputChannels[] PROGMEM;
extern uint8 osAnalogInputCounter[ANALOG_INPUTS];
extern uint osAnalogInputBuildup[ANALOG_INPUTS];
extern uint8 osAnalogInputPos; // Current sampling position
extern volatile uint osAnalogInputValues[ANALOG_INPUTS];
extern byte pwm_pos[4]; // 0-2 = Heater 0-2 of extruder, 3 = Fan
extern int target_bed_celsius;
#if HEATED_BED_SENSOR_TYPE!=0
extern int current_bed_raw;
extern int target_bed_raw;
#endif
#ifdef USE_ADVANCE
#ifdef ENABLE_QUADRATIC_ADVANCE
extern int maxadv;
#endif
extern int maxadv2;
extern float maxadvspeed;
#endif
extern Extruder *current_extruder;
extern Extruder extruder[];
// Initalize extruder and heated bed related pins
extern void initExtruder();
extern void extruder_select(byte ext_num);
// Set current extruder position
//extern void extruder_set_position(float pos,bool relative);
// set the temperature of current extruder
extern void extruder_set_temperature(int temp_celsius,byte extr);
extern int extruder_get_temperature();
// Set temperature of heated bed
extern void heated_bed_set_temperature(int temp_celsius);
//extern long extruder_steps_to_position(float value,byte relative);
extern void extruder_set_direction(byte steps);
extern void extruder_disable();
extern byte heated_bed_output;
//#ifdef TEMP_PID
//extern byte current_extruder_out;
//#endif
/** \brief Sends the high-signal to the stepper for next extruder step.
Call this function only, if interrupts are disabled.
*/
inline void extruder_step() {
#if NUM_EXTRUDER==1
#else
switch(current_extruder->id) {
case 0:
WRITE(EXT0_STEP_PIN,HIGH);
break;
#ifdef EXT1_STEP_PIN
case 1:
WRITE(EXT1_STEP_PIN,HIGH);
break;
#endif
#ifdef EXT2_STEP_PIN
case 2:
WRITE(EXT2_STEP_PIN,HIGH);
break;
#endif
}
#endif
}
/** \brief Sets stepper signal to low for current extruder.
Call this function only, if interrupts are disabled.
*/
inline void extruder_unstep() {
#if NUM_EXTRUDER==1
WRITE(EXT0_STEP_PIN,LOW);
#else
switch(current_extruder->id) {
case 0:
WRITE(EXT0_STEP_PIN,LOW);
break;
#ifdef EXT1_STEP_PIN
case 1:
WRITE(EXT1_STEP_PIN,LOW);
break;
#endif
#ifdef EXT2_STEP_PIN
case 2:
WRITE(EXT2_STEP_PIN,LOW);
break;
#endif
}
#endif
}
/** \brief Activates the extruder stepper and sets the direction. */
inline void extruder_set_direction(byte dir) {
#if NUM_EXTRUDER==1
if(dir)
WRITE(EXT0_DIR_PIN,!EXT0_INVERSE);
else
WRITE(EXT0_DIR_PIN,EXT0_INVERSE);
#else
switch(current_extruder->id) {
case 0:
if(dir)
WRITE(EXT0_DIR_PIN,!EXT0_INVERSE);
else
WRITE(EXT0_DIR_PIN,EXT0_INVERSE);
break;
#ifdef EXT1_DIR_PIN
case 1:
if(dir)
WRITE(EXT1_DIR_PIN,!EXT1_INVERSE);
else
WRITE(EXT1_DIR_PIN,EXT1_INVERSE);
break;
#endif
#ifdef EXT2_DIR_PIN
case 2:
if(dir)
WRITE(EXT2_DIR_PIN,!EXT2_INVERSE);
else
WRITE(EXT2_DIR_PIN,EXT2_INVERSE);
break;
#endif
}
#endif
}
inline void extruder_enable() {
#if NUM_EXTRUDER==1
#if EXT0_ENABLE_PIN>-1
WRITE(EXT0_ENABLE_PIN,EXT0_ENABLE_ON );
#endif
#else
if(current_extruder->enablePin > -1)
digitalWrite(current_extruder->enablePin,current_extruder->enableOn);
#endif
}
extern void(* resetFunc) (void);
// Read a temperature and return its value in °C
// this high level method supports all known methods
extern int read_raw_temperature(byte type,byte pin);
extern int heated_bed_get_temperature();
// Convert a raw temperature value into °C
extern int conv_raw_temp(byte type,int raw_temp);
// Converts a temperture temp in °C into a raw value
// which can be compared with results of read_raw_temperature
extern int conv_temp_raw(byte type,int temp);
// Updates the temperature of all extruders and heated bed if it's time.
// Toggels the heater power if necessary.
extern void manage_temperatures();
extern byte manage_monitor;
void process_command(GCode *code);
void manage_inactivity(byte debug);
extern void wait_until_end_of_move();
extern void update_ramps_parameter();
extern void finishNextSegment();
extern void printPosition();
extern void change_feedrate_multiply(int factor); ///< Set feedrate multiplier
extern void set_fan_speed(int speed,bool wait); /// Set fan speed 0..255
extern void home_axis(bool xaxis,bool yaxis,bool zaxis); /// Home axis
extern byte get_coordinates(GCode *com);
extern void move_steps(long x,long y,long z,long e,float feedrate,bool waitEnd,bool check_endstop);
extern void queue_move(byte check_endstops,byte pathOptimize);
extern void linear_move(long steps_remaining[]);
extern inline void disable_x();
extern inline void disable_y();
extern inline void disable_z();
extern inline void enable_x();
extern inline void enable_y();
extern inline void enable_z();
extern void kill(byte only_steppers);
extern float axis_steps_per_unit[];
extern float inv_axis_steps_per_unit[];
extern float max_feedrate[];
extern float homing_feedrate[];
extern float max_start_speed_units_per_second[];
extern long max_acceleration_units_per_sq_second[];
extern long max_travel_acceleration_units_per_sq_second[];
extern unsigned long axis_steps_per_sqr_second[];
extern unsigned long axis_travel_steps_per_sqr_second[];
extern byte relative_mode; ///< Determines absolute (false) or relative Coordinates (true).
extern byte relative_mode_e; ///< Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
extern byte unit_inches;
extern unsigned long previous_millis_cmd;
extern unsigned long max_inactive_time;
extern unsigned long stepper_inactive_time;
extern void setupTimerInterrupt();
typedef struct { // RAM usage: 72 Byte
byte flag0; // 1 = stepper disabled
#if USE_OPS==1 || defined(USE_ADVANCE)
volatile int extruderStepsNeeded; ///< This many extruder steps are still needed, <0 = reverse steps needed.
// float extruderSpeed; ///< Extruder speed in mm/s.
byte minExtruderSpeed; ///< Timer delay for start extruder speed
byte maxExtruderSpeed; ///< Timer delay for end extruder speed
byte extruderAccelerateDelay; ///< delay between 2 speec increases
#endif
long interval; ///< Last step duration in ticks.
#if USE_OPS==1
bool filamentRetracted; ///< Is the extruder filament retracted
#endif
unsigned long timer; ///< used for acceleration/deceleration timing
unsigned long stepNumber; ///< Step number in current move.
#ifdef USE_ADVANCE
#ifdef ENABLE_QUADRATIC_ADVANCE
long advance_executed; ///< Executed advance steps
#endif
int advance_steps_set;
unsigned int advance_lin_set;
#endif
long currentPositionSteps[4]; ///< Position in steps from origin.
long destinationSteps[4]; ///< Target position in steps.
#if USE_OPS==1
int opsRetractSteps; ///< Retract filament this much steps
int opsPushbackSteps; ///< Retract+extra distance for backslash
float opsMinDistance;
float opsRetractDistance;
float opsRetractBackslash;
byte opsMode; ///< OPS operation mode. 0 = Off, 1 = Classic, 2 = Fast
float opsMoveAfter; ///< Start move after opsModeAfter percent off full retract.
int opsMoveAfterSteps; ///< opsMoveAfter converted in steps (negative value!).
#endif
long xMaxSteps; ///< For software endstops, limit of move in positive direction.
long yMaxSteps; ///< For software endstops, limit of move in positive direction.
long zMaxSteps; ///< For software endstops, limit of move in positive direction.
float feedrate; ///< Last requested feedrate.
int feedrateMultiply; ///< Multiplier for feedrate in percent (factor 1 = 100)
unsigned int extrudeMultiply; ///< Flow multiplier in percdent (factor 1 = 100)
float maxJerk; ///< Maximum allowed jerk in mm/s
float maxZJerk; ///< Maximum allowed jerk in z direction in mm/s
long offsetX; ///< X-offset for different extruder positions.
long offsetY; ///< Y-offset for different extruder positions.
unsigned int vMaxReached; ///< MAximumu reached speed
byte stepper_loops;
} PrinterState;
extern PrinterState printer_state;
/** Marks the first step of a new move */
#define FLAG_WARMUP 1
#define FLAG_ACCELERATING 2
#define FLAG_DECELERATING 4
#define FLAG_ACCELERATION_ENABLED 8
#define FLAG_CHECK_ENDSTOPS 16
#define FLAG_SKIP_ACCELERATING 32
#define FLAG_SKIP_DEACCELERATING 64
#define FLAG_BLOCKED 128
/** Are the step parameter computed */
#define FLAG_JOIN_STEPPARAMS_COMPUTED 1
/** The right speed is fixed. Don't check this block or any block to the left. */
#define FLAG_JOIN_END_FIXED 2
/** The left speed is fixed. Don't check left block. */
#define FLAG_JOIN_START_FIXED 4
/** Start filament retraction at move start */
#define FLAG_JOIN_START_RETRACT 8
/** Wait for filament pushback, before ending move */
#define FLAG_JOIN_END_RETRACT 16
/** Disable retract for this line */
#define FLAG_JOIN_NO_RETRACT 32
/** Wait for the extruder to finish it's up movement */
#define FLAG_JOIN_WAIT_EXTRUDER_UP 64
/** Wait for the extruder to finish it's down movement */
#define FLAG_JOIN_WAIT_EXTRUDER_DOWN 128
// Printing related data
typedef struct { // RAM usage: 24*4+15 = 111 Byte
byte primaryAxis;
byte flags;
byte joinFlags;
byte halfstep; ///< 0 = disabled, 1 = halfstep, 2 = fulstep
byte dir; ///< Direction of movement. 1 = X+, 2 = Y+, 4= Z+, values can be combined.
long delta[4]; ///< Steps we want to move.
long error[4]; ///< Error calculation for Bresenham algorithm
float speedX; ///< Speed in x direction at fullInterval in mm/s
float speedY; ///< Speed in y direction at fullInterval in mm/s
float speedZ; ///< Speed in z direction at fullInterval in mm/s
float fullSpeed; ///< Desired speed mm/s
float acceleration; ///< Real acceleration mm/s²
float distance;
float startFactor;
float endFactor;
unsigned long fullInterval; ///< interval at full speed in ticks/step.
unsigned long stepsRemaining; ///< Remaining steps, until move is finished
unsigned int accelSteps; ///< How much steps does it take, to reach the plateau.
unsigned int decelSteps; ///< How much steps does it take, to reach the end speed.
unsigned long accelerationPrim; ///< Acceleration along primary axis
unsigned long facceleration; ///< accelerationPrim*262144/F_CPU
unsigned int vMax; ///< Maximum reached speed in steps/s.
unsigned int vStart; ///< Starting speed in steps/s.
unsigned int vEnd; ///< End speed in steps/s
#ifdef USE_ADVANCE
#ifdef ENABLE_QUADRATIC_ADVANCE
long advanceRate; ///< Advance steps at full speed
long advanceFull; ///< Maximum advance at fullInterval [steps*65536]
long advanceStart;
long advanceEnd;
#endif
unsigned int advanceL; ///< Recomputated L value
#endif
#if USE_OPS==1
long opsReverseSteps; ///< How many steps are needed to reverse retracted filament at full speed
#endif
#ifdef DEBUG_STEPCOUNT
long totalStepsRemaining;
#endif
} PrintLine;
extern PrintLine lines[];
extern byte lines_write_pos; // Position where we write the next cached line move
extern byte lines_pos; // Position for executing line movement
extern volatile byte lines_count; // Number of lines cached 0 = nothing to do
extern byte printmoveSeen;
extern long baudrate;
#ifdef SIMULATE_FAN_PWM
extern int fan_speed;
#endif
#if OS_ANALOG_INPUTS>0
// Get last result for pin x
extern volatile uint osAnalogInputValues[OS_ANALOG_INPUTS];
#endif
#define BEGIN_INTERRUPT_PROTECTED {byte sreg=SREG;__asm volatile( "cli" ::: "memory" );
#define END_INTERRUPT_PROTECTED SREG=sreg;}
#define ESCAPE_INTERRUPT_PROTECTED SREG=sreg;
#define SECONDS_TO_TICKS(s) (unsigned long)(s*(float)F_CPU)
extern long CPUDivU2(unsigned int divisor);
extern byte counter_periodical;
extern volatile byte execute_periodical;
extern byte counter_250ms;
extern void write_monitor();
extern void check_periodical();
#define CELSIUS_EXTRA_BITS 3
#define ANALOG_REDUCE_BITS 0
#define ANALOG_REDUCE_FACTOR 1
#ifdef SDSUPPORT
extern Sd2Card card; // ~14 Byte
extern SdVolume volume;
extern SdFile root;
extern SdFile file;
extern uint32_t filesize;
extern uint32_t sdpos;
extern bool sdmode;
extern bool sdactive;
extern bool savetosd;
extern int16_t n;
#endif
I don't know what to declare as those variables, but I know they are variables that need to be defined. How can I fix this problem?

Get a list of all available network interfaces (en0, en1, en2, etc) with Cocoa?

In my Cocoa application I want to show the user a list of available network interfaces, like Wireshark does:
What is the best way of getting such a list? Does Apple provide a framework for this, or must I use a C API from the standard library or another library?
Better than wrapping ifconfig you shall check the reference of SCNetworkConfiguration which is part of Core Foundation.
Check SCNetworkInterfaceXxx functions for details.
related answer:
Using Cocoa / Objective-C, get currently connected network's security type in Mac OS X
The following code will get all the interfaces from OS X through System Configuration, then use standard C functions to get the IP addresses (where available).
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/ioctl.h>
#include <net/if.h>
#define IFT_ETHER 0x6
#include <SystemConfiguration/SCDynamicStore.h>
+(void)getInterfaces
{
SCDynamicStoreRef storeRef = SCDynamicStoreCreate(NULL, (CFStringRef)#"FindCurrentInterfaceIpMac", NULL, NULL);
CFPropertyListRef global = SCDynamicStoreCopyValue (storeRef,CFSTR("State:/Network/Interface"));
id primaryInterface = [(__bridge NSDictionary *)global valueForKey:#"Interfaces"];
for (NSString* item in primaryInterface)
{
if(get_iface_address([item UTF8String]))
{
NSString *ip = [NSString stringWithUTF8String:get_iface_address([item UTF8String])];
NSLog(#"interface: %# - %#",item,ip);
} else
NSLog(#"interface: %#",item);
}
}
static char * get_iface_address (char *interface)
{
int sock;
uint32_t ip;
struct ifreq ifr;
char *val;
if (!interface)
return NULL;
/* determine UDN according to MAC address */
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
perror ("socket");
return NULL;
}
strcpy (ifr.ifr_name, interface);
ifr.ifr_addr.sa_family = AF_INET;
if (ioctl (sock, SIOCGIFADDR, &ifr) < 0)
{
perror ("ioctl");
close (sock);
return NULL;
}
val = (char *) malloc (16 * sizeof (char));
ip = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
ip = ntohl (ip);
sprintf (val, "%d.%d.%d.%d",
(ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF);
close (sock);
return val;
}
#include <SystemConfiguration/SCDynamicStore.h>
SCDynamicStoreRef storeRef = SCDynamicStoreCreate(NULL, (CFStringRef)#"FindCurrentInterfaceIpMac", NULL, NULL);
CFPropertyListRef global = SCDynamicStoreCopyValue (storeRef,CFSTR("State:/Network/Interface"));
id primaryInterface = [(__bridge NSDictionary *)global valueForKey:#"Interfaces"];
for (NSString* item in primaryInterface)
{
NSLog(#"%#", item);
}
Your quickest and best bet is to write a wrapper for ifconfig command.