Hey guys,
I get the following error when I try to compile my code:
[Linker error] undefined reference to 'outgoing_response'
I get this error when compiling file example-635.c
It contains the code
Code:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "typedefs.h"
#include "serial.h"
#include "cf_packet.h"
#include "show_packet.h"
#include "TTYINFO.H"
//#include "MTTTY.H"
#define MAX_WRITE_BUFFER 1024
#define MAX_READ_BUFFER 2048
char gszPort[10];
//============================================================================
int main(int argc, char* argv[])
{
printf("Ultra-simple CFA-635 command-line communications example.\n");
printf("Crystalfontz America, Inc. http://www.crystalfontz.com\n\n");
printf("Usage:\n");
printf("%s PORT BAUD\n");
printf("PORT is COM1\n");
printf("BAUD is 115200\n");
/*//If only 0 or 1 parameter is entered, prompt for the missing parameter(s)
if(argc < 3)
{
printf("\nMISSING A PARAMETER. Enter both PORT and BAUD.\n\n");
return(0);
}*/
//Check for optional "clear" parameter and set flag if found
/*int
cleardisplay=0;
if((argc > 3)&&(!strcmp(argv[3],"clear"))) cleardisplay=1;*/
/* int
baud;
//default the baud to 115200
if(strcmp(argv[2],"19200"))
baud=115200;
else
baud=19200;*/
if(SetupCommPort())
{
printf("Could not open port.");
return(1);
}
else
printf("Comm Port Opened");
//For some reason, Linux seems to buffer up data from the LCD, and they are sometimes
//dumped at the start of the program. Clear the serial buffer.
//while(BytesAvail())
// GetByte();
//Outgoing command packets. Either clear the screen
//or send our line information
//**********************************************
/* if(cleardisplay)
{
outgoing_response.command = 6;
outgoing_response.data_length = 0;
send_packet();
}
else
{*/
//Send line 1 to the 635 using command 31
outgoing_response.command = 31;
outgoing_response.data[0]=0; //col
outgoing_response.data[1]=0; //row
memcpy(&outgoing_response.data[2],">>>This is line 1<<<",20);
outgoing_response.data_length = 22; //the col & row position + the 20 char data length
send_packet();
//CFA-635 communications protocol only allows
//one outstanding packet at a time. Wait for the response
//packet from the CFA-635 before sending another
//packet.
int
k;
int
timed_out;
timed_out = 1; //default timed_out is true
for(k=0;k<=10000;k++)
if(check_for_packet())
{
ShowReceivedPacket();
timed_out = 0; //set timed_out to false
break;
}
if(timed_out)
printf("Timed out waiting for a response.\n");
//Send line 2 to the 635 using command 31
outgoing_response.command = 31;
outgoing_response.data[0]=0; //col
outgoing_response.data[1]=1; //row
memcpy(&outgoing_response.data[2],">>>This is line 2<<<",20);
outgoing_response.data_length = 22;
send_packet();
timed_out = 1; //default timed_out is true
for(k=0;k<=10000;k++)
if(check_for_packet())
{
ShowReceivedPacket();
timed_out = 0; //set timed_out to false
break;
}
if(timed_out)
printf("Timed out waiting for a response.\n");
//Send line 3 to the 635 using command 31
outgoing_response.command = 31;
outgoing_response.data[0]=0; //col
outgoing_response.data[1]=2; //row
memcpy(&outgoing_response.data[2],">>>This is line 3<<<",20);
outgoing_response.data_length = 22;
send_packet();
timed_out = 1; //default timed_out is true
for(k=0;k<=10000;k++)
if(check_for_packet())
{
ShowReceivedPacket();
timed_out = 0; //set timed_out to false
break;
}
if(timed_out)
printf("Timed out waiting for a response.\n");
//Send line 4 to the 635 using command 31
outgoing_response.command = 31;
outgoing_response.data[0]=0; //col
outgoing_response.data[1]=3; //row
memcpy(&outgoing_response.data[2],">>>This is line 4<<<",20);
outgoing_response.data_length = 22;
send_packet();
timed_out = 1; //default timed_out is true
for(k=0;k<=10000;k++)
if(check_for_packet())
{
ShowReceivedPacket();
timed_out = 0; //set timed_out to false
break;
}
if(timed_out)
printf("Timed out waiting for a response.\n");
//}
//**********************************************
printf("\nCtrl-C to exit.\n");
printf("Updated display, now waiting for packets\n\n");
/* while(!cleardisplay)
{
usleep(100000); // 1/10 second
if(check_for_packet())
ShowReceivedPacket();
}*/
/* if(cleardisplay) printf("Display Cleared.\n");
printf("Done.\n\n");*/
BreakDownCommPort();
//Uninit_Serial();
return 0;
}
//============================================================================
HANDLE SetupCommPort()
{
//
// get tty settings from settings dialog
//
UpdateTTYInfo();
//
// open communication port handle
//
COMDEV( TTYInfo ) = CreateFile( gszPort,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
0);
if (COMDEV(TTYInfo) == INVALID_HANDLE_VALUE) {
ErrorReporter("CreateFile");
return NULL;
}
//
// Save original comm timeouts and set new ones
//
if (!GetCommTimeouts( COMDEV(TTYInfo), &(TIMEOUTSORIG(TTYInfo))))
ErrorReporter("GetCommTimeouts");
//
// Set port state
//
UpdateConnection();
//
// set comm buffer sizes
//
SetupComm(COMDEV(TTYInfo), MAX_READ_BUFFER, MAX_WRITE_BUFFER);
//
// raise DTR
//
if (!EscapeCommFunction(COMDEV(TTYInfo), SETDTR))
ErrorReporter("EscapeCommFunction (SETDTR)");
//
// start threads and set initial thread state to not done
//
StartThreads();
//
// set overall connect flag
//
CONNECTED( TTYInfo ) = TRUE ;
return COMDEV(TTYInfo);
}
//==============================================================================
the 'outgoing_response' variable is defined in the following file 'cf_packet.h' and as you can see cf_packet.h is included in 'example-635.c'
Code:
//============================================================================
// 635 Linux Demonstration Code.
// 635_packet,h: Ultra-simple 635 command-line communications example
// Copyright 2005, Crystalfontz America, Inc. Written by Brent A. Crosby
// www.crystalfontz.com, [email protected]
//============================================================================
#define MAX_DATA_LENGTH 22
//============================================================================
#define MAX_COMMAND 35
//============================================================================
typedef struct
{
ubyte
command;
ubyte
data_length;
ubyte
data[MAX_DATA_LENGTH];
WORD_UNION
CRC;
}COMMAND_PACKET;
//============================================================================
word get_crc(ubyte *bufptr,word len,word seed);
//============================================================================
extern COMMAND_PACKET
incoming_command;
extern COMMAND_PACKET
outgoing_response;
//============================================================================
ubyte check_for_packet(void);
void send_packet(void);
//============================================================================
Can anyone tell me how to declare the variable 'outgoing_response' in cf_packet.h' so that it can be recognised by any other file especially 'example-635.c'?
Any help is greatly appreciated