Commit 9ee87b3c authored by Claes's avatar Claes

Arduino board trimmed

parent 80759d43
......@@ -46,7 +46,7 @@ byte msgData[100];
byte rmsg[40];
int sizeErrorCnt = 0;
int noMessageCnt = 0;
const int delayTime = 5;
const int delayTime = 1;
const int debug = 0;
const int MSG_TYPE_WRITE = 1;
......@@ -127,7 +127,7 @@ int serialRead()
void setup()
{
// Start serial port at 9600 baud
// Start serial port at the configured baud rate
Serial.begin(9600);
Serial.flush();
}
......
......@@ -48,6 +48,9 @@ typedef struct {
unsigned char AiMask[AI_MAX_SIZE];
unsigned char AoMask[AO_MAX_SIZE];
int IdCnt;
int DiPollId;
int DiPendingPoll;
int AiIntervalCnt;
io_sChannel *DChanList[D_MAX_SIZE * 8];
io_sChannel *AiChanList[AI_MAX_SIZE * 8];
io_sChannel *AoChanList[AO_MAX_SIZE * 8];
......@@ -63,6 +66,20 @@ typedef struct {
#include <termios.h>
static FILE *fp;
static void logg( const char *str)
{
pwr_tTime t;
char timstr[40];
time_GetTime( &t);
time_AtoAscii( 0, time_eFormat_Time, timstr, sizeof(timstr));
timstr[9] = 0;
fprintf( fp, "%s%04lld %s\n", timstr, t.tv_nsec/100000, str);
}
typedef enum {
ard_eMsgType_Write = 1,
ard_eMsgType_DiRead = 2,
......@@ -103,11 +120,17 @@ static int receive( int fd, int id, ard_sMsg *rmsg, int size)
msize = 0;
msize += read( fd, rmsg, 1);
logg( "Receive read");
while ( msize < rmsg->size) {
sts = select(fd+1, &rfd, NULL, NULL, &tv);
if ( sts == 0) return ARD__NOMSG;
msize += read( fd, (char *)rmsg + msize, rmsg->size - msize);
logg( "Receive read ++");
}
if ( rmsg->type == ard_eMsgType_Debug) {
......@@ -126,6 +149,22 @@ static int receive( int fd, int id, ard_sMsg *rmsg, int size)
return ARD__NOMSG;
}
static int poll_di( ard_sMsg *msg, io_sLocal *local)
{
int sts;
msg->size = 3;
msg->id = local->IdCnt++;
msg->type = ard_eMsgType_DiRead;
logg( "Poll Di");
sts = write( local->fd, msg, msg->size);
local->DiPollId = msg->id;
local->DiPendingPoll = 1;
return sts;
}
static pwr_tStatus IoCardInit( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
......@@ -137,6 +176,9 @@ static pwr_tStatus IoCardInit( io_tCtx ctx,
pwr_tStatus sts;
int i;
unsigned char wdg;
struct termios tty_attributes;
fp = fopen( "/home/claes/ard.log", "w"); // Test
local = (io_sLocal *) calloc( 1, sizeof(io_sLocal));
cp->Local = local;
......@@ -264,6 +306,50 @@ static pwr_tStatus IoCardInit( io_tCtx ctx,
return IO__INITFAIL;
}
tcgetattr( local->fd, &tty_attributes);
#if defined OS_LINUX
tty_attributes.c_cflag &= ~CBAUD; //maska bort all hastighet
#endif
switch( op->BaudRate) {
case 300:
tty_attributes.c_cflag |= B300;
break;
case 1200:
tty_attributes.c_cflag |= B1200;
break;
case 2400:
tty_attributes.c_cflag |= B2400;
break;
case 4800:
tty_attributes.c_cflag |= B4800;
break;
case 9600:
tty_attributes.c_cflag |= B9600;
break;
case 19200:
tty_attributes.c_cflag |= B19200;
break;
case 38400:
tty_attributes.c_cflag |= B38400;
break;
case 57600:
tty_attributes.c_cflag |= B57600;
break;
case 115200:
tty_attributes.c_cflag |= B115200;
break;
default:
tty_attributes.c_cflag |= B9600;
break;
}
sts = tcsetattr( local->fd, TCSANOW, &tty_attributes);
if ( sts < 0) {
errh_Error( "IO Init Card '%s', unable to set baud rate on device %s", cp->Name, op->Device);
op->Status = pwr_eArduino_StatusEnum_DeviceSetupError;
return IO__INITFAIL;
}
tcflush( local->fd, TCIOFLUSH);
// Send config message
......@@ -328,6 +414,9 @@ static pwr_tStatus IoCardClose( io_tCtx ctx,
close( local->fd);
free( cp->Local);
fclose(fp); //Test
return IO__SUCCESS;
}
......@@ -349,13 +438,22 @@ static pwr_tStatus IoCardRead( io_tCtx ctx,
int i, j;
unsigned char m;
if ( !local->DiPendingPoll)
poll_di( &msg, local);
#if 0
msg.size = 3;
msg.id = local->IdCnt++;
msg.type = ard_eMsgType_DiRead;
logg( "Poll Di");
sts = write( local->fd, &msg, msg.size);
#endif
sts = receive( local->fd, msg.id, &rmsg, local->DiSize);
local->DiPendingPoll = 0;
sts = receive( local->fd, local->DiPollId, &rmsg, local->DiSize);
op->Status = sts;
if ( EVEN(sts)) {
op->ErrorCount++;
......@@ -374,6 +472,17 @@ static pwr_tStatus IoCardRead( io_tCtx ctx,
}
if ( local->AiSize) {
int skip_ai = 0;
if ( op->AiScanInterval > 1) {
skip_ai = local->AiIntervalCnt;
local->AiIntervalCnt++;
if ( local->AiIntervalCnt >= op->AiScanInterval)
local->AiIntervalCnt = 0;
}
if ( !skip_ai) {
ard_sMsg msg, rmsg;
pwr_tInt32 ivalue;
pwr_tFloat32 actvalue;
......@@ -419,6 +528,7 @@ static pwr_tStatus IoCardRead( io_tCtx ctx,
}
}
}
}
if ( op->ErrorCount >= op->ErrorSoftLimit &&
error_count < op->ErrorSoftLimit) {
......@@ -464,6 +574,7 @@ static pwr_tStatus IoCardWrite( io_tCtx ctx,
}
logg( "Write Do");
sts = write( local->fd, &msg, msg.size);
}
......@@ -477,6 +588,13 @@ static pwr_tStatus IoCardWrite( io_tCtx ctx,
return IO__ERRDEVICE;
}
if ( local->DiSize &&
op->Options & pwr_mArduino_OptionsMask_OptimizedDiPoll) {
ard_sMsg msg;
poll_di( &msg, local);
}
return IO__SUCCESS;
}
......
Volume OtherIO $ClassVolume 0.0.250.10
Body SysBody 01-JAN-1970 01:00:00.00
Attr NextOix = "_X159"
Attr NextOix = "_X170"
Attr NextCix = "_X17"
Attr NextTix[0] = "_X6"
Attr NextTix[0] = "_X8"
EndBody
Object Type $TypeHier 1 15-NOV-2007 14:35:37.90
Object MotionControl_StatusEnum $TypeDef 1 15-NOV-2007 14:36:24.17
......@@ -300,7 +300,7 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndObject
EndObject
Object Arduino_StatusEnum $TypeDef 5 13-DEC-2010 21:41:03.92
Body SysBody 13-DEC-2010 21:41:17.54
Body SysBody 03-JAN-2011 21:07:03.74
Attr TypeRef = "pwrs:Type-$Enum"
Attr Elements = 1
EndBody
......@@ -367,6 +367,95 @@ Volume OtherIO $ClassVolume 0.0.250.10
Attr Value = 18
EndBody
EndObject
Object DeviceSetupError $Value 168 03-JAN-2011 21:33:12.93
Body SysBody 03-JAN-2011 21:33:18.63
Attr Text = "DeviceSetupError"
Attr PgmName = "DeviceSetupError"
Attr Value = 20
EndBody
EndObject
EndObject
Object Arduino_BaudRateEnum $TypeDef 6 03-JAN-2011 21:16:43.20
Body SysBody 03-JAN-2011 21:07:09.34
Attr TypeRef = "pwrs:Type-$Enum"
Attr Elements = 1
EndBody
Object BaudRate_2400 $Value 161 03-JAN-2011 21:17:13.04
Body SysBody 03-JAN-2011 21:17:14.30
Attr Text = "2400"
Attr PgmName = "BaudRate_2400"
Attr Value = 2400
EndBody
EndObject
Object BaudRate_4800 $Value 162 03-JAN-2011 21:17:21.73
Body SysBody 03-JAN-2011 21:17:22.82
Attr Text = "4800"
Attr PgmName = "BaudRate_4800"
Attr Value = 4800
EndBody
EndObject
Object BaudRate_9600 $Value 163 03-JAN-2011 21:17:29.93
Body SysBody 03-JAN-2011 21:17:31.07
Attr Text = "9600"
Attr PgmName = "BaudRate_9600"
Attr Value = 9600
EndBody
EndObject
Object BaudRate_14400 $Value 160 09-JAN-2011 20:23:56.52
Body SysBody 09-JAN-2011 20:24:03.52
Attr Text = "14400"
Attr PgmName = "BaudRate_14400"
Attr Value = 14400
EndBody
EndObject
Object BaudRate_19200 $Value 164 03-JAN-2011 21:17:37.54
Body SysBody 03-JAN-2011 21:17:38.64
Attr Text = "19200"
Attr PgmName = "BaudRate_19200"
Attr Value = 19200
EndBody
EndObject
Object BaudRate_28800 $Value 170 09-JAN-2011 20:24:24.78
Body SysBody 09-JAN-2011 20:24:31.34
Attr Text = "28800"
Attr PgmName = "BaudRate_28800"
Attr Value = 28800
EndBody
EndObject
Object BaudRate_38400 $Value 165 03-JAN-2011 21:17:44.96
Body SysBody 03-JAN-2011 21:17:46.11
Attr Text = "38400"
Attr PgmName = "BaudRate_38400"
Attr Value = 38400
EndBody
EndObject
Object BaudRate_57600 $Value 166 03-JAN-2011 21:17:53.04
Body SysBody 03-JAN-2011 21:17:54.16
Attr Text = "57600"
Attr PgmName = "BaudRate_57600"
Attr Value = 57600
EndBody
EndObject
Object BaudRate_115200 $Value 167 03-JAN-2011 21:18:13.86
Body SysBody 03-JAN-2011 21:18:14.96
Attr Text = "115200"
Attr PgmName = "BaudRate_115200"
Attr Value = 115200
EndBody
EndObject
EndObject
Object Arduino_OptionsMask $TypeDef 7 06-JAN-2011 15:51:06.94
Body SysBody 06-JAN-2011 15:48:58.95
Attr TypeRef = "pwrs:Type-$Mask"
Attr Elements = 1
EndBody
Object OptimizedDiPoll $Bit 169 06-JAN-2011 15:49:48.79
Body SysBody 06-JAN-2011 15:49:55.05
Attr Text = "OptimizedDiPoll"
Attr PgmName = "OptimizedDiPoll"
Attr Value = 1
EndBody
EndObject
EndObject
EndObject
Object Class $ClassHier 2 15-NOV-2007 14:35:40.72
......@@ -2292,6 +2381,7 @@ Volume OtherIO $ClassVolume 0.0.250.10
! @Group IO
! @Summary Rack object for Arduino USB devices.
! Rack object for Arduino USB devices.
! This object is configured below the Node object.
!
! @b See also
! @classlink Arduino_Uno otherio_arduino_uno.html
......@@ -2388,7 +2478,7 @@ Volume OtherIO $ClassVolume 0.0.250.10
Object RtBody $ObjBodyDef 1 13-DEC-2010 21:36:40.01
Body SysBody 13-DEC-2010 21:39:07.38
Attr StructName = "Arduino_Uno"
Attr NextAix = "_X21"
Attr NextAix = "_X24"
EndBody
!/**
! Optional description.
......@@ -2502,6 +2592,41 @@ Volume OtherIO $ClassVolume 0.0.250.10
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
!/**
! Baud rate of the USB connection.
! For fast scantimes the baud rate has to be increased.
!*/
Object BaudRate $Attribute 21 03-JAN-2011 21:18:39.87
Body SysBody 03-JAN-2011 21:19:00.44
Attr PgmName = "BaudRate"
Attr TypeRef = "OtherIO:Type-Arduino_BaudRateEnum"
EndBody
EndObject
!/**
! Options.
! If OptimizedDiPoll is set the poll message for Di values are sent
! at the end of the execution of the prevoius scan, instead of at
! the start of the execution.
!*/
Object Options $Attribute 22 06-JAN-2011 15:50:22.78
Body SysBody 06-JAN-2011 15:51:32.48
Attr PgmName = "Options"
Attr TypeRef = "OtherIO:Type-Arduino_OptionsMask"
EndBody
EndObject
!/**
! Specifies, in relation to the scantime of the thread, how often
! the Ai channels of the board are handled. If AiScanInterval is 1 or 0,
! the Ai are handled every scan. If AiScanInterval is for example 10, they
! are handled every 10'th scan, i.e. the scantime for the module
! will be AiScanInterval times the scantime of the thread.
!*/
Object AiScanInterval $Attribute 23 09-JAN-2011 10:37:58.02
Body SysBody 09-JAN-2011 10:38:12.99
Attr PgmName = "AiScanInterval"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
EndObject
Object IoMethods $RtMethod 144 13-DEC-2010 21:36:40.01
Object IoCardInit $Method 145 13-DEC-2010 21:36:40.01
......@@ -2531,10 +2656,11 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody
EndObject
Object Template Arduino_Uno 2151907328 01-JAN-1970 01:00:00.00
Body RtBody 13-DEC-2010 21:54:49.89
Body RtBody 03-JAN-2011 21:19:26.25
Attr ErrorSoftLimit = 25
Attr ErrorHardLimit = 50
Attr WatchdogTime = 5.000000e+00
Attr BaudRate = 9600
EndBody
EndObject
EndObject
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment