Reformat optoscan.c to Linux Style

Use astyle to format to Linux Style.
Hamlib-3.1
Nate Bargmann 2016-02-14 18:08:54 -06:00
rodzic dbf25c5139
commit 785e926db9
1 zmienionych plików z 463 dodań i 434 usunięć

Wyświetl plik

@ -76,15 +76,18 @@ int optoscan_open(RIG *rig)
priv = (struct icom_priv_data *)rs->priv;
pltstate = malloc(sizeof(pltstate_t));
if (!pltstate) {
return -RIG_ENOMEM;
}
memset(pltstate, 0, sizeof(pltstate_t));
priv->pltstate = pltstate;
/* select REMOTE control */
retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_REMOTE,
NULL, 0, ackbuf, &ack_len);
if (retval != RIG_OK) {
free(pltstate);
return retval;
@ -117,6 +120,7 @@ int optoscan_close(RIG *rig)
/* select LOCAL control */
retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_LOCAL,
NULL, 0, ackbuf, &ack_len);
if (retval != RIG_OK)
return retval;
@ -144,6 +148,7 @@ const char* optoscan_get_info(RIG *rig)
/* select LOCAL control */
retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDID,
NULL, 0, ackbuf, &ack_len);
if (retval != RIG_OK)
return NULL;
@ -173,6 +178,7 @@ int optoscan_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDCTCSS, NULL, 0,
tonebuf, &tone_len);
if (retval != RIG_OK)
return retval;
@ -202,6 +208,7 @@ int optoscan_get_dcs_code(RIG * rig, vfo_t vfo, tone_t *code)
retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDDCS, NULL, 0,
tonebuf, &tone_len);
if (retval != RIG_OK)
return retval;
@ -225,12 +232,14 @@ int optoscan_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length)
int len, retval, digitpos;
unsigned char xlate[] = {'0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', 'A', 'B', 'C', 'D',
'*','#'};
'*', '#'
};
digitpos = 0;
do {
retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDDTMF,
NULL, 0, dtmfbuf, &len);
if (retval != RIG_OK)
return retval;
@ -241,8 +250,7 @@ int optoscan_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length)
digit = dtmfbuf[2];
if( digit < 0x16 )
{
if (digit < 0x16) {
digits[digitpos] = xlate[digit];
digitpos++;
}
@ -251,12 +259,9 @@ int optoscan_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length)
*length = digitpos;
digits[digitpos] = 0;
if(*length > 0)
{
if (*length > 0) {
rig_debug(RIG_DEBUG_ERR, "optoscan_recv_dtmf: %d digits - %s\n", *length, digits);
}
else
{
} else {
rig_debug(RIG_DEBUG_ERR, "optoscan_recv_dtmf: no digits to read.\n");
}
@ -279,33 +284,37 @@ int optoscan_set_ext_parm(RIG *rig, token_t token, value_t val)
case TOK_TAPECNTL:
if (val.i == 0) {
subcode = S_OPTO_TAPE_OFF;
}
else {
} else {
subcode = S_OPTO_TAPE_ON;
}
break;
case TOK_5KHZWIN:
if (val.i == 0) {
subcode = S_OPTO_5KSCOFF;
}
else {
} else {
subcode = S_OPTO_5KSCON;
}
break;
case TOK_SPEAKER:
if (val.i == 0) {
subcode = S_OPTO_SPKROFF;
}
else {
} else {
subcode = S_OPTO_SPKRON;
}
break;
default:
return -RIG_EINVAL;
}
retval = icom_transaction(rig, C_CTL_MISC, subcode, epbuf, 0,
ackbuf, &ack_len);
if (retval != RIG_OK)
return retval;
@ -336,27 +345,35 @@ int optoscan_get_ext_parm(RIG *rig, token_t token, value_t *val)
case TOK_TAPECNTL:
val->i = status_block.tape_enabled;
break;
case TOK_5KHZWIN:
val->i = status_block.fivekhz_enabled;
break;
case TOK_SPEAKER:
val->i = status_block.speaker_enabled;
break;
case TOK_AUDIO:
val->i = status_block.audio_present;
break;
case TOK_DTMFPEND:
val->i = status_block.DTMF_pending;
break;
case TOK_DTMFOVRR:
val->i = status_block.DTMF_overrun;
break;
case TOK_CTCSSACT:
val->i = status_block.CTCSS_active;
break;
case TOK_DCSACT:
val->i = status_block.DCS_active;
break;
default:
return -RIG_ENIMPL;
}
@ -389,13 +406,15 @@ int optoscan_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
switch (level) {
case RIG_LEVEL_AF:
lvl_cn = C_CTL_MISC;
if (icom_val == 0) {
lvl_sc = S_OPTO_SPKROFF;
}
else {
} else {
lvl_sc = S_OPTO_SPKRON;
}
break;
default:
rig_debug(RIG_DEBUG_ERR, "Unsupported set_level %d", level);
return -RIG_EINVAL;
@ -403,6 +422,7 @@ int optoscan_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
retval = icom_transaction(rig, lvl_cn, lvl_sc, lvlbuf, 0,
ackbuf, &ack_len);
if (retval != RIG_OK)
return retval;
@ -429,13 +449,13 @@ int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
int cmdhead;
int retval;
if( level != RIG_LEVEL_AF )
{
if (level != RIG_LEVEL_AF) {
switch (level) {
case RIG_LEVEL_RAWSTR:
lvl_cn = C_RD_SQSM;
lvl_sc = S_SML;
break;
default:
rig_debug(RIG_DEBUG_ERR, "Unsupported get_level %d", level);
return -RIG_EINVAL;
@ -443,6 +463,7 @@ int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
retval = icom_transaction(rig, lvl_cn, lvl_sc, NULL, 0,
lvlbuf, &lvl_len);
if (retval != RIG_OK)
return retval;
@ -463,15 +484,14 @@ int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
* (from_bcd is little endian)
*/
icom_val = from_bcd_be(lvlbuf + cmdhead, lvl_len * 2);
}
else /* level == RIG_LEVEL_AF */
{
} else { /* level == RIG_LEVEL_AF */
retval = optoscan_get_status_block(rig, &status_block);
if (retval != RIG_OK)
return retval;
icom_val = 0;
if (status_block.speaker_enabled == 1)
icom_val = 255;
}
@ -480,6 +500,7 @@ int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
case RIG_LEVEL_RAWSTR:
val->i = icom_val;
break;
default:
if (RIG_LEVEL_IS_FLOAT(level))
val->f = (float)icom_val / 255;
@ -534,8 +555,7 @@ int optoscan_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch)
if (state == NULL)
return -RIG_EINTERNAL;
if(state->freq==0) /* pltstate_t is not initialized - perform setup */
{
if (state->freq == 0) { /* pltstate_t is not initialized - perform setup */
/* time for CIV command to be sent. this is subtracted from */
/* rcvr settle time */
state->usleep_time = (1000000 / (rig->state.rigport.parm.serial.rate))
@ -543,6 +563,7 @@ int optoscan_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch)
rc = cb(rig, vfo, &(state->next_freq), &(state->next_mode),
&(state->next_width), rig->callbacks.pltune_arg);
if (rc == RIG_SCAN_STOP)
return RIG_OK; /* callback halted loop */
@ -551,8 +572,8 @@ int optoscan_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch)
}
rc = !RIG_SCAN_STOP;
while(rc!=RIG_SCAN_STOP)
{
while (rc != RIG_SCAN_STOP) {
optoscan_RTS_toggle(rig); /*Step 3*/
state->freq = state->next_freq;
@ -562,16 +583,16 @@ int optoscan_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch)
rc = cb(rig, vfo, &(state->next_freq), &(state->next_mode),
&(state->next_width), rig->callbacks.pltune_arg);
if(rc!=RIG_SCAN_STOP)
{
if (rc != RIG_SCAN_STOP) {
optoscan_send_freq(rig, state); /*Step 4*/
}
optoscan_wait_timer(rig, state); /*Step 5*/
ser_get_car(&rs->rigport, &pin_state);
if( pin_state ) /*Step 6*/
{
if (pin_state) { /*Step 6*/
return RIG_OK; /* we've broken squelch - return(). caller can */
/* get current freq & mode out of state str */
}
@ -599,14 +620,15 @@ static int optoscan_get_status_block(RIG *rig, struct optostat *status_block)
if (retval != RIG_OK)
return retval;
switch( rig->caps->rig_model )
{
switch (rig->caps->rig_model) {
case RIG_MODEL_OS456:
expected_len = 4;
break;
case RIG_MODEL_OS535:
expected_len = 5;
break;
default:
rig_debug(RIG_DEBUG_ERR, "optoscan_get_status_block: unknown rig model");
return -RIG_ERJCTED;
@ -620,15 +642,23 @@ static int optoscan_get_status_block(RIG *rig, struct optostat *status_block)
}
if (ackbuf[2] & 1) status_block->remote_control = 1;
if (ackbuf[2] & 2) status_block->DTMF_pending = 1;
if (ackbuf[2] & 4) status_block->DTMF_overrun = 1;
if (ackbuf[2] & 16) status_block->squelch_open = 1;
if (ackbuf[2] & 32) status_block->CTCSS_active = 1;
if (ackbuf[2] & 64) status_block->DCS_active = 1;
if (ackbuf[3] & 1) status_block->tape_enabled = 1;
if (ackbuf[3] & 2) status_block->speaker_enabled = 1;
if (ackbuf[3] & 4) status_block->fivekhz_enabled = 1;
if (ackbuf[3] & 16) status_block->audio_present = 1;
rig_debug(RIG_DEBUG_VERBOSE, "remote_control = %d\n", status_block->remote_control);
@ -708,8 +738,7 @@ static int optoscan_wait_timer(RIG *rig, pltstate_t *state)
usec_diff = abs((state->timer_current.tv_usec) -
(state->timer_start.tv_usec));
if( usec_diff < settle_usec )
{
if (usec_diff < settle_usec) {
usleep(settle_usec - usec_diff); /* sleep balance of settle_time */
}