Göra om C till PHP - Relativt enkelt skulle jag tro, men behöver hjälp
Hej
Jag har en kodsnutt i C (tror jag) som jag skulle behöva göra om (förstå) till php.
Det är följande:
240 int createNexaString(const char * pHouseStr, const char * pChannelStr,
241 const char * pOn_offStr, char * pTxStr, int waveman)
242 {
243 * pTxStr = '\0'; /* Make sure tx string is empty */
244 int houseCode;
245 int channelCode;
246 int on_offCode;
247 int txCode = 0;
248 const int unknownCode = 0x6;
249 int bit;
250 int bitmask = 0x0001;
251
252 houseCode = (int)((* pHouseStr) - 65); /* House 'A'..'P' */
253 channelCode = atoi(pChannelStr) - 1; /* Channel 1..16 */
254 on_offCode = atoi(pOn_offStr); /* ON/OFF 0..1 */
255
256 #ifdef RFCMD_DEBUG
257 printf("House: %d, channel: %d, on_off: %d\n", houseCode, channelCode, on_offCode);
258 #endif
259
260 /* check converted parameters for validity */
261 if((houseCode < 0) || (houseCode > 15) || // House 'A'..'P'
262 (channelCode < 0) || (channelCode > 15) ||
263 (on_offCode < 0) || (on_offCode > 1))
264 {
265
266 } else {
267 /* b0..b11 txCode where 'X' will be represented by 1 for simplicity.
268 b0 will be sent first */
269 txCode = houseCode;
270 txCode |= (channelCode << 4);
271 if (waveman && on_offCode == 0) {
272 } else {
273 txCode |= (unknownCode << 8);
274 txCode |= (on_offCode << 11);
275 }
276
277 /* convert to send cmd string */
278 strcat(pTxStr,"S");
279 for(bit=0;bit<12;bit++)
280 {
281 if((bitmask & txCode) == 0) {
282 /* bit timing might need further refinement */
283 strcat(pTxStr," ` `"); /* 320 us high, 960 us low, 320 us high, 960 us low */
284 /* strcat(pTxStr,"$k$k"); *//* 360 us high, 1070 us low, 360 us high, 1070 us low */
285 } else { /* add 'X' (floating bit) */
286 strcat(pTxStr," `` "); /* 320 us high, 960 us low, 960 us high, 320 us low */
287 /*strcat(pTxStr,"$kk$"); *//* 360 us high, 1070 us low, 1070 us high, 360 us low */
288 }
289 bitmask = bitmask<<1;
290 }
291 /* add stop/sync bit and command termination char '+'*/
292 strcat(pTxStr," }+");
293 /* strcat(pTxStr,"$}+"); */
294 }
295
296 #ifdef RFCMD_DEBUG
297 printf("txCode: %04X\n", txCode);
298 #endif
299
300 return strlen(pTxStr);
301 }
Det enda jag inte förstår är typ:
281 if((bitmask & txCode) == 0) {
Jag är van att man måste ha 2 st && i en if-sats, men här det bara en, så vad betyder det?
bitmask är ju satt till "0x0001" och txCode defineras först på rad 269
Jag skulle gissa att pHouseStr är en bokstav i spannet A-P, men det konverteras tydligen till siffror nånstans, kan det vara här:
252 houseCode = (int)((* pHouseStr) - 65); /* House 'A'..'P' */
Vad betyder |= och << som tex finns här:
270 txCode |= (channelCode << 4);
Någon som kan reda ut dessa saker åt mig?
MVH Niclas
Har bytt namn från: nulleman ~ Blogg: http://skorpion.se
MacBook Pro: 15.4' ~ 1.83GHz ~ 1512MB RAM ~ 80GB HDD
Medlem i signaturen blodtörstiga Appleanvändare