Fixed SICS-392 RF Generator command truncation.

Code cleanup

r2906 | ffr | 2010-05-05 15:33:00 +1000 (Wed, 05 May 2010) | 3 lines
This commit is contained in:
Ferdi Franceschini
2010-05-05 15:33:00 +10:00
committed by Douglas Clowes
parent 0ce2db7bac
commit 7a456163b5
4 changed files with 25 additions and 70 deletions

View File

@@ -20,6 +20,7 @@
#include <ctype.h> #include <ctype.h>
#include <ascon.h> #include <ascon.h>
#include <ascon.i> #include <ascon.i>
#include <string.h>
#include <dynstring.h> #include <dynstring.h>
#define ERRLEN 128 #define ERRLEN 128
@@ -29,6 +30,9 @@
#define MAXCURRSPEC 71 #define MAXCURRSPEC 71
#define MINFREQ 170 #define MINFREQ 170
#define MAXFREQ 500 #define MAXFREQ 500
#define LCMDLEN 4
#define SCMDLEN 10
#define REPLYLEN 13
struct RFAmpData { struct RFAmpData {
int transactInProg; int transactInProg;
@@ -42,6 +46,8 @@ void RFAmpKill(void *private)
free(data); free(data);
} }
enum transactionState {txNormalRead, txPreCheck};
/** /**
* @brief Translates ASCII command string into a properly formatted command for the RF amplifier * @brief Translates ASCII command string into a properly formatted command for the RF amplifier
*/ */
@@ -72,7 +78,7 @@ int RFAmpWriteStart (Ascon *a)
switch (ctype) { switch (ctype) {
case 'L': case 'L':
sprintf(data->rfCmd,"%c%c%c%c", 2, address, ctype, 3); sprintf(data->rfCmd,"%c%c%c%c", 2, address, ctype, 3);
DynStringReplace(a->wrBuffer, data->rfCmd,0); DynStringReplaceWithLen(a->wrBuffer, data->rfCmd,0, LCMDLEN);
a->state = AsconWriting; a->state = AsconWriting;
a->noResponse = 0; a->noResponse = 0;
a->wrPos = 0; a->wrPos = 0;
@@ -123,8 +129,8 @@ int RFAmpWriteStart (Ascon *a)
return 1; return 1;
} }
sprintf(statusCmd,"%c%c%c%c", 2, address, 'L', 3); sprintf(statusCmd,"%c%c%c%c", 2, address, 'L', 3);
DynStringReplace(a->wrBuffer, statusCmd, 0); DynStringReplaceWithLen(a->wrBuffer, statusCmd, 0, LCMDLEN);
data->transactInProg = 1; data->transactInProg = txPreCheck;
data->targetCurrent = curr; data->targetCurrent = curr;
a->state = AsconWriting; a->state = AsconWriting;
a->noResponse = 0; a->noResponse = 0;
@@ -143,7 +149,7 @@ int RFAmpWriteStart (Ascon *a)
int RFAmpReading (Ascon *a) int RFAmpReading (Ascon *a)
{ {
int rdChRet, scanRet, GetReplyFailed=0, errNum=0; int rdChRet, GetReplyFailed=0, errNum=0;
char chr, address, ctype, curr[3], freq[4], voltage[3], replyStr[128]; char chr, address, ctype, curr[3], freq[4], voltage[3], replyStr[128];
unsigned char switches, opstate; unsigned char switches, opstate;
unsigned char K3, K2, K1, outOn, CC, CV, heat; unsigned char K3, K2, K1, outOn, CC, CV, heat;
@@ -174,16 +180,17 @@ int RFAmpReading (Ascon *a)
GetReplyFailed = 1; GetReplyFailed = 1;
break; break;
} }
scanRet = sscanf(GetCharArray(a->rdBuffer), "%c%c%2s%3s%2s%c%c", &address, &ctype, curr, freq, voltage, &switches, &opstate); address = GetCharArray(a->rdBuffer)[0];
if (scanRet < 7) { ctype = GetCharArray(a->rdBuffer)[1];
strcpy(errMsg, "ANSRFAMP: Failed to parse reply"); strncpy(curr, &GetCharArray(a->rdBuffer)[2], 2);
GetReplyFailed = 1; strncpy(freq, &GetCharArray(a->rdBuffer)[4], 3);
break; strncpy(voltage, &GetCharArray(a->rdBuffer)[7], 2);
} switches = GetCharArray(a->rdBuffer)[9];
if (data->transactInProg) { opstate = GetCharArray(a->rdBuffer)[10];
data->transactInProg = 0; if (data->transactInProg == txPreCheck) {
data->transactInProg = txNormalRead;
if (abs(data->targetCurrent - atoi(curr)) <= 5) { if (abs(data->targetCurrent - atoi(curr)) <= 5) {
DynStringReplace(a->wrBuffer, data->rfCmd,0); DynStringReplaceWithLen(a->wrBuffer, data->rfCmd,0, SCMDLEN);
a->state = AsconWriting; a->state = AsconWriting;
a->noResponse = 1; a->noResponse = 1;
a->wrPos = 0; a->wrPos = 0;
@@ -192,7 +199,7 @@ int RFAmpReading (Ascon *a)
GetReplyFailed = 1; GetReplyFailed = 1;
break; break;
} }
} else { } else if (data->transactInProg == txNormalRead) {
K3 = (switches & 0x08) >> 3; K3 = (switches & 0x08) >> 3;
K2 = (switches & 0x04) >> 2; K2 = (switches & 0x04) >> 2;
K1 = (switches & 0x02) >> 1; K1 = (switches & 0x02) >> 1;
@@ -201,7 +208,7 @@ int RFAmpReading (Ascon *a)
CV = (opstate & 0x02) >> 1; CV = (opstate & 0x02) >> 1;
heat = opstate & 0x01; heat = opstate & 0x01;
snprintf(replyStr, 128, "address=%c|type=%c|curr=%s|freq=%s|voltage=%s|K3=%d|K2=%d|K1=%d|O=%d|CC=%d|CV=%d|H=%d", address, ctype, curr, freq, voltage, K3, K2, K1, outOn, CC, CV, heat); snprintf(replyStr, 128, "address=%c|type=%c|curr=%s|freq=%s|voltage=%s|K3=%d|K2=%d|K1=%d|O=%d|CC=%d|CV=%d|H=%d", address, ctype, curr, freq, voltage, K3, K2, K1, outOn, CC, CV, heat);
if (0 == DynStringReplace(a->rdBuffer, replyStr, 0)) { if (0 == DynStringReplaceWithLen(a->rdBuffer, replyStr, 0, 128)) {
strcpy(errMsg, "ANSRFAMP: DynStringReplace failed:"); strcpy(errMsg, "ANSRFAMP: DynStringReplace failed:");
errNum = ENOMEM; errNum = ENOMEM;
GetReplyFailed = 1; GetReplyFailed = 1;
@@ -265,7 +272,7 @@ int RFAmpInit(Ascon *a, SConnection *con, int argc, char *argv[])
struct RFAmpData *data; struct RFAmpData *data;
a->readState=0; a->readState=0;
a->private = data = (struct RFAmpData *) malloc(sizeof(struct RFAmpData)); a->private = data = (struct RFAmpData *) malloc(sizeof(struct RFAmpData));
data->transactInProg = 0; data->transactInProg = txNormalRead;
data->targetCurrent = 0; data->targetCurrent = 0;
data->rfCmd[0] = '\0'; data->rfCmd[0] = '\0';
a->killPrivate = RFAmpKill; a->killPrivate = RFAmpKill;

View File

@@ -1344,15 +1344,13 @@ foreach expt $::nexus::exports {
# objects name. It is useful for making links to datasets. # objects name. It is useful for making links to datasets.
# dim0 = vertical axis on detector # dim0 = vertical axis on detector
# dim1 = horizontal axis on detector # dim1 = horizontal axis on detector
# $Name: not supported by cvs2svn $
# $Revision: 1.51.2.10 $
set tmpstr [string map {"$" ""} {$Name: not supported by cvs2svn $}] set tmpstr [string map {"$" ""} {$Name: not supported by cvs2svn $}]
set nx_content_release_tag [lindex $tmpstr [expr [llength $tmpstr] - 1]] set nx_content_release_tag [lindex $tmpstr [expr [llength $tmpstr] - 1]]
::utility::mkVar sics_release Text manager sics_release true entry true true ::utility::mkVar sics_release Text manager sics_release true entry true true
sics_release $nx_content_release_tag sics_release $nx_content_release_tag
sics_release lock sics_release lock
set tmpstr [string map {"$" ""} {$Revision: 1.51.2.10 $}] set tmpstr [string map {"$" ""} {$Revision: 1.51.2.11 $}]
set nx_content_revision_num [lindex $tmpstr [expr [llength $tmpstr] - 1]] set nx_content_revision_num [lindex $tmpstr [expr [llength $tmpstr] - 1]]
#namespace eval data { #namespace eval data {

View File

@@ -57,7 +57,7 @@ source gumxml.tcl
#add_ls3xx tc1 ca5-[instname] 4001 "\r\n" 0.5 340 #add_ls3xx tc1 ca5-[instname] 4001 "\r\n" 0.5 340
#add_ls3xx tc2 ca5-[instname] 4001 "\r" 0.5 340 #add_ls3xx tc2 ca5-[instname] 4001 "\r" 0.5 340
::environment::temperature::add_west400 137.157.201.14 #::environment::temperature::add_west400 137.157.201.14
###::robot::add_robby ###::robot::add_robby
server_init server_init
########################################### ###########################################

View File

@@ -1,50 +0,0 @@
proc TrimReply { str } {
set reply [string trim $str " :"]
return $reply
}
proc pop { which } {
set down { -1 1 -1 1 1 }
set speed 50000
set motions { 0 0 0 0 0 }
set indices { 0 1 2 3 4 }
set motors { BS1 BS2 BS3 BS4 BS5 }
if {($which < 1)||($which > [llength $indices])} {
clientput "Pop must be between 1 and [llength $indices]"
return
}
incr which -1
foreach i $indices {
lset motions $i [expr $speed * [lindex $down $i]]
}
lset motions $which [expr -1 * [lindex $motions $which]]
foreach i $indices { [lindex $motors $i] send SH` }
foreach i $indices { [lindex $motors $i] send JG`=[lindex $motions $i] }
foreach i $indices { [lindex $motors $i] send BG` }
set x 0
set started [clock seconds]
while { $x == 0 } {
set x 1
set current [clock seconds]
foreach i $indices {
if { [TrimReply [[lindex $motors $i] send MG _BG`]] > 0 } {
set x 0
if { ([expr $current - 60] > $started) } {
clientput [lindex $motors $i] send ST`
[lindex $motors $i] send ST`
}
}
}
}
foreach i $indices {
set forward [TrimReply [[lindex $motors $i] send MG _LF`]]
set reverse [TrimReply [[lindex $motors $i] send MG _LR`]]
if { [expr $forward * $reverse] > 0 } {
clientput "[lindex $motors $i] is between limits"
}
}
clientput "POP [expr $which + 1] took [expr $current -$started] seconds"
}
publish pop user